Skip to content

Commit

Permalink
using tomllib but not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Alandlt15 committed Jan 2, 2025
1 parent ca207a2 commit 3536058
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 57 deletions.
19 changes: 10 additions & 9 deletions FC_Board/cdh.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import time
import random
import commandsConfig
import json
import tomllib

commands = commandsConfig.commands
# parses config data from json file & assigns data to variables
with open("config.json", "r") as json_file:
json_data = json_file.read()
parsed_data = json.loads(json_data)

jokereply = parsed_data["jokereply"]
super_secret_code = parsed_data["super_secret_code"].encode("utf-8")
repeat_code = parsed_data["repeat_code"].encode("utf-8")
# parses toml file & assigns data to variables
with open("configs.toml", "rb") as f:
toml_data: dict = tomllib.load(f)

jokereply = toml_data["jokereply"]
super_secret_code = toml_data["super_secret_code"].encode(
"utf-8"
) # put your own code here
repeat_code = toml_data["repeat_code"].encode("utf-8")
print(f"Super secret code is: {super_secret_code}")


Expand Down
47 changes: 33 additions & 14 deletions FC_Board/config.json → FC_Board/configs.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"cubesatName": "Orpheus",
"callsign": "KO6AZM",
"last_battery_temp": 20.0,
"sleep_duration": 30,
"detumble_enable_z": true,
"detumble_enable_x": true,
"detumble_enable_y": true,
"jokes": [
#configs for functions.py
cubesatName = "Orpheus"
callsig = "KO6AZM"
last_battery_temp = 20.0
sleep_duration = 30
detumble_enable_z = true
detumble_enable_x = true
detumble_enable_y = true
jokes = [
"Hey it is pretty cold up here, did someone forget to pay the electric bill?",
"sudo rf - rf*",
"Why did the astronaut break up with his girlfriend? He needed space.",
Expand Down Expand Up @@ -42,14 +42,33 @@
"CQ CQ KN6NAQ ... KN6NAT are you out there?",
"Woah is that the Launcher Orbiter?????",
"Everything in life is a spring if you think hard enough!"
],
"super_secret_code": "ABCD",
"repeat_code": "RP",
"jokereply": [
]

#configs for pysquared.py
debug = true
legacy = false
heating = false
orpheus = true
is_licensed = true
NORMAL_TEMP = 20
NORMAL_BATT_TEMP = 1
NORMAL_MICRO_TEMP = 20
NORMAL_CHARGE_CURRENT = 0.5
NORMAL_BATTERY_VOLTAGE = 6.9
CRITICAL_BATTERY_VOLTAGE = 6.6
vlowbatt = 6.0
battery_voltage = 3.3
current_draw = 255
REBOOT_TIME = 3600
turbo_clock = false

#configs for cdh.py
super_secret_code = "ABCD"
repeat_code = "RP"
jokereply = [
"Your Mom",
"Your Mum",
"Your Face",
"not True lol",
"I have brought peace, freedom, justice, and security to my new empire! Your New Empire?"
]
}
25 changes: 12 additions & 13 deletions FC_Board/lib/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import gc
import traceback
import random
import json
import tomllib
from debugcolor import co
from battery_helper import BatteryHelper
from packet_manager import PacketManager
Expand Down Expand Up @@ -39,23 +39,22 @@ def __init__(self, cubesat: Satellite) -> None:
self.pm: PacketManager = PacketManager(max_packet_size=128)
self.ps: PacketSender = PacketSender(cubesat.radio1, self.pm, max_retries=3)

# parses config data from json file & assigns data to variables
with open("config.json", "r") as json_file:
json_data = json_file.read()
parsed_data = json.loads(json_data)
# parses toml file & assigns data to variables
with open("configs.toml", "rb") as f:
toml_data: dict = tomllib.load(f)

self.cubesatName: str = parsed_data["cubesatName"]
self.cubesatName: str = toml_data["cubesatName"]
self.Errorcount: int = 0
self.facestring: list = [None, None, None, None, None]
self.jokes: list[str] = parsed_data["jokes"]
self.last_battery_temp: float = parsed_data["last_battery_temp"]
self.sleep_duration: int = parsed_data["sleep_duration"]
self.callsign: str = parsed_data["callsign"]
self.jokes: list[str] = toml_data["jokes"]
self.last_battery_temp: float = toml_data["last_battery_temp"]
self.sleep_duration: int = toml_data["sleep_duration"]
self.callsign: str = toml_data["callsign"]
self.state_bool: bool = False
self.face_data_baton: bool = False
self.detumble_enable_z: bool = parsed_data["detumble_enable_z"]
self.detumble_enable_x: bool = parsed_data["detumble_enable_x"]
self.detumble_enable_y: bool = parsed_data["detumble_enable_y"]
self.detumble_enable_z: bool = toml_data["detumble_enable_z"]
self.detumble_enable_x: bool = toml_data["detumble_enable_x"]
self.detumble_enable_y: bool = toml_data["detumble_enable_y"]

"""
Satellite Management Functions
Expand Down
41 changes: 20 additions & 21 deletions FC_Board/lib/pysquared.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import adafruit_tca9548a # I2C Multiplexer
import rv3028
import adafruit_ov5640
import json
import tomllib

# CAN Bus Import
from adafruit_mcp2515 import MCP2515 as CAN
Expand Down Expand Up @@ -81,44 +81,43 @@ def error_print(self, statement):
print(co("[pysquared]" + str(statement), "red", "bold"))

def __init__(self):
# parses config data from json file & assigns data to variables
with open("config.json", "r") as json_file:
json_data = json_file.read()
parsed_data = json.loads(json_data)
# parses toml file & assigns data to variables
with open("configs.toml", "rb") as f:
toml_data: dict = tomllib.load(f)

"""
Big init routine as the whole board is brought up. Starting with config variables.
"""
self.debug = parsed_data["debug"] # Define verbose output here. True or False
self.legacy = parsed_data[
self.debug = toml_data["debug"] # Define verbose output here. True or False
self.legacy = toml_data[
"legacy"
] # Define if the board is used with legacy or not
self.heating = parsed_data["heating"] # Currently not used
self.orpheus = parsed_data[
self.heating = toml_data["heating"] # Currently not used
self.orpheus = toml_data[
"orpheus"
] # Define if the board is used with Orpheus or not
self.is_licensed = parsed_data["is_licensed"]
self.is_licensed = toml_data["is_licensed"]

"""
Define the normal power modes
"""
self.NORMAL_TEMP = parsed_data["NORMAL_TEMP"]
self.NORMAL_BATT_TEMP = parsed_data[
self.NORMAL_TEMP = toml_data["NORMAL_TEMP"]
self.NORMAL_BATT_TEMP = toml_data[
"NORMAL_BATT_TEMP"
] # Set to 0 BEFORE FLIGHT!!!!!
self.NORMAL_MICRO_TEMP = parsed_data["NORMAL_MICRO_TEMP"]
self.NORMAL_CHARGE_CURRENT = parsed_data["NORMAL_CHARGE_CURRENT"]
self.NORMAL_BATTERY_VOLTAGE = parsed_data["NORMAL_BATTERY_VOLTAGE"] # 6.9
self.CRITICAL_BATTERY_VOLTAGE = parsed_data["CRITICAL_BATTERY_VOLTAGE"] # 6.6
self.vlowbatt = parsed_data["vlowbatt"]
self.battery_voltage = parsed_data[
self.NORMAL_MICRO_TEMP = toml_data["NORMAL_MICRO_TEMP"]
self.NORMAL_CHARGE_CURRENT = toml_data["NORMAL_CHARGE_CURRENT"]
self.NORMAL_BATTERY_VOLTAGE = toml_data["NORMAL_BATTERY_VOLTAGE"] # 6.9
self.CRITICAL_BATTERY_VOLTAGE = toml_data["CRITICAL_BATTERY_VOLTAGE"] # 6.6
self.vlowbatt = toml_data["vlowbatt"]
self.battery_voltage = toml_data[
"battery_voltage"
] # default value for testing REPLACE WITH REAL VALUE
self.current_draw = parsed_data[
self.current_draw = toml_data[
"current_draw"
] # default value for testing REPLACE WITH REAL VALUE
self.REBOOT_TIME = parsed_data["REBOOT_TIME"] # 1 hour
self.turbo_clock = parsed_data["turbo_clock"]
self.REBOOT_TIME = toml_data["REBOOT_TIME"] # 1 hour
self.turbo_clock = toml_data["turbo_clock"]

"""
Setting up data buffers
Expand Down

0 comments on commit 3536058

Please sign in to comment.