| LIN_master_portable_Arduino 1.9 Arduino library for Local Interconnect Network master node emulation

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

LIN master node base class. More...

`#include <LIN_master_Base.h>`

Inheritance diagram for LIN_Master_Base:
[legend]

## 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

## Detailed Description

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.

## Member Enumeration Documentation

## ◆ error_t

enum LIN_Master_Base::error_t : uint8_t

LIN error codes. Use bitmasks, as error is latched. Use same as LIN_slave_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_MISC | misc error, should not occur

Definition at line 138 of file LIN_master_Base.h.

## ◆ frame_t

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.

## ◆ state_t

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.

## ◆ version_t

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.

## Constructor & Destructor Documentation

## ◆ LIN_Master_Base()

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

Parameters

  [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.

Here is the caller graph for this function:

## ◆ ~LIN_Master_Base()

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

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.

## Member Function Documentation

## ◆ _calculateChecksum()

uint8_t LIN_Master_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 58 of file LIN_master_Base.cpp.

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

## ◆ _calculatePID()

uint8_t LIN_Master_Base::_calculatePID | ( | void |  | ) |
| protected

Calculate protected frame ID.

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

Returns
  Protected frame ID

Definition at line 29 of file LIN_master_Base.cpp.

Here is the caller graph for this function:

## ◆ _checkFrame()

LIN_Master_Base::error_t LIN_Master_Base::_checkFrame | ( | void |  | ) |
| protected

Check received LIN frame.

Check received LIN frame for echo and frame checksum

Returns
  error check result

Definition at line 92 of file LIN_master_Base.cpp.

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

## ◆ _disableTransmitter()

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

Disable RS485 transmitter (DE=low)

Definition at line 213 of file LIN_master_Base.h.

Here is the caller graph for this function:

## ◆ _enableTransmitter()

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

Enable RS485 transmitter (DE=high)

Definition at line 201 of file LIN_master_Base.h.

Here is the caller graph for this function:

## ◆ _receiveFrame()

LIN_Master_Base::state_t LIN_Master_Base::_receiveFrame | ( | void |  | ) |
| protected virtual

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!

Returns
  current state of LIN state machine

Reimplemented in LIN_Master_HardwareSerial, LIN_Master_HardwareSerial_ESP32, LIN_Master_HardwareSerial_ESP8266, LIN_Master_HardwareSerial_STM32, and LIN_master_SoftwareSerial.

Definition at line 191 of file LIN_master_Base.cpp.

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

## ◆ _sendBreak()

LIN_Master_Base::state_t LIN_Master_Base::_sendBreak | ( | void |  | ) |
| protected virtual

Send LIN break.

Send LIN break (=16bit low). Here dummy!

Returns
  current state of LIN state machine

Reimplemented in LIN_Master_HardwareSerial, LIN_Master_HardwareSerial_ESP32, LIN_Master_HardwareSerial_ESP8266, LIN_Master_HardwareSerial_STM32, and LIN_master_SoftwareSerial.

Definition at line 137 of file LIN_master_Base.cpp.

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

## ◆ _sendFrame()

LIN_Master_Base::state_t LIN_Master_Base::_sendFrame | ( | void |  | ) |
| protected virtual

Send LIN frame body.

Send LIN frame body (request frame: SYNC+ID+DATA[]+CHK; response frame: SYNC+ID). Here dummy!

Returns
  current state of LIN state machine

Reimplemented in LIN_Master_HardwareSerial, LIN_Master_HardwareSerial_ESP32, LIN_Master_HardwareSerial_ESP8266, LIN_Master_HardwareSerial_STM32, and LIN_master_SoftwareSerial.

Definition at line 171 of file LIN_master_Base.cpp.

Here is the caller graph for this function:

## ◆ begin()

void LIN_Master_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_Master_HardwareSerial, LIN_Master_HardwareSerial_ESP32, LIN_Master_HardwareSerial_ESP8266, LIN_Master_HardwareSerial_STM32, and LIN_master_SoftwareSerial.

Definition at line 240 of file LIN_master_Base.cpp.

Here is the caller graph for this function:

## ◆ end()

void LIN_Master_Base::end | ( | void |  | ) |
| virtual

Close serial interface.

Close serial interface. Here dummy!

Reimplemented in LIN_Master_HardwareSerial, LIN_Master_HardwareSerial_ESP32, LIN_Master_HardwareSerial_ESP8266, LIN_Master_HardwareSerial_STM32, and LIN_master_SoftwareSerial.

Definition at line 279 of file LIN_master_Base.cpp.

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

## ◆ getError()

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

Getter for LIN state machine error.

Definition at line 277 of file LIN_master_Base.h.

## ◆ getFrame()

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

Getter for LIN frame.

Definition at line 289 of file LIN_master_Base.h.

Here is the caller graph for this function:

## ◆ getState()

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

Getter for LIN state machine state.

Definition at line 254 of file LIN_master_Base.h.

## ◆ handler()

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

Returns
  LIN state machine state

Definition at line 449 of file LIN_master_Base.cpp.

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

## ◆ receiveSlaveResponse()

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

Parameters

  [in] | Version | LIN protocol version
  [in] | Id | frame idendifier (protected or unprotected)
  [in] | NumData | number of data bytes (0..8)

Returns
  LIN state machine state

Definition at line 378 of file LIN_master_Base.cpp.

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

## ◆ receiveSlaveResponseBlocking()

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

Parameters

  [in] | Version | LIN protocol version
  [in] | Id | frame idendifier (protected or unprotected)
  [in] | NumData | number of data bytes (0..8)
  [out] | Data | data bytes

Returns
  LIN error

Definition at line 420 of file LIN_master_Base.cpp.

Here is the call graph for this function:

## ◆ resetError()

void LIN_Master_Base::resetError | ( | void |  | ) |
| inline

Clear error of LIN state machine.

Definition at line 266 of file LIN_master_Base.h.

## ◆ resetStateMachine()

void LIN_Master_Base::resetStateMachine | ( | void |  | ) |
| inline

Reset LIN state machine.

Definition at line 243 of file LIN_master_Base.h.

## ◆ sendMasterRequest()

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

Parameters

  [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

Returns
  LIN state machine state

Definition at line 305 of file LIN_master_Base.cpp.

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

## ◆ sendMasterRequestBlocking()

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

Parameters

  [in] | Version | LIN protocol version
  [in] | Id | frame idendifier (protected or unprotected)
  [in] | NumData | number of data bytes (0..8)
  [in] | Data | data bytes

Returns
  LIN error

Definition at line 349 of file LIN_master_Base.cpp.

Here is the call graph for this function:

## Member Data Documentation

## ◆ baudrate

uint16_t LIN_Master_Base::baudrate
| protected

communication baudrate [Baud]

Definition at line 154 of file LIN_master_Base.h.

## ◆ bufRx

uint8_t LIN_Master_Base::bufRx[12]
| protected

receive buffer incl. BREAK, SYNC, DATA and CHK (max. 12B)

Definition at line 167 of file LIN_master_Base.h.

## ◆ bufTx

uint8_t LIN_Master_Base::bufTx[12]
| protected

send buffer incl. BREAK, SYNC, DATA and CHK (max. 12B)

Definition at line 165 of file LIN_master_Base.h.

## ◆ error

LIN_Master_Base::error_t LIN_Master_Base::error
| protected

error state. Is latched until cleared

Definition at line 156 of file LIN_master_Base.h.

## ◆ id

uint8_t LIN_Master_Base::id
| protected

LIN frame identifier (protected or unprotected)

Definition at line 163 of file LIN_master_Base.h.

## ◆ lenRx

uint8_t LIN_Master_Base::lenRx
| protected

receive buffer length (max. 12)

Definition at line 166 of file LIN_master_Base.h.

## ◆ lenTx

uint8_t LIN_Master_Base::lenTx
| protected

send buffer length (max. 12)

Definition at line 164 of file LIN_master_Base.h.

## ◆ nameLIN

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.

## ◆ pinTxEN

int8_t LIN_Master_Base::pinTxEN
| protected

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

Definition at line 153 of file LIN_master_Base.h.

## ◆ state

LIN_Master_Base::state_t LIN_Master_Base::state
| protected

status of LIN state machine

Definition at line 155 of file LIN_master_Base.h.

## ◆ timeoutFrame

uint32_t LIN_Master_Base::timeoutFrame
| protected

max. frame duration [us]

Definition at line 158 of file LIN_master_Base.h.

## ◆ timePerByte

uint32_t LIN_Master_Base::timePerByte
| protected

time [us] per byte at specified baudrate

Definition at line 157 of file LIN_master_Base.h.

## ◆ timeStart

uint32_t LIN_Master_Base::timeStart
| protected

starting time [us] for frame timeout

Definition at line 168 of file LIN_master_Base.h.

## ◆ type

LIN_Master_Base::frame_t LIN_Master_Base::type
| protected

LIN frame type.

Definition at line 162 of file LIN_master_Base.h.

## ◆ version

LIN_Master_Base::version_t LIN_Master_Base::version
| protected

LIN protocol version.

Definition at line 161 of file LIN_master_Base.h.

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

- LIN_master_Base.h
- LIN_master_Base.cpp