Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #12 from AlbertaSat/startup_telemetry_alt
Browse files Browse the repository at this point in the history
Startup telemetry alt
  • Loading branch information
arrooney authored Nov 12, 2021
2 parents b7805bc + 2ae2ad2 commit 31db4dd
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 14 deletions.
44 changes: 35 additions & 9 deletions hardware_interface/include/eps.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
/**
* @file eps.h
* @author Andrew Rooney, Dustin Wagner
* @author Andrew Rooney, Dustin Wagner, Grace Yi
* @date 2020-12-28
*/
#ifndef EX2_SERVICES_PLATFORM_OBC_EPS_H_
Expand Down Expand Up @@ -58,7 +58,7 @@ typedef struct __attribute__((packed)) {

struct __attribute__((packed)) eps_instantaneous_telemetry {
uint8_t cmd; // value 0
int8_t status; // 0 on success
int8_t status; // 0 on success
double timestampInS; // with ms precision
uint32_t uptimeInS;
uint32_t bootCnt; // system startup count
Expand All @@ -80,26 +80,52 @@ struct __attribute__((packed)) eps_instantaneous_telemetry {
uint16_t outputOnDelta[18]; // seconds
uint16_t outputOffDelta[18]; // seconds
uint8_t outputFaultCnt[18];
int8_t temp[14]; // 1-4 MPPT converter temp, 5-8 output converter temp, 9 on-board battery temp, 1012
// external battery pack temp, 13-14 -output expander temp
uint8_t battMode; // 0 critical, 1 safe, 2 normal, 3 full
uint8_t mpptMode; // 0 HW, 1 manual, 2 auto, 3 auto with timeout
uint8_t batHeaterMode; // 0 manual, 1 auto
uint8_t batHeaterState; // 0 off, 1 on
int8_t temp[14]; // 1-4 MPPT converter temp, 5-8 output converter temp, 9 on-board battery temp, 10-12
// external battery pack temp, 13-14 -output expander temp
uint8_t battMode; // 0 critical, 1 safe, 2 normal, 3 full
uint8_t mpptMode; // 0 HW, 1 manual, 2 auto, 3 auto with timeout
uint8_t batHeaterMode; // 0 manual, 1 auto
uint8_t batHeaterState; // 0 off, 1 on
uint16_t PingWdt_toggles; // Total number of power channel toggles caused by failed ping watchdog
uint8_t PingWdt_turnOffs; // Total number of power channel offs caused by failed ping watchdog
};

struct __attribute__((packed)) eps_startup_telemetry {
uint8_t cmd;
int8_t status;
double timestamp; // with ms precision
uint32_t last_reset_reason_reg; //Last reset reason register value, see below
uint32_t bootCnt; // total system boot count
uint8_t FallbackConfigUsed;
uint8_t rtcInit;
uint8_t rtcClkSourceLSE;
// uint8_t flashAppInit;
int8_t Fram4kPartitionInit;
int8_t Fram520kPartitionInit;
int8_t intFlashPartitionInit;
int8_t FSInit;
int8_t FTInit;
int8_t supervisorInit;
uint8_t uart1App;
uint8_t uart2App;
int8_t tmp107Init;
};


enum eps_mode { critical = 0, safe = 1, normal = 2, full = 3 };

typedef struct eps_instantaneous_telemetry eps_instantaneous_telemetry_t;
typedef struct eps_startup_telemetry eps_startup_telemetry_t;
typedef enum eps_mode eps_mode_e;

SAT_returnState eps_refresh_instantaneous_telemetry();
SAT_returnState eps_refresh_startup_telemetry();
eps_instantaneous_telemetry_t get_eps_instantaneous_telemetry();
void EPS_getHK(eps_instantaneous_telemetry_t *telembuf);
eps_startup_telemetry_t get_eps_startup_telemetry();
void EPS_getHK(eps_instantaneous_telemetry_t *telembuf, eps_startup_telemetry_t *telem_startup_buf);
eps_mode_e get_eps_batt_mode();
void prv_instantaneous_telemetry_letoh(eps_instantaneous_telemetry_t *telembuf);
void prv_startup_telemetry_letoh(eps_startup_telemetry_t *telem_startup_buf);
// If changing the two functions below, update system tasks, too.
uint8_t eps_get_pwr_chnl(uint8_t pwr_chnl_port);
int8_t eps_set_pwr_chnl(uint8_t pwr_chnl_port, bool status);
Expand Down
75 changes: 70 additions & 5 deletions hardware_interface/source/eps.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
/**
* @file eps.c
* @author Andrew Rooney, Dustin Wagner
* @author Andrew Rooney, Dustin Wagner, Grace Yi
* @date 2020-12-28
*/

Expand All @@ -34,13 +34,16 @@
#include "services.h"

void prv_instantaneous_telemetry_letoh(eps_instantaneous_telemetry_t *telembuf);
void prv_startup_telemetry(eps_startup_telemetry_t *telem_startup_buf);
static inline void prv_set_instantaneous_telemetry(eps_instantaneous_telemetry_t telembuf);
static inline void prv_set_startup_telemetry(eps_startup_telemetry_t telem_startup_buf);
static inline void prv_get_lock(eps_t *eps);
static inline void prv_give_lock(eps_t *eps);
static eps_t *prv_get_eps();

struct eps_t {
eps_instantaneous_telemetry_t hk_telemetery;
eps_startup_telemetry_t hk_startup_telemetry;
SemaphoreHandle_t eps_lock;
};

Expand All @@ -51,9 +54,9 @@ static eps_t prvEps;
SAT_returnState eps_refresh_instantaneous_telemetry() {
uint8_t cmd = 0; // 'subservice' command
eps_instantaneous_telemetry_t telembuf;
int res = csp_ping(EPS_APP_ID, 10000, 100, CSP_O_NONE);
int res = csp_ping(EPS_APP_ID, EPS_REQUEST_TIMEOUT, 100, CSP_O_NONE);

csp_transaction_w_opts(CSP_PRIO_LOW, EPS_APP_ID, EPS_INSTANTANEOUS_TELEMETRY, 10000, &cmd, sizeof(cmd),
csp_transaction_w_opts(CSP_PRIO_LOW, EPS_APP_ID, EPS_INSTANTANEOUS_TELEMETRY, EPS_REQUEST_TIMEOUT, &cmd, sizeof(cmd),
&telembuf, sizeof(eps_instantaneous_telemetry_t), CSP_O_CRC32);
// data is little endian, must convert to host order
// refer to the NanoAvionics datasheet for details
Expand All @@ -62,6 +65,19 @@ SAT_returnState eps_refresh_instantaneous_telemetry() {
return SATR_OK;
}

SAT_returnState eps_refresh_startup_telemetry() {
uint8_t cmd = 1; // ' subservice' command defined in ICD Section 24.2.2
eps_startup_telemetry_t telem_startup_buf;

csp_transaction_w_opts(CSP_PRIO_LOW, EPS_APP_ID, EPS_INSTANTANEOUS_TELEMETRY, EPS_REQUEST_TIMEOUT, &cmd, sizeof(cmd),
&telem_startup_buf, sizeof(eps_startup_telemetry_t), CSP_O_CRC32);
// data is little endian, must convert to host order
// refer to the NanoAvionics datasheet for details
prv_startup_telemetry_letoh(&telem_startup_buf);
prv_set_startup_telemetry(telem_startup_buf);
return SATR_OK;
}

eps_instantaneous_telemetry_t get_eps_instantaneous_telemetry() {
eps_instantaneous_telemetry_t telembuf;
eps_t *eps;
Expand All @@ -73,6 +89,17 @@ eps_instantaneous_telemetry_t get_eps_instantaneous_telemetry() {
return telembuf;
}

eps_startup_telemetry_t get_eps_startup_telemetry() {
eps_startup_telemetry_t telem_startup_buf;
eps_t *eps;
eps = prv_get_eps();
prv_get_lock(eps);
configASSERT(eps);
telem_startup_buf = eps->hk_startup_telemetry;
prv_give_lock(eps);
return telem_startup_buf;
}

/**
* @brief
* Electronic Power System get Housekeeping data
Expand All @@ -87,12 +114,13 @@ eps_instantaneous_telemetry_t get_eps_instantaneous_telemetry() {
* but currently no return
*
*/
void EPS_getHK(eps_instantaneous_telemetry_t *telembuf) {
void EPS_getHK(eps_instantaneous_telemetry_t *telembuf, eps_startup_telemetry_t *telem_startup_buf) {
eps_t *eps;
eps = prv_get_eps();
prv_get_lock(eps);
configASSERT(eps);

//General telemetry (defined in ICD Section 24.2.1)
telembuf->cmd = eps->hk_telemetery.cmd;
telembuf->status = eps->hk_telemetery.status;
telembuf->timestampInS = eps->hk_telemetery.timestampInS;
Expand Down Expand Up @@ -136,6 +164,26 @@ void EPS_getHK(eps_instantaneous_telemetry_t *telembuf) {
telembuf->temp[i] = eps->hk_telemetery.temp[i];
}

//Startup telemetry (defined in ICD Section 24.2.2)
telem_startup_buf->cmd = eps->hk_startup_telemetry.cmd;
telem_startup_buf->status = eps->hk_startup_telemetry.status;
telem_startup_buf->timestamp = eps->hk_startup_telemetry.timestamp;
telem_startup_buf->last_reset_reason_reg = eps->hk_startup_telemetry.last_reset_reason_reg;
telem_startup_buf->bootCnt = eps->hk_startup_telemetry.bootCnt;
telem_startup_buf->FallbackConfigUsed = eps->hk_startup_telemetry.FallbackConfigUsed;
telem_startup_buf->rtcInit = eps->hk_startup_telemetry.rtcInit;
telem_startup_buf->rtcClkSourceLSE = eps->hk_startup_telemetry.rtcClkSourceLSE;
//telem_startup_buf->flashAppInit = eps->hk_startup_telemetry.flashAppInit;
telem_startup_buf->Fram4kPartitionInit = eps->hk_startup_telemetry.Fram4kPartitionInit;
telem_startup_buf->Fram520kPartitionInit = eps->hk_startup_telemetry.Fram520kPartitionInit;
telem_startup_buf->intFlashPartitionInit = eps->hk_startup_telemetry.intFlashPartitionInit;
telem_startup_buf->FSInit = eps->hk_startup_telemetry.FSInit;
telem_startup_buf->FTInit = eps->hk_startup_telemetry.FTInit;
telem_startup_buf->supervisorInit = eps->hk_startup_telemetry.supervisorInit;
telem_startup_buf->uart1App = eps->hk_startup_telemetry.uart1App;
telem_startup_buf->uart2App = eps->hk_startup_telemetry.uart2App;
telem_startup_buf->tmp107Init = eps->hk_startup_telemetry.tmp107Init;

prv_give_lock(eps);
}

Expand All @@ -162,7 +210,7 @@ int8_t eps_set_pwr_chnl(uint8_t pwr_chnl_port, bool status) {
cmd[1] = pwr_chnl_port;
cmd[2] = status;
// delay = 0 so cmd{4] = cmd[5] = 0
csp_transaction_w_opts(CSP_PRIO_LOW, EPS_APP_ID, EPS_POWER_CONTROL, 10000, &cmd, sizeof(cmd), &response,
csp_transaction_w_opts(CSP_PRIO_LOW, EPS_APP_ID, EPS_POWER_CONTROL, EPS_REQUEST_TIMEOUT, &cmd, sizeof(cmd), &response,
sizeof(response), CSP_O_CRC32);
return response[1];
}
Expand Down Expand Up @@ -248,3 +296,20 @@ void prv_instantaneous_telemetry_letoh(eps_instantaneous_telemetry_t *telembuf)
telembuf->PingWdt_toggles = csp_letoh16(telembuf->PingWdt_toggles);
telembuf->timestampInS = csp_letohd(telembuf->timestampInS);
}

static inline void prv_set_startup_telemetry(eps_startup_telemetry_t telem_startup_buf) {
eps_t *eps = prv_get_eps();
prv_get_lock(eps);
eps->hk_startup_telemetry = telem_startup_buf;
prv_give_lock(eps);
return;
}

void prv_startup_telemetry_letoh(eps_startup_telemetry_t *telem_startup_buf) {
uint8_t i;

telem_startup_buf->timestamp = csp_letohd(telem_startup_buf->timestamp);
telem_startup_buf->last_reset_reason_reg = csp_letoh32(telem_startup_buf->last_reset_reason_reg);
telem_startup_buf->bootCnt = csp_letoh32(telem_startup_buf->bootCnt);

}

0 comments on commit 31db4dd

Please sign in to comment.