|
@@ -12,16 +12,28 @@
|
|
|
#include <sys/time.h>
|
|
#include <sys/time.h>
|
|
|
#include <opendroneid.h>
|
|
#include <opendroneid.h>
|
|
|
|
|
|
|
|
|
|
+#include "options.h"
|
|
|
#include "mavlink.h"
|
|
#include "mavlink.h"
|
|
|
#include "DroneCAN.h"
|
|
#include "DroneCAN.h"
|
|
|
#include "WiFi_TX.h"
|
|
#include "WiFi_TX.h"
|
|
|
#include "BLE_TX.h"
|
|
#include "BLE_TX.h"
|
|
|
|
|
|
|
|
|
|
+#if AP_DRONECAN_ENABLED
|
|
|
static DroneCAN dronecan;
|
|
static DroneCAN dronecan;
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+#if AP_MAVLINK_ENABLED
|
|
|
static MAVLinkSerial mavlink1{Serial1, MAVLINK_COMM_0};
|
|
static MAVLinkSerial mavlink1{Serial1, MAVLINK_COMM_0};
|
|
|
static MAVLinkSerial mavlink2{Serial, MAVLINK_COMM_1};
|
|
static MAVLinkSerial mavlink2{Serial, MAVLINK_COMM_1};
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+#if AP_WIFI_NAN_ENABLED
|
|
|
static WiFi_NAN wifi;
|
|
static WiFi_NAN wifi;
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+#if AP_BLE_ENABLED
|
|
|
static BLE_TX ble;
|
|
static BLE_TX ble;
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
#define OUTPUT_RATE_HZ 5
|
|
#define OUTPUT_RATE_HZ 5
|
|
|
|
|
|
|
@@ -50,11 +62,22 @@ void setup()
|
|
|
// Serial1 for MAVLink
|
|
// Serial1 for MAVLink
|
|
|
Serial1.begin(MAVLINK_BAUDRATE, SERIAL_8N1, RX_PIN, TX_PIN);
|
|
Serial1.begin(MAVLINK_BAUDRATE, SERIAL_8N1, RX_PIN, TX_PIN);
|
|
|
|
|
|
|
|
|
|
+ // set all fields to invalid/initial values
|
|
|
|
|
+ odid_initUasData(&UAS_data);
|
|
|
|
|
+
|
|
|
|
|
+#if AP_MAVLINK_ENABLED
|
|
|
mavlink1.init();
|
|
mavlink1.init();
|
|
|
mavlink2.init();
|
|
mavlink2.init();
|
|
|
|
|
+#endif
|
|
|
|
|
+#if AP_DRONECAN_ENABLED
|
|
|
dronecan.init();
|
|
dronecan.init();
|
|
|
|
|
+#endif
|
|
|
|
|
+#if AP_WIFI_NAN_ENABLED
|
|
|
wifi.init();
|
|
wifi.init();
|
|
|
|
|
+#endif
|
|
|
|
|
+#if AP_BLE_ENABLED
|
|
|
ble.init();
|
|
ble.init();
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#define MIN(x,y) ((x)<(y)?(x):(y))
|
|
#define MIN(x,y) ((x)<(y)?(x):(y))
|
|
@@ -124,38 +147,42 @@ static void set_data_mavlink(MAVLinkSerial &m)
|
|
|
UAS_data.SelfIDValid = 1;
|
|
UAS_data.SelfIDValid = 1;
|
|
|
|
|
|
|
|
// System
|
|
// System
|
|
|
- UAS_data.System.OperatorLocationType = (ODID_operator_location_type_t)system.operator_location_type;
|
|
|
|
|
- UAS_data.System.ClassificationType = (ODID_classification_type_t)system.classification_type;
|
|
|
|
|
- UAS_data.System.OperatorLatitude = system.operator_latitude * 1.0e-7;
|
|
|
|
|
- UAS_data.System.OperatorLongitude = system.operator_longitude * 1.0e-7;
|
|
|
|
|
- UAS_data.System.AreaCount = system.area_count;
|
|
|
|
|
- UAS_data.System.AreaRadius = system.area_radius;
|
|
|
|
|
- UAS_data.System.AreaCeiling = system.area_ceiling;
|
|
|
|
|
- UAS_data.System.AreaFloor = system.area_floor;
|
|
|
|
|
- UAS_data.System.CategoryEU = (ODID_category_EU_t)system.category_eu;
|
|
|
|
|
- UAS_data.System.ClassEU = (ODID_class_EU_t)system.class_eu;
|
|
|
|
|
- UAS_data.System.OperatorAltitudeGeo = system.operator_altitude_geo;
|
|
|
|
|
- UAS_data.System.Timestamp = system.timestamp;
|
|
|
|
|
- UAS_data.SystemValid = 1;
|
|
|
|
|
|
|
+ if (system.timestamp != 0) {
|
|
|
|
|
+ UAS_data.System.OperatorLocationType = (ODID_operator_location_type_t)system.operator_location_type;
|
|
|
|
|
+ UAS_data.System.ClassificationType = (ODID_classification_type_t)system.classification_type;
|
|
|
|
|
+ UAS_data.System.OperatorLatitude = system.operator_latitude * 1.0e-7;
|
|
|
|
|
+ UAS_data.System.OperatorLongitude = system.operator_longitude * 1.0e-7;
|
|
|
|
|
+ UAS_data.System.AreaCount = system.area_count;
|
|
|
|
|
+ UAS_data.System.AreaRadius = system.area_radius;
|
|
|
|
|
+ UAS_data.System.AreaCeiling = system.area_ceiling;
|
|
|
|
|
+ UAS_data.System.AreaFloor = system.area_floor;
|
|
|
|
|
+ UAS_data.System.CategoryEU = (ODID_category_EU_t)system.category_eu;
|
|
|
|
|
+ UAS_data.System.ClassEU = (ODID_class_EU_t)system.class_eu;
|
|
|
|
|
+ UAS_data.System.OperatorAltitudeGeo = system.operator_altitude_geo;
|
|
|
|
|
+ UAS_data.System.Timestamp = system.timestamp;
|
|
|
|
|
+ UAS_data.SystemValid = 1;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Location
|
|
// Location
|
|
|
- UAS_data.Location.Status = (ODID_status_t)location.status;
|
|
|
|
|
- UAS_data.Location.Direction = location.direction*0.01;
|
|
|
|
|
- UAS_data.Location.SpeedHorizontal = location.speed_horizontal*0.01;
|
|
|
|
|
- UAS_data.Location.SpeedVertical = location.speed_vertical*0.01;
|
|
|
|
|
- UAS_data.Location.Latitude = location.latitude*1.0e-7;
|
|
|
|
|
- UAS_data.Location.Longitude = location.longitude*1.0e-7;
|
|
|
|
|
- UAS_data.Location.AltitudeBaro = location.altitude_barometric;
|
|
|
|
|
- UAS_data.Location.AltitudeGeo = location.altitude_geodetic;
|
|
|
|
|
- UAS_data.Location.HeightType = (ODID_Height_reference_t)location.height_reference;
|
|
|
|
|
- UAS_data.Location.Height = location.height;
|
|
|
|
|
- UAS_data.Location.HorizAccuracy = (ODID_Horizontal_accuracy_t)location.horizontal_accuracy;
|
|
|
|
|
- UAS_data.Location.VertAccuracy = (ODID_Vertical_accuracy_t)location.vertical_accuracy;
|
|
|
|
|
- UAS_data.Location.BaroAccuracy = (ODID_Vertical_accuracy_t)location.barometer_accuracy;
|
|
|
|
|
- UAS_data.Location.SpeedAccuracy = (ODID_Speed_accuracy_t)location.speed_accuracy;
|
|
|
|
|
- UAS_data.Location.TSAccuracy = (ODID_Timestamp_accuracy_t)location.timestamp_accuracy;
|
|
|
|
|
- UAS_data.Location.TimeStamp = location.timestamp;
|
|
|
|
|
- UAS_data.LocationValid = 1;
|
|
|
|
|
|
|
+ if (location.timestamp != 0) {
|
|
|
|
|
+ UAS_data.Location.Status = (ODID_status_t)location.status;
|
|
|
|
|
+ UAS_data.Location.Direction = location.direction*0.01;
|
|
|
|
|
+ UAS_data.Location.SpeedHorizontal = location.speed_horizontal*0.01;
|
|
|
|
|
+ UAS_data.Location.SpeedVertical = location.speed_vertical*0.01;
|
|
|
|
|
+ UAS_data.Location.Latitude = location.latitude*1.0e-7;
|
|
|
|
|
+ UAS_data.Location.Longitude = location.longitude*1.0e-7;
|
|
|
|
|
+ UAS_data.Location.AltitudeBaro = location.altitude_barometric;
|
|
|
|
|
+ UAS_data.Location.AltitudeGeo = location.altitude_geodetic;
|
|
|
|
|
+ UAS_data.Location.HeightType = (ODID_Height_reference_t)location.height_reference;
|
|
|
|
|
+ UAS_data.Location.Height = location.height;
|
|
|
|
|
+ UAS_data.Location.HorizAccuracy = (ODID_Horizontal_accuracy_t)location.horizontal_accuracy;
|
|
|
|
|
+ UAS_data.Location.VertAccuracy = (ODID_Vertical_accuracy_t)location.vertical_accuracy;
|
|
|
|
|
+ UAS_data.Location.BaroAccuracy = (ODID_Vertical_accuracy_t)location.barometer_accuracy;
|
|
|
|
|
+ UAS_data.Location.SpeedAccuracy = (ODID_Speed_accuracy_t)location.speed_accuracy;
|
|
|
|
|
+ UAS_data.Location.TSAccuracy = (ODID_Timestamp_accuracy_t)location.timestamp_accuracy;
|
|
|
|
|
+ UAS_data.Location.TimeStamp = location.timestamp;
|
|
|
|
|
+ UAS_data.LocationValid = 1;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
m.set_parse_fail(check_parse());
|
|
m.set_parse_fail(check_parse());
|
|
|
}
|
|
}
|
|
@@ -163,6 +190,7 @@ static void set_data_mavlink(MAVLinkSerial &m)
|
|
|
#undef ODID_COPY_STR
|
|
#undef ODID_COPY_STR
|
|
|
#define ODID_COPY_STR(to, from) memcpy(to, from.data, MIN(from.len, sizeof(to)))
|
|
#define ODID_COPY_STR(to, from) memcpy(to, from.data, MIN(from.len, sizeof(to)))
|
|
|
|
|
|
|
|
|
|
+#if AP_DRONECAN_ENABLED
|
|
|
static void set_data_dronecan(void)
|
|
static void set_data_dronecan(void)
|
|
|
{
|
|
{
|
|
|
const auto &operator_id = dronecan.get_operator_id();
|
|
const auto &operator_id = dronecan.get_operator_id();
|
|
@@ -188,43 +216,46 @@ static void set_data_dronecan(void)
|
|
|
UAS_data.SelfIDValid = 1;
|
|
UAS_data.SelfIDValid = 1;
|
|
|
|
|
|
|
|
// System
|
|
// System
|
|
|
- UAS_data.System.OperatorLocationType = (ODID_operator_location_type_t)system.operator_location_type;
|
|
|
|
|
- UAS_data.System.ClassificationType = (ODID_classification_type_t)system.classification_type;
|
|
|
|
|
- UAS_data.System.OperatorLatitude = system.operator_latitude * 1.0e-7;
|
|
|
|
|
- UAS_data.System.OperatorLongitude = system.operator_longitude * 1.0e-7;
|
|
|
|
|
- UAS_data.System.AreaCount = system.area_count;
|
|
|
|
|
- UAS_data.System.AreaRadius = system.area_radius;
|
|
|
|
|
- UAS_data.System.AreaCeiling = system.area_ceiling;
|
|
|
|
|
- UAS_data.System.AreaFloor = system.area_floor;
|
|
|
|
|
- UAS_data.System.CategoryEU = (ODID_category_EU_t)system.category_eu;
|
|
|
|
|
- UAS_data.System.ClassEU = (ODID_class_EU_t)system.class_eu;
|
|
|
|
|
- UAS_data.System.OperatorAltitudeGeo = system.operator_altitude_geo;
|
|
|
|
|
- UAS_data.System.Timestamp = system.timestamp;
|
|
|
|
|
- UAS_data.SystemValid = 1;
|
|
|
|
|
|
|
+ if (system.timestamp != 0) {
|
|
|
|
|
+ UAS_data.System.OperatorLocationType = (ODID_operator_location_type_t)system.operator_location_type;
|
|
|
|
|
+ UAS_data.System.ClassificationType = (ODID_classification_type_t)system.classification_type;
|
|
|
|
|
+ UAS_data.System.OperatorLatitude = system.operator_latitude * 1.0e-7;
|
|
|
|
|
+ UAS_data.System.OperatorLongitude = system.operator_longitude * 1.0e-7;
|
|
|
|
|
+ UAS_data.System.AreaCount = system.area_count;
|
|
|
|
|
+ UAS_data.System.AreaRadius = system.area_radius;
|
|
|
|
|
+ UAS_data.System.AreaCeiling = system.area_ceiling;
|
|
|
|
|
+ UAS_data.System.AreaFloor = system.area_floor;
|
|
|
|
|
+ UAS_data.System.CategoryEU = (ODID_category_EU_t)system.category_eu;
|
|
|
|
|
+ UAS_data.System.ClassEU = (ODID_class_EU_t)system.class_eu;
|
|
|
|
|
+ UAS_data.System.OperatorAltitudeGeo = system.operator_altitude_geo;
|
|
|
|
|
+ UAS_data.System.Timestamp = system.timestamp;
|
|
|
|
|
+ UAS_data.SystemValid = 1;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Location
|
|
// Location
|
|
|
- UAS_data.Location.Status = (ODID_status_t)location.status;
|
|
|
|
|
- UAS_data.Location.Direction = location.direction*0.01;
|
|
|
|
|
- UAS_data.Location.SpeedHorizontal = location.speed_horizontal*0.01;
|
|
|
|
|
- UAS_data.Location.SpeedVertical = location.speed_vertical*0.01;
|
|
|
|
|
- UAS_data.Location.Latitude = location.latitude*1.0e-7;
|
|
|
|
|
- UAS_data.Location.Longitude = location.longitude*1.0e-7;
|
|
|
|
|
- UAS_data.Location.AltitudeBaro = location.altitude_barometric;
|
|
|
|
|
- UAS_data.Location.AltitudeGeo = location.altitude_geodetic;
|
|
|
|
|
- UAS_data.Location.HeightType = (ODID_Height_reference_t)location.height_reference;
|
|
|
|
|
- UAS_data.Location.Height = location.height;
|
|
|
|
|
- UAS_data.Location.HorizAccuracy = (ODID_Horizontal_accuracy_t)location.horizontal_accuracy;
|
|
|
|
|
- UAS_data.Location.VertAccuracy = (ODID_Vertical_accuracy_t)location.vertical_accuracy;
|
|
|
|
|
- UAS_data.Location.BaroAccuracy = (ODID_Vertical_accuracy_t)location.barometer_accuracy;
|
|
|
|
|
- UAS_data.Location.SpeedAccuracy = (ODID_Speed_accuracy_t)location.speed_accuracy;
|
|
|
|
|
- UAS_data.Location.TSAccuracy = (ODID_Timestamp_accuracy_t)location.timestamp_accuracy;
|
|
|
|
|
- UAS_data.Location.TimeStamp = location.timestamp;
|
|
|
|
|
- UAS_data.LocationValid = 1;
|
|
|
|
|
|
|
+ if (location.timestamp != 0) {
|
|
|
|
|
+ UAS_data.Location.Status = (ODID_status_t)location.status;
|
|
|
|
|
+ UAS_data.Location.Direction = location.direction*0.01;
|
|
|
|
|
+ UAS_data.Location.SpeedHorizontal = location.speed_horizontal*0.01;
|
|
|
|
|
+ UAS_data.Location.SpeedVertical = location.speed_vertical*0.01;
|
|
|
|
|
+ UAS_data.Location.Latitude = location.latitude*1.0e-7;
|
|
|
|
|
+ UAS_data.Location.Longitude = location.longitude*1.0e-7;
|
|
|
|
|
+ UAS_data.Location.AltitudeBaro = location.altitude_barometric;
|
|
|
|
|
+ UAS_data.Location.AltitudeGeo = location.altitude_geodetic;
|
|
|
|
|
+ UAS_data.Location.HeightType = (ODID_Height_reference_t)location.height_reference;
|
|
|
|
|
+ UAS_data.Location.Height = location.height;
|
|
|
|
|
+ UAS_data.Location.HorizAccuracy = (ODID_Horizontal_accuracy_t)location.horizontal_accuracy;
|
|
|
|
|
+ UAS_data.Location.VertAccuracy = (ODID_Vertical_accuracy_t)location.vertical_accuracy;
|
|
|
|
|
+ UAS_data.Location.BaroAccuracy = (ODID_Vertical_accuracy_t)location.barometer_accuracy;
|
|
|
|
|
+ UAS_data.Location.SpeedAccuracy = (ODID_Speed_accuracy_t)location.speed_accuracy;
|
|
|
|
|
+ UAS_data.Location.TSAccuracy = (ODID_Timestamp_accuracy_t)location.timestamp_accuracy;
|
|
|
|
|
+ UAS_data.Location.TimeStamp = location.timestamp;
|
|
|
|
|
+ UAS_data.LocationValid = 1;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
dronecan.set_parse_fail(check_parse());
|
|
dronecan.set_parse_fail(check_parse());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-static uint8_t beacon_payload[256];
|
|
|
|
|
|
|
+#endif // AP_DRONECAN_ENABLED
|
|
|
|
|
|
|
|
void loop()
|
|
void loop()
|
|
|
{
|
|
{
|
|
@@ -232,7 +263,9 @@ void loop()
|
|
|
|
|
|
|
|
mavlink1.update();
|
|
mavlink1.update();
|
|
|
mavlink2.update();
|
|
mavlink2.update();
|
|
|
|
|
+#if AP_DRONECAN_ENABLED
|
|
|
dronecan.update();
|
|
dronecan.update();
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
const uint32_t now_ms = millis();
|
|
const uint32_t now_ms = millis();
|
|
|
|
|
|
|
@@ -241,27 +274,46 @@ void loop()
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const bool mavlink1_ok = mavlink1.location_valid() && mavlink1.system_valid();
|
|
|
|
|
- const bool mavlink2_ok = mavlink2.location_valid() && mavlink2.system_valid();
|
|
|
|
|
- const bool dronecan_ok = dronecan.location_valid() && dronecan.system_valid();
|
|
|
|
|
- if (!mavlink1_ok && !mavlink2_ok && !dronecan_ok) {
|
|
|
|
|
|
|
+ bool data_ok = false;
|
|
|
|
|
+
|
|
|
|
|
+#if AP_MAVLINK_ENABLED
|
|
|
|
|
+ const bool mavlink1_ok = mavlink1.location_valid();
|
|
|
|
|
+ const bool mavlink2_ok = mavlink2.location_valid();
|
|
|
|
|
+ data_ok |= mavlink1_ok || mavlink2_ok;
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+#if AP_DRONECAN_ENABLED
|
|
|
|
|
+ const bool dronecan_ok = dronecan.location_valid();
|
|
|
|
|
+ data_ok |= dronecan_ok;
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+#if !AP_BROADCAST_ON_POWER_UP
|
|
|
|
|
+ if (!data_ok) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
|
+#if AP_MAVLINK_ENABLED
|
|
|
if (mavlink1_ok) {
|
|
if (mavlink1_ok) {
|
|
|
set_data_mavlink(mavlink1);
|
|
set_data_mavlink(mavlink1);
|
|
|
}
|
|
}
|
|
|
if (mavlink2_ok) {
|
|
if (mavlink2_ok) {
|
|
|
set_data_mavlink(mavlink2);
|
|
set_data_mavlink(mavlink2);
|
|
|
}
|
|
}
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+#if AP_DRONECAN_ENABLED
|
|
|
if (dronecan_ok) {
|
|
if (dronecan_ok) {
|
|
|
set_data_dronecan();
|
|
set_data_dronecan();
|
|
|
}
|
|
}
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
last_update = now_ms;
|
|
last_update = now_ms;
|
|
|
|
|
|
|
|
- const auto length = odid_message_build_pack(&UAS_data,beacon_payload,255);
|
|
|
|
|
-
|
|
|
|
|
|
|
+#if AP_WIFI_NAN_ENABLED
|
|
|
wifi.transmit(UAS_data);
|
|
wifi.transmit(UAS_data);
|
|
|
|
|
+#endif
|
|
|
|
|
+#if AP_BLE_ENABLED
|
|
|
ble.transmit(UAS_data);
|
|
ble.transmit(UAS_data);
|
|
|
|
|
+#endif
|
|
|
}
|
|
}
|