| LIN_slave_portable_Arduino 1.4 Arduino library for Local Interconnect Network slave node emulation

Loading...
Searching...
No Matches
LIN_slave_SoftwareSerial.h
Go to the documentation of this file.
1
10// assert platform which supports SoftwareSerial. Note: ARDUINO_ARCH_ESP32 requires library ESPSoftwareSerial
11#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
12
13/*-----------------------------------------------------------------------------
14 MODULE DEFINITION FOR MULTIPLE INCLUSION
15-----------------------------------------------------------------------------*/
16#ifndef _LIN_SLAVE_SW_SERIAL_H_
17#define _LIN_SLAVE_SW_SERIAL_H_
18
19
20/*-----------------------------------------------------------------------------
21 INCLUDE FILES
22-----------------------------------------------------------------------------*/
23
24// include required libraries
25#include <LIN_slave_Base.h>
26#include <SoftwareSerial.h>
27
28
29/*-----------------------------------------------------------------------------
30 GLOBAL CLASS
31-----------------------------------------------------------------------------*/
32
38 class LIN_Slave_SoftwareSerial : public LIN_Slave_Base
39{
40 // PRIVATE VARIABLES
41 private:
42
43 SoftwareSerial SWSerial;
44 uint8_t pinRx;
45 uint8_t pinTx;
46 bool inverseLogic;
47 bool flagBreak;
48 uint16_t minFramePause;
49
50
51 // PROTECTED METHODS
52 protected:
53
55 bool _getBreakFlag(void);
56
58 void _resetBreakFlag(void);
59
60
62 inline uint8_t _serialPeek(void) { return SWSerial.peek(); }
63
65 inline uint8_t _serialRead(void) { return SWSerial.read(); }
66
68 inline void _serialWrite(uint8_t buf[], uint8_t num)
69 {
70 SWSerial.stopListening();
71 SWSerial.write(buf, num);
72 SWSerial.flush();
73 SWSerial.listen();
74 }
75
76
77 // PUBLIC METHODS
78 public:
79
81 LIN_Slave_SoftwareSerial(uint8_t PinRx, uint8_t PinTx, bool InverseLogic = false, uint16_t MinFramePause=1000L,
82 LIN_Slave_Base::version_t Version = LIN_Slave_Base::LIN_V2, const char NameLIN[] = "Slave", uint32_t TimeoutRx = 1500L, const int8_t PinTxEN = INT8_MIN);
83
85 void begin(uint16_t Baudrate = 19200);
86
88 void end(void);
89
91 inline bool available(void) { return SWSerial.available(); }
92
94 virtual void handler(void);
95
96}; // class LIN_Slave_SoftwareSerial
97
98
99/*-----------------------------------------------------------------------------
100 END OF MODULE DEFINITION FOR MULTIPLE INLUSION
101-----------------------------------------------------------------------------*/
102#endif // _LIN_SLAVE_SW_SERIAL_H_
103
104#endif // ARDUINO_ARCH_AVR || ARDUINO_ARCH_ESP8266 || ARDUINO_ARCH_ESP32
105
106/*-----------------------------------------------------------------------------
107 END OF FILE
108-----------------------------------------------------------------------------*/
LIN_slave_Base.h
Base class for LIN slave emulation (non-functional)
LIN_Slave_Base
LIN slave node base class.
Definition LIN_slave_Base.h:52
LIN_Slave_Base::version_t
version_t
LIN protocol version.
Definition LIN_slave_Base.h:58
LIN_Slave_Base::LIN_V2
@ LIN_V2
LIN protocol version 2.x.
Definition LIN_slave_Base.h:60
LIN_Slave_SoftwareSerial
LIN slave node class via generic SoftwareSerial.
Definition LIN_slave_SoftwareSerial.h:39
LIN_Slave_SoftwareSerial::_serialPeek
uint8_t _serialPeek(void)
peek next byte from Rx buffer
Definition LIN_slave_SoftwareSerial.h:62
LIN_Slave_SoftwareSerial::handler
virtual void handler(void)
Handle LIN protocol and call user-defined frame handlers.
Definition LIN_slave_SoftwareSerial.cpp:137
LIN_Slave_SoftwareSerial::begin
void begin(uint16_t Baudrate=19200)
Open serial interface.
Definition LIN_slave_SoftwareSerial.cpp:85
LIN_Slave_SoftwareSerial::_resetBreakFlag
void _resetBreakFlag(void)
Clear break detection flag.
Definition LIN_slave_SoftwareSerial.cpp:39
LIN_Slave_SoftwareSerial::end
void end(void)
Close serial interface.
Definition LIN_slave_SoftwareSerial.cpp:111
LIN_Slave_SoftwareSerial::_serialRead
uint8_t _serialRead(void)
read next byte from Rx buffer
Definition LIN_slave_SoftwareSerial.h:65
LIN_Slave_SoftwareSerial::available
bool available(void)
check if a byte is available in Rx buffer
Definition LIN_slave_SoftwareSerial.h:91
LIN_Slave_SoftwareSerial::_serialWrite
void _serialWrite(uint8_t buf[], uint8_t num)
write bytes to Tx buffer (blocking). Disable receive to avoid inter-byte pauses on AVR
Definition LIN_slave_SoftwareSerial.h:68
LIN_Slave_SoftwareSerial::_getBreakFlag
bool _getBreakFlag(void)
Get break detection flag.
Definition LIN_slave_SoftwareSerial.cpp:26