Skip to content
Draft
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
Binary file added apps/.DS_Store
Binary file not shown.
Binary file added apps/obc/.DS_Store
Binary file not shown.
155 changes: 155 additions & 0 deletions apps/obc/src/idle.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* Copyright (c) 2025 The FINCH CubeSat Project Flight Software Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @file
* @brief Idle command sequence implementation
*/

#include "idle.h"
#include <stdbool.h>
#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(idle, LOG_LEVEL_INF);

/**
* @brief OBC transmits spacecraft orient command
*/
int obc_command_orient(const char *attitude)
{
// sim transmission
return 0;
}

/**
* @brief Orient satellite through ADCS
*/
static bool adcs_execute_orient(const char *attitude)
{
// sim execution
return true;
}

/**
* @brief Performs internal system health check on OBC
*/
static bool obc_system_health_check(void)
{
//add internal logic
return true;
}

/**
* @brief OBC checks for scheduled tasks
*/
static bool obc_check_scheduled(void)
{
// sim check
return true;
}

/**
* @brief OBC Schedules mode change
*/
int obc_scheduled_mode_change(const char *command_mode, const char *mode_params, const char *schedule)
{
// sim succcessful scheduling
return 0;
}

/**
* @brief OBC logs error
*/
void obc_log_error(const char *errortype)
{
LOG_INF("OBC error: %s", errortype);
}

/**
* @brief if contact is not established between RF and OBC
*/
void rf_msg_error(const char *errortype)
{
LOG_INF("RF message error: %s", errortype);
}

/**
* @brief PAY enters specified mode
*/
int pay_enter_mode(const char *command_mode)
{
// sim mode entry
return 0;
}

/**
* @brief RF transmits command to OBC
*/
static bool rf_transmit_command_modechange(const char *command_mode, const char *mode_params, const char *schedule)
{
// sim transmission
return true;
}

/**
* @brief MCC transmits command to RF
*/
int mcc_transmit_command_modechange(const char *command_mode, const char *mode_params, const char *schedule)
{
// sim transmission
return 0;
}

/**
* @brief Main loop handling the idle command sequence logic
*/
int idle_command_sequence(void)
{
const char *attitude = "sunpointing";
const char *command_mode = "cmdmode";
const char *mode_params = "modeparams";
const char *schedule = "scheduled";
const char *errortype = "comms";

// unused for now
(void)attitude;
(void)command_mode;
(void)mode_params;
(void)schedule;
(void)errortype;

obc_command_orient("sunpointing");
if (adcs_execute_orient("sunpointing") == true) {
if (obc_system_health_check() == false) {
pay_enter_mode("safety");
}
} else {
pay_enter_mode("safety");
}

if (obc_check_scheduled() == true) {
// sim scheduled
pay_enter_mode("cmdmode");
}

mcc_transmit_command_modechange("cmdmode", "modeparams", "scheduled");

if (rf_transmit_command_modechange("cmdmode", "modeparams", "scheduled") == true) {
if (obc_scheduled_mode_change("cmdmode", "modeparams", "scheduled") == true) {
pay_enter_mode("cmdmode");
} else {
obc_log_error("comms");
}
} else {
rf_msg_error("comms");
obc_log_error("comms");
pay_enter_mode("safety");
}
return 0;
}

// to avoid unused function warning cppcheck
(void)idle_command_sequence;
34 changes: 34 additions & 0 deletions apps/obc/src/idle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2025 The FINCH CubeSat Project Flight Software Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @file idle.h
* @brief Header for Idle Command Sequence Logic
*/

#ifndef idle_h
#define idle_h

#include <stdbool.h>

/**
* @brief system modules involved in idle command sequence
*/
typedef enum system_module {
MODULE_OPERATOR,
MODULE_MCC_GS,
MODULE_RF,
MODULE_OBC,
MODULE_ADCS,
MODULE_PAY
} system_module;

/**
* @brief executes the idle command sequence
*/
int idle_command_sequence(void);

#endif
72 changes: 72 additions & 0 deletions apps/obc/src/obc_check.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2025 The FINCH CubeSat Project Flight Software Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "obc_check.h"
#include <stdbool.h>
#include <stdio.h>

/*
* static functions keep internal logic here
*/

// individual node pings (Level 3)
static bool ping_srs4(void)
{
printf("Pinging SRS4...\n");
// TODO: implement actual logic
return true; // simulated success
}

static bool ping_eps(void)
{
printf("Pining EPS (Power)...\n");
// TODO: actual logic
return true; // simulated success
}

static bool ping_10m(void)
{
printf("Pinging ADCS...\n");
// TODO: actual logic
return true; // simulated success
}

// Level 2
static bool ping_all_CSP_nodes(void)
{
bool srs4_ok = ping_srs4();
bool EPS_ok = ping_eps();
bool ADCS_ok = ping_10m();

return srs4_ok && EPS_ok && ADCS_ok;
}

static bool flash_check(void)
{
printf("checking flash memory...\n");
// TODO: logic
return true; // simnulated success
}

static bool external_RTC_check(void)
{
printf("Checking external RTC...\n");
// TODO: logic
return true; // sim success
}

// level 1
bool obc_check(void)
{
bool ping_ok = ping_all_CSP_nodes;
bool flash_ok = flash_check;
bool RTC_ok = external_RTC_check;

return ping_ok && flash_ok && RTC_ok;
}

// to avoid unused function warning cppcheck
(void)obc_check;
25 changes: 25 additions & 0 deletions apps/obc/src/obc_check.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2025 The FINCH CubeSat Project Flight Software Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef OBC_CHECK_H
#define OBC_CHECK_H

#include <stdbool.h>

/**
* @brief Runs the full OBC system check
*
* Checks:
* - Ping all CSP nodes (RF, ADCS, EPS)
* - Flash memory health
* - External RTC functionality
*
* @return true is all checks pass, fail otherwise
*/

bool obc_check(void);

#endif
Loading