Skip to content

Commit

Permalink
devFlyBeeper : fix Fanet-id range
Browse files Browse the repository at this point in the history
  • Loading branch information
brunotl committed Aug 3, 2024
1 parent 70b39f3 commit f6a2723
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions Common/Source/Devices/devFlyBeeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ payload_t serialize_tracking(const NMEA_INFO& Basic, const DERIVED_INFO& Calcula
return buffer;
}

payload_t serialize_gound_tracking(const NMEA_INFO& Basic, const DERIVED_INFO& Calculated) {
payload_t buffer;
buffer.reserve(6);
auto out_it = std::back_inserter(buffer);

/* position */
Frame::coord2payload_absolut(Basic.Latitude, Basic.Longitude, out_it);


/* state & Online Tracking */
constexpr uint8_t state = 0;
constexpr uint8_t online_tracking = 0x01;

out_it = (state&0x0F)<<4 | online_tracking;

return buffer;
}

payload_t serialize_name() {
std::string name = to_utf8(PilotName_Config);
return { name.begin(), name.end() };
Expand All @@ -94,22 +112,16 @@ MacAddr generate_id() {

DeviceSettings settings(_T("FlyBeeper"));
try {
return {
settings.get<uint8_t>("fanet-manufacturer"),
settings.get<uint16_t>("fanet-id")
};
return MacAddr{ settings.get<uint32_t>("fanet-id") };
}
catch(std::exception& e) { }

std::random_device rd; // a seed source for the random number engine
std::mt19937 gen(rd()); // mersenne_twister_engine seeded with rd()
std::uniform_int_distribution<uint16_t> distrib(1, std::numeric_limits<uint16_t>::max());
std::uniform_int_distribution<uint16_t> distrib(1, 0xFFFE);

MacAddr addr = { 0xFC, distrib(gen) };

settings.set<int>("fanet-manufacturer", addr.manufacturer);
settings.set<int>("fanet-id", addr.id);

settings.set<int>("fanet-id", addr.get());
return addr;
}

Expand All @@ -133,7 +145,12 @@ BOOL SendData(DeviceDescriptor_t* d, const NMEA_INFO& Basic, const DERIVED_INFO&
static PeriodClock timeState;
if (timeState.CheckUpdate(5000)) {
// Every 5 second : Send current state
return SendData(d, FRM_TYPE_TRACKING, serialize_tracking(Basic, Calculated));
if (Calculated.Flying) {
return SendData(d, FRM_TYPE_TRACKING, serialize_tracking(Basic, Calculated));
}
else {
return SendData(d, FRM_TYPE_GROUNDTRACKING, serialize_gound_tracking(Basic, Calculated));
}
}

static PeriodClock timeName;
Expand All @@ -153,7 +170,6 @@ bool EnableGattCharacteristic(DeviceDescriptor_t& d, uuid_t service, uuid_t char
if (service == "00001819-0000-1000-8000-00805F9B34FB") { // Location and Navigation service
if (characteristic == "FEC81438-CB89-4C37-93D0-BADFCED4376E") {
// FANET characteristic is available, enable SendData
d.SendData = SendData;
return true;
}
return (characteristic == "234337BF-F931-4D2D-A13C-07E2F06A0249"); // TAS
Expand Down

0 comments on commit f6a2723

Please sign in to comment.