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

Commit

Permalink
Update EPS housekeeping telemetry parameters (#5)
Browse files Browse the repository at this point in the history
* Update EPS telemetry parameters

* Update telemetry struct based on NA comments

* Add csp_letohd

* Update getHK based on new telemetry struct

* remove outdated members
  • Loading branch information
ArashYzd authored Jun 4, 2021
1 parent 1a4b7f9 commit 8593bff
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 59 deletions.
49 changes: 24 additions & 25 deletions hardware_interface/include/eps.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

#define SET_TELEMETRY_PERIOD 255
#define EPS_REQUEST_TIMEOUT 1000
#define EPS_INSTANTANEOUS_TELEMETRY 20
#define EPS_INSTANTANEOUS_TELEMETRY 7

QueueHandle_t eps_gatekeeper_q;

Expand Down Expand Up @@ -57,37 +57,35 @@ 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
uint32_t wdt_gs_time_left; //seconds
uint32_t wdt_gs_counter;
uint16_t mpptConverterVoltage[4]; //mV
uint16_t curSolarPanels[8]; //mA
uint16_t vBatt; //mV
uint16_t curSolar; //mA
uint16_t curBattIn; //mA
uint16_t curBattOut; //mA
uint16_t reserved1; //reserved for future use
uint16_t curOutput[10]; //mA
uint16_t curOutput[18]; //mA
uint16_t AOcurOutput[2]; //mA
uint16_t OutputConverterVoltage[4]; //mV
uint8_t outputConverterState[4];
uint16_t outputStatus; //10-bits
uint16_t outputFaultStatus; //10-bits
uint16_t outputOnDelta[10]; //seconds
uint16_t outputOffDelta[10]; //seconds
uint32_t outputFaultCnt[10];
uint16_t reserved2[6]; //reserved for future use
uint32_t wdt_gs_time_left; //seconds
uint16_t reserved3[7]; //reserved for future use
uint32_t wdt_gs_counter;
uint16_t reserved4[4]; //reserved for future use
int16_t temp[12]; //0-3 �MPPT converter temp, 4-7 �output converter temp, 8 �on-board battery temp, 9 �11 �external battery pack temp
uint32_t rstReason; //0x04000000 �NRST_pin, 0x14000000 �Software, 0x0C800000 �Power_on, 0x24000000 �IWDG
uint32_t bootCnt;
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 reserved5; //reserved for future use

uint16_t OutputConverterVoltage[8]; //mV
uint8_t outputConverterState;
uint32_t outputStatus; //18-bits
uint32_t outputFaultStatus; //18-bits
uint16_t protectedOutputAccessCnt;
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, 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
};

enum eps_mode {
Expand All @@ -108,5 +106,6 @@ void prv_instantaneous_telemetry_letoh (eps_instantaneous_telemetry_t *telembuf)
// If changing the two functions below, update system tasks, too.
int8_t eps_get_pwr_chnl(uint8_t pwr_chnl_port);
void eps_set_pwr_chnl(uint8_t pwr_chnl_port, bool bit);
double csp_letohd(double d);

#endif /* EX2_SERVICES_PLATFORM_OBC_EPS_H_ */
73 changes: 46 additions & 27 deletions hardware_interface/source/eps.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ SAT_returnState eps_refresh_instantaneous_telemetry() {
sizeof(eps_instantaneous_telemetry_t), CSP_O_CRC32);
// data is little endian, must convert to host order
// refer to the NanoAvionics datasheet for details
// prv_instantaneous_telemetry_letoh(&telembuf);
prv_instantaneous_telemetry_letoh(&telembuf);
prv_set_instantaneous_telemetry(telembuf);
return SATR_OK;
}
Expand Down Expand Up @@ -96,49 +96,44 @@ void EPS_getHK(eps_instantaneous_telemetry_t* telembuf) {

telembuf->cmd = eps->hk_telemetery.cmd;
telembuf->status = eps->hk_telemetery.status;
telembuf->timestampInS = eps->hk_telemetery.timestampInS;
telembuf->uptimeInS = eps->hk_telemetery.uptimeInS;
telembuf->bootCnt = eps->hk_telemetery.bootCnt;
telembuf->wdt_gs_time_left = eps->hk_telemetery.wdt_gs_time_left;
telembuf->wdt_gs_counter = eps->hk_telemetery.wdt_gs_counter;
telembuf->vBatt = eps->hk_telemetery.vBatt;
telembuf->curSolar = eps->hk_telemetery.curSolar;
telembuf->curBattIn = eps->hk_telemetery.curBattIn;
telembuf->curBattOut = eps->hk_telemetery.curBattOut;
telembuf->reserved1 = eps->hk_telemetery.reserved1;
telembuf->outputConverterState = eps->hk_telemetery.outputConverterState;
telembuf->outputStatus = eps->hk_telemetery.outputStatus;
telembuf->outputFaultStatus = eps->hk_telemetery.outputFaultStatus;
telembuf->wdt_gs_time_left = eps->hk_telemetery.wdt_gs_time_left;
telembuf->wdt_gs_counter = eps->hk_telemetery.wdt_gs_counter;
telembuf->rstReason = eps->hk_telemetery.rstReason;
telembuf->bootCnt = eps->hk_telemetery.bootCnt;
telembuf->protectedOutputAccessCnt = eps->hk_telemetery.protectedOutputAccessCnt;
telembuf->battMode = eps->hk_telemetery.battMode;
telembuf->mpptMode = eps->hk_telemetery.mpptMode;
telembuf->batHeaterMode = eps->hk_telemetery.batHeaterMode;
telembuf->batHeaterState = eps->hk_telemetery.batHeaterState;
telembuf->reserved5 = eps->hk_telemetery.reserved5;
telembuf->PingWdt_toggles = eps->hk_telemetery.PingWdt_toggles;
telembuf->PingWdt_turnOffs = eps->hk_telemetery.PingWdt_turnOffs;

uint8_t i;
for (i = 0; i < 2; i++) {
telembuf->AOcurOutput[i] = eps->hk_telemetery.AOcurOutput[i];
}
for (i = 0; i < 4; i++) {
telembuf->mpptConverterVoltage[i] = eps->hk_telemetery.mpptConverterVoltage[i];
telembuf->OutputConverterVoltage[i] = eps->hk_telemetery.OutputConverterVoltage[i];
telembuf->outputConverterState[i] = eps->hk_telemetery.outputConverterState[i];
telembuf->reserved4[i] = eps->hk_telemetery.reserved4[i];
}
for (i = 0; i < 6; i++) {
telembuf->reserved2[i] = eps->hk_telemetery.reserved2[i];
}
for (i = 0; i < 7; i++) {
telembuf->reserved3[i] = eps->hk_telemetery.reserved3[i];
}
for (i = 0; i < 8; i++) {
telembuf->curSolarPanels[i] = eps->hk_telemetery.curSolarPanels[i];
telembuf->OutputConverterVoltage[i] = eps->hk_telemetery.OutputConverterVoltage[i];
}
for (i = 0; i < 10; i++) {
for (i = 0; i < 18; i++) {
telembuf->curOutput[i] = eps->hk_telemetery.curOutput[i];
telembuf->outputOnDelta[i] = eps->hk_telemetery.outputOnDelta[i];
telembuf->outputOffDelta[i] = eps->hk_telemetery.outputOffDelta[i];
telembuf->outputFaultCnt[i] = eps->hk_telemetery.outputFaultCnt[i];
}
for (i = 0; i < 12; i++) {
for (i = 0; i < 14; i++) {
telembuf->temp[i] = eps->hk_telemetery.temp[i];
}

Expand All @@ -158,6 +153,30 @@ void eps_set_pwr_chnl(uint8_t pwr_chnl_port, bool bit){

}

/**
* @brief Convert 64-bit number from host byte order to little endian byte order
* @attention csp_letoh64 does not work correctly. Moving this function to
* csp_endian also returns a wrong value. The reason is probably the limitations
* of MCU on processing double precision floats.
*/
inline double __attribute__ ((__const__)) csp_letohd(double d) {
union v {
double d;
uint64_t i;
};
union v val;
val.d = d;
val.i = (((val.i & 0xff00000000000000LL) >> 56) |
((val.i & 0x00000000000000ffLL) << 56) |
((val.i & 0x00ff000000000000LL) >> 40) |
((val.i & 0x000000000000ff00LL) << 40) |
((val.i & 0x0000ff0000000000LL) >> 24) |
((val.i & 0x0000000000ff0000LL) << 24) |
((val.i & 0x000000ff00000000LL) >> 8) |
((val.i & 0x00000000ff000000LL) << 8));
return val.d;
}

/*------------------------------Private-------------------------------------*/

static eps_t* prv_get_eps() {
Expand Down Expand Up @@ -193,29 +212,29 @@ void prv_instantaneous_telemetry_letoh (eps_instantaneous_telemetry_t *telembuf)
}
for (i = 0; i < 4; i++) {
telembuf->mpptConverterVoltage[i] = csp_letoh16(telembuf->mpptConverterVoltage[i]);
telembuf->OutputConverterVoltage[i] = csp_letoh16(telembuf->OutputConverterVoltage[i]);
}
for (i = 0; i < 8; i++) {
telembuf->curSolarPanels[i] = csp_letoh16(telembuf->curSolarPanels[i]);
telembuf->OutputConverterVoltage[i] = csp_letoh16(telembuf->OutputConverterVoltage[i]);
}
for (i = 0; i < 10; i++) {
for (i = 0; i < 18; i++) {
telembuf->curOutput[i] = csp_letoh16(telembuf->curOutput[i]);
telembuf->outputOnDelta[i] = csp_letoh16(telembuf->outputOnDelta[i]);
telembuf->outputOffDelta[i] = csp_letoh16(telembuf->outputOffDelta[i]);
telembuf->outputFaultCnt[i] = csp_letoh32(telembuf->outputFaultCnt[i]);
}
for (i = 0; i < 12; i++) {
telembuf->temp[i] = csp_letoh16(telembuf->temp[i]);
}

telembuf->vBatt = csp_letoh16(telembuf->vBatt);
telembuf->curSolar = csp_letoh16(telembuf->curSolar);
telembuf->curBattIn = csp_letoh16(telembuf->curBattIn);
telembuf->curBattOut = csp_letoh16(telembuf->curBattOut);
telembuf->outputStatus = csp_letoh16(telembuf->outputStatus);
telembuf->outputStatus = csp_letoh32(telembuf->outputStatus);

telembuf->outputFaultStatus = csp_letoh16(telembuf->outputFaultStatus);
telembuf->outputFaultStatus = csp_letoh32(telembuf->outputFaultStatus);
telembuf->wdt_gs_time_left = csp_letoh32(telembuf->wdt_gs_time_left);
telembuf->wdt_gs_counter = csp_letoh32(telembuf->wdt_gs_counter);
telembuf->rstReason = csp_letoh32(telembuf->rstReason);
telembuf->bootCnt = csp_letoh32(telembuf->bootCnt);

telembuf->uptimeInS = csp_letoh32(telembuf->uptimeInS);
telembuf->PingWdt_toggles = csp_letoh16(telembuf->PingWdt_toggles);
telembuf->timestampInS = csp_letohd(telembuf->timestampInS);
}
7 changes: 0 additions & 7 deletions hardware_interface/source/mocks/mock_eps.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ static SAT_returnState prv_fill_dummy_data(csp_packet_t *packet) {
.curSolar = 10,
.curBattIn = 10,
.curBattOut = 10,
.reserved1 = 0,
.curOutput = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
.AOcurOutput = {1, 2},
.OutputConverterVoltage = {1, 2, 3, 4},
Expand All @@ -78,19 +77,13 @@ static SAT_returnState prv_fill_dummy_data(csp_packet_t *packet) {
.outputOnDelta = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
.outputOffDelta = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
.outputFaultCnt = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
.reserved2 = {1, 2, 3, 4, 5, 6},
.wdt_gs_time_left = 10,
.reserved3 = {1, 2, 3, 4, 5, 6, 7},
.wdt_gs_counter = 10,
.reserved4 = {1, 2, 3, 4},
.temp = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12},
.rstReason = 0x14000000,
.bootCnt = 10,
.battMode = 2,
.mpptMode = 2,
.batHeaterMode = 1,
.batHeaterState = 1,
.reserved5 = 0
};
// prv_instantaneous_telemetry_letoh(&telem);
memcpy(&packet->data, &telem, sizeof(eps_instantaneous_telemetry_t));
Expand Down

0 comments on commit 8593bff

Please sign in to comment.