allow receiving seasmart messages, correctly handle source for actisense and seasmart in converter
This commit is contained in:
parent
cca050eca6
commit
73eee8461e
|
@ -34,12 +34,11 @@
|
|||
|
||||
|
||||
N2kDataToNMEA0183::N2kDataToNMEA0183(GwLog * logger, GwBoatData *boatData,
|
||||
tSendNMEA0183MessageCallback callback, int id,String talkerId)
|
||||
SendNMEA0183MessageCallback callback, String talkerId)
|
||||
{
|
||||
this->SendNMEA0183MessageCallback=callback;
|
||||
this->sendNMEA0183MessageCallback=callback;
|
||||
strncpy(this->talkerId,talkerId.c_str(),2);
|
||||
this->talkerId[2]=0;
|
||||
sourceId=id;
|
||||
this->talkerId[2]=0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,7 +49,7 @@ void N2kDataToNMEA0183::loop() {
|
|||
|
||||
//*****************************************************************************
|
||||
void N2kDataToNMEA0183::SendMessage(const tNMEA0183Msg &NMEA0183Msg) {
|
||||
if ( SendNMEA0183MessageCallback != 0 ) SendNMEA0183MessageCallback(NMEA0183Msg, sourceId);
|
||||
sendNMEA0183MessageCallback(NMEA0183Msg, sourceId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -148,8 +147,9 @@ private:
|
|||
virtual String handledKeys(){
|
||||
return converters.handledKeys();
|
||||
}
|
||||
virtual void HandleMsg(const tN2kMsg &N2kMsg)
|
||||
virtual void HandleMsg(const tN2kMsg &N2kMsg, int sourceId)
|
||||
{
|
||||
this->sourceId=sourceId;
|
||||
String key=String(N2kMsg.PGN);
|
||||
bool rt=converters.handleMessage(key,N2kMsg,this);
|
||||
if (! rt){
|
||||
|
@ -1489,9 +1489,9 @@ private:
|
|||
|
||||
public:
|
||||
N2kToNMEA0183Functions(GwLog *logger, GwBoatData *boatData,
|
||||
tSendNMEA0183MessageCallback callback, int sourceId,
|
||||
SendNMEA0183MessageCallback callback,
|
||||
String talkerId, GwXDRMappings *xdrMappings, int minXdrInterval)
|
||||
: N2kDataToNMEA0183(logger, boatData, callback,sourceId,talkerId)
|
||||
: N2kDataToNMEA0183(logger, boatData, callback,talkerId)
|
||||
{
|
||||
LastPosSend = 0;
|
||||
lastLoopTime = 0;
|
||||
|
@ -1516,9 +1516,9 @@ private:
|
|||
|
||||
|
||||
N2kDataToNMEA0183* N2kDataToNMEA0183::create(GwLog *logger, GwBoatData *boatData,
|
||||
tSendNMEA0183MessageCallback callback, int sourceId,String talkerId, GwXDRMappings *xdrMappings,
|
||||
SendNMEA0183MessageCallback callback, String talkerId, GwXDRMappings *xdrMappings,
|
||||
int minXdrInterval){
|
||||
LOG_DEBUG(GwLog::LOG,"creating N2kToNMEA0183");
|
||||
return new N2kToNMEA0183Functions(logger,boatData,callback, sourceId,talkerId,xdrMappings,minXdrInterval);
|
||||
return new N2kToNMEA0183Functions(logger,boatData,callback, talkerId,xdrMappings,minXdrInterval);
|
||||
}
|
||||
//*****************************************************************************
|
||||
|
|
|
@ -22,6 +22,7 @@ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
*/
|
||||
#ifndef _N2KDATATONMEA0183_H
|
||||
#define _N2KDATATONMEA0183_H
|
||||
#include <functional>
|
||||
#include <NMEA0183.h>
|
||||
#include <NMEA2000.h>
|
||||
|
||||
|
@ -34,22 +35,22 @@ class GwJsonDocument;
|
|||
class N2kDataToNMEA0183
|
||||
{
|
||||
public:
|
||||
using tSendNMEA0183MessageCallback = void (*)(const tNMEA0183Msg &NMEA0183Msg, int id);
|
||||
typedef std::function<void(const tNMEA0183Msg &NMEA0183Msg,int id)> SendNMEA0183MessageCallback;
|
||||
|
||||
protected:
|
||||
GwLog *logger;
|
||||
GwBoatData *boatData;
|
||||
int sourceId;
|
||||
int sourceId=0;
|
||||
char talkerId[3];
|
||||
tSendNMEA0183MessageCallback SendNMEA0183MessageCallback;
|
||||
SendNMEA0183MessageCallback sendNMEA0183MessageCallback;
|
||||
void SendMessage(const tNMEA0183Msg &NMEA0183Msg);
|
||||
N2kDataToNMEA0183(GwLog *logger, GwBoatData *boatData,
|
||||
tSendNMEA0183MessageCallback callback, int sourceId,String talkerId);
|
||||
SendNMEA0183MessageCallback callback, String talkerId);
|
||||
|
||||
public:
|
||||
static N2kDataToNMEA0183* create(GwLog *logger, GwBoatData *boatData, tSendNMEA0183MessageCallback callback,
|
||||
int sourceId,String talkerId, GwXDRMappings *xdrMappings,int minXdrInterval=100);
|
||||
virtual void HandleMsg(const tN2kMsg &N2kMsg) = 0;
|
||||
static N2kDataToNMEA0183* create(GwLog *logger, GwBoatData *boatData, SendNMEA0183MessageCallback callback,
|
||||
String talkerId, GwXDRMappings *xdrMappings,int minXdrInterval=100);
|
||||
virtual void HandleMsg(const tN2kMsg &N2kMsg, int sourceId) = 0;
|
||||
virtual void loop();
|
||||
virtual ~N2kDataToNMEA0183(){}
|
||||
virtual unsigned long* handledPgns()=0;
|
||||
|
|
|
@ -22,7 +22,7 @@ typedef size_t (*GwBufferHandleFunction)(uint8_t *buffer, size_t len, void *para
|
|||
class GwBuffer{
|
||||
public:
|
||||
static const size_t TX_BUFFER_SIZE=1620; // app. 20 NMEA messages
|
||||
static const size_t RX_BUFFER_SIZE=400; // enough for 1 NMEA message or actisense message
|
||||
static const size_t RX_BUFFER_SIZE=600; // enough for 1 NMEA message or actisense message or seasmart message
|
||||
typedef enum {
|
||||
OK,
|
||||
ERROR,
|
||||
|
|
17
src/main.cpp
17
src/main.cpp
|
@ -68,7 +68,7 @@ const unsigned long HEAP_REPORT_TIME=2000; //set to 0 to disable heap reporting
|
|||
|
||||
|
||||
#define MAX_NMEA2000_MESSAGE_SEASMART_SIZE 500
|
||||
#define MAX_NMEA0183_MESSAGE_SIZE 150 // For AIS
|
||||
#define MAX_NMEA0183_MESSAGE_SIZE MAX_NMEA2000_MESSAGE_SEASMART_SIZE
|
||||
//https://curiouser.cheshireeng.com/2014/08/19/c-compile-time-assert/
|
||||
#define CASSERT(predicate, text) _impl_CASSERT_LINE(predicate,__LINE__)
|
||||
#define _impl_PASTE(a,b) a##b
|
||||
|
@ -195,7 +195,7 @@ void handleN2kMessage(const tN2kMsg &n2kMsg,int sourceId, bool isConverted=false
|
|||
c->sendActisense(n2kMsg,sourceId);
|
||||
});
|
||||
if (! isConverted){
|
||||
nmea0183Converter->HandleMsg(n2kMsg);
|
||||
nmea0183Converter->HandleMsg(n2kMsg,sourceId);
|
||||
}
|
||||
if (sourceId != N2K_CHANNEL_ID){
|
||||
countNMEA2KOut.add(n2kMsg.PGN);
|
||||
|
@ -630,7 +630,7 @@ void setup() {
|
|||
[](const tNMEA0183Msg &msg, int sourceId){
|
||||
SendNMEA0183Message(msg,sourceId,false);
|
||||
}
|
||||
, N2K_CHANNEL_ID,
|
||||
,
|
||||
config.getString(config.talkerId,String("GP")),
|
||||
&xdrMappings,
|
||||
config.getInt(config.minXdrInterval,100)
|
||||
|
@ -770,7 +770,16 @@ void loop() {
|
|||
oc->loop(false,true);
|
||||
});
|
||||
if (c->sendToN2K()){
|
||||
toN2KConverter->parseAndSend(buffer, sourceId);
|
||||
if (strlen(buffer) > 6 && strncmp(buffer,"$PCDIN",6) == 0){
|
||||
tN2kMsg n2kMsg;
|
||||
uint32_t timestamp;
|
||||
if (SeasmartToN2k(buffer,timestamp,n2kMsg)){
|
||||
handleN2kMessage(n2kMsg,sourceId);
|
||||
}
|
||||
}
|
||||
else{
|
||||
toN2KConverter->parseAndSend(buffer, sourceId);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue