14#if defined(LIN_MASTER_DEBUG_SERIAL)
15 #warning Debug interface is active, see file 'LIN_master_Base.h'
35 pid_tmp = (uint8_t) (this->
id & 0x3F);
36 tmp = (uint8_t) ((pid_tmp ^ (pid_tmp>>1) ^ (pid_tmp>>2) ^ (pid_tmp>>4)) & 0x01);
37 pid_tmp |= (uint8_t) (tmp << 6);
38 tmp = (uint8_t) (~((pid_tmp>>1) ^ (pid_tmp>>3) ^ (pid_tmp>>4) ^ (pid_tmp>>5)) & 0x01);
39 pid_tmp |= (uint8_t) (tmp << 7);
42 DEBUG_PRINT(3,
"PID=0x%02X", pid_tmp);
65 if (!((this->
version ==
LIN_V1) || (
id == 0x3C) || (
id == 0x3D)))
69 for (uint8_t i = 0; i < NumData; i++)
71 chk += (uint16_t) (Data[i]);
75 chk = (uint8_t)(0xFF - ((uint8_t) chk));
78 DEBUG_PRINT(3,
"CHK=0x%02X", chk);
95 for (uint8_t i = 0; i < this->
lenTx; i++)
100 DEBUG_PRINT(1,
"echo error: Tx[%d]=0x%02X, Rx[%d]=0x%02X", (
int) i, (
int) this->
bufTx[i], (
int) i, (
int) this->
bufRx[i]);
123 DEBUG_PRINT(3,
"ok");
143 DEBUG_PRINT(1,
"wrong state 0x%02X", this->
state);
157 DEBUG_PRINT(3,
"ok");
177 DEBUG_PRINT(2,
"ok");
198 DEBUG_PRINT(2,
"ok");
224 memcpy(this->
nameLIN, NameLIN, LIN_MASTER_BUFLEN_NAME);
243 #if defined(LIN_MASTER_DEBUG_SERIAL)
244 LIN_MASTER_DEBUG_SERIAL.begin(115200);
245 #if defined(LIN_MASTER_DEBUG_PORT_TIMEOUT) && (LIN_MASTER_DEBUG_PORT_TIMEOUT > 0)
246 uint32_t startMillis = millis();
247 while ((!LIN_MASTER_DEBUG_SERIAL) && (millis() - startMillis < LIN_MASTER_DEBUG_PORT_TIMEOUT));
249 while (!LIN_MASTER_DEBUG_SERIAL);
264 digitalWrite(this->
pinTxEN, LOW);
265 pinMode(this->
pinTxEN, OUTPUT);
269 DEBUG_PRINT(2,
"BR=%d", (
int) Baudrate);
311 this->
lenTx = NumData + 4;
312 this->
bufTx[0] = 0x00;
313 this->
bufTx[1] = 0x55;
315 memcpy(this->
bufTx+3, Data, NumData);
320 memset(this->
bufRx, 0, 12);
385 this->
bufTx[0] = 0x00;
386 this->
bufTx[1] = 0x55;
388 this->
lenRx = NumData + 4;
391 memset(this->
bufRx, 0, 12);
452 DEBUG_PRINT(3,
"state=%d", (
int) this->
state);
475 DEBUG_PRINT(1,
"wrong state 0x%02X", this->state);
Base class for LIN master emulation (non-functional)
uint8_t lenRx
receive buffer length (max. 12)
virtual void begin(uint16_t Baudrate=19200)
Open serial interface.
uint16_t baudrate
communication baudrate [Baud]
@ MASTER_REQUEST
LIN master request frame.
@ SLAVE_RESPONSE
LIN slave response frame.
void getFrame(LIN_Master_Base::frame_t &Type, uint8_t &Id, uint8_t &NumData, uint8_t Data[])
Getter for LIN frame.
uint8_t bufTx[12]
send buffer incl. BREAK, SYNC, DATA and CHK (max. 12B)
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)
version_t
LIN protocol version.
@ LIN_V1
LIN protocol version 1.x.
uint8_t _calculatePID(void)
Calculate protected frame ID.
LIN_Master_Base::error_t _checkFrame(void)
Check received LIN frame.
LIN_Master_Base::error_t error
error state. Is latched until cleared
char nameLIN[LIN_MASTER_BUFLEN_NAME]
LIN node name, e.g. for debug.
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)
uint32_t timeStart
starting time [us] for frame timeout
int8_t pinTxEN
optional Tx direction pin, e.g. for LIN via RS485
uint8_t lenTx
send buffer length (max. 12)
LIN_Master_Base::state_t handler(void)
Handle LIN background operation (call until STATE_DONE is returned)
uint8_t _calculateChecksum(uint8_t NumData, uint8_t Data[])
Calculate LIN frame checksum.
LIN_Master_Base::state_t state
status of LIN state machine
virtual LIN_Master_Base::state_t _sendFrame(void)
Send LIN frame body.
void _disableTransmitter(void)
Disable RS485 transmitter (DE=low)
error_t
LIN error codes. Use bitmasks, as error is latched. Use same as LIN_slave_portable.
@ ERROR_STATE
error in LIN state machine
@ ERROR_CHK
LIN checksum error.
@ ERROR_ECHO
error reading response echo
@ ERROR_MISC
misc error, should not occur
virtual LIN_Master_Base::state_t _receiveFrame(void)
Receive LIN frame.
uint32_t timePerByte
time [us] per byte at specified baudrate
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::version_t version
LIN protocol version.
state_t
state of LIN master state machine. Use bitmasks for fast checking multiple states
@ STATE_BODY
rest of frame is being sent/received
@ STATE_OFF
LIN interface closed.
@ STATE_BREAK
sync break is being transmitted
@ STATE_IDLE
no LIN transmission ongoing
@ STATE_DONE
frame completed
virtual void end(void)
Close serial interface.
uint8_t bufRx[12]
receive buffer incl. BREAK, SYNC, DATA and CHK (max. 12B)
LIN_Master_Base::frame_t type
LIN frame type.
LIN_Master_Base(const char NameLIN[]="Master", const int8_t PinTxEN=INT8_MIN)
LIN master node constructor.
virtual LIN_Master_Base::state_t _sendBreak(void)
Send LIN break.
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)
uint32_t timeoutFrame
max. frame duration [us]