Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 29 additions & 30 deletions public/prism/drivers/A4401_BOND/A4401_BOND.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ class A4401_BOND:
# if that FW is not running, there is probably a problem! See method init().
_version_file = os.path.join(os.path.dirname(__file__), "server/teensy4_server/version.h")

def __init__(self, port, loggerIn=None):
self.lock = threading.Lock()
def __init__(self, port, loggerIn=None, header_def_filename=None):

if loggerIn:
self.logger = loggerIn
else:
self.logger = StubLogger()

self._header_def_filename = header_def_filename

self._lock = threading.Lock()
self.port = port
self.rpc = None
Expand All @@ -82,14 +83,14 @@ def __init__(self, port, loggerIn=None):
def set_port(self, port):
self.port = port

def init(self, header_def_filename=None):
def init(self, skip_max11311=False):
""" Init Teensy SimpleRPC connection

:param skip_init: True/False, skips MAX11311 setup, assume thats already done
:param skip_max11311: True/False, skips MAX11311 setup. Allow access other functions
:return: <True/False> whether Teensy SimpleRPC connection was created
"""
self.logger.info(f"installing BOND on port {self.port} using {header_def_filename}")
if header_def_filename is None:
self.logger.info(f"installing BOND on port {self.port} using {self._header_def_filename}")
if not skip_max11311 and self._header_def_filename is None:
self.logger.error("MAX11311 port definition file must be specified")
return False

Expand All @@ -107,9 +108,9 @@ def init(self, header_def_filename=None):
return False

if self.my_version != version_response["result"]["version"]:
self.logger.error("version does not match, Python: {} Arduino: {}".format(self.my_version,
version_response["result"][
"version"]))
self.logger.error("version does not match, "
f"Python: {self.my_version} "
f"Arduino: {version_response["result"]["version"]}")
return False

status_response = self.status()
Expand All @@ -123,30 +124,28 @@ def init(self, header_def_filename=None):
# check if jig close has valid GPIOs
self._jig_close_check()

if header_def_filename is None:
self.logger.error(f"Header pin definition filename not supplied")
return False

if not os.path.exists(header_def_filename):
self.logger.error(f"Header pin definition filename {header_def_filename} does not exist")
return False
if not skip_max11311:
if not os.path.exists(self._header_def_filename):
self.logger.error(f"Header pin definition filename {self._header_def_filename} "
"does not exist")
return False

# init MAX11311 pins per the JSON defintion
# also calibrates the battery emulator if needed
success = self._init_maxs(header_def_filename)
if not success:
self.logger.error(f"Failed to init MAX11311 pins")
return False
# init MAX11311 pins per the JSON defintion
# also calibrates the battery emulator if needed
success = self._init_maxs(self._header_def_filename)
if not success:
self.logger.error("Failed to init MAX11311 pins")
return False

status_response = self.iox_vbat_con(False)
if not status_response["success"]:
self.logger.error(f"iox_vbat_con {status_response}")
return False
status_response = self.iox_vbat_con(False)
if not status_response["success"]:
self.logger.error(f"iox_vbat_con {status_response}")
return False

status_response = self.iox_selftest(False)
if not status_response["success"]:
self.logger.error(f"iox_vbat_con {status_response}")
return False
status_response = self.iox_selftest(False)
if not status_response["success"]:
self.logger.error(f"iox_vbat_con {status_response}")
return False

# check bist voltages
for _v in self.BIST_VOLTAGES:
Expand Down
12 changes: 6 additions & 6 deletions public/prism/drivers/A4401_BOND/A4401_BOND_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ def parse_args():
python A4401_BOND_cli.py --port /dev/ttyACM0 led --on

Port: Teensy4 when plugged into USB on Linux will show up as a ttyACM# device in /dev.
Use 'ls -al /dev/ttyACM*' to find the port.
Use 'ls -al /dev/ttyACM*' to find the port.

Getting Help for a command:
$ python3 A4401_BOND_cli.py --port /dev/ttyACM0 write_gpio --help
usage: A4401_BOND_cli.py write_gpio [-h] --pin-number _PIN_NUMBER --state {True,False}

options:
-h, --help show this help message and exit
--pin-number _PIN_NUMBER
GPIO number (0-41)
--state {True,False} True|False

Examples:
(venv) martin@martin-ThinkPad-L13:~/git/scripts/public/prism/drivers/A4401_BOND$ python A4401_BOND_cli.py -p /dev/ttyACM0 version
(venv) martin@martin-ThinkPad-L13:~/git/scripts/public/prism/drivers/A4401_BOND$ python A4401_BOND_cli.py -p /dev/ttyACM0 -n iox_led_green --enable
Expand Down Expand Up @@ -507,9 +507,9 @@ def sequence(args):
else:
logging.basicConfig(level=logging.DEBUG, format='%(filename)20s %(levelname)6s %(lineno)4s %(message)s')

teensy = A4401_BOND(args.port, loggerIn=logging)
teensy = A4401_BOND(args.port, loggerIn=logging, header_def_filename="pogo_hdr_definition._json")

success = teensy.init(header_def_filename="pogo_hdr_definition._json")
success = teensy.init()
if not success:
logging.error("Failed to create teensy instance")
exit(1)
Expand Down
8 changes: 5 additions & 3 deletions public/prism/drivers/A4401_BOND/hwdrv_A4401_BOND.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self):
self._num_chan = 0
self.teensys = [] # holds a list of all objects found

def discover_channels(self, scriptArgs):
def discover_channels(self, scriptArgs=None):
""" determine the number of channels, and populate hw drivers into shared state

[ {"id": i, # ~slot number of the channel (see Note 1)
Expand Down Expand Up @@ -98,8 +98,10 @@ def discover_channels(self, scriptArgs):
#https: // stackoverflow.com / questions / 21050671 / how - to - check - if -device - is -connected - pyserial / 49450813
# test if this COM port is really a Teensy
# create an instance of Teensy()
_teensy['hwdrv'] = A4401_BOND(port, loggerIn=logging.getLogger("teensy.try"))
success = _teensy['hwdrv'].init(scriptArgs)
_teensy['hwdrv'] = A4401_BOND(port,
loggerIn=logging.getLogger("teensy.try"),
header_def_filename=scriptArgs)
success = _teensy['hwdrv'].init()
if not success:
self.logger.error("failed on {}...".format(port))
continue
Expand Down
2 changes: 1 addition & 1 deletion public/prism/drivers/A4401_BOND/hwdrv_A4401_BOND_prog.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self):
self._num_chan = 0
self.teensys = []

def discover_channels(self):
def discover_channels(self, scriptArgs=None):
""" determine the number of channels, and populate hw drivers into shared state

[ {"id": i, # ~slot number of the channel (see Note 1)
Expand Down
49 changes: 20 additions & 29 deletions public/prism/scripts/example/BOND_v0/bond_P00xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ def P200_Program(self):
'-v',
'-s',
file_path],
stdout=subprocess.PIPE).stdout.decode('utf-8')
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True)

self.logger.info(result)

self.shared_lock(DRIVER_TYPE_PROG).release()
Expand All @@ -154,13 +157,13 @@ def P200_Program(self):
# Booting

# check for some key words to confirm success
if not result.count('Programming'):
self.log_bullet(f"Unexpected Programming")
if not result.stdout.count('Programming'):
self.log_bullet(f"'Programming' did not occur")
self.item_end(ResultAPI.RECORD_RESULT_INTERNAL_ERROR)
return

if not result.count('Booting'):
self.log_bullet(f"Unexpected Booting")
if not result.stdout.count('Booting'):
self.log_bullet(f"'Booting' did not occur")
self.item_end(ResultAPI.RECORD_RESULT_INTERNAL_ERROR)
return

Expand Down Expand Up @@ -190,19 +193,20 @@ def P300_Reconnect(self):
self.logger.info("Trying teensy at {}...".format(port))

# create an instance of Teensy()
# Bare minimum init -- does not require 'pogo_hdr_definition._json'
_teensy = A4401_BOND(port, loggerIn=logging.getLogger("teensy.try"))
success = _teensy.init()
success = _teensy.init(skip_max11311=True)
if not success:
self.log_bullet(f"Failed init")
self.log_bullet("Failed init")
self.logger.error("failed on {}...".format(port))

else:
self.log_bullet(f"Found teensy")
self.log_bullet("Found teensy")
found_teensy = True
break

if not found_teensy:
self.log_bullet(f"Teensy not found")
self.log_bullet("Teensy not found")
self.item_end(ResultAPI.RECORD_RESULT_INTERNAL_ERROR)
return

Expand Down Expand Up @@ -310,7 +314,9 @@ def P600_Update(self):
'-w',
'-v',
file_path],
stdout=subprocess.PIPE).stdout.decode('utf-8')
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True)
self.logger.info(result)

# expected output looks like,
Expand All @@ -324,7 +330,7 @@ def P600_Update(self):
# Booting

# check for some keywords to confirm success
if result.count('Programming') and result.count('Booting'):
if result.stdout.count('Programming') and result.stdout.count('Booting'):
success = True
break

Expand Down Expand Up @@ -412,24 +418,9 @@ def P700_Verify(self):

self.logger.info("Trying teensy at {}...".format(port))

# (re)create an instance of Teensy()
self.teensy = A4401_BOND(port, loggerIn=logging.getLogger("teensy.try"))

# get the header_def_filename from script drivers section
header_def_filename = None
for i in ctx.config.drivers:
if "hwdrv_A4401_BOND" in i[0]:
header_def_filename = i[1]
break
if header_def_filename is None:
self.logger.error(f"header_def_filename: {header_def_filename}")
self.log_bullet(f"Failed header_def_filename")
self.shared_lock(DRIVER_TYPE).release()
self.item_end(ResultAPI.RECORD_RESULT_INTERNAL_ERROR)
return
self.logger.info(f"header_def_filename: {header_def_filename}")

success = self.teensy.init(header_def_filename)
# re-connect to teensy at new port
self.teensy.set_port(port)
success = self.teensy.init()
if not success:
self.log_bullet(f"Failed init")
self.logger.error("failed on {}...".format(self._teensy_port))
Expand Down
6 changes: 3 additions & 3 deletions public/prism/scripts/example/BOND_v0/bond_progfresh_0.scr
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
},
"config": {
"fail_fast": true,
"drivers": [["public.prism.drivers.A4401_BOND.hwdrv_A4401_BOND",
"public/prism/scripts/example/BOND_v0/assets/pogo_hdr_definition._json"]]
"drivers": ["public.prism.drivers.A4401_BOND.hwdrv_A4401_BOND_prog"]
},
"tests": [
{
Expand All @@ -28,7 +27,8 @@
{"id": "P000_SETUP", "enable": true },
{"id": "P100_Check", "enable": true },
{"id": "P200_Program", "enable": true, "file": "teensy4_server.ino.hex" },
{"id": "P300_Verify", "enable": true, "delay": 10 },
{"id": "P300_Reconnect", "enable": true, "timeout": 30, "delay": 24 },
{"id": "P900_TEARDOWN", "enable": true}
]
}
]
Expand Down
1 change: 1 addition & 0 deletions public/prism/scripts/example/BOND_v0/bond_update_0.scr
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
{"id": "P500_SETUP", "enable": true, "timeout": 30 },
{"id": "P600_Update", "enable": true, "file": "teensy4_server.ino.hex" },
{"id": "P700_Verify", "enable": true, "delay": 24, "timeout": 30 },
{"id": "P900_TEARDOWN", "enable": true}
]
}
]
Expand Down