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

Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | List of all members
LIN_Slave_Base Class Reference

LIN slave node base class. More...

`#include <LIN_slave_Base.h>`

Inheritance diagram for LIN_Slave_Base:
[legend]

## Classes
struct | callback_t
| User-defined callback function with data length. More...

## Public Types
enum | version_t : uint8_t { LIN_V1 = 1 , LIN_V2 = 2 }
| LIN protocol version. More...
enum | frame_t : uint8_t { MASTER_REQUEST = 0x10 , SLAVE_RESPONSE = 0x20 }
| LIN frame type. Use high nibble for type, low nibble for number of data bytes -> minimize callback[] size. More...
enum | state_t : uint8_t { STATE_OFF = 0x01 , STATE_WAIT_FOR_BREAK = 0x02 , STATE_WAIT_FOR_SYNC = 0x04 , STATE_WAIT_FOR_PID = 0x08 , STATE_RECEIVING_DATA = 0x10 , STATE_RECEIVING_ECHO = 0x20 , STATE_WAIT_FOR_CHK = 0x40 , STATE_DONE = 0x80 }
| LIN state machine states. 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_SYNC = 0x10 , ERROR_PID = 0x20 , ERROR_MISC = 0x80 }
| LIN error codes. Use bitmasks, as error is latched. Use same as LIN_master_portable. More...

## Public Member Functions
| LIN_Slave_Base (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)
| LIN slave node constructor.
virtual | ~LIN_Slave_Base (void)
| LIN slave 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.
virtual bool | available (void)
| check if a byte is available in Rx buffer. Here dummy
void | resetStateMachine (void)
| Reset LIN state machine.
LIN_Slave_Base::state_t | getState (void)
| Getter for LIN state machine state.
void | resetError (void)
| Clear error of LIN state machine.
LIN_Slave_Base::error_t | getError (void)
| Getter for LIN state machine error.
void | getFrame (LIN_Slave_Base::frame_t &Type, uint8_t &Id, uint8_t &NumData, uint8_t Data[])
| Getter for LIN frame.
void | registerMasterRequestHandler (uint8_t ID, LIN_Slave_Base::LinMessageCallback Fct, uint8_t NumData)
| Attach user callback function for master request frame.
void | registerSlaveResponseHandler (uint8_t ID, LIN_Slave_Base::LinMessageCallback Fct, uint8_t NumData)
| Attach user callback function for slave response frame.
virtual void | handler (void)
| Handle LIN protocol and call user-defined frame callbacks.

## Public Attributes
char | nameLIN [LIN_SLAVE_BUFLEN_NAME]
| LIN node name, e.g. for debug.

## Protected Types
typedef void(* | LinMessageCallback) (uint8_t numData, uint8_t *data)
| Type for frame callback function.

## Protected Member Functions
uint8_t | _calculatePID (uint8_t ID)
| Calculate protected frame ID.
uint8_t | _calculateChecksum (uint8_t NumData, uint8_t Data[])
| Calculate LIN frame checksum.
virtual bool | _getBreakFlag (void)
| Get break detection flag. Is hardware dependent.
virtual void | _resetBreakFlag (void)
| Clear break detection flag. Is hardware dependent.
virtual uint8_t | _serialPeek (void)
| peek next byte from Rx buffer. Here dummy
virtual uint8_t | _serialRead (void)
| read next byte from Rx buffer. Here dummy
virtual void | _serialWrite (uint8_t buf[], uint8_t num)
| write bytes to Tx buffer. Here dummy
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_Slave_Base::version_t | version
| LIN protocol version.
LIN_Slave_Base::state_t | state
| status of LIN state machine
LIN_Slave_Base::error_t | error
| error state. Is latched until cleared
bool | flagBreak
| flag for BREAK detected. Needs to be set in Rx-ISR
LIN_Slave_Base::callback_t | callback [64]
| array of user callback functions for IDs 0x00..0x3F
uint8_t | pid
| protected frame identifier
uint8_t | id
| unprotected frame identifier
LIN_Slave_Base::frame_t | type
| frame type (master request or slave response)
uint8_t | numData
| number of data bytes in frame
uint8_t | bufData [9]
| buffer for data bytes (max. 8B) + checksum
uint8_t | idxData
| current index in bufData
uint32_t | timeoutRx
| timeout [us] for bytes in frame
uint32_t | timeLastRx
| time [us] of last received byte in frame

## Detailed Description

LIN slave node base class.

LIN slave node base class. From this class the actual LIN classes for a Serialx are derived.

Definition at line 51 of file LIN_slave_Base.h.

## Member Typedef Documentation

## ◆ LinMessageCallback

typedef void(* LIN_Slave_Base::LinMessageCallback) (uint8_t numData, uint8_t *data)
| protected

Type for frame callback function.

Definition at line 104 of file LIN_slave_Base.h.

## Member Enumeration Documentation

## ◆ error_t

enum LIN_Slave_Base::error_t : uint8_t

LIN error codes. Use bitmasks, as error is latched. Use same as LIN_master_portable.

Enumerator
NO_ERROR | no error
ERROR_STATE | error in LIN state machine
ERROR_ECHO | error reading response echo
ERROR_TIMEOUT | frame timeout error
ERROR_CHK | LIN checksum error.
ERROR_SYNC | error in SYNC (not 0x55)
ERROR_PID | ID parity error.
ERROR_MISC | misc error, should not occur

Definition at line 87 of file LIN_slave_Base.h.

## ◆ frame_t

enum LIN_Slave_Base::frame_t : uint8_t

LIN frame type. Use high nibble for type, low nibble for number of data bytes -> minimize callback[] size.

Enumerator
MASTER_REQUEST | LIN master request frame.
SLAVE_RESPONSE | LIN slave response frame.

Definition at line 65 of file LIN_slave_Base.h.

## ◆ state_t

enum LIN_Slave_Base::state_t : uint8_t

LIN state machine states. Use bitmasks for fast checking multiple states.

Enumerator
STATE_OFF | LIN interface closed.
STATE_WAIT_FOR_BREAK | no LIN transmission ongoing, wait for BRK
STATE_WAIT_FOR_SYNC | BRK received, wait for SYNC.
STATE_WAIT_FOR_PID | SYNC received, wait for frame PID.
STATE_RECEIVING_DATA | receiving master request data
STATE_RECEIVING_ECHO | receiving slave response echo
STATE_WAIT_FOR_CHK | waiting for checksum
STATE_DONE | frame is completed

Definition at line 73 of file LIN_slave_Base.h.

## ◆ version_t

enum LIN_Slave_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 57 of file LIN_slave_Base.h.

## Constructor & Destructor Documentation

## ◆ LIN_Slave_Base()

LIN_Slave_Base::LIN_Slave_Base | ( | 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`
| ) |  |

LIN slave node constructor.

LIN slave 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

Parameters

  [in] | Version | LIN protocol version (default = v2)
  [in] | NameLIN | LIN node name (default = "Slave")
  [in] | TimeoutRx | timeout [us] for bytes in frame (default = 1500)
  [in] | PinTxEN | optional Tx enable pin (high active) e.g. for LIN via RS485 (default = -127/none)

Definition at line 127 of file LIN_slave_Base.cpp.

## ◆ ~LIN_Slave_Base()

virtual LIN_Slave_Base::~LIN_Slave_Base | ( | void |  | ) |
| inline virtual

LIN slave node destructor, here dummy. Any class with virtual functions should have virtual destructor.

Definition at line 206 of file LIN_slave_Base.h.

## Member Function Documentation

## ◆ _calculateChecksum()

uint8_t LIN_Slave_Base::_calculateChecksum | ( | uint8_t | NumData,
|  | uint8_t | Data[]
| ) |  |
| protected

Calculate LIN frame checksum.

Calculate LIN frame checksum as described in LIN1.x / LIN2.x specs

Parameters

  [in] | NumData | number of data bytes in frame
  [in] | Data | frame data bytes

Returns
  calculated checksum, depending on protocol version

Definition at line 56 of file LIN_slave_Base.cpp.

Here is the caller graph for this function:

## ◆ _calculatePID()

uint8_t LIN_Slave_Base::_calculatePID | ( | uint8_t | ID | ) |
| protected

Calculate protected frame ID.

Calculate protected frame ID as described in LIN2.0 spec "2.3.1.3 Protected identifier field"

Parameters

  [in] | ID | frame ID (protected or unprotected)

Returns
  Protected frame ID

Definition at line 30 of file LIN_slave_Base.cpp.

Here is the caller graph for this function:

## ◆ _disableTransmitter()

void LIN_Slave_Base::_disableTransmitter | ( | void |  | ) |
| inline protected

Disable RS485 transmitter (DE=low)

Definition at line 184 of file LIN_slave_Base.h.

Here is the caller graph for this function:

## ◆ _enableTransmitter()

void LIN_Slave_Base::_enableTransmitter | ( | void |  | ) |
| inline protected

Enable RS485 transmitter (DE=high)

Definition at line 170 of file LIN_slave_Base.h.

Here is the caller graph for this function:

## ◆ _getBreakFlag()

bool LIN_Slave_Base::_getBreakFlag | ( | void |  | ) |
| protected virtual

Get break detection flag. Is hardware dependent.

Get break detection flag. Is hardware dependent, here dummy!

Returns
  status of break detection

Reimplemented in LIN_Slave_HardwareSerial, LIN_Slave_HardwareSerial_ESP32, LIN_Slave_NeoHWSerial_AVR, and LIN_Slave_SoftwareSerial.

Definition at line 93 of file LIN_slave_Base.cpp.

Here is the caller graph for this function:

## ◆ _resetBreakFlag()

void LIN_Slave_Base::_resetBreakFlag | ( | void |  | ) |
| protected virtual

Clear break detection flag. Is hardware dependent.

Clear break detection flag. Is hardware dependent, here dummy!

Reimplemented in LIN_Slave_HardwareSerial, LIN_Slave_HardwareSerial_ESP32, LIN_Slave_NeoHWSerial_AVR, and LIN_Slave_SoftwareSerial.

Definition at line 106 of file LIN_slave_Base.cpp.

Here is the caller graph for this function:

## ◆ _serialPeek()

virtual uint8_t LIN_Slave_Base::_serialPeek | ( | void |  | ) |
| inline protected virtual

peek next byte from Rx buffer. Here dummy

Reimplemented in LIN_Slave_HardwareSerial, LIN_Slave_HardwareSerial_ESP32, LIN_Slave_NeoHWSerial_AVR, and LIN_Slave_SoftwareSerial.

Definition at line 160 of file LIN_slave_Base.h.

## ◆ _serialRead()

virtual uint8_t LIN_Slave_Base::_serialRead | ( | void |  | ) |
| inline protected virtual

read next byte from Rx buffer. Here dummy

Reimplemented in LIN_Slave_HardwareSerial, LIN_Slave_HardwareSerial_ESP32, LIN_Slave_NeoHWSerial_AVR, and LIN_Slave_SoftwareSerial.

Definition at line 163 of file LIN_slave_Base.h.

Here is the caller graph for this function:

## ◆ _serialWrite()

virtual void LIN_Slave_Base::_serialWrite | ( | uint8_t | buf[],
|  | uint8_t | num
| ) |  |
| inline protected virtual

write bytes to Tx buffer. Here dummy

Reimplemented in LIN_Slave_HardwareSerial, LIN_Slave_HardwareSerial_ESP32, LIN_Slave_NeoHWSerial_AVR, and LIN_Slave_SoftwareSerial.

Definition at line 166 of file LIN_slave_Base.h.

Here is the caller graph for this function:

## ◆ available()

virtual bool LIN_Slave_Base::available | ( | void |  | ) |
| inline virtual

check if a byte is available in Rx buffer. Here dummy

Reimplemented in LIN_Slave_HardwareSerial, LIN_Slave_HardwareSerial_ESP32, LIN_Slave_NeoHWSerial_AVR, and LIN_Slave_SoftwareSerial.

Definition at line 216 of file LIN_slave_Base.h.

Here is the caller graph for this function:

## ◆ begin()

void LIN_Slave_Base::begin | ( | uint16_t | Baudrate = `19200` | ) |
| virtual

Open serial interface.

Open serial interface with specified baudrate. Here dummy!

Parameters

  [in] | Baudrate | communication speed [Baud] (default = 19200)

Reimplemented in LIN_Slave_HardwareSerial, LIN_Slave_HardwareSerial_ESP32, LIN_Slave_HardwareSerial_ESP8266, LIN_Slave_NeoHWSerial_AVR, and LIN_Slave_SoftwareSerial.

Definition at line 171 of file LIN_slave_Base.cpp.

Here is the caller graph for this function:

## ◆ end()

void LIN_Slave_Base::end | ( | void |  | ) |
| virtual

Close serial interface.

Close serial interface. Here dummy!

Reimplemented in LIN_Slave_HardwareSerial, LIN_Slave_HardwareSerial_ESP32, LIN_Slave_HardwareSerial_ESP8266, LIN_Slave_NeoHWSerial_AVR, and LIN_Slave_SoftwareSerial.

Definition at line 209 of file LIN_slave_Base.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ getError()

LIN_Slave_Base::error_t LIN_Slave_Base::getError | ( | void |  | ) |
| inline

Getter for LIN state machine error.

Definition at line 260 of file LIN_slave_Base.h.

## ◆ getFrame()

void LIN_Slave_Base::getFrame | ( | LIN_Slave_Base::frame_t & | Type,
|  | uint8_t & | Id,
|  | uint8_t & | NumData,
|  | uint8_t | Data[]
| ) |  |
| inline

Getter for LIN frame.

Definition at line 274 of file LIN_slave_Base.h.

## ◆ getState()

LIN_Slave_Base::state_t LIN_Slave_Base::getState | ( | void |  | ) |
| inline

Getter for LIN state machine state.

Definition at line 233 of file LIN_slave_Base.h.

## ◆ handler()

void LIN_Slave_Base::handler | ( | void |  | ) |
| virtual

Handle LIN protocol and call user-defined frame callbacks.

Handle LIN protocol and call user-defined frame callback functions.

Handle LIN protocol and call user-defined frame callback functions, both for slave request and slave response frames

Reimplemented in LIN_Slave_HardwareSerial, and LIN_Slave_SoftwareSerial.

Definition at line 288 of file LIN_slave_Base.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ registerMasterRequestHandler()

void LIN_Slave_Base::registerMasterRequestHandler | ( | uint8_t | ID,
|  | LIN_Slave_Base::LinMessageCallback | Fct,
|  | uint8_t | NumData
| ) |  |

Attach user callback function for master request frame.

Attach user callback function for master request frame. Callback functions are called by handler() after reception of a master request frame

Parameters

  [in] | ID | frame ID (protected or unprotected)
  [in] | Fct | user callback function
  [in] | NumData | number of frame data bytes

Definition at line 235 of file LIN_slave_Base.cpp.

## ◆ registerSlaveResponseHandler()

void LIN_Slave_Base::registerSlaveResponseHandler | ( | uint8_t | ID,
|  | LIN_Slave_Base::LinMessageCallback | Fct,
|  | uint8_t | NumData
| ) |  |

Attach user callback function for slave response frame.

Attach user callback function for slave response frame. Callback functions are called by handler() after reception of a PID

Parameters

  [in] | ID | frame ID (protected or unprotected)
  [in] | Fct | user callback function
  [in] | NumData | number of frame data bytes

Definition at line 263 of file LIN_slave_Base.cpp.

## ◆ resetError()

void LIN_Slave_Base::resetError | ( | void |  | ) |
| inline

Clear error of LIN state machine.

Definition at line 247 of file LIN_slave_Base.h.

## ◆ resetStateMachine()

void LIN_Slave_Base::resetStateMachine | ( | void |  | ) |
| inline

Reset LIN state machine.

Definition at line 220 of file LIN_slave_Base.h.

## Member Data Documentation

## ◆ baudrate

uint16_t LIN_Slave_Base::baudrate
| protected

communication baudrate [Baud]

Definition at line 119 of file LIN_slave_Base.h.

## ◆ bufData

uint8_t LIN_Slave_Base::bufData[9]
| protected

buffer for data bytes (max. 8B) + checksum

Definition at line 131 of file LIN_slave_Base.h.

## ◆ callback

LIN_Slave_Base::callback_t LIN_Slave_Base::callback[64]
| protected

array of user callback functions for IDs 0x00..0x3F

Definition at line 124 of file LIN_slave_Base.h.

## ◆ error

LIN_Slave_Base::error_t LIN_Slave_Base::error
| protected

error state. Is latched until cleared

Definition at line 122 of file LIN_slave_Base.h.

## ◆ flagBreak

bool LIN_Slave_Base::flagBreak
| protected

flag for BREAK detected. Needs to be set in Rx-ISR

Definition at line 123 of file LIN_slave_Base.h.

## ◆ id

uint8_t LIN_Slave_Base::id
| protected

unprotected frame identifier

Definition at line 128 of file LIN_slave_Base.h.

## ◆ idxData

uint8_t LIN_Slave_Base::idxData
| protected

current index in bufData

Definition at line 132 of file LIN_slave_Base.h.

## ◆ nameLIN

char LIN_Slave_Base::nameLIN[LIN_SLAVE_BUFLEN_NAME]

LIN node name, e.g. for debug.

Definition at line 140 of file LIN_slave_Base.h.

## ◆ numData

uint8_t LIN_Slave_Base::numData
| protected

number of data bytes in frame

Definition at line 130 of file LIN_slave_Base.h.

## ◆ pid

uint8_t LIN_Slave_Base::pid
| protected

protected frame identifier

Definition at line 127 of file LIN_slave_Base.h.

## ◆ pinTxEN

int8_t LIN_Slave_Base::pinTxEN
| protected

optional Tx direction pin, e.g. for LIN via RS485

Definition at line 118 of file LIN_slave_Base.h.

## ◆ state

LIN_Slave_Base::state_t LIN_Slave_Base::state
| protected

status of LIN state machine

Definition at line 121 of file LIN_slave_Base.h.

## ◆ timeLastRx

uint32_t LIN_Slave_Base::timeLastRx
| protected

time [us] of last received byte in frame

Definition at line 134 of file LIN_slave_Base.h.

## ◆ timeoutRx

uint32_t LIN_Slave_Base::timeoutRx
| protected

timeout [us] for bytes in frame

Definition at line 133 of file LIN_slave_Base.h.

## ◆ type

LIN_Slave_Base::frame_t LIN_Slave_Base::type
| protected

frame type (master request or slave response)

Definition at line 129 of file LIN_slave_Base.h.

## ◆ version

LIN_Slave_Base::version_t LIN_Slave_Base::version
| protected

LIN protocol version.

Definition at line 120 of file LIN_slave_Base.h.

The documentation for this class was generated from the following files:

- LIN_slave_Base.h
- LIN_slave_Base.cpp