diff --git a/software/firmware/source/SoftRF/src/driver/WiFi.cpp b/software/firmware/source/SoftRF/src/driver/WiFi.cpp index 92f0ef63b..2036f2286 100644 --- a/software/firmware/source/SoftRF/src/driver/WiFi.cpp +++ b/software/firmware/source/SoftRF/src/driver/WiFi.cpp @@ -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) { @@ -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() @@ -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() diff --git a/software/firmware/source/SoftRF/src/protocol/radio/RemoteID.cpp b/software/firmware/source/SoftRF/src/protocol/radio/RemoteID.cpp new file mode 100644 index 000000000..82a4cda01 --- /dev/null +++ b/software/firmware/source/SoftRF/src/protocol/radio/RemoteID.cpp @@ -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 . + */ + +#include + +#include "../../../SoftRF.h" +#include "../../driver/RF.h" + +#if defined(ENABLE_REMOTE_ID) +#include + +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 */ diff --git a/software/firmware/source/SoftRF/src/protocol/radio/RemoteID.h b/software/firmware/source/SoftRF/src/protocol/radio/RemoteID.h new file mode 100644 index 000000000..6d8dff35f --- /dev/null +++ b/software/firmware/source/SoftRF/src/protocol/radio/RemoteID.h @@ -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 . + */ + +#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 + +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 */