Gogee90 / egts-python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EGTS Packet Encoder

Python library for encoding vehicle data to EGTS packets

Required packages:

  • enum

Installation

  1. Rename "setup_egts.py" to "setup.py"
  2. Run "python setup.py"
  3. After setup is done run "pip install ."

Usage

  • To create a EGTS message use EGTS class from interface package: from egts.interface.egts import EGTS
  • For manual data assignment:
    • Use the codes module to get EGTS protocol codes: from egts.interface import codes
    • You must specify Packet Types and Subrecord Types:
      • In constructor:
      msg = EGTS(PacketType.EGTS_PT_APPDATA, (SubrecordType.EGTS_SR_ACCEL_DATA,), (SubrecordType.EGTS_SR_TRACK_DATA, SubrecordType.EGTS_SR_TRACK_DATA))
      This command creates a EGTS_PT_APPDATA packet with two records: record #1 has one EGTS_SR_ACCEL_DATA subrecord; record #2 has two EGTS_SR_TRACK_DATA subrecords
      OR
      • Via set_packet_type, add_record and add_subrecord methods:
      msg = EGTS()
      msg.set_packet_type(PacketType.EGTS_PT_APPDATA)
      record1 = msg.add_record((SubrecordType.EGTS_SR_ACCEL_DATA,))
      record2 = msg.add_record()
      subrecord1 = record2.add_subrecord(SubrecordType.EGTS_SR_TRACK_DATA)
      subrecord2 = record2.add_subrecord(SubrecordType.EGTS_SR_TRACK_DATA)
    • To work with a specific record within a packet, retrieve it using the number of the record:
    record1 = msg[0]
    • To work with a specific subrecord within a record, retrieve it using the number of the record:
    subrecord1 = record1[0]
    • Use __setitem__ to set field values, there is a deep search so you don't have to retrieve compound fields every time:
    subrecord1['cid'] = 1
    subrecord1['cct'] = 0 # does the same that subrecord1['type_flags']['cct'] = 0
    • You can use __getitem__ to get fields if neccessary:
    flags = subrecord1['type_flags']
    flags['cct'] = 0
  • For JSON assignment:
    • Use load_json method:
    msg = EGTS()
    msg.load_json('/home/sanchez486/data.json')
    You can find json examples in /tests/json/data folder
  • Use __str__ to get a EGTS packet byte string:
egts_string = str(msg)
pring egts_string # 0100000B0012000100018807000100040000D90F0202180400010203047EB2
  • Use bytes property to get packet representation in bytes:
egts_bytes = msg.bytes
  • Use write method to write the packet bytes in a file:
msg.write('/home/sanchez486/data.hex')

Contacts

I apologize for confusing import names and weird installation instructions. I didn't have a chance to create some order in the packages. The library was not properly tested with a real gear so it may show some unexpected behavior. If you have any questions, suggestions or fix requests please free to contact me in github or via these credentials:

About


Languages

Language:Python 100.0%