diff --git a/apps/.DS_Store b/apps/.DS_Store new file mode 100644 index 0000000..fd781e5 Binary files /dev/null and b/apps/.DS_Store differ diff --git a/apps/obc/.DS_Store b/apps/obc/.DS_Store new file mode 100644 index 0000000..4eaef20 Binary files /dev/null and b/apps/obc/.DS_Store differ diff --git a/apps/obc/src/idle.c b/apps/obc/src/idle.c new file mode 100644 index 0000000..df4b8c4 --- /dev/null +++ b/apps/obc/src/idle.c @@ -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 +#include + +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; diff --git a/apps/obc/src/idle.h b/apps/obc/src/idle.h new file mode 100644 index 0000000..80abc5e --- /dev/null +++ b/apps/obc/src/idle.h @@ -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 + +/** + * @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 diff --git a/apps/obc/src/obc_check.c b/apps/obc/src/obc_check.c new file mode 100644 index 0000000..bc8afee --- /dev/null +++ b/apps/obc/src/obc_check.c @@ -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 +#include + +/* + * 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; diff --git a/apps/obc/src/obc_check.h b/apps/obc/src/obc_check.h new file mode 100644 index 0000000..53d801b --- /dev/null +++ b/apps/obc/src/obc_check.h @@ -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 + +/** + * @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