-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added telegram dissector with CRC computation (in Python).
- Loading branch information
1 parent
abf30ce
commit 1cbefb0
Showing
9 changed files
with
454 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rmdir env /s /q |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Telegram | ||
|
||
A python script to dissecting and pretty print telegrams with CRC check. | ||
|
||
## Introduction | ||
|
||
This is a Python application that, when fed with the bytes that | ||
make up a telegram, pretty prints a dissection of those bytes | ||
into telegram fields. | ||
|
||
As a bonus the application computes and checks the OSP CRC | ||
of the telegram bytes. | ||
|
||
|
||
## File architecture | ||
|
||
This application uses the following support files | ||
|
||
- `setup.bat` first file to run, sets up a virtual Python environment. | ||
You might need to tweak the line that sets the `LOCATION` of the python executable. | ||
- `requirements.txt` is used by `setup.bat` to install packages. | ||
In this case, the file contains the a CRC library. | ||
- `run.bat` actually runs `telegram.py`. | ||
- `telegram.py` the script started by `run.bat`. | ||
- `clean.bat` deletes the virtual environment. | ||
- `readme.md` this file. | ||
|
||
|
||
## Run | ||
|
||
Once the project is setup (`setup.bat`), run the python app via `run.bat`. | ||
We must pass it the bytes that make up the telegram. | ||
They must be passed in hex, space separated. | ||
|
||
This example shows the result of pretty printing the reply | ||
for an initbidir of a chain of length 5. | ||
|
||
``` | ||
(env) OSP_aospi\python\telegram>run A0 15 02 6F 50 30 | ||
+---------------+---------------+---------------+---------------+---------------+---------------+ | ||
byteval | A0 | 15 | 02 | 6F | 50 | 30 | | ||
byteix |0 0 0 0 0 0 0 0|1 1 1 1 1 1 1 1|2 2 2 2 2 2 2 2|3 3 3 3 3 3 3 3|4 4 4 4 4 4 4 4|5 5 5 5 5 5 5 5| | ||
bitix |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| | ||
bitval |1 0 1 0 0 0 0 0|0 0 0 1 0 1 0 1|0 0 0 0 0 0 1 0|0 1 1 0 1 1 1 1|0 1 0 1 0 0 0 0|0 0 1 1 0 0 0 0| | ||
+-------+-------+-----------+---+-+-------------+-------------------------------+---------------+ | ||
field |preambl| address | psi | command | payload | crc | | ||
bin | 1010 | 0000000101 | 010 | 0000010 | 01101111 : 01010000 | 00110000 | | ||
hex | 0xA | 0x005 | 0x2 | 0x02 | 0x6F : 0x50 | 0x30 (ok) | | ||
meaning | - | 5 | 2 | initbidir | 111 : 80 | 48 (ok) | | ||
+-------+-------------------+-----+-------------+-------------------------------+---------------+ | ||
``` | ||
|
||
If we pass the wrong CRC as last byte, we get | ||
|
||
``` | ||
(env) OSP_aospi\python\telegram>run A0 15 02 6F 50 31 | ||
+---------------+---------------+---------------+---------------+---------------+---------------+ | ||
byteval | A0 | 15 | 02 | 6F | 50 | 31 | | ||
byteix |0 0 0 0 0 0 0 0|1 1 1 1 1 1 1 1|2 2 2 2 2 2 2 2|3 3 3 3 3 3 3 3|4 4 4 4 4 4 4 4|5 5 5 5 5 5 5 5| | ||
bitix |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| | ||
bitval |1 0 1 0 0 0 0 0|0 0 0 1 0 1 0 1|0 0 0 0 0 0 1 0|0 1 1 0 1 1 1 1|0 1 0 1 0 0 0 0|0 0 1 1 0 0 0 1| | ||
+-------+-------+-----------+---+-+-------------+-------------------------------+---------------+ | ||
field |preambl| address | psi | command | payload | crc | | ||
bin | 1010 | 0000000101 | 010 | 0000010 | 01101111 : 01010000 | 00110001 | | ||
hex | 0xA | 0x005 | 0x2 | 0x02 | 0x6F : 0x50 |0x31 (ERR) 0x30| | ||
meaning | - | 5 | 2 | initbidir | 111 : 80 | 49 (ERR) 48 | | ||
+-------+-------------------+-----+-------------+-------------------------------+---------------+ | ||
``` | ||
|
||
Run `OSP_aoapi\python\cleanall.bat` to remove the virtual environment. | ||
|
||
(end) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
crcmod | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@ECHO off | ||
IF "(env) " neq "%PROMPT:~0,6%" ECHO Please run setup.bat first && EXIT /b | ||
|
||
python telegram.py %* | ||
|
||
ECHO.Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@ECHO OFF | ||
|
||
SET LOCATION=C:\programs\python311\ | ||
|
||
%LOCATION%python.exe -m venv env | ||
CALL env\Scripts\activate.bat | ||
env\Scripts\python -m pip install --upgrade pip setuptools wheel | ||
IF EXIST requirements.txt ( | ||
pip install -r requirements.txt | ||
) |
Oops, something went wrong.