This is the directory storing the code for the TARS data-streaming module to be used with HILSIM server. Feel free to clone this repository and edit it to suit your specific use-cases.
I've written a couple of wrapper libraries around GitPython and Platformio which should make development much simpler. They are located in git_commands and pio_commands respectively, I suggest taking a look into each one, but they're both quite simple:
git_commands exposes 4 functions, which each call the remote_commands script with different parameters. remote_commands is the actual wrapper around GitPython (if you're interested in why I chose to do it this way, feel free to ask!) and doesn't need to be edited directly unless you wish to add functionality. The other two libraries will be (to some extent) dependent on the actual architecture we're uploading stuff.
What is implemented for you:
util/git_commands.py -- This is a library that performs all the git actions you will need for this application
util/pio_commands.py -- Library to handle all the pio commands you will need for this application
util/packets.py -- Constructors for all communication packets we'll be sending.
util/serial_wrapper.py -- Not fully implemented! IDENT functionality and packet decoding is implemented for you, but you will need to handle the other packets (explained below).
av_platform/run_setup.py -- Not fully implemented! I took the liberty of doing the easy ones, you need to implement the platform-specific flash command and the platform specific run_hilsim command.
What needs to be implemented:
The rest of util/serial_wrapper.py -- Implement communication with the server (fun part)!
main.py -- The actual server itself
The rest of av_platform/run_setup.py -- Implement platform-specific code pushing and hilsim runs.
Here are your technical requirements for server communication:
- Whenever an
IDENT?packet is recieved, IF this board was assigned an id before, send an ID-CONF packet with the board type and board id stored. OTHERWISE, send an IDENT packet. - Whenever an
ACKpacket is recieved, store the board ID assigned and which port sent it (This will be the server port). - Whenever a
REASSIGNpacket is recieved, change to board_id but do not terminate any jobs. - Whenever a
TERMINATEpacket is recieved, immediately terminate all currently running jobs, then, send aREADYpacket. - Whenever a
CYCLEpacket is recieved, terminate all currently running jobs. If the current platform supports power cycling, then power cycle the test stand, then send aREADYpacket. If the current platform cannot power cycle, immediately send aREADYpacket. stream_dataruns in a while loop, so to implement the above two bullet points you will need to figure out how to communicate to the server while running a hilsim job. (I don't know exactly how to do that so go ham)- Whenever a
JOBpacket is recieved, IF a job is currently running, send aBUSYpacket back with the currently running job data. Otherwise, run the job and sendJOB-UPDpackets with the status of the job while it's running (The first status should always be"Accepted")
Most of the places where code needs to be implemented is marked with a TODO. Good luck!
The util/ directory contains multiple wrapper scripts written for development convenience. They expose functions to interface with Git and with Platformio. Their exposed functions are below:
git_commands.py:
run_script(str[] args)--> Runsremote_command.pywith the specified arguments (Used in the definition of all the other functions)remote_clone()--> Clones the remote into the directory specified inconfig.pyremote_reset()--> Discards all changes and checks out/pullsorigin/main. Runsremote_clonefirst if the remote does not exist.remote_pull_branch(str branch)--> Checks out and pulls the branchbranchfrom the remote. Runsremote_clonefirst if the remote does not exist.
pio_commands.py:
run_script(str[] args)--> Runsplatformiowith the specified arguments.pio_build(str build_target)--> Runsplatformio run. Ifbuild_targetis specified, then it adds the--environmentflag withbuild_target.pio_upload(str build_target)--> Runsplatformio run --target upload. Ifbuild_targetis specified, then it adds the--environmentflag withbuild_target. (Flashes code once the build completes)pio_clean(str build_target)--> Runsplatformio run --target clean. Ifbuild_targetis specified, then it adds the--environmentflag withbuild_target. (Does a clean build)