It works like this:
Code: Select all
LinBus* lin;
//Would be called by scheduler in fixed time interval, say 100ms
void CyclicTask()
{
lin->Send(22, 0, 0); //Read request feature ID 22
//or send command, controlled by some state machine (only send one lin command per cycle!):
uint8_t lindata[4] = { 1, 2, 3, 4 };
lin->Send(21, lindata, sizeof(lindata)); //Send data "1 2 3 4" to ID 21
//check if we received a reply on ID 22 that is 8 bytes long
if (lin->HasReceived(22, 8))
{
uint8_t* data = lin->GetReceivedBytes();
Param::SetInt(Param::tmpheater, data[1] - 40);
}
}
extern "C" int main(void)
{
clock_setup();
//various init
LinBus l(USART1, 9600);
lin = &l;
}
HasReceived now takes ID without parity.
https://github.com/jsphuebner/libopenin ... linbus.cpp
EDIT: Updated example