![]() |
LIN_master_portable_Arduino 1.4
Arduino library for Local Interconnect Network master node emulation
|
LIN master node base class. More...
#include <LIN_master_Base.h>

Public Types | |
| enum | version_t : uint8_t { LIN_V1 = 1 , LIN_V2 = 2 } |
| LIN protocol version. More... | |
| enum | frame_t : uint8_t { MASTER_REQUEST = 0x01 , SLAVE_RESPONSE = 0x02 } |
| LIN frame type. More... | |
| enum | state_t : uint8_t { STATE_OFF = 0x01 , STATE_IDLE = 0x02 , STATE_BREAK = 0x04 , STATE_BODY = 0x08 , STATE_DONE = 0x10 } |
| state of LIN master state machine. Use bitmasks for fast checking multiple states More... | |
| enum | error_t : uint8_t { NO_ERROR = 0x00 , ERROR_STATE = 0x01 , ERROR_ECHO = 0x02 , ERROR_TIMEOUT = 0x04 , ERROR_CHK = 0x08 , ERROR_MISC = 0x80 } |
| LIN error codes. Use bitmasks, as error is latched. Use same as LIN_slave_portable. More... | |
Public Member Functions | |
| LIN_Master_Base (const char NameLIN[]="Master", const int8_t PinTxEN=INT8_MIN) | |
| LIN master node constructor. | |
| virtual | ~LIN_Master_Base (void) |
| LIN master node destructor, here dummy. Any class with virtual functions should have virtual destructor. | |
| virtual void | begin (uint16_t Baudrate=19200) |
| Open serial interface. | |
| virtual void | end (void) |
| Close serial interface. | |
| void | resetStateMachine (void) |
| Reset LIN state machine. | |
| LIN_Master_Base::state_t | getState (void) |
| Getter for LIN state machine state. | |
| void | resetError (void) |
| Clear error of LIN state machine. | |
| LIN_Master_Base::error_t | getError (void) |
| Getter for LIN state machine error. | |
| void | getFrame (LIN_Master_Base::frame_t &Type, uint8_t &Id, uint8_t &NumData, uint8_t Data[]) |
| Getter for LIN frame. | |
| LIN_Master_Base::state_t | sendMasterRequest (LIN_Master_Base::version_t Version=LIN_Master_Base::LIN_V2, uint8_t Id=0x00, uint8_t NumData=0, uint8_t Data[]=NULL) |
| Start sending a LIN master request frame in background (if supported) | |
| LIN_Master_Base::error_t | sendMasterRequestBlocking (LIN_Master_Base::version_t Version=LIN_Master_Base::LIN_V2, uint8_t Id=0x00, uint8_t NumData=0, uint8_t Data[]=NULL) |
| Send a blocking LIN master request frame (no background operation) | |
| LIN_Master_Base::state_t | receiveSlaveResponse (LIN_Master_Base::version_t Version=LIN_Master_Base::LIN_V2, uint8_t Id=0x00, uint8_t NumData=0) |
| Start sending a LIN slave response frame in background (if supported) | |
| LIN_Master_Base::error_t | receiveSlaveResponseBlocking (LIN_Master_Base::version_t Version=LIN_Master_Base::LIN_V2, uint8_t Id=0x00, uint8_t NumData=0, uint8_t *Data=NULL) |
| Send a blocking LIN slave response frame (no background operation) | |
| LIN_Master_Base::state_t | handler (void) |
| Handle LIN background operation (call until STATE_DONE is returned) | |
Public Attributes | |
| char | nameLIN [LIN_MASTER_BUFLEN_NAME] |
| LIN node name, e.g. for debug. | |
Protected Member Functions | |
| uint8_t | _calculatePID (void) |
| Calculate protected frame ID. | |
| uint8_t | _calculateChecksum (uint8_t NumData, uint8_t Data[]) |
| Calculate LIN frame checksum. | |
| LIN_Master_Base::error_t | _checkFrame (void) |
| Check received LIN frame. | |
| virtual LIN_Master_Base::state_t | _sendBreak (void) |
| Send LIN break. | |
| virtual LIN_Master_Base::state_t | _sendFrame (void) |
| Send LIN frame body. | |
| virtual LIN_Master_Base::state_t | _receiveFrame (void) |
| Receive LIN frame. | |
| void | _enableTransmitter (void) |
| Enable RS485 transmitter (DE=high) | |
| void | _disableTransmitter (void) |
| Disable RS485 transmitter (DE=low) | |
Protected Attributes | |
| int8_t | pinTxEN |
| optional Tx direction pin, e.g. for LIN via RS485 | |
| uint16_t | baudrate |
| communication baudrate [Baud] | |
| LIN_Master_Base::state_t | state |
| status of LIN state machine | |
| LIN_Master_Base::error_t | error |
| error state. Is latched until cleared | |
| uint32_t | timePerByte |
| time [us] per byte at specified baudrate | |
| uint32_t | timeoutFrame |
| max. frame duration [us] | |
| LIN_Master_Base::version_t | version |
| LIN protocol version. | |
| LIN_Master_Base::frame_t | type |
| LIN frame type. | |
| uint8_t | id |
| LIN frame identifier (protected or unprotected) | |
| uint8_t | lenTx |
| send buffer length (max. 12) | |
| uint8_t | bufTx [12] |
| send buffer incl. BREAK, SYNC, DATA and CHK (max. 12B) | |
| uint8_t | lenRx |
| receive buffer length (max. 12) | |
| uint8_t | bufRx [12] |
| receive buffer incl. BREAK, SYNC, DATA and CHK (max. 12B) | |
| uint32_t | timeStart |
| starting time [us] for frame timeout | |
LIN master node base class.
LIN master node base class. From this class the actual LIN classes for a Serialx are derived.
Definition at line 105 of file LIN_master_Base.h.
| enum LIN_Master_Base::error_t : uint8_t |
LIN error codes. Use bitmasks, as error is latched. Use same as LIN_slave_portable.
Definition at line 138 of file LIN_master_Base.h.
| enum LIN_Master_Base::frame_t : uint8_t |
LIN frame type.
| Enumerator | |
|---|---|
| MASTER_REQUEST | LIN master request frame. |
| SLAVE_RESPONSE | LIN slave response frame. |
Definition at line 119 of file LIN_master_Base.h.
| enum LIN_Master_Base::state_t : uint8_t |
state of LIN master state machine. Use bitmasks for fast checking multiple states
| Enumerator | |
|---|---|
| STATE_OFF | LIN interface closed. |
| STATE_IDLE | no LIN transmission ongoing |
| STATE_BREAK | sync break is being transmitted |
| STATE_BODY | rest of frame is being sent/received |
| STATE_DONE | frame completed |
Definition at line 127 of file LIN_master_Base.h.
| enum LIN_Master_Base::version_t : uint8_t |
LIN protocol version.
| Enumerator | |
|---|---|
| LIN_V1 | LIN protocol version 1.x. |
| LIN_V2 | LIN protocol version 2.x. |
Definition at line 111 of file LIN_master_Base.h.
| LIN_Master_Base::LIN_Master_Base | ( | const char | NameLIN[] = "Master", |
| const int8_t | PinTxEN = INT8_MIN |
||
| ) |
LIN master node constructor.
LIN master node constructor. Initialize class variables to default values. For an explanation of the LIN bus and protocol e.g. see https://en.wikipedia.org/wiki/Local_Interconnect_Network. Optional direction switching via TxEn pin, e.g. for LIN via RS485
| [in] | NameLIN | LIN node name (default = "Master") |
| [in] | PinTxEN | optional Tx enable pin (high active) e.g. for LIN via RS485 (default = -127/none) |
Definition at line 219 of file LIN_master_Base.cpp.
|
inlinevirtual |
LIN master node destructor, here dummy. Any class with virtual functions should have virtual destructor.
Definition at line 232 of file LIN_master_Base.h.
|
protected |
Calculate LIN frame checksum.
Calculate LIN frame checksum as described in LIN1.x / LIN2.x specs
| [in] | NumData | number of data bytes in frame |
| [in] | Data | frame data bytes |
Definition at line 58 of file LIN_master_Base.cpp.


|
protected |
Calculate protected frame ID.
Calculate protected frame ID as described in LIN2.0 spec "2.3.1.3 Protected identifier field"
Definition at line 29 of file LIN_master_Base.cpp.

|
protected |
Check received LIN frame.
Check received LIN frame for echo and frame checksum
Definition at line 92 of file LIN_master_Base.cpp.


|
inlineprotected |
Disable RS485 transmitter (DE=low)
Definition at line 213 of file LIN_master_Base.h.

|
inlineprotected |
Enable RS485 transmitter (DE=high)
Definition at line 201 of file LIN_master_Base.h.

|
protectedvirtual |
Receive LIN frame.
Receive and check LIN frame.
Receive and check LIN frame (request frame: check echo; response frame: check header echo & checksum). Here dummy!
Reimplemented in LIN_Master_HardwareSerial, LIN_Master_HardwareSerial_ESP32, LIN_Master_HardwareSerial_ESP8266, and LIN_Master_SoftwareSerial.
Definition at line 191 of file LIN_master_Base.cpp.


|
protectedvirtual |
Send LIN break.
Send LIN break (=16bit low). Here dummy!
Reimplemented in LIN_Master_HardwareSerial, LIN_Master_HardwareSerial_ESP32, LIN_Master_HardwareSerial_ESP8266, and LIN_Master_SoftwareSerial.
Definition at line 137 of file LIN_master_Base.cpp.


|
protectedvirtual |
Send LIN frame body.
Send LIN frame body (request frame: SYNC+ID+DATA[]+CHK; response frame: SYNC+ID). Here dummy!
Reimplemented in LIN_Master_HardwareSerial, LIN_Master_HardwareSerial_ESP32, LIN_Master_HardwareSerial_ESP8266, and LIN_Master_SoftwareSerial.
Definition at line 171 of file LIN_master_Base.cpp.

|
virtual |
Open serial interface.
Open serial interface with specified baudrate. Here dummy!
| [in] | Baudrate | communication speed [Baud] (default = 19200) |
Reimplemented in LIN_Master_HardwareSerial, LIN_Master_HardwareSerial_ESP32, LIN_Master_HardwareSerial_ESP8266, and LIN_Master_SoftwareSerial.
Definition at line 240 of file LIN_master_Base.cpp.

|
virtual |
Close serial interface.
Close serial interface. Here dummy!
Reimplemented in LIN_Master_HardwareSerial, LIN_Master_HardwareSerial_ESP32, LIN_Master_HardwareSerial_ESP8266, and LIN_Master_SoftwareSerial.
Definition at line 279 of file LIN_master_Base.cpp.


|
inline |
Getter for LIN state machine error.
Definition at line 277 of file LIN_master_Base.h.
|
inline |
Getter for LIN frame.
Definition at line 289 of file LIN_master_Base.h.

|
inline |
Getter for LIN state machine state.
Definition at line 254 of file LIN_master_Base.h.
| LIN_Master_Base::state_t LIN_Master_Base::handler | ( | void | ) |
Handle LIN background operation (call until STATE_DONE is returned)
Handle LIN background operation (call until STATE_DONE is returned). For an explanation of the LIN bus and protocol e.g. see https://en.wikipedia.org/wiki/Local_Interconnect_Network
Definition at line 449 of file LIN_master_Base.cpp.


| LIN_Master_Base::state_t LIN_Master_Base::receiveSlaveResponse | ( | LIN_Master_Base::version_t | Version = LIN_Master_Base::LIN_V2, |
| uint8_t | Id = 0x00, |
||
| uint8_t | NumData = 0 |
||
| ) |
Start sending a LIN slave response frame in background (if supported)
Send/receive a blocking LIN slave response frame (no background operation)
Send/receive a blocking LIN slave response frame (no background operation). For an explanation of the LIN bus and protocol e.g. see https://en.wikipedia.org/wiki/Local_Interconnect_Network
| [in] | Version | LIN protocol version |
| [in] | Id | frame idendifier (protected or unprotected) |
| [in] | NumData | number of data bytes (0..8) |
Definition at line 378 of file LIN_master_Base.cpp.


| LIN_Master_Base::error_t LIN_Master_Base::receiveSlaveResponseBlocking | ( | LIN_Master_Base::version_t | Version = LIN_Master_Base::LIN_V2, |
| uint8_t | Id = 0x00, |
||
| uint8_t | NumData = 0, |
||
| uint8_t * | Data = NULL |
||
| ) |
Send a blocking LIN slave response frame (no background operation)
Send/receive a blocking LIN slave response frame (no background operation)
Send/receive a blocking LIN slave response frame (no background operation). For an explanation of the LIN bus and protocol e.g. see https://en.wikipedia.org/wiki/Local_Interconnect_Network
| [in] | Version | LIN protocol version |
| [in] | Id | frame idendifier (protected or unprotected) |
| [in] | NumData | number of data bytes (0..8) |
| [out] | Data | data bytes |
Definition at line 420 of file LIN_master_Base.cpp.

|
inline |
Clear error of LIN state machine.
Definition at line 266 of file LIN_master_Base.h.
|
inline |
Reset LIN state machine.
Definition at line 243 of file LIN_master_Base.h.
| LIN_Master_Base::state_t LIN_Master_Base::sendMasterRequest | ( | LIN_Master_Base::version_t | Version = LIN_Master_Base::LIN_V2, |
| uint8_t | Id = 0x00, |
||
| uint8_t | NumData = 0, |
||
| uint8_t | Data[] = NULL |
||
| ) |
Start sending a LIN master request frame in background (if supported)
Start sending a LIN master request frame in background (if supported). Background handling is handling by handler(). For an explanation of the LIN bus and protocol e.g. see https://en.wikipedia.org/wiki/Local_Interconnect_Network
| [in] | Version | LIN protocol version (default = v2) |
| [in] | Id | frame idendifier (protected or unprotected) |
| [in] | NumData | number of data bytes (0..8) |
| [in] | Data | data bytes |
Definition at line 305 of file LIN_master_Base.cpp.


| LIN_Master_Base::error_t LIN_Master_Base::sendMasterRequestBlocking | ( | LIN_Master_Base::version_t | Version = LIN_Master_Base::LIN_V2, |
| uint8_t | Id = 0x00, |
||
| uint8_t | NumData = 0, |
||
| uint8_t | Data[] = NULL |
||
| ) |
Send a blocking LIN master request frame (no background operation)
Send a blocking LIN master request frame (no background operation). For an explanation of the LIN bus and protocol e.g. see https://en.wikipedia.org/wiki/Local_Interconnect_Network
| [in] | Version | LIN protocol version |
| [in] | Id | frame idendifier (protected or unprotected) |
| [in] | NumData | number of data bytes (0..8) |
| [in] | Data | data bytes |
Definition at line 349 of file LIN_master_Base.cpp.

|
protected |
communication baudrate [Baud]
Definition at line 154 of file LIN_master_Base.h.
|
protected |
receive buffer incl. BREAK, SYNC, DATA and CHK (max. 12B)
Definition at line 167 of file LIN_master_Base.h.
|
protected |
send buffer incl. BREAK, SYNC, DATA and CHK (max. 12B)
Definition at line 165 of file LIN_master_Base.h.
|
protected |
error state. Is latched until cleared
Definition at line 156 of file LIN_master_Base.h.
|
protected |
LIN frame identifier (protected or unprotected)
Definition at line 163 of file LIN_master_Base.h.
|
protected |
receive buffer length (max. 12)
Definition at line 166 of file LIN_master_Base.h.
|
protected |
send buffer length (max. 12)
Definition at line 164 of file LIN_master_Base.h.
| char LIN_Master_Base::nameLIN[LIN_MASTER_BUFLEN_NAME] |
LIN node name, e.g. for debug.
Definition at line 174 of file LIN_master_Base.h.
|
protected |
optional Tx direction pin, e.g. for LIN via RS485
Definition at line 153 of file LIN_master_Base.h.
|
protected |
status of LIN state machine
Definition at line 155 of file LIN_master_Base.h.
|
protected |
max. frame duration [us]
Definition at line 158 of file LIN_master_Base.h.
|
protected |
time [us] per byte at specified baudrate
Definition at line 157 of file LIN_master_Base.h.
|
protected |
starting time [us] for frame timeout
Definition at line 168 of file LIN_master_Base.h.
|
protected |
LIN frame type.
Definition at line 162 of file LIN_master_Base.h.
|
protected |
LIN protocol version.
Definition at line 161 of file LIN_master_Base.h.