mirror of
https://github.com/lowobservable/coax.git
synced 2026-03-02 18:14:50 +00:00
Implement LOAD_MASK, SEARCH_FORWARD and SEARCH_BACKWARD
This commit is contained in:
@@ -257,9 +257,11 @@ def load_secondary_control(interface, control, **kwargs):
|
||||
|
||||
_execute_write_command(interface, command_word, bytes([control.value]), **kwargs)
|
||||
|
||||
def load_mask(interface):
|
||||
def load_mask(interface, mask, **kwargs):
|
||||
"""Execute a LOAD_MASK command."""
|
||||
raise NotImplementedError
|
||||
command_word = _pack_command_word(Command.LOAD_MASK)
|
||||
|
||||
_execute_write_command(interface, command_word, bytes([mask]), **kwargs)
|
||||
|
||||
def load_address_counter_hi(interface, address, **kwargs):
|
||||
"""Execute a LOAD_ADDRESS_COUNTER_HI command."""
|
||||
@@ -283,13 +285,17 @@ def clear(interface):
|
||||
"""Execute a CLEAR command."""
|
||||
raise NotImplementedError
|
||||
|
||||
def search_forward(interface):
|
||||
def search_forward(interface, pattern, **kwargs):
|
||||
"""Execute a SEARCH_FORWARD command."""
|
||||
raise NotImplementedError
|
||||
command_word = _pack_command_word(Command.SEARCH_FORWARD)
|
||||
|
||||
def search_backward(interface):
|
||||
_execute_write_command(interface, command_word, bytes([pattern]), **kwargs)
|
||||
|
||||
def search_backward(interface, pattern, **kwargs):
|
||||
"""Execute a SEARCH_BACKWARD command."""
|
||||
raise NotImplementedError
|
||||
command_word = _pack_command_word(Command.SEARCH_BACKWARD)
|
||||
|
||||
_execute_write_command(interface, command_word, bytes([pattern]), **kwargs)
|
||||
|
||||
def insert_byte(interface):
|
||||
"""Execute a INSERT_BYTE command."""
|
||||
|
||||
83
pycoax/examples/12_search.py
Executable file
83
pycoax/examples/12_search.py
Executable file
@@ -0,0 +1,83 @@
|
||||
#!/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, read_status, load_address_counter_hi, load_address_counter_lo, write_data, load_mask, search_forward, search_backward
|
||||
|
||||
print('Opening serial port...')
|
||||
|
||||
with Serial('/dev/ttyACM0', 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'))
|
||||
|
||||
load_address_counter_hi(interface, 0)
|
||||
load_address_counter_lo(interface, 81)
|
||||
|
||||
load_mask(interface, 0xff)
|
||||
|
||||
search_forward(interface, 0x83)
|
||||
|
||||
status = read_status(interface)
|
||||
|
||||
print(status)
|
||||
|
||||
while status.busy:
|
||||
status = read_status(interface)
|
||||
|
||||
print(status)
|
||||
|
||||
hi = read_address_counter_hi(interface)
|
||||
lo = read_address_counter_lo(interface)
|
||||
|
||||
print(f'hi = {hi}, lo = {lo}')
|
||||
|
||||
search_backward(interface, 0x84)
|
||||
|
||||
status = read_status(interface)
|
||||
|
||||
print(status)
|
||||
|
||||
while status.busy:
|
||||
status = read_status(interface)
|
||||
|
||||
print(status)
|
||||
|
||||
hi = read_address_counter_hi(interface)
|
||||
lo = read_address_counter_lo(interface)
|
||||
|
||||
print(f'hi = {hi}, lo = {lo}')
|
||||
|
||||
load_mask(interface, 0xf0)
|
||||
|
||||
search_forward(interface, 0x30)
|
||||
|
||||
status = read_status(interface)
|
||||
|
||||
print(status)
|
||||
|
||||
while status.busy:
|
||||
status = read_status(interface)
|
||||
|
||||
print(status)
|
||||
|
||||
hi = read_address_counter_hi(interface)
|
||||
lo = read_address_counter_lo(interface)
|
||||
|
||||
print(f'hi = {hi}, lo = {lo}')
|
||||
Reference in New Issue
Block a user