-
Notifications
You must be signed in to change notification settings - Fork 3
Sdcard logging #27
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
Open
asiemsen
wants to merge
6
commits into
main
Choose a base branch
from
sdcard_logging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Sdcard logging #27
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1528d8b
change boot sequence to allow for writing to internal file system
asiemsen ec5382f
adding sd init to main.py
asiemsen f6f62da
cleaned files
asiemsen deac851
getting rid of usbmodem101 directory
asiemsen 83708bd
move sd card injection after sd init
asiemsen 7c3e576
new boot sequence to use mkdir function
asiemsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from lib.pysquared.boot.filesystem import mkdir | ||
|
||
# Create the SD card directory so we can mount it later | ||
mkdir("/sd") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from lib.pysquared.boot.filesystem import mkdir | ||
|
||
# Create the SD card directory so we can mount it later | ||
mkdir("/sd") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"critical_battery_voltage": 6.6, | ||
"cubesat_name": "PROVES-MY_SATELLITE_NAME", | ||
"current_draw": 240.5, | ||
"debug": true, | ||
"degraded_battery_voltage": 5.4, | ||
"detumble_enable_x": true, | ||
"detumble_enable_y": true, | ||
"detumble_enable_z": true, | ||
"heating": false, | ||
"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.", | ||
"Why did the sun go to school? To get a little brighter.", | ||
"why is the mall called the mall? because instead of going to one store you go to them all", | ||
"Alien detected. Blurring photo...", | ||
"Wait it is all open source? Always has been... www.github.com/proveskit", | ||
"What did 0 say to 1? You're a bit too much.", | ||
"Pleiades - Orpheus has been recently acquired by the Onion News Network", | ||
"This jokesat was brought to you by the Bronco Space Ministry of Labor and Job Placement", | ||
"Catch you on the next pass!", | ||
"Pleiades - Orpheus was not The Impostor", | ||
"Sorry for messing with your long-exposure astrophoto!", | ||
"Better buy a telescope. Wanna see me. Buy a telescope. Gonna be in space.", | ||
"According to all known laws of aviation, there is no way bees should be able to fly...", | ||
"You lost the game ", | ||
"Bobby Tables is a good friend of mine", | ||
"Why did the computer cross the road? To get a byte to eat!", | ||
"Why are the astronauts not hungry when they got to space? They had a big launch.", | ||
"Why did the computer get glasses? To improve its web sight!", | ||
"What are computers favorite snacks? Chips!", | ||
"Wait! I think I see a White 2019 Subaru Crosstrek 2.0i Premium", | ||
"IS THAT A SUPRA?!", | ||
"Finally escpaed the LA Traffic", | ||
"My CubeSat is really good at jokes, but its delivery is always delayed.", | ||
"exec order 66", | ||
"I had a joke about UDP, but I am not sure if you'd get it.", | ||
"I am not saying FSK modulation is the best way to send jokes, but at least it is never monotone!", | ||
"I am sorry David, I am afrain I can not do that.", | ||
"My memory is volatile like RAM, so it only makes sense that I forget things.", | ||
"Imagine it gets stuck and just keeps repeating this joke every 2 mins", | ||
"Check Engine: Error Code 404: Joke Not Found", | ||
"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!", | ||
"Your Mom", | ||
"Your Mum", | ||
"Your Face", | ||
"not True lol", | ||
"I have brought peace, freedom, justice, and security to my new empire! Your New Empire?" | ||
], | ||
"last_battery_temp": 20.0, | ||
"longest_allowable_sleep_time": 600, | ||
"normal_battery_temp": 1, | ||
"normal_battery_voltage": 6.9, | ||
"normal_charge_current": 0.5, | ||
"normal_micro_temp": 20, | ||
"normal_temp": 20, | ||
"radio": { | ||
"fsk": { | ||
"broadcast_address": 255, | ||
"modulation_type": 0, | ||
"node_address": 1 | ||
}, | ||
"license": "KK4PDM", | ||
"lora": { | ||
"ack_delay": 0.2, | ||
"coding_rate": 8, | ||
"cyclic_redundancy_check": true, | ||
"max_output": true, | ||
"spreading_factor": 8, | ||
"transmit_power": 23 | ||
}, | ||
"modulation": "LoRa", | ||
"start_time": 80000, | ||
"transmit_frequency": 437.4 | ||
}, | ||
"reboot_time": 3600, | ||
"repeat_code": "RP", | ||
"sleep_duration": 30, | ||
"super_secret_code": "ABCD", | ||
"turbo_clock": false | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
# This is where the magic happens! | ||
# This file is executed on every boot (including wake-boot from deepsleep) | ||
# Created By: Michael Pham | ||
|
||
""" | ||
Built for the PySquared FC Board | ||
Version: 2.0.0 | ||
Published: Nov 19, 2024 | ||
""" | ||
|
||
import gc | ||
import os | ||
import time | ||
|
||
import digitalio | ||
import microcontroller | ||
from busio import SPI | ||
|
||
try: | ||
from board_definitions import proveskit_rp2040_v4 as board | ||
except ImportError: | ||
import board | ||
|
||
from lib.proveskit_rp2040_v4.register import Register | ||
from lib.pysquared.beacon import Beacon | ||
from lib.pysquared.cdh import CommandDataHandler | ||
from lib.pysquared.config.config import Config | ||
from lib.pysquared.hardware.busio import _spi_init, initialize_i2c_bus | ||
from lib.pysquared.hardware.digitalio import initialize_pin | ||
from lib.pysquared.hardware.imu.manager.lsm6dsox import LSM6DSOXManager | ||
from lib.pysquared.hardware.magnetometer.manager.lis2mdl import LIS2MDLManager | ||
from lib.pysquared.hardware.radio.manager.rfm9x import RFM9xManager | ||
from lib.pysquared.hardware.radio.packetizer.packet_manager import PacketManager | ||
from lib.pysquared.hardware.sd_card.manager.sd_card import SDCardManager | ||
from lib.pysquared.logger import Logger, LogLevel | ||
from lib.pysquared.nvm.counter import Counter | ||
from lib.pysquared.rtc.manager.microcontroller import MicrocontrollerManager | ||
from lib.pysquared.sleep_helper import SleepHelper | ||
from lib.pysquared.watchdog import Watchdog | ||
from version import __version__ | ||
|
||
boot_time: float = time.time() | ||
|
||
rtc = MicrocontrollerManager() | ||
|
||
(boot_count := Counter(index=Register.boot_count)).increment() | ||
error_count: Counter = Counter(index=Register.error_count) | ||
|
||
|
||
logger: Logger = Logger( | ||
error_counter=error_count, | ||
colorized=False, | ||
log_level=LogLevel.INFO, | ||
) | ||
|
||
logger.info( | ||
"Booting", | ||
hardware_version=os.uname().version, | ||
software_version=__version__, | ||
) | ||
|
||
try: | ||
loiter_time: int = 5 | ||
for i in range(loiter_time): | ||
logger.info(f"Code Starting in {loiter_time-i} seconds") | ||
time.sleep(1) | ||
|
||
watchdog = Watchdog(logger, board.WDT_WDI) | ||
watchdog.pet() | ||
|
||
logger.debug("Initializing Config") | ||
config: Config = Config("config.json") | ||
|
||
# TODO(nateinaction): fix spi init | ||
spi0: SPI = _spi_init( | ||
logger, | ||
board.SPI0_SCK, | ||
board.SPI0_MOSI, | ||
board.SPI0_MISO, | ||
) | ||
|
||
sdCard: SDCardManager = SDCardManager(spi0, board.SPI0_CS1) | ||
|
||
logger.set_log_dir("/sd") | ||
|
||
radio = RFM9xManager( | ||
logger, | ||
config.radio, | ||
spi0, | ||
initialize_pin(logger, board.SPI0_CS0, digitalio.Direction.OUTPUT, True), | ||
initialize_pin(logger, board.RF1_RST, digitalio.Direction.OUTPUT, True), | ||
) | ||
|
||
packet_manager = PacketManager( | ||
logger, | ||
radio, | ||
config.radio.license, | ||
Counter(Register.message_count), | ||
0.2, | ||
) | ||
|
||
i2c1 = initialize_i2c_bus( | ||
logger, | ||
board.I2C1_SCL, | ||
board.I2C1_SDA, | ||
100000, | ||
) | ||
|
||
magnetometer = LIS2MDLManager(logger, i2c1) | ||
|
||
imu = LSM6DSOXManager(logger, i2c1, 0x6B) | ||
|
||
sleep_helper = SleepHelper(logger, config, watchdog) | ||
|
||
cdh = CommandDataHandler(logger, config, packet_manager) | ||
|
||
beacon = Beacon( | ||
logger, | ||
config.cubesat_name, | ||
packet_manager, | ||
boot_time, | ||
imu, | ||
magnetometer, | ||
radio, | ||
error_count, | ||
boot_count, | ||
) | ||
|
||
def nominal_power_loop(): | ||
logger.debug( | ||
"FC Board Stats", | ||
bytes_remaining=gc.mem_free(), | ||
) | ||
|
||
packet_manager.send(config.radio.license.encode("utf-8")) | ||
|
||
beacon.send() | ||
|
||
cdh.listen_for_commands(10) | ||
|
||
sleep_helper.safe_sleep(config.sleep_duration) | ||
|
||
try: | ||
logger.info("Entering main loop") | ||
while True: | ||
# TODO(nateinaction): Modify behavior based on power state | ||
nominal_power_loop() | ||
|
||
except Exception as e: | ||
logger.critical("Critical in Main Loop", e) | ||
time.sleep(10) | ||
microcontroller.on_next_reset(microcontroller.RunMode.NORMAL) | ||
microcontroller.reset() | ||
finally: | ||
logger.info("Going Neutral!") | ||
|
||
except Exception as e: | ||
logger.critical("An exception occured within main.py", e) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Let's bring this into the pysquared repo. How about we create a new module inside of pysquared called
boot
and we can add this as a callable function from that module. It looks like the function might take 3 arguments:mount_points
,wait_time
, andattempts
. Once it's in pysquared, we can write tests and reuse this in the other board repos.