Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: slcan.h
- Revision:
- 0:f2565808eea5
- Child:
- 2:1327e61cc56b
diff -r 000000000000 -r f2565808eea5 slcan.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/slcan.h Sat Jun 04 04:40:58 2016 +0000
@@ -0,0 +1,82 @@
+#ifndef SLCAN_H_INCLUDED
+#define SLCAN_H_INCLUDED
+
+#include <mbed.h>
+#include <USBSerial.h>
+
+class SLCANBase {
+public:
+ bool update();
+
+protected:
+ SLCANBase();
+ virtual ~SLCANBase();
+
+ // To be implemented by subclasses
+ virtual bool setBaudrate(int baudrate) = 0;
+ virtual bool setMode(CAN::Mode mode) = 0;
+ virtual bool transmitMessage(CANMessage& msg) = 0;
+
+ virtual bool processCommands() = 0;
+ virtual bool processCANMessages() = 0;
+ virtual bool flush() = 0;
+
+ // Shared amongst subclasses
+ static size_t formatCANMessage(const CANMessage& msg, char* buf, size_t max_len);
+ static size_t formattedCANMessageLength(const CANMessage& msg);
+ bool execCommand(const char* command);
+
+private:
+ bool execConfigCommand(const char* command);
+ bool execTransmitCommand(const char* command);
+};
+
+class USBSLCAN : public SLCANBase {
+public:
+ USBSLCAN(USBSerial& stream, CAN& can);
+protected:
+ virtual bool setBaudrate(int baudrate);
+ virtual bool setMode(CAN::Mode mode);
+ virtual bool transmitMessage(CANMessage& msg);
+
+ virtual bool processCommands();
+ virtual bool processCANMessages();
+ virtual bool flush();
+
+ bool getNextCANMessage(CANMessage& msg);
+private:
+ USBSerial& stream;
+ CAN& can;
+ CANMessage queuedMessage;
+ bool messageQueued;
+ bool commandQueued;
+ bool commandOverflow;
+ char inputCommandBuffer[32];
+ char outputPacketBuffer[64];
+ size_t inputCommandLen;
+ size_t outputPacketLen;
+};
+
+class SerialSLCAN : public SLCANBase {
+public:
+ SerialSLCAN(Serial& stream, CAN& can);
+protected:
+ virtual bool setBaudrate(int baudrate);
+ virtual bool setMode(CAN::Mode mode);
+ virtual bool transmitMessage(CANMessage& msg);
+
+ virtual bool processCommands();
+ virtual bool processCANMessages();
+ virtual bool flush();
+
+ bool getNextCANMessage(CANMessage& msg);
+private:
+ Serial& stream;
+ CAN& can;
+ bool commandQueued;
+ bool commandOverflow;
+ char inputCommandBuffer[32];
+ size_t inputCommandLen;
+};
+
+#endif
\ No newline at end of file