send 129285 on RMB

This commit is contained in:
andreas 2021-11-02 11:18:32 +01:00
parent ac9f113b54
commit ce954e41f8
1 changed files with 20 additions and 10 deletions

View File

@ -57,11 +57,11 @@ private:
this->lastUsed=ts; this->lastUsed=ts;
} }
}; };
std::map<String,WaypointNumber> waypointMap;
unsigned long waypointId=0;
const size_t MAXWAYPOINTS=100; const size_t MAXWAYPOINTS=100;
std::map<String,WaypointNumber> waypointMap;
uint8_t waypointId=1;
unsigned long getWaypointId(const char *name){ uint8_t getWaypointId(const char *name){
String wpName(name); String wpName(name);
auto it=waypointMap.find(wpName); auto it=waypointMap.find(wpName);
if (it != waypointMap.end()){ if (it != waypointMap.end()){
@ -70,6 +70,7 @@ private:
} }
unsigned long now=millis(); unsigned long now=millis();
auto oldestIt=waypointMap.begin(); auto oldestIt=waypointMap.begin();
uint8_t newNumber=0;
if (waypointMap.size() > MAXWAYPOINTS){ if (waypointMap.size() > MAXWAYPOINTS){
LOG_DEBUG(GwLog::DEBUG+1,"removing oldest from waypoint map"); LOG_DEBUG(GwLog::DEBUG+1,"removing oldest from waypoint map");
for (it=waypointMap.begin();it!=waypointMap.end();it++){ for (it=waypointMap.begin();it!=waypointMap.end();it++){
@ -77,10 +78,14 @@ private:
oldestIt=it; oldestIt=it;
} }
} }
newNumber=oldestIt->second.id;
waypointMap.erase(oldestIt); waypointMap.erase(oldestIt);
} }
else{
waypointId++; waypointId++;
WaypointNumber newWp(waypointId,now); newNumber=waypointId;
}
WaypointNumber newWp(newNumber,now);
waypointMap[wpName]=newWp; waypointMap[wpName]=newWp;
return newWp.id; return newWp.id;
} }
@ -115,6 +120,8 @@ private:
uint32_t getUint32(GwBoatItem<uint32_t> *src){ uint32_t getUint32(GwBoatItem<uint32_t> *src){
return src->getDataWithDefault(N2kUInt32NA); return src->getDataWithDefault(N2kUInt32NA);
} }
#define UD(item) updateDouble(boatData->item, item, msg.sourceId)
#define UI(item) updateUint32(boatData->item, item, msg.sourceId)
void convertRMB(const SNMEA0183Msg &msg) void convertRMB(const SNMEA0183Msg &msg)
{ {
LOG_DEBUG(GwLog::DEBUG + 1, "convert RMB"); LOG_DEBUG(GwLog::DEBUG + 1, "convert RMB");
@ -149,6 +156,8 @@ private:
SetN2kXTE(n2kMsg,1,mode,false,rmb.xte); SetN2kXTE(n2kMsg,1,mode,false,rmb.xte);
send(n2kMsg); send(n2kMsg);
} }
uint8_t destinationId=getWaypointId(rmb.destID);
uint8_t sourceId=getWaypointId(rmb.originID);
if (boatData->DTW->update(rmb.dtw,msg.sourceId) if (boatData->DTW->update(rmb.dtw,msg.sourceId)
&& boatData->BTW->update(rmb.btw,msg.sourceId) && boatData->BTW->update(rmb.btw,msg.sourceId)
&& boatData->WPLatitude->update(rmb.latitude,msg.sourceId) && boatData->WPLatitude->update(rmb.latitude,msg.sourceId)
@ -162,17 +171,18 @@ private:
N2kUInt16NA, N2kUInt16NA,
N2kDoubleNA, N2kDoubleNA,
rmb.btw, rmb.btw,
getWaypointId(rmb.originID), sourceId,
getWaypointId(rmb.destID), destinationId,
rmb.latitude, rmb.latitude,
rmb.longitude, rmb.longitude,
rmb.vmg rmb.vmg
); );
send(n2kMsg); send(n2kMsg);
SetN2kPGN129285(n2kMsg,sourceId,1,1,true,true,"default");
AppendN2kPGN129285(n2kMsg,destinationId,rmb.destID,rmb.latitude,rmb.longitude);
send(n2kMsg);
} }
} }
#define UD(item) updateDouble(boatData->item, item, msg.sourceId)
#define UI(item) updateUint32(boatData->item, item, msg.sourceId)
void convertRMC(const SNMEA0183Msg &msg) void convertRMC(const SNMEA0183Msg &msg)
{ {
double SecondsSinceMidnight=0, Latitude=0, Longitude=0, COG=0, SOG=0, Variation=0; double SecondsSinceMidnight=0, Latitude=0, Longitude=0, COG=0, SOG=0, Variation=0;