-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented config files #64
Conversation
Looks like a good start to me! I think that these init variables from """
Big init routine as the whole board is brought up. Starting with config variables.
"""
self.debug = True # Define verbose output here. True or False
self.legacy = False # Define if the board is used with legacy or not
self.heating = False # Currently not used
self.orpheus = True # Define if the board is used with Orpheus or not
self.is_licensed = True
"""
Define the normal power modes
"""
self.NORMAL_TEMP = 20
self.NORMAL_BATT_TEMP = 1 # Set to 0 BEFORE FLIGHT!!!!!
self.NORMAL_MICRO_TEMP = 20
self.NORMAL_CHARGE_CURRENT = 0.5
self.NORMAL_BATTERY_VOLTAGE = 6.9 # 6.9
self.CRITICAL_BATTERY_VOLTAGE = 6.6 # 6.6
self.vlowbatt = 6.0
self.battery_voltage = 3.3 # default value for testing REPLACE WITH REAL VALUE
self.current_draw = 255 # default value for testing REPLACE WITH REAL VALUE
self.REBOOT_TIME = 3600 # 1 hour
self.turbo_clock = False You may also want to take a look at how CircuitPython has tried to natively introduce the use of a |
Ended up finishing the toml file for configuration. But when I connect to the board and the countdown starts, I get a "module named 'tomllib' not found" error. I did some digging and found that tomllib, which is a library I need to parse data from the config file, was introduced in Python 3.11, which I know the actual board is about 6 versions behind. My question is, would I be able to use a third party library called 'toml' I would simply need to run the command pip install toml I think, and parse exactly how I was attempting with the 'tomllib'. But I'm not too sure if that's a valid solution to this. Otherwise, I believe my only option is to keep using json. |
Hey @Alandlt15 I think this one of those things that is a mismatch between mainstream Python and CircuitPython. It would appear from the CircuitPython docs that they only natively support accessing a import os
print(os.getenv("test_variable")) I'm not sure if this allows us to actually write values to the |
I ended up settling with JSON. One reason behind this is because CircuitPython "only supports a subset of the full TOML specification" leading to only integers and strings being supported. (I have floats, booleans, and lists inside my config file). I did give the third party TOML a try but at first I kept getting "module named 'toml' not found". I kinda figured that toml was not installed directly on the board, so I decided to manually add the toml folders to the lib directory on the FC_Board directory. This seemed to solve that, however I then encountered another "module named 'datetime' not found" issue. Additionally, there are bugs that accept invalid TOML files. It is mentioned those will be fixed with no timeframe specified. This might not seem like a big deal to files that are valid TOML, but I believe it is safer and better to settle with JSON for configuration. I've yet to test if values can be changed at runtime, I think it is achievable, but still need to do some research and testing on that. Nevertheless, the current JSON config implementation works on the board! |
Cool! Thanks for the testing and write up. Do you think we should keep this PR open until we finish migrating everything, we want to be in the Like you mentioned in your last comment, being able to overwrite the values in the |
Now that I'm thinking about it, it would be wise to just leave it open until the migration is done. This would allow me to definitely implement value changes at runtime, and discover if other variables should be added to the config. Thank you for taking the time to review and comment! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a good start. I think you should consider merging and continuing to improve/modify in small PRs based on the mainline rather than continuing to build on this PR and merging a larger PR later. PRs of this size are easier to review.
My suggested next steps are:
- Only read the config file once on application startup: This will be a challenging refactor but will help us implement the ability to update config values in-flight because the control flow will be more easily understandable.
- Create a config class/module which, on initialization, reads the config file and places all the values into private member variables. Provide a public getter method on the class so other parts of the program can access the config values. This structure will allow you to more easily control how config values are changed in the future by providing setter method where you can implement how configs values are changed. If we want to follow the FPrime model and allow values to be set temporarily before being made permanent on restart, this is probably the right structure.
- Create a public setter method that allows changing the member variables but don't write that variable to the config file.
- Create a public writer method that allows modifying the config file with the updated config value.
fixed small error
okay should be good now this time
That sounds like a plan to me, I fixed some conflicts, black linter was giving me some trouble but I fixed it. Did one last test with the board and all is working fine. I will merge shortly, thank you all for your time and advice! |
commandsConfig.py: holds dictionary of commands
config.json: holds other configuration data (eg. cubesat name, radio callsign, jokes, etc)