From 70f44bef898c9e4fecd69b47b00db5bbced20661 Mon Sep 17 00:00:00 2001 From: Andrew Kay Date: Mon, 23 Dec 2019 19:55:32 -0600 Subject: [PATCH] Implement INSERT_BYTE --- pycoax/coax/protocol.py | 6 +++-- pycoax/examples/13_insert_byte.py | 42 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100755 pycoax/examples/13_insert_byte.py diff --git a/pycoax/coax/protocol.py b/pycoax/coax/protocol.py index f79c8aa..c2a688f 100644 --- a/pycoax/coax/protocol.py +++ b/pycoax/coax/protocol.py @@ -297,9 +297,11 @@ def search_backward(interface, pattern, **kwargs): _execute_write_command(interface, command_word, bytes([pattern]), **kwargs) -def insert_byte(interface): +def insert_byte(interface, byte, **kwargs): """Execute a INSERT_BYTE command.""" - raise NotImplementedError + command_word = _pack_command_word(Command.INSERT_BYTE) + + _execute_write_command(interface, command_word, bytes([byte]), **kwargs) def start_operation(interface): """Execute a START_OPERATION command.""" diff --git a/pycoax/examples/13_insert_byte.py b/pycoax/examples/13_insert_byte.py new file mode 100755 index 0000000..4444b1a --- /dev/null +++ b/pycoax/examples/13_insert_byte.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +import sys +import time +from serial import Serial + +sys.path.append('..') + +from coax import Interface1, read_address_counter_hi, read_address_counter_lo, load_address_counter_hi, load_address_counter_lo, write_data, insert_byte + +print('Opening serial port...') + +with Serial('/dev/ttyUSB0', 115200) as serial: + print('Sleeping to allow interface time to wake up...') + + time.sleep(3) + + interface = Interface1(serial) + + print('Resetting interface...') + + version = interface.reset() + + print(f'Firmware version is {version}') + + load_address_counter_hi(interface, 0) + load_address_counter_lo(interface, 80) + write_data(interface, bytes.fromhex('a7 84 8b 8b 8e 33 00 96 8e 91 8b 83 19')) + + input('Press ENTER...') + + load_address_counter_hi(interface, 0) + load_address_counter_lo(interface, 81) + + insert_byte(interface, 0xb7) + + input('Press ENTER...') + + load_address_counter_hi(interface, 0) + load_address_counter_lo(interface, 88) + + insert_byte(interface, 0xb7)