Skip to content

Commit

Permalink
multiple choice of traffic alarm triggers + cleanup + stealth/no_track
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Jun 25, 2018
1 parent dad6e19 commit 5064e67
Show file tree
Hide file tree
Showing 24 changed files with 426 additions and 239 deletions.
2 changes: 0 additions & 2 deletions software/firmware/source/SoftRF/BaroHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include "SoCHelper.h"
#include "BaroHelper.h"

extern ufo_t ThisAircraft;

barochip_ops_t *baro_chip = NULL;

Adafruit_BMP085 bmp180;
Expand Down
6 changes: 2 additions & 4 deletions software/firmware/source/SoftRF/D1090Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "GNSSHelper.h"
#include "GDL90Helper.h"
#include "EEPROMHelper.h"
#include "TrafficHelper.h"
#include "SoftRF.h"

#define ADDR_TO_HEX_STR(s, c) (s += (c < 0x10 ? "0" : "") + String(c, HEX))
Expand All @@ -35,9 +36,6 @@
} \
})

extern ufo_t fo, Container[MAX_TRACKING_OBJECTS];
extern ufo_t ThisAircraft;

void D1090_Export()
{
frame_data_t df17;
Expand All @@ -49,7 +47,7 @@ void D1090_Export()
for (int i=0; i < MAX_TRACKING_OBJECTS; i++) {
if (Container[i].addr && (this_moment - Container[i].timestamp) <= EXPORT_EXPIRATION_TIME) {

distance = gnss.distanceBetween(ThisAircraft.latitude, ThisAircraft.longitude, Container[i].latitude, Container[i].longitude);
distance = Container[i].distance;

if (distance < ALARM_ZONE_NONE) {

Expand Down
13 changes: 13 additions & 0 deletions software/firmware/source/SoftRF/Deprecated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,16 @@ void rx_test_loop()
ClearExpired();
}
#endif

#if 0
#define take_degrees(x) ( (int) x )
#define take_minutes(x) ( fabs(x - (float) take_degrees(x)) * 60.00)

char * dtostrf_workaround(double number, signed char width, unsigned char prec, char *s) {
char * rval = dtostrf(number, width, prec, s);
if (number < 10.0) {
s[0] = '0';
}
return rval;
}
#endif
28 changes: 19 additions & 9 deletions software/firmware/source/SoftRF/EEPROMHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "LEDHelper.h"
#include "SoundHelper.h"
#include "BluetoothHelper.h"
#include "TrafficHelper.h"

// start reading from the first byte (address 0) of the EEPROM

Expand All @@ -46,10 +47,16 @@ void EEPROM_setup()
Serial.println(F("Warning! EEPROM magic mismatch! Loading defaults..."));

EEPROM_defaults();
}
Serial.print(F("EEPROM version: "));
Serial.println(eeprom_block.field.version);
} else {
Serial.print(F("EEPROM version: "));
Serial.println(eeprom_block.field.version);

if (eeprom_block.field.version != SOFTRF_EEPROM_VERSION) {
Serial.println(F("Warning! EEPROM version mismatch! Loading defaults..."));

EEPROM_defaults();
}
}
settings = &eeprom_block.field.settings;
}

Expand All @@ -65,13 +72,16 @@ void EEPROM_defaults()
eeprom_block.field.settings.volume = BUZZER_VOLUME_FULL;
eeprom_block.field.settings.pointer = DIRECTION_NORTH_UP;
eeprom_block.field.settings.bluetooth = BLUETOOTH_OFF;
eeprom_block.field.settings.alarm = TRAFFIC_ALARM_DISTANCE;

eeprom_block.field.settings.nmea_g = false;
eeprom_block.field.settings.nmea_p = false;
eeprom_block.field.settings.nmea_l = false;
eeprom_block.field.settings.nmea_u = false;
eeprom_block.field.settings.gdl90 = false;
eeprom_block.field.settings.d1090 = false;
eeprom_block.field.settings.nmea_g = false;
eeprom_block.field.settings.nmea_p = false;
eeprom_block.field.settings.nmea_l = false;
eeprom_block.field.settings.nmea_u = false;
eeprom_block.field.settings.gdl90 = false;
eeprom_block.field.settings.d1090 = false;
eeprom_block.field.settings.stealth = false;
eeprom_block.field.settings.no_track = false;
}

void EEPROM_store()
Expand Down
8 changes: 6 additions & 2 deletions software/firmware/source/SoftRF/EEPROMHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "SoftRF.h"

#define SOFTRF_EEPROM_MAGIC 0xBABADEDA
#define SOFTRF_EEPROM_VERSION 0x0000005A
#define SOFTRF_EEPROM_VERSION 0x0000005B

typedef struct Settings {
uint8_t mode;
Expand All @@ -45,7 +45,11 @@ typedef struct Settings {
bool resvd1:1;
bool resvd2:1;

uint8_t bluetooth; /* ESP32 built-in Bluetooth */
uint8_t bluetooth:3; /* ESP32 built-in Bluetooth */
uint8_t alarm:3;
bool stealth:1;
bool no_track:1;

uint8_t resvd3;
uint8_t resvd4;
uint8_t resvd5;
Expand Down
7 changes: 2 additions & 5 deletions software/firmware/source/SoftRF/GDL90Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "SoftRF.h"
#include "SoCHelper.h"
#include "WiFiHelper.h"
#include "TrafficHelper.h"

#define isValidFix() (gnss.location.isValid() && (gnss.location.age() <= 3000))
#define ADDR_TO_HEX_STR(s, c) (s += (c < 0x10 ? "0" : "") + String(c, HEX))
Expand All @@ -37,10 +38,6 @@ static GDL90_Msg_HeartBeat_t HeartBeat;
static GGDL90_Msg_Traffic_t Traffic;
static GDL90_Msg_OwnershipGeometricAltitude_t GeometricAltitude;

extern ufo_t fo, Container[MAX_TRACKING_OBJECTS];
extern ufo_t ThisAircraft;
extern char UDPpacketBuffer[256];

const char *GDL90_CallSign_Prefix[] = {
[RF_PROTOCOL_LEGACY] = "FL",
[RF_PROTOCOL_OGNTP] = "OG",
Expand Down Expand Up @@ -350,7 +347,7 @@ void GDL90_Export()
for (int i=0; i < MAX_TRACKING_OBJECTS; i++) {
if (Container[i].addr && (this_moment - Container[i].timestamp) <= EXPORT_EXPIRATION_TIME) {

distance = gnss.distanceBetween(ThisAircraft.latitude, ThisAircraft.longitude, Container[i].latitude, Container[i].longitude);
distance = Container[i].distance;

if (distance < ALARM_ZONE_NONE) {
size = makeTrafficReport(buf, &Container[i]);
Expand Down
3 changes: 0 additions & 3 deletions software/firmware/source/SoftRF/GNSSHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
#define GNSS_DEBUG_PRINTLN Serial.println
#endif

extern char UDPpacketBuffer[256];
extern ufo_t ThisAircraft;

unsigned long GNSSTimeSyncMarker = 0;

#if 0
Expand Down
10 changes: 6 additions & 4 deletions software/firmware/source/SoftRF/LEDHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "LEDHelper.h"
#include "BatteryHelper.h"
#include "SoCHelper.h"
#include "TrafficHelper.h"

static uint32_t prev_tx_packets_counter = 0;
static uint32_t prev_rx_packets_counter = 0;
Expand Down Expand Up @@ -148,13 +149,14 @@ void LED_DisplayTraffic() {
for (int i=0; i < MAX_TRACKING_OBJECTS; i++) {

if (Container[i].addr && (now() - Container[i].timestamp) <= LED_EXPIRATION_TIME) {
bearing = (int) gnss.courseTo(ThisAircraft.latitude,
ThisAircraft.longitude, Container[i].latitude, Container[i].longitude);
distance = (int) gnss.distanceBetween(ThisAircraft.latitude,
ThisAircraft.longitude, Container[i].latitude, Container[i].longitude);

bearing = (int) Container[i].bearing;
distance = (int) Container[i].distance;

if (settings->pointer == DIRECTION_TRACK_UP) {
bearing = (360 + bearing - (int)ThisAircraft.course) % 360;
}

led_num = ((bearing + LED_ROTATE_ANGLE + SECTOR_PER_LED/2) % 360) / SECTOR_PER_LED;
// Serial.print(bearing);
// Serial.print(" , ");
Expand Down
2 changes: 0 additions & 2 deletions software/firmware/source/SoftRF/LEDHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ void LED_DisplayTraffic();
void LED_Clear();

extern Adafruit_NeoPixel strip;
extern ufo_t Container[MAX_TRACKING_OBJECTS];
extern uint32_t tx_packets_counter, rx_packets_counter;
extern ufo_t ThisAircraft;

#endif /* LEDHELPER_H */
109 changes: 0 additions & 109 deletions software/firmware/source/SoftRF/Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "RFHelper.h"
#include "SoCHelper.h"
#include "WiFiHelper.h"
#include "WebHelper.h"

#include "SoftRF.h"

#if LOGGER_IS_ENABLED
#include "LogHelper.h"
#endif /* LOGGER_IS_ENABLED */

char UDPpacketBuffer[256]; //buffer to hold incoming and outgoing packets

void WiFi_forward_to_argus(void);
void WiFi_forward_to_cloud(void);
void *WiFi_relay_from_android(void);

ufo_t fo, Container[MAX_TRACKING_OBJECTS], EmptyFO;
extern ufo_t ThisAircraft;

#if DEBUG
String TxDataTemplate = "0282dd204901f981798a85b69764bdf99ed77fd3c2300000";
Expand Down Expand Up @@ -136,50 +118,6 @@ const float txrx_test_positions[90][2] PROGMEM = {
};
#endif

void ParseData()
{

#if DEBUG
Hex2Bin(TxDataTemplate, RxBuffer);
#endif

fo.raw = Bin2Hex(RxBuffer);

if (settings->nmea_p) {
StdOut.print(F("$PSRFI,"));
StdOut.print(now()); StdOut.print(F(","));
StdOut.print(RF_last_rssi); StdOut.print(F(","));
StdOut.println(fo.raw);
}

if (protocol_decode && (*protocol_decode)((void *) RxBuffer, &ThisAircraft, &fo)) {

fo.rssi = RF_last_rssi;

for (int i=0; i < MAX_TRACKING_OBJECTS; i++) {
int max_dist_ndx = 0;

if (Container[i].addr == fo.addr) {
Container[i] = fo;
break;
} else {
if (now() - Container[i].timestamp > ENTRY_EXPIRATION_TIME) {
Container[i] = fo;
break;
}
#if 0
if (Container[i].distance > Container[max_dist_ndx].distance) {
max_dist_ndx = i;
}
if ((i == (MAX_TRACKING_OBJECTS-1)) && (Container[max_dist_ndx].distance > fo.distance) ) {
Container[max_dist_ndx] = fo;
}
#endif
}
}
}
}

void Misc_info()
{
Serial.println("\r\n");
Expand All @@ -203,50 +141,3 @@ void Misc_info()
Serial.println(F("Flash Chip configuration ok.\n"));
}
}

void ClearExpired()
{
for (int i=0; i < MAX_TRACKING_OBJECTS; i++) {
if (Container[i].addr && (now() - Container[i].timestamp) > LED_EXPIRATION_TIME) {
Container[i] = EmptyFO;
}
}
}

#define take_degrees(x) ( (int) x )
#define take_minutes(x) ( fabs(x - (float) take_degrees(x)) * 60.00)

char * dtostrf_workaround(double number, signed char width, unsigned char prec, char *s) {
char * rval = dtostrf(number, width, prec, s);
if (number < 10.0) {
s[0] = '0';
}
return rval;
}

size_t Raw_Receive_UDP(uint8_t *buf)
{
int noBytes = Uni_Udp.parsePacket();
if ( noBytes ) {

if (noBytes > MAX_PKT_SIZE) {
noBytes = MAX_PKT_SIZE;
}

// We've received a packet, read the data from it
Uni_Udp.read(buf,noBytes); // read the packet into the buffer

return (size_t) noBytes;
} else {
return 0;
}
}

void Raw_Transmit_UDP()
{
size_t num = fo.raw.length();
// ASSERT(sizeof(UDPpacketBuffer) > 2 * PKT_SIZE + 1)
fo.raw.toCharArray(UDPpacketBuffer, sizeof(UDPpacketBuffer));
UDPpacketBuffer[num] = '\n';
SoC->WiFi_transmit_UDP(RELAY_DST_PORT, (byte *)UDPpacketBuffer, num + 1);
}
1 change: 1 addition & 0 deletions software/firmware/source/SoftRF/MAVLinkHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "GDL90Helper.h"
#include "SoCHelper.h"
#include "WiFiHelper.h"
#include "TrafficHelper.h"

static unsigned long MAVLinkTimeSyncMarker = 0;
static bool MAVLinkAPisArmed = false;
Expand Down
2 changes: 0 additions & 2 deletions software/firmware/source/SoftRF/MAVLinkHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,4 @@ void MAVLinkTimeSync();
void MAVLinkShareTraffic();
void MAVLinkSetWiFiPower();

extern ufo_t Container[ /*MAX_TRACKING_OBJECTS*/];

#endif /* MAVLINKHELPER_H */
Loading

0 comments on commit 5064e67

Please sign in to comment.