A python program to decode and check IrDA serial data
Project detail
I need a Python developer.
A python program to decode and check the IrDA serial data from a hydrogen fuel cell vehicle, used for fuelling (I would consider switching to C / C++ if it was felt to be a better language for this project)
Currently I am using Python 3.8 with pyserial 3.5 on windows 10
The program will also be run on a RPi
The program will incorporate, as well as CRC frame checks
Data integrity checks (Data type, proper delimiters)
Tag checks
Properly Defined Value Check for Required Character Data and numerical Data
Data Interval Check (Data frames sent at 10 Hz max 500ms between valid Data points)
The serial data is receive only
Each byte is transmitted asynchronously with a start bit, 8 data bits, and a stop bit. Data bits are transmitted in serial byte order, with the least significant bit (LSB) transmitted first and the most significant bit (MSB) transmitted last. Bits are transmitted at a rate of 38400 bits per second.
Data link framing is used as described in Section 10.1 of IrLAP 1.1.
The following control characters are used for the data link framing :
XBOF – Extra Begin of Frame character shall be 0xFF hexadecimal. (XBOF x 5 at the beginning of each frame)
BOF – Beginning of Frame character shall be 0xC0 hexadecimal.
EOF – End of Frame character shall be 0xC1 hexadecimal.
CE – Control Escape character shall be 0x7D hexadecimal (see A.1.1).
A single pipe character (“|” ASCII, 0x7C hexadecimal) is used to delimit all pieces of data. All valid data is contained between two pipe characters.
Data Link Frame
The application data packets are transmitted in data link frames as described in Section 10 of IrLAP 1.1. The application data packets shall be transmitted in data link frames. Five XBOF characters shall precede the data link frame transmission. A single BOF character shall be transmitted at the start of the data link frame. The application data packet shall be transmitted immediately following the BOF character. A frame check sequence field shall be transmitted immediately following the application data packet. The data link frame shall be terminated with an EOF character as shown:
5 x XBOFs BOF APPLICATION DATA FCS EOF
Frame Check Sequence (FCS) Field
The frame check sequence field detects errors in the received frame as described in Section 10.1.2 of IrLAP 1.1. The FCS field shall be a 16-bit CRC-CCITT cyclic redundancy check computed on the bytes in the application data. The polynomial for the CRC shall be X16 + X12 + X5 + 1. The FCS is transmitted with the least significant byte first followed by the most significant byte.
Transparency
A transparency character is defined to transform application data bytes (and FCS field bytes) which correspond to data link control characters as described in Section 10.1.3 of IrLAP 1.1. The transmitting side of the data link shall transform any data bytes, or FCS bytes, corresponding to control characters XBOF, BOF, EOF, or CE into non-control characters prior to transmitting the data link frame.
The transformation method on the transmitting side shall be:
a. Insert a control escape (CE) byte preceding the data byte.
b. Exclusive OR the data byte with 0x20 hexadecimal.
The receiving side shall reverse the transformation whenever a CE byte is received in the data stream.
See B.2 for an IrDA frame example with the maximum transparency characters possible.
The receiving side shall reverse the transformation using the following method:
a. Discard the control escape (CE) byte.
b. Exclusive OR the data byte with 0x20 hexadecimal.
The full description is shown in the attached file
Typical data frame with no transparency:
B1=0xFF 0xFF0xFF0xFF0xFF 0xC0 |ID=SAE˽J2799|VN=01.00|TV=0119.0|RT=H70|FC=Halt
|MP=050.0|MT=273.0|FCS1 FCS2 0xC1
On terminal, with HEX to ASCII
test_frame = “ÿÿÿÿÿÀ|ID=SAE J2799|VN=01.00|TV=0119.0|RT=H70|FC=Halt|MP=050.0|MT=273.0|C1C2Á”
Output of program:
To update the global variables (for every validated frame)
Full description attached