Skip to content

Commit

Permalink
very basic support for Remote ID radio protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Sep 27, 2023
1 parent c8718bd commit 5650e73
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 0 deletions.
43 changes: 43 additions & 0 deletions software/firmware/source/SoftRF/src/driver/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ char UDPpacketBuffer[256]; // buffer to hold incoming and outgoing packets
static unsigned long WiFi_No_Clients_Time_ms = 0;
#endif

#if defined(ENABLE_REMOTE_ID)
#include "../protocol/radio/RemoteID.h"
static unsigned long RID_Time_Marker = 0;
#endif /* ENABLE_REMOTE_ID */

size_t Raw_Receive_UDP(uint8_t *buf)
{
Expand Down Expand Up @@ -187,6 +191,34 @@ void WiFi_setup()
#if defined(POWER_SAVING_WIFI_TIMEOUT)
WiFi_No_Clients_Time_ms = millis();
#endif

#if defined(ENABLE_REMOTE_ID)
memset(&utm_parameters,0,sizeof(utm_parameters));

#if 0
strcpy(utm_parameters.UAS_operator,"GBR-OP-1234ABCDEFGH");
#elif defined(ARDUINO_ARCH_ESP32)
strcpy(utm_parameters.UAS_operator,"GBR-OP-ESP32");
#elif defined(ARDUINO_ARCH_ESP8266)
strcpy(utm_parameters.UAS_operator,"GBR-OP-ESP8266");
#elif defined(ARDUINO_ARCH_RP2040)
strcpy(utm_parameters.UAS_operator,"GBR-OP-PICOW");
#else
strcpy(utm_parameters.UAS_operator,"GBR-OP-UNKNOWN");
#endif

utm_parameters.region = 1;
utm_parameters.EU_category = 1;
utm_parameters.EU_class = 5;

squitter.init(&utm_parameters);

memset(&utm_data,0,sizeof(utm_data));

utm_data.satellites = 8;

RID_Time_Marker = millis();
#endif /* ENABLE_REMOTE_ID */
}

void WiFi_loop()
Expand Down Expand Up @@ -214,6 +246,17 @@ void WiFi_loop()
}
}
#endif

#if defined(ENABLE_REMOTE_ID)
if (WiFi.getMode() == WIFI_AP && isValidFix()) {
if ((millis() - RID_Time_Marker) > (RID_TX_INTERVAL_MIN + RID_TX_INTERVAL_MAX)/2) {
rid_encode((void *) &utm_data, &ThisAircraft);
squitter.transmit(&utm_data);

RID_Time_Marker = millis();
}
}
#endif /* ENABLE_REMOTE_ID */
}

void WiFi_fini()
Expand Down
89 changes: 89 additions & 0 deletions software/firmware/source/SoftRF/src/protocol/radio/RemoteID.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Protocol_RID.cpp
*
* Encoder for Remote ID radio protocol
* Copyright (C) 2023 Linar Yusupov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdint.h>

#include "../../../SoftRF.h"
#include "../../driver/RF.h"

#if defined(ENABLE_REMOTE_ID)
#include <id_open.h>

ID_OpenDrone squitter;
UTM_Utilities utm_utils;

struct UTM_parameters utm_parameters;
struct UTM_data utm_data;

double RID_Base_Lat = 0.0;
double RID_Base_Lon = 0.0;
float RID_Base_Alt = 0.0;

size_t rid_encode(void *pkt, ufo_t *this_aircraft) {

uint32_t id = this_aircraft->addr & 0x00FFFFFF;

#if !defined(SOFTRF_ADDRESS)
uint8_t addr_type = ADDR_TYPE_ANONYMOUS;
#else
uint8_t addr_type = id == SOFTRF_ADDRESS ? ADDR_TYPE_ICAO : ADDR_TYPE_ANONYMOUS;
#endif

uint8_t acft_type = this_aircraft->aircraft_type > AIRCRAFT_TYPE_STATIC ?
AIRCRAFT_TYPE_UNKNOWN : this_aircraft->aircraft_type;

utm_data.latitude_d = (double) this_aircraft->latitude;
utm_data.longitude_d = (double) this_aircraft->longitude;
utm_data.alt_msl_m = (float) this_aircraft->altitude;
utm_data.alt_agl_m = (float) 0.0 /* TBD */;
utm_data.speed_kn = (int) this_aircraft->speed;
utm_data.heading = (int) this_aircraft->course;

utm_data.base_valid = (RID_Base_Lat == 0.0 && RID_Base_Lon == 0.0) ? 0 : 1;
if (utm_data.base_valid) {
utm_data.base_latitude = RID_Base_Lat;
utm_data.base_longitude = RID_Base_Lon;
utm_data.base_alt_m = RID_Base_Alt;
} else if (this_aircraft->latitude != 0.0 && this_aircraft->longitude != 0.0) {
RID_Base_Lat = utm_data.latitude_d;
RID_Base_Lon = utm_data.longitude_d;
RID_Base_Alt = utm_data.alt_msl_m;
}

#if 0
char text[64], lat_s[16], long_s[16];

dtostrf(utm_data.latitude_d, 10,7,lat_s);
dtostrf(utm_data.longitude_d,10,7,long_s);

sprintf(text,"%s,%s\r\n", lat_s,long_s);
Serial.print(text);
#endif

return 0;
}

bool rid_decode(void *pkt, ufo_t *this_aircraft, ufo_t *fop) {

/* N/A */

return false;
}
#endif /* ENABLE_REMOTE_ID */
49 changes: 49 additions & 0 deletions software/firmware/source/SoftRF/src/protocol/radio/RemoteID.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Protocol_RID.h
*
* Encoder for Remote ID radio protocol
* Copyright (C) 2023 Linar Yusupov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef PROTOCOL_RID_H
#define PROTOCOL_RID_H

#define RID_TX_INTERVAL_MIN 900 /* in ms */
#define RID_TX_INTERVAL_MAX 1100

typedef struct {

/* Dummy type definition. */

} rid_packet_t;

bool rid_decode(void *, ufo_t *, ufo_t *);
size_t rid_encode(void *, ufo_t *);

#if defined(ENABLE_REMOTE_ID)
#include <id_open.h>

extern ID_OpenDrone squitter;
extern UTM_Utilities utm_utils;
extern struct UTM_parameters utm_parameters;
extern struct UTM_data utm_data;

extern double RID_Base_Lat;
extern double RID_Base_Lon;
extern float RID_Base_Alt;

#endif /* ENABLE_REMOTE_ID */
#endif /* PROTOCOL_RID_H */

1 comment on commit 5650e73

@lyusupov
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.