@@ -29,12 +29,14 @@ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
29
#include < string.h>
30
30
#include < stdlib.h>
31
31
32
- #define DebugStream Serial
32
+ // #define DebugStream Serial // outputs debug messages to the serial console (only for Arduino)
33
+ #define DebugStream (*ForwardStream) // outputs debug messages to same destination as ForwardStream
33
34
34
35
// #define NMEA2000_FRAME_ERROR_DEBUG
35
36
// #define NMEA2000_FRAME_IN_DEBUG
36
37
// #define NMEA2000_FRAME_OUT_DEBUG
37
- // #define NMEA2000_MSG_DEBUG
38
+ // #define NMEA2000_MSG_TX_DEBUG
39
+ // #define NMEA2000_MSG_RX_DEBUG // This one spams the console with every parsed message
38
40
// #define NMEA2000_BUF_DEBUG
39
41
// #define NMEA2000_DEBUG
40
42
@@ -68,7 +70,7 @@ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
68
70
# define N2kFrameOutDbgln (fmt, args... )
69
71
#endif
70
72
71
- #if defined(NMEA2000_MSG_DEBUG )
73
+ #if defined(NMEA2000_MSG_TX_DEBUG )
72
74
# define N2kMsgDbgStart (fmt, args... ) DebugStream.print(N2kMillis()); DebugStream.print(" : " ); DebugStream.print (fmt , ## args)
73
75
# define N2kMsgDbg (fmt, args... ) DebugStream.print (fmt , ## args)
74
76
# define N2kMsgDbgln (fmt, args... ) DebugStream.println (fmt , ## args)
@@ -78,6 +80,16 @@ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
78
80
# define N2kMsgDbgln (fmt, args... )
79
81
#endif
80
82
83
+ #if defined(NMEA2000_MSG_RX_DEBUG)
84
+ # define N2kMsgRxDbgStart (fmt, args... ) DebugStream.print(N2kMillis()); DebugStream.print(" : " ); DebugStream.print (fmt , ## args)
85
+ # define N2kMsgRxDbg (fmt, args... ) DebugStream.print (fmt , ## args)
86
+ # define N2kMsgRxDbgln (fmt, args... ) DebugStream.println (fmt , ## args)
87
+ #else
88
+ # define N2kMsgRxDbgStart (fmt, args... )
89
+ # define N2kMsgRxDbg (fmt, args... )
90
+ # define N2kMsgRxDbgln (fmt, args... )
91
+ #endif
92
+
81
93
#if defined(NMEA2000_BUF_DEBUG)
82
94
# define DbgPrintBuf (len, buf, addln ) PrintBuf(&DebugStream, len, buf, addln)
83
95
#else
@@ -2032,7 +2044,7 @@ uint8_t tNMEA2000::SetN2kCANBufMsg(unsigned long canId, unsigned char len, unsig
2032
2044
);
2033
2045
MsgIndex++);
2034
2046
if (MsgIndex<MaxN2kCANMsgs) { // we found start for this message, so add data to it.
2035
- N2kMsgDbgStart (" Use msg slot: " ); N2kMsgDbgln (MsgIndex);
2047
+ N2kMsgRxDbgStart (" Use msg slot: " ); N2kMsgRxDbgln (MsgIndex);
2036
2048
if (N2kCANMsgBuf[MsgIndex].LastFrame +1 == buf[0 ]) { // Right frame is coming
2037
2049
N2kCANMsgBuf[MsgIndex].LastFrame =buf[0 ];
2038
2050
CopyBufToCANMsg (N2kCANMsgBuf[MsgIndex],1 ,len,buf);
@@ -2053,7 +2065,7 @@ uint8_t tNMEA2000::SetN2kCANBufMsg(unsigned long canId, unsigned char len, unsig
2053
2065
FindFreeCANMsgIndex (PGN,Source,Destination,MsgIndex);
2054
2066
#endif
2055
2067
if ( MsgIndex<MaxN2kCANMsgs ) { // we found free place, so handle frame
2056
- N2kMsgDbgStart (" Use msg slot: " ); N2kMsgDbgln (MsgIndex);
2068
+ N2kMsgRxDbgStart (" Use msg slot: " ); N2kMsgRxDbgln (MsgIndex);
2057
2069
N2kCANMsgBuf[MsgIndex].FreeMsg =false ;
2058
2070
N2kCANMsgBuf[MsgIndex].KnownMessage =KnownMessage;
2059
2071
N2kCANMsgBuf[MsgIndex].SystemMessage =SystemMessage;
@@ -2631,17 +2643,17 @@ void tNMEA2000::ParseMessages() {
2631
2643
2632
2644
while (FramesRead<MaxReadFramesOnParse && CANGetFrame (canId,len,buf) ) { // check if data coming
2633
2645
FramesRead++;
2634
- N2kMsgDbgStart (" Received frame, can ID:" ); N2kMsgDbg (canId); N2kMsgDbg (" len:" ); N2kMsgDbg (len); N2kMsgDbg (" data:" ); DbgPrintBuf (len,buf,false ); N2kMsgDbgln ();
2646
+ N2kMsgRxDbgStart (" Received frame, can ID:" ); N2kMsgRxDbg (canId); N2kMsgRxDbg (" len:" ); N2kMsgRxDbg (len); N2kMsgRxDbg (" data:" ); DbgPrintBuf (len,buf,false ); N2kMsgRxDbgln ();
2635
2647
MsgIndex=SetN2kCANBufMsg (canId,len,buf);
2636
2648
if (MsgIndex<MaxN2kCANMsgs) {
2637
2649
if ( !HandleReceivedSystemMessage (MsgIndex) ) {
2638
- N2kMsgDbgStart (" - Non system message, MsgIndex: " ); N2kMsgDbgln (MsgIndex);
2650
+ N2kMsgRxDbgStart (" - Non system message, MsgIndex: " ); N2kMsgRxDbgln (MsgIndex);
2639
2651
ForwardMessage (N2kCANMsgBuf[MsgIndex]);
2640
2652
}
2641
2653
// N2kCANMsgBuf[MsgIndex].N2kMsg.Print(Serial);
2642
2654
RunMessageHandlers (N2kCANMsgBuf[MsgIndex].N2kMsg );
2643
2655
N2kCANMsgBuf[MsgIndex].FreeMessage ();
2644
- N2kMsgDbgStart (" - Free message, MsgIndex: " ); N2kMsgDbg (MsgIndex); N2kMsgDbgln ();
2656
+ N2kMsgRxDbgStart (" - Free message, MsgIndex: " ); N2kMsgRxDbg (MsgIndex); N2kMsgRxDbgln ();
2645
2657
}
2646
2658
}
2647
2659
0 commit comments