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 e953483
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 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 Down

0 comments on commit e953483

Please sign in to comment.