prepare message for AIS
This commit is contained in:
parent
a57d91c63d
commit
8d1895ad3a
|
@ -3,6 +3,7 @@
|
||||||
#include "N2kMessages.h"
|
#include "N2kMessages.h"
|
||||||
#include "ConverterList.h"
|
#include "ConverterList.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <strings.h>
|
||||||
NMEA0183DataToN2K::NMEA0183DataToN2K(GwLog *logger, GwBoatData *boatData,N2kSender callback)
|
NMEA0183DataToN2K::NMEA0183DataToN2K(GwLog *logger, GwBoatData *boatData,N2kSender callback)
|
||||||
{
|
{
|
||||||
this->sender = callback;
|
this->sender = callback;
|
||||||
|
@ -16,11 +17,29 @@ bool NMEA0183DataToN2K::parseAndSend(const char *buffer, int sourceId) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
class SNMEA0183Msg {
|
class SNMEA0183Msg : public tNMEA0183Msg{
|
||||||
public:
|
public:
|
||||||
int sourceId;
|
int sourceId;
|
||||||
const char *line;
|
const char *line;
|
||||||
tNMEA0183Msg msg;
|
bool isAis=false;
|
||||||
|
SNMEA0183Msg(const char *line, int sourceId){
|
||||||
|
this->sourceId=sourceId;
|
||||||
|
this->line=line;
|
||||||
|
int len=strlen(line);
|
||||||
|
if (len >6){
|
||||||
|
if (strncasecmp(line,"!AIVDM",6) == 0
|
||||||
|
||
|
||||||
|
strncasecmp(line,"!AIVDO",6) == 0
|
||||||
|
) isAis=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String getKey(){
|
||||||
|
if (!isAis) return MessageCode();
|
||||||
|
char buf[6];
|
||||||
|
strncpy(buf,line+1,5);
|
||||||
|
return String(buf);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
class NMEA0183DataToN2KFunctions : public NMEA0183DataToN2K
|
class NMEA0183DataToN2KFunctions : public NMEA0183DataToN2K
|
||||||
{
|
{
|
||||||
|
@ -74,7 +93,7 @@ private:
|
||||||
unsigned long DaysSince1970=0;
|
unsigned long DaysSince1970=0;
|
||||||
time_t DateTime;
|
time_t DateTime;
|
||||||
char status;
|
char status;
|
||||||
if (!NMEA0183ParseRMC_nc(msg.msg, SecondsSinceMidnight, status, Latitude, Longitude, COG, SOG, DaysSince1970, Variation, &DateTime))
|
if (!NMEA0183ParseRMC_nc(msg, SecondsSinceMidnight, status, Latitude, Longitude, COG, SOG, DaysSince1970, Variation, &DateTime))
|
||||||
{
|
{
|
||||||
logger->logDebug(GwLog::DEBUG, "failed to parse RMC %s", msg.line);
|
logger->logDebug(GwLog::DEBUG, "failed to parse RMC %s", msg.line);
|
||||||
return;
|
return;
|
||||||
|
@ -120,15 +139,15 @@ public:
|
||||||
virtual bool parseAndSend(const char *buffer, int sourceId)
|
virtual bool parseAndSend(const char *buffer, int sourceId)
|
||||||
{
|
{
|
||||||
LOG_DEBUG(GwLog::DEBUG + 1, "NMEA0183DataToN2K[%d] parsing %s", sourceId, buffer)
|
LOG_DEBUG(GwLog::DEBUG + 1, "NMEA0183DataToN2K[%d] parsing %s", sourceId, buffer)
|
||||||
SNMEA0183Msg msg;
|
SNMEA0183Msg msg(buffer,sourceId);
|
||||||
msg.sourceId=sourceId;
|
if (! msg.isAis){
|
||||||
msg.line=buffer;
|
if (!msg.SetMessage(buffer))
|
||||||
if (!msg.msg.SetMessage(buffer))
|
{
|
||||||
{
|
LOG_DEBUG(GwLog::DEBUG, "NMEA0183DataToN2K[%d] invalid message %s", sourceId, buffer)
|
||||||
LOG_DEBUG(GwLog::DEBUG, "NMEA0183DataToN2K[%d] invalid message %s", sourceId, buffer)
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
}
|
||||||
String code = msg.msg.MessageCode();
|
String code = msg.getKey();
|
||||||
bool rt = converters.handleMessage(code, msg, this);
|
bool rt = converters.handleMessage(code, msg, this);
|
||||||
if (!rt)
|
if (!rt)
|
||||||
{
|
{
|
||||||
|
@ -145,6 +164,10 @@ public:
|
||||||
return converters.handledPgns();
|
return converters.handledPgns();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual int numConverters(){
|
||||||
|
return converters.numConverters();
|
||||||
|
}
|
||||||
|
|
||||||
NMEA0183DataToN2KFunctions(GwLog *logger, GwBoatData *boatData, N2kSender callback)
|
NMEA0183DataToN2KFunctions(GwLog *logger, GwBoatData *boatData, N2kSender callback)
|
||||||
: NMEA0183DataToN2K(logger, boatData, callback)
|
: NMEA0183DataToN2K(logger, boatData, callback)
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,6 +15,7 @@ class NMEA0183DataToN2K{
|
||||||
NMEA0183DataToN2K(GwLog *logger,GwBoatData *boatData,N2kSender callback);
|
NMEA0183DataToN2K(GwLog *logger,GwBoatData *boatData,N2kSender callback);
|
||||||
virtual bool parseAndSend(const char *buffer, int sourceId);
|
virtual bool parseAndSend(const char *buffer, int sourceId);
|
||||||
virtual unsigned long *handledPgns()=0;
|
virtual unsigned long *handledPgns()=0;
|
||||||
|
virtual int numConverters()=0;
|
||||||
static NMEA0183DataToN2K* create(GwLog *logger,GwBoatData *boatData,N2kSender callback);
|
static NMEA0183DataToN2K* create(GwLog *logger,GwBoatData *boatData,N2kSender callback);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue