diff --git a/NMEA2000.cpp b/NMEA2000.cpp index 4ff704d8..dc45a615 100644 --- a/NMEA2000.cpp +++ b/NMEA2000.cpp @@ -31,17 +31,26 @@ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define DebugStream Serial -// #define NMEA2000_FRAME_DEBUG +// #define NMEA2000_FRAME_IN_DEBUG +// #define NMEA2000_FRAME_OUT_DEBUG // #define NMEA2000_MSG_DEBUG // #define NMEA2000_BUF_DEBUG // #define NMEA2000_DEBUG -#if defined(NMEA2000_FRAME_DEBUG) -# define N2kFrameDbg(fmt, args...) DebugStream.print (fmt , ## args) -# define N2kFrameDbgln(fmt, args...) DebugStream.println (fmt , ## args) +#if defined(NMEA2000_FRAME_IN_DEBUG) +# define N2kFrameInDbg(fmt, args...) DebugStream.print (fmt , ## args) +# define N2kFrameInDbgln(fmt, args...) DebugStream.println (fmt , ## args) #else -# define N2kFrameDbg(fmt, args...) -# define N2kFrameDbgln(fmt, args...) +# define N2kFrameInDbg(fmt, args...) +# define N2kFrameInDbgln(fmt, args...) +#endif + +#if defined(NMEA2000_FRAME_OUT_DEBUG) +# define N2kFrameOutDbg(fmt, args...) DebugStream.print (fmt , ## args) +# define N2kFrameOutDbgln(fmt, args...) DebugStream.println (fmt , ## args) +#else +# define N2kFrameOutDbg(fmt, args...) +# define N2kFrameOutDbgln(fmt, args...) #endif #if defined(NMEA2000_MSG_DEBUG) @@ -235,6 +244,7 @@ tNMEA2000::tNMEA2000() { #if !defined(N2K_NO_GROUP_FUNCTION_SUPPORT) pGroupFunctionHandlers=0; #endif + ForwardStream=0; SingleFrameMessages[0]=DefSingleFrameMessages; FastPacketMessages[0]=DefFastPacketMessages; @@ -277,6 +287,7 @@ void tNMEA2000::SetDeviceCount(const uint8_t _DeviceCount) { //***************************************************************************** void tNMEA2000::InitDevices() { if ( Devices==0 ) { + N2kDbgln("Init devices"); Devices=new tDevice[DeviceCount]; MaxCANSendFrames*=DeviceCount; // We need bigger buffer for sending all information // for (int i=0; i0 ) CANSendFrameBuf = new tCANSendFrame[MaxCANSendFrames]; + N2kDbg("Initialize frame buffer. Size: "); N2kDbg(MaxCANSendFrames); N2kDbg(", address:"); N2kDbgln((uint32_t)CANSendFrameBuf); CANSendFrameBufferWrite=0; CANSendFrameBufferRead=0; } @@ -559,7 +571,7 @@ bool tNMEA2000::SendFrames() temp = (CANSendFrameBufferRead + 1) % MaxCANSendFrames; if ( CANSendFrame(CANSendFrameBuf[temp].id, CANSendFrameBuf[temp].len, CANSendFrameBuf[temp].buf, CANSendFrameBuf[temp].wait_sent) ) { CANSendFrameBufferRead=temp; - N2kFrameDbg("Frame unbuffered "); N2kFrameDbgln(CANSendFrameBuf[temp].id); + N2kFrameOutDbg("Frame unbuffered "); N2kFrameOutDbgln(CANSendFrameBuf[temp].id); } else return false; } @@ -572,14 +584,14 @@ bool tNMEA2000::SendFrame(unsigned long id, unsigned char len, const unsigned ch if ( !SendFrames() || !CANSendFrame(id,len,buf,wait_sent) ) { // If we can not sent frame immediately, add it to buffer tCANSendFrame *Frame=GetNextFreeCANSendFrame(); if ( Frame==0 ) { - N2kFrameDbg("Frame failed "); N2kFrameDbgln(id); + N2kFrameOutDbg("Frame failed "); N2kFrameOutDbgln(id); return false; } Frame->id=id; Frame->len=len; Frame->wait_sent=wait_sent; for (int i=0; ibuf[i]=buf[i]; - N2kFrameDbg("Frame buffered "); N2kFrameDbgln(id); + N2kFrameOutDbg("Frame buffered "); N2kFrameOutDbgln(id); } return true; @@ -641,8 +653,8 @@ tNMEA2000::tCANSendFrame *tNMEA2000::GetNextFreeCANSendFrame() { //***************************************************************************** void tNMEA2000::SendPendingInformation() { for (int i=0; i