๐Ÿ“ฆ wagoodman / protocol-tools

โ˜… 1 stars โ‘‚ 0 forks ๐Ÿ‘ 1 watching โš–๏ธ MIT License
acarsprotocol
๐Ÿ“ฅ Clone https://github.com/wagoodman/protocol-tools.git
HTTPS git clone https://github.com/wagoodman/protocol-tools.git
SSH git clone git@github.com:wagoodman/protocol-tools.git
CLI gh repo clone wagoodman/protocol-tools
wagoodman wagoodman first commit 7daa021 8 years ago ๐Ÿ“ History
๐Ÿ“‚ master View all commits โ†’
๐Ÿ“ protocols
๐Ÿ“„ .gitignore
๐Ÿ“„ example.py
๐Ÿ“„ LICENSE
๐Ÿ“„ README.md
๐Ÿ“„ README.md

protocol-tools

Just a small collection of tools to parsing simple character oriented protocols. ARINC 618 is a public communications spec that shows off what the ByteProtocol class can do:

Easily create new messages from scratch:

>>> message = Acars618.assemble({'text': 'Hello, world!', 'tail':'WG12345'})
>>> print "Message:", repr(message)
Message: '\x012WG12345\x15H11\x02M01AUA9090Hello, world!\x03'

Parse out a message into individual fields:

>>> values, spans = parsedMessage = Acars618.detect(message)
>>> print "Fields:", repr(values)
Fields: {'dbi': '1', 'flight': '9090', 'ack': '\x15', 'soh': '\x01', 'agency': 'UA', 'label': 'H1', 'msn': 'M01A', 'tail': 'WG12345', 'mode': '2', 'text': 'Hello, world!', 'trailer': '\x03', 'sot': '\x02'}

Change selected fields of an example protocol string:

>>> newMessage = Acars618.mutate(message, {'text': "I'm Replaced!"})
>>> print "New Message:", repr(newMessage)
New Message: "\x012WG12345\x15H11\x02M01AUA9090I'm Replaced!\x03"

Given two example strings, show the fields that have different values:

>>> diffs = Acars618.difference(message, newMessage)
>>> print "Differences:", repr(diffs)
Differences: ['text']

Censor a selection of fields:

>>> censoredMessage = Acars618.censor(message, parseCensorFields=['text', 'tail'])
>>> print "Censored Message", repr(censoredMessage)
Censored Message '\x012!!!!!!!\x15H11\x02M01AUA9090!!!!!!!!!!!!!\x03'