mirror of
https://github.com/Seeed-Studio/Seeed_Arduino_CAN.git
synced 2026-07-28 04:06:45 +00:00
Revert "- Use Hardware Serial in CAN-monitor example"
please uncomment the line to enable Hardware Serial "//#define debug Serial"
This reverts commit 1fc462f2b2.
This commit is contained in:
@@ -15,6 +15,32 @@
|
||||
#include "mcp_can.h"
|
||||
#include "can-serial.h"
|
||||
|
||||
#define LOGGING_ENABLED
|
||||
|
||||
#ifdef LOGGING_ENABLED
|
||||
#define dbg_begin(x) debug.begin(x)
|
||||
#define dbg0(x) debug.print(x)
|
||||
#define dbg1(x) debug.println(x)
|
||||
#define dbg2(x,y) debug.print(x); debug.println(y)
|
||||
#define dbgH(x) debug.print(x,HEX)
|
||||
#define DEBUG_RX_PIN 8
|
||||
#define DEBUG_TX_PIN 9
|
||||
#else
|
||||
#define dbg_begin(x)
|
||||
#define dbg0(x)
|
||||
#define dbg1(x)
|
||||
#define dbg2(x,y)
|
||||
#define dbgH(x)
|
||||
#endif
|
||||
|
||||
#ifdef LOGGING_ENABLED
|
||||
// software serial #2: TX = digital pin 8, RX = digital pin 9
|
||||
// on the Mega, use other pins instead, since 8 and 9 don't work on the Mega
|
||||
SoftwareSerial debug(DEBUG_RX_PIN, DEBUG_TX_PIN);
|
||||
|
||||
//#define debug Serial
|
||||
#endif
|
||||
|
||||
CanSerial* CanSerial::_instance = 0;
|
||||
|
||||
CanSerial* CanSerial::instance() {
|
||||
@@ -24,8 +50,8 @@ CanSerial* CanSerial::instance() {
|
||||
}
|
||||
|
||||
void CanSerial::init(INT8U defaultCanSpeed, const INT8U clock) {
|
||||
Serial.begin(LWUART_DEFAULT_BAUD_RATE); // logging through software serial
|
||||
Serial.println("CAN ASCII. Welcome to debug");
|
||||
dbg_begin(LWUART_DEFAULT_BAUD_RATE); // logging through software serial
|
||||
dbg1("CAN ASCII. Welcome to debug");
|
||||
|
||||
instance()->LWUARTCanSpeedSelection = defaultCanSpeed;
|
||||
instance()->LWUARTMcpModuleClock = clock;
|
||||
@@ -53,7 +79,7 @@ void CanSerial::serialEvent() {
|
||||
|
||||
void CanSerial::initFunc() {
|
||||
if (!inputString.reserve(LWUART_INPUT_STRING_BUFFER_SIZE)) {
|
||||
Serial.print("inputString.reserve failed in initFunc. less optimal String work is expected");
|
||||
dbg0("inputString.reserve failed in initFunc. less optimal String work is expected");
|
||||
}
|
||||
// LWUARTAutoStart = true; //todo: read from eeprom
|
||||
// LWUARTAutoPoll = false; //todo: read from eeprom
|
||||
@@ -72,7 +98,7 @@ void CanSerial::setFilterFunc(INT8U (*userFunc)(INT32U)) {
|
||||
|
||||
void CanSerial::loopFunc() {
|
||||
if (stringComplete) {
|
||||
unsigned int len = inputString.length();
|
||||
int len = inputString.length();
|
||||
if (len > 0 && len < LWUART_FRAME_MAX_SIZE) {
|
||||
strcpy((char*)LWUARTMessage, inputString.c_str());
|
||||
exec();
|
||||
@@ -84,7 +110,7 @@ void CanSerial::loopFunc() {
|
||||
if (LWUARTCanChannelMode != LWUART_STATUS_CAN_CLOSED) {
|
||||
int recv = 0;
|
||||
while (CAN_MSGAVAIL == checkReceive() && recv++<5) {
|
||||
Serial.print('+');
|
||||
dbg0('+');
|
||||
if (CAN_OK == receiveSingleFrame()) {
|
||||
Serial.write(LWUART_CR);
|
||||
}
|
||||
@@ -103,8 +129,7 @@ void CanSerial::serialEventFunc() {
|
||||
}
|
||||
|
||||
INT8U CanSerial::exec() {
|
||||
Serial.print("Command received:");
|
||||
Serial.println(inputString);
|
||||
dbg2("Command received:", inputString);
|
||||
LWUARTLastErr = parseAndRunCommand();
|
||||
switch (LWUARTLastErr) {
|
||||
case LWUART_OK:
|
||||
@@ -501,12 +526,15 @@ void CanSerial::parseCanExtId() {
|
||||
void HexHelper::printFullByte(INT8U b) {
|
||||
if (b < 0x10) {
|
||||
Serial.print('0');
|
||||
// dbg0('0');
|
||||
}
|
||||
Serial.print(b, HEX);
|
||||
//dbgH(b);
|
||||
}
|
||||
|
||||
void HexHelper::printNibble(INT8U b) {
|
||||
Serial.print(b & 0x0F, HEX);
|
||||
//dbgH(b & 0x0F);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,12 +17,33 @@
|
||||
|
||||
#include "mcp_can.h"
|
||||
|
||||
|
||||
#define LOGGING_ENABLED
|
||||
|
||||
#ifdef LOGGING_ENABLED
|
||||
#include "SoftwareSerial.h"
|
||||
#define dbg_begin(x) debug.begin(x)
|
||||
#define dbg0(x) debug.print(x)
|
||||
#define dbg1(x) debug.println(x)
|
||||
#define dbg2(x,y) debug.print(x); debug.println(y)
|
||||
#define dbgH(x) debug.print(x,HEX)
|
||||
#define DEBUG_RX_PIN 8
|
||||
#define DEBUG_TX_PIN 9
|
||||
#else
|
||||
#define dbg_begin(x)
|
||||
#define dbg0(x)
|
||||
#define dbg1(x)
|
||||
#define dbg2(x,y)
|
||||
#define dbgH(x)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define LWUART_LAWICEL_VERSION_STR "V1013"
|
||||
#define LWUART_LAWICEL_SERIAL_NUM "NA123"
|
||||
#define LWUART_CAN_BUS_SHIELD_CS_PIN 10
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Commands not supported/not implemented:
|
||||
@@ -71,7 +92,7 @@
|
||||
#define HIGH_WORD(x) ((unsigned short)(((x)>>16)&0xFFFF))
|
||||
|
||||
#ifndef INT32U
|
||||
#define INT32U unsigned long
|
||||
#define INT32U unsigned long
|
||||
#endif
|
||||
|
||||
#ifndef INT16U
|
||||
|
||||
Reference in New Issue
Block a user