n2k engine pgns, untested

This commit is contained in:
wellenvogel 2021-11-25 22:16:51 +01:00
parent 99ba4b3d8e
commit dbadb6fb11
5 changed files with 79 additions and 6 deletions

View File

@ -284,7 +284,7 @@ template<class T> GwBoatItem<T> *GwBoatData::getOrCreate(T initial, GwBoatItemNa
name.c_str(),rt->getCurrentType());
return rt;
}
template<class T> bool GwBoatData::update(T value,int source,GwBoatItemNameProvider *provider){
template<class T> bool GwBoatData::update(const T value,int source,GwBoatItemNameProvider *provider){
GwBoatItem<T> *item=getOrCreate(value,provider);
if (! item) return false;
return item->update(value,source);

View File

@ -105,10 +105,18 @@ private:
return false;
return item->update(value,sourceId);
}
bool updateDouble(GwXDRFoundMapping * mapping, double &value){
bool updateDouble(GwXDRFoundMapping * mapping, const double &value){
if (mapping->empty) return false;
if (value == N2kDoubleNA)
return false;
return boatData->update(value,sourceId,mapping);
}
bool updateDouble(GwXDRFoundMapping * mapping, const int8_t &value){
if (mapping->empty) return false;
if (value == N2kInt8NA)
return false;
return boatData->update((double)value,sourceId,mapping);
}
unsigned long LastPosSend;
unsigned long NextRMCSend;
@ -1230,6 +1238,59 @@ private:
addToXdr(mapping.buildXdrEntry(ActualPressure));
finalizeXdr();
}
void Handle127489(const tN2kMsg &msg){
unsigned char instance=-1;
double values[8];
int8_t ivalues[2];
if (! ParseN2kPGN127489(msg,instance,
values[0],values[1],values[2],values[3],values[4],values[5],
values[6],values[7],ivalues[0],ivalues[1]
)){
LOG_DEBUG(GwLog::DEBUG,"unable to parse PGN %d",msg.PGN);
}
for (int i=0;i<8;i++){
GwXDRFoundMapping mapping=xdrMappings->getMapping(XDRENGINE,0,i,instance);
if (! updateDouble(&mapping,values[i])) continue;
addToXdr(mapping.buildXdrEntry(values[i]));
}
for (int i=0;i< 2;i++){
GwXDRFoundMapping mapping=xdrMappings->getMapping(XDRENGINE,0,i+8,instance);
if (! updateDouble(&mapping,ivalues[i])) continue;
addToXdr(mapping.buildXdrEntry((double)values[i]));
}
finalizeXdr();
}
void Handle127488(const tN2kMsg &msg){
unsigned char instance=-1;
double speed,pressure;
int8_t tilt;
if (! ParseN2kPGN127488(msg,instance,
speed,pressure,tilt)){
LOG_DEBUG(GwLog::DEBUG,"unable to parse PGN %d",msg.PGN);
}
GwXDRFoundMapping mapping=xdrMappings->getMapping(XDRENGINE,0,10,instance);
if (updateDouble(&mapping,speed)){
addToXdr(mapping.buildXdrEntry(speed));
}
mapping=xdrMappings->getMapping(XDRENGINE,0,11,instance);
if (updateDouble(&mapping,pressure)){
addToXdr(mapping.buildXdrEntry(pressure));
}
mapping=xdrMappings->getMapping(XDRENGINE,0,12,instance);
if (updateDouble(&mapping,tilt)){
addToXdr(mapping.buildXdrEntry((double)tilt));
}
finalizeXdr();
if (speed == N2kDoubleNA) return;
tNMEA0183Msg nmeaMsg;
if (! nmeaMsg.Init("RPM",talkerId)) return;
if (! nmeaMsg.AddStrField("E")) return;
if (! nmeaMsg.AddDoubleField(instance)) return;
if (! nmeaMsg.AddDoubleField(speed)) return;
if (! nmeaMsg.AddEmptyField()) return;
if (! nmeaMsg.AddStrField("V")) return;
SendMessage(nmeaMsg);
}
void registerConverters()
@ -1260,6 +1321,8 @@ private:
converters.registerConverter(130312UL, &N2kToNMEA0183Functions::Handle130312);
converters.registerConverter(130313UL, &N2kToNMEA0183Functions::Handle130313);
converters.registerConverter(130314UL, &N2kToNMEA0183Functions::Handle130314);
converters.registerConverter(127489UL, &N2kToNMEA0183Functions::Handle127489);
converters.registerConverter(127488UL, &N2kToNMEA0183Functions::Handle127488);
#define HANDLE_AIS
#ifdef HANDLE_AIS
converters.registerConverter(129038UL, &N2kToNMEA0183Functions::HandleAISClassAPosReport); // AIS Class A Position Report, Message Type 1

View File

@ -51,6 +51,9 @@ GwXDRType *types[] = {
new GwXDRType(GwXDRType::VOLPERCENT, "V", "P"),
new GwXDRType(GwXDRType::VOLUME, "V", "M", m3ToL, ltrTom3),
new GwXDRType(GwXDRType::FLOW, "R", "I", ps2ph, ph2ps),
new GwXDRType(GwXDRType::GENERIC, "G", ""),
new GwXDRType(GwXDRType::DISPLACEMENT, "A", "P"),
new GwXDRType(GwXDRType::RPM,"T","R"),
//important to have 2x NULL!
NULL,
NULL};

View File

@ -33,6 +33,9 @@ class GwXDRType{
VOLPERCENT=6,
VOLUME=7,
FLOW=8,
GENERIC=9,
DISPLACEMENT=10,
RPM=11,
UNKNOWN=99
}TypeCode;
typedef double (* convert)(double);

View File

@ -299,18 +299,22 @@
]
},
"Engine":{
"d":"127489",
"d":"127489,1278488",
"id":10,
"fields":[
{"l":"EngineOilPress","t":0},
{"l":"EngineOilTemp","t":4},
{"l":"EngineCoolantTemp","t":4},
{"l":"AlternatorVoltage","t":2},
{"l":"FuelRate","t":8},
{"l":"EngineHours","t":99},
{"l":"EngineHours","t":9},
{"l":"EngineCoolantPress","t":0},
{"l":"EngineFuelPress","t":0},
{"l":"EngineLoad","t":99},
{"l":"EngineTorque","t":99}
{"l":"EngineLoad","t":9},
{"l":"EngineTorque","t":9},
{"l":"EngineSpeed","t":11},
{"l":"EngineBoostPressure","t":0},
{"l":"EngineTiltTrim","t":10}
]
}
}