cleanup of unused code, streamline main
This commit is contained in:
parent
bb7f2085a4
commit
483e79f99e
|
@ -31,10 +31,11 @@
|
|||
|
||||
|
||||
|
||||
N2kDataToNMEA0183::N2kDataToNMEA0183(GwLog * logger, GwBoatData *boatData, tNMEA2000 *NMEA2000, tNMEA0183 *NMEA0183, int id)
|
||||
N2kDataToNMEA0183::N2kDataToNMEA0183(GwLog * logger, GwBoatData *boatData, tNMEA2000 *NMEA2000,
|
||||
tSendNMEA0183MessageCallback callback, int id)
|
||||
: tNMEA2000::tMsgHandler(0,NMEA2000){
|
||||
SendNMEA0183MessageCallback=0;
|
||||
pNMEA0183=NMEA0183;
|
||||
this->SendNMEA0183MessageCallback=callback;
|
||||
sourceId=id;
|
||||
}
|
||||
|
||||
|
@ -51,8 +52,8 @@ void N2kDataToNMEA0183::SendMessage(const tNMEA0183Msg &NMEA0183Msg) {
|
|||
}
|
||||
|
||||
N2kDataToNMEA0183* N2kDataToNMEA0183::create(GwLog *logger, GwBoatData *boatData, tNMEA2000 *NMEA2000,
|
||||
tNMEA0183 *NMEA0183, int sourceId){
|
||||
tSendNMEA0183MessageCallback callback, int sourceId){
|
||||
LOG_DEBUG(GwLog::LOG,"creating N2kToNMEA0183");
|
||||
return new N2kToNMEA0183Functions(logger,boatData,NMEA2000,NMEA0183, sourceId);
|
||||
return new N2kToNMEA0183Functions(logger,boatData,NMEA2000,callback, sourceId);
|
||||
}
|
||||
//*****************************************************************************
|
||||
|
|
|
@ -42,15 +42,11 @@ protected:
|
|||
int sourceId;
|
||||
tSendNMEA0183MessageCallback SendNMEA0183MessageCallback;
|
||||
void SendMessage(const tNMEA0183Msg &NMEA0183Msg);
|
||||
N2kDataToNMEA0183(GwLog *logger, GwBoatData *boatData, tNMEA2000 *NMEA2000, tNMEA0183 *NMEA0183, int sourceId);
|
||||
N2kDataToNMEA0183(GwLog *logger, GwBoatData *boatData, tNMEA2000 *NMEA2000, tSendNMEA0183MessageCallback callback, int sourceId);
|
||||
|
||||
public:
|
||||
static N2kDataToNMEA0183* create(GwLog *logger, GwBoatData *boatData, tNMEA2000 *NMEA2000, tNMEA0183 *NMEA0183, int sourceId);
|
||||
static N2kDataToNMEA0183* create(GwLog *logger, GwBoatData *boatData, tNMEA2000 *NMEA2000, tSendNMEA0183MessageCallback callback, int sourceId);
|
||||
virtual void HandleMsg(const tN2kMsg &N2kMsg) = 0;
|
||||
void SetSendNMEA0183MessageCallback(tSendNMEA0183MessageCallback _SendNMEA0183MessageCallback)
|
||||
{
|
||||
SendNMEA0183MessageCallback = _SendNMEA0183MessageCallback;
|
||||
}
|
||||
virtual void loop();
|
||||
virtual ~N2kDataToNMEA0183(){}
|
||||
virtual unsigned long* handledPgns()=0;
|
||||
|
|
|
@ -850,8 +850,8 @@ private:
|
|||
}
|
||||
|
||||
public:
|
||||
N2kToNMEA0183Functions(GwLog *logger, GwBoatData *boatData, tNMEA2000 *NMEA2000, tNMEA0183 *NMEA0183, int sourceId)
|
||||
: N2kDataToNMEA0183(logger, boatData, NMEA2000, NMEA0183,sourceId)
|
||||
N2kToNMEA0183Functions(GwLog *logger, GwBoatData *boatData, tNMEA2000 *NMEA2000, tSendNMEA0183MessageCallback callback, int sourceId)
|
||||
: N2kDataToNMEA0183(logger, boatData, NMEA2000, callback,sourceId)
|
||||
{
|
||||
LastPosSend = 0;
|
||||
lastLoopTime = 0;
|
||||
|
|
59
src/main.cpp
59
src/main.cpp
|
@ -49,6 +49,9 @@ const unsigned long HEAP_REPORT_TIME=2000; //set to 0 to disable heap reporting
|
|||
#define SERIAL1_CHANNEL_ID 2
|
||||
#define MIN_TCP_CHANNEL_ID 3
|
||||
|
||||
#define MAX_NMEA2000_MESSAGE_SEASMART_SIZE 500
|
||||
#define MAX_NMEA0183_MESSAGE_SIZE 150 // For AIS
|
||||
|
||||
typedef std::map<String,String> StringMap;
|
||||
|
||||
|
||||
|
@ -66,40 +69,19 @@ int numCan=0;
|
|||
int NodeAddress; // To store last Node Address
|
||||
|
||||
Preferences preferences; // Nonvolatile storage on ESP32 - To store LastDeviceAddress
|
||||
|
||||
bool SendNMEA0183Conversion = true; // Do we send NMEA2000 -> NMEA0183 conversion
|
||||
bool SendSeaSmart = false; // Do we send NMEA2000 messages in SeaSmart format
|
||||
|
||||
N2kDataToNMEA0183 *nmea0183Converter=NULL;
|
||||
|
||||
// Set the information for other bus devices, which messages we support
|
||||
const unsigned long TransmitMessages[] PROGMEM = {127489L, // Engine dynamic
|
||||
0
|
||||
};
|
||||
// Forward declarations
|
||||
void HandleNMEA2000Msg(const tN2kMsg &N2kMsg);
|
||||
|
||||
void SendNMEA0183Message(const tNMEA0183Msg &NMEA0183Msg,int id);
|
||||
|
||||
GwRequestQueue mainQueue(&logger,20);
|
||||
GwWebServer webserver(&logger,&mainQueue,80);
|
||||
|
||||
// Serial port 2 config (GPIO 16)
|
||||
const int baudrate = 38400;
|
||||
const int rs_config = SERIAL_8N1;
|
||||
|
||||
// Buffer config
|
||||
|
||||
#define MAX_NMEA0183_MESSAGE_SIZE 150 // For AIS
|
||||
char buff[MAX_NMEA0183_MESSAGE_SIZE];
|
||||
|
||||
|
||||
tNMEA0183 NMEA0183;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//configs that we need in main
|
||||
GwConfigInterface *sendUsb=NULL;
|
||||
GwConfigInterface *sendTCP=NULL;
|
||||
GwConfigInterface *sendSeasmart=NULL;
|
||||
|
@ -125,7 +107,7 @@ void delayedRestart(){
|
|||
|
||||
#define JSON_OK "{\"status\":\"OK\"}"
|
||||
|
||||
//register the requests at the webserver that should
|
||||
//WebServer requests that should
|
||||
//be processed inside the main loop
|
||||
//this prevents us from the need to sync all the accesses
|
||||
class ResetRequest : public GwRequestMessage
|
||||
|
@ -304,8 +286,8 @@ void setup() {
|
|||
|
||||
webserver.begin();
|
||||
|
||||
nmea0183Converter= N2kDataToNMEA0183::create(&logger, &boatData,&NMEA2000, 0, N2K_CHANNEL_ID);
|
||||
// Reserve enough buffer for sending all messages. This does not work on small memory devices like Uno or Mega
|
||||
nmea0183Converter= N2kDataToNMEA0183::create(&logger, &boatData,&NMEA2000,
|
||||
SendNMEA0183Message, N2K_CHANNEL_ID);
|
||||
|
||||
NMEA2000.SetN2kCANMsgBufSize(8);
|
||||
NMEA2000.SetN2kCANReceiveFrameBufSize(250);
|
||||
|
@ -342,11 +324,15 @@ void setup() {
|
|||
|
||||
NMEA2000.ExtendTransmitMessages(TransmitMessages);
|
||||
NMEA2000.ExtendReceiveMessages(nmea0183Converter->handledPgns());
|
||||
NMEA2000.AttachMsgHandler(nmea0183Converter); // NMEA 2000 -> NMEA 0183 conversion
|
||||
NMEA2000.SetMsgHandler(HandleNMEA2000Msg); // Also send all NMEA2000 messages in SeaSmart format
|
||||
|
||||
nmea0183Converter->SetSendNMEA0183MessageCallback(SendNMEA0183Message);
|
||||
|
||||
NMEA2000.SetMsgHandler([](const tN2kMsg &n2kMsg){
|
||||
numCan++;
|
||||
if ( sendSeasmart->asBoolean() ) {
|
||||
char buf[MAX_NMEA2000_MESSAGE_SEASMART_SIZE];
|
||||
if ( N2kToSeasmart(n2kMsg, millis(), buf, MAX_NMEA2000_MESSAGE_SEASMART_SIZE) == 0 ) return;
|
||||
socketServer.sendToClients(buf,N2K_CHANNEL_ID);
|
||||
}
|
||||
nmea0183Converter->HandleMsg(n2kMsg);
|
||||
});
|
||||
NMEA2000.Open();
|
||||
|
||||
}
|
||||
|
@ -356,18 +342,7 @@ void setup() {
|
|||
|
||||
|
||||
|
||||
#define MAX_NMEA2000_MESSAGE_SEASMART_SIZE 500
|
||||
//*****************************************************************************
|
||||
//NMEA 2000 message handler
|
||||
void HandleNMEA2000Msg(const tN2kMsg &N2kMsg) {
|
||||
|
||||
numCan++;
|
||||
if ( !sendSeasmart->asBoolean() ) return;
|
||||
|
||||
char buf[MAX_NMEA2000_MESSAGE_SEASMART_SIZE];
|
||||
if ( N2kToSeasmart(N2kMsg, millis(), buf, MAX_NMEA2000_MESSAGE_SEASMART_SIZE) == 0 ) return;
|
||||
socketServer.sendToClients(buf,N2K_CHANNEL_ID);
|
||||
}
|
||||
|
||||
void sendBufferToChannels(const char * buffer, int sourceId){
|
||||
if (sendTCP->asBoolean()){
|
||||
|
|
Loading…
Reference in New Issue