GithubHelp home page GithubHelp logo

15738897318 / mcity-v2x-tscbm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mcity/mcity-v2x-tscbm

0.0 1.0 0.0 21 KB

Traffic Signal Controller Broadcast Message (TSCBM) parser/decoders in Python and C. Includes Python/C binding examples.

License: MIT License

Makefile 0.59% C 39.47% Python 59.94%

mcity-v2x-tscbm's Introduction

Mcity Traffic Signal Controller Broadcast Message (tscbm) SPaT parser

Traffic Signal Controller Broadcast Mesasag SPaT format parser/decoders in Python and C. Includes Python/C binding examples.

Used for parsing V2X Signal Phase and Timing Messages (SPaT) sent from traffic controllers in Mini SPaT / MIBSPaT format.

Files

test_TSCBM.py

  • Makes use of Python byte array and uses array indexing to parse results.

test_TSCBM_bit.py

  • Uses python bitstring ConstBitStream to implement the same TSCBM parser. About 30% slower than the byte array version, but easier to read and follow.

test_c_TSCBM.py

  • Calls the C library version of the TSCBM parser from Python. Allocates and frees string buffers in C, so that library is "threadsafe".

TSCBM.c

  • Parser for TSCBM format messages written in C. Can be built as stand alone example for shared library. Written for readability vs speed. Possible speed improvements are listed in comments in the C code.

Makefile

  • Builds both the stand alone and shared library version of the C code.

requirements.txt

  • Package listing for packages used with python examples.

Sample message

All examples attempt to parse the following hex encoded SPaT message:

cd100100dc02aa0000000000000000020000007d00dc02aa000000000300dc01db000000000000000004003f00bc003f00bc0000000005003f02d400000000000000000600000093003f02d40000000007003f00d2000000000000000008003f01a1003f01a100000000090000000000000000000000000a0000000000000000000000000b0000000000000000000000000c0000000000000000000000000d0000000000000000000000000e0000000000000000000000000f0000000000000000000000001000000000000000000000000000dd0000002200ff00000000000000000000000000000000085d003eca03ce00000000

This is the binary representation of that message:

1100110100010000000000010000000011011100000000101010101000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000001111101000000001101110000000010101010100000000000000000000000000000000000000011000000001101110000000001110110110000000000000000000000000000000000000000000000000000000000000000000001000000000000111111000000001011110000000000001111110000000010111100000000000000000000000000000000000000010100000000001111110000001011010100000000000000000000000000000000000000000000000000000000000000000000000110000000000000000000000000100100110000000000111111000000101101010000000000000000000000000000000000000001110000000000111111000000001101001000000000000000000000000000000000000000000000000000000000000000000000100000000000001111110000000110100001000000000011111100000001101000010000000000000000000000000000000000001001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011011101000000000000000000000000001000100000000011111111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100001011101000000000011111011001010000000111100111000000000000000000000000000000000

Usage

Python

Two python examples are provided. One is an easy to read implementation done with the bitstring library. A second is a faster version done using byte arrays.

Setup

$ python3 -m venv venv #Create a new virtual environment
$ source venv/bin/activate #Start a virtual environment
$ pip install -r requirements.txt # Install Python Packages

Run

$ source venv/bin/activate #Start a virtual environment
$ python test_TSCBM.py #Try byte array version
$ python test_TSCBM_bit.py #Try bitstring version

C

The C code in this package can build both stand alone and shared library versions of the code.

$ make main #Build both the main and library versions. Alternatively make all
$ ./a.out #Try the stand alone version. 

Cleanup

$ make clean #Cleanup all build components.

C Shared Library

This builds the shared library version of the C TSCBM parser.

$ make library #Build both the main and library versions. Alternatively make all
$ ./a.out #Try the stand alone version. 

Depending on your environment you may need to add your PWD to LD_LIBRARY_PATH so that Python can find the shared library.

$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD

Cleanup

$ make clean #Cleanup all build components.

Python C bindings

This is an example of using C bindings from Python to call the C shared library version of the code.

Setup

$ python3 -m venv venv #Create a new virtual environment
$ source venv/bin/activate #Start a virtual environment
$ pip install -r requirements.txt # Install Python Packages
$ make library #Build the C library

Run

$ source venv/bin/activate #Start a virtual environment
$ python test_c_TSCBM.py #Test the shared library version of the code.

Clean-up

$ make clean

mcity-v2x-tscbm's People

Contributors

tsworman avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.