Skip to content

Commit

Permalink
0.5.5
Browse files Browse the repository at this point in the history
- Added telegram dissector with CRC computation (in Python).
  • Loading branch information
maarten-pennings committed Oct 16, 2024
1 parent abf30ce commit 1cbefb0
Show file tree
Hide file tree
Showing 9 changed files with 454 additions and 2 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=OSP 2wireSPI aospi
version=0.5.4
version=0.5.5
author=ams-OSRAM
maintainer=ams-OSRAM
sentence=A library that implements 2-wire SPI towards and from OSP nodes.
Expand Down
1 change: 1 addition & 0 deletions python/telegram/clean.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rmdir env /s /q
73 changes: 73 additions & 0 deletions python/telegram/readme.md
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)

2 changes: 2 additions & 0 deletions python/telegram/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
crcmod

6 changes: 6 additions & 0 deletions python/telegram/run.bat
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
10 changes: 10 additions & 0 deletions python/telegram/setup.bat
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
)
Loading

0 comments on commit 1cbefb0

Please sign in to comment.