Skip to content

Commit

Permalink
Merge pull request #198 from spacelab-ufsc/fix/eps-data-structure/#197
Browse files Browse the repository at this point in the history
Fix/eps data structure/#197
  • Loading branch information
joaoclaudioeb authored Sep 26, 2024
2 parents 760f3af + 0e02363 commit a696d69
Show file tree
Hide file tree
Showing 25 changed files with 265 additions and 114 deletions.
42 changes: 37 additions & 5 deletions firmware/app/structs/eps2_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
* \{
*/

#include <FreeRTOS.h>
#include <task.h>
#include <system/sys_log/sys_log.h>
#include <system/system.h>

Expand All @@ -55,14 +57,19 @@ eps_data_t eps_data_buff = {

.heater2_mode = 0,
.heater2_duty_cycle = 50,

.beacon_enable = 0,

.firmware_version = 0x00000300,
.hardware_version = 0,
.time_counter_ms = 0,
.reset_counter = 0,
.device_id = 0xEEE2
};

int eps_buffer_write(uint8_t id, uint32_t *value)
{
taskENTER_CRITICAL();
switch(id)
{
case EPS2_PARAM_ID_TIMESTAMP:
Expand Down Expand Up @@ -190,19 +197,31 @@ int eps_buffer_write(uint8_t id, uint32_t *value)
eps_data_buff.heater2_duty_cycle = *value;
break;
case EPS2_PARAM_ID_HW_VERSION:
eps_data_buff.firmware_version = *value;
eps_data_buff.hardware_version = *value;
break;
case EPS2_PARAM_ID_FW_VERSION:
eps_data_buff.hardware_version = *value;
eps_data_buff.firmware_version = *value;
break;
case EPS2_PARAM_ID_MPPT_1_MODE:
eps_data_buff.mppt_1_mode = *value;
if (eps_data_buff.mppt_1_mode == 1) // MPPT is set to manual mode
{
eps_data_buff.mppt_1_duty_cycle = 40;
}
break;
case EPS2_PARAM_ID_MPPT_2_MODE:
eps_data_buff.mppt_2_mode = *value;
if (eps_data_buff.mppt_2_mode == 1) // MPPT is set to manual mode
{
eps_data_buff.mppt_2_duty_cycle = 40;
}
break;
case EPS2_PARAM_ID_MPPT_3_MODE:
eps_data_buff.mppt_3_mode = *value;
if (eps_data_buff.mppt_3_mode == 1) // MPPT is set to manual mode
{
eps_data_buff.mppt_3_duty_cycle = 40;
}
break;
case EPS2_PARAM_ID_BAT_HEATER_1_MODE:
eps_data_buff.heater1_mode = *value;
Expand All @@ -213,17 +232,22 @@ int eps_buffer_write(uint8_t id, uint32_t *value)
case EPS2_PARAM_ID_DEVICE_ID:
eps_data_buff.device_id = *value;
break;
case EPS2_PARAM_ID_BEACON_ENABLE:
eps_data_buff.beacon_enable = *value;
break;
default:
sys_log_print_event_from_module(SYS_LOG_ERROR, EPS_DATA_NAME, "Unknown parameter ID!");
sys_log_new_line();
return -1;
}
taskEXIT_CRITICAL();

return 0;
}

int eps_buffer_read(uint8_t id, uint32_t *value)
{
taskENTER_CRITICAL();

#if CONFIG_SET_DUMMY_EPS == 1
switch(id)
Expand Down Expand Up @@ -375,6 +399,9 @@ int eps_buffer_read(uint8_t id, uint32_t *value)
case EPS2_PARAM_ID_DEVICE_ID:
*value = 0xEEE2U;
break;
case EPS2_PARAM_ID_BEACON_ENABLE:
*value = 1;
break;
default:
sys_log_print_event_from_module(SYS_LOG_ERROR, EPS_DATA_NAME, "Unknown parameter ID!");
sys_log_new_line();
Expand Down Expand Up @@ -477,7 +504,8 @@ int eps_buffer_read(uint8_t id, uint32_t *value)
*value = eps_data_buff.batteries_accumulated_ma;
break;
case EPS2_PARAM_ID_BAT_CHARGE:
*value = eps_data_buff.batteries_charge_mah;
/* DEPRECATED PARAMETER! Returns the accumulated current value. */
*value = eps_data_buff.batteries_accumulated_ma;
break;
case EPS2_PARAM_ID_BAT_MONITOR_TEMP:
*value = eps_data_buff.bm_temp_kelvin;
Expand Down Expand Up @@ -510,10 +538,10 @@ int eps_buffer_read(uint8_t id, uint32_t *value)
*value = eps_data_buff.heater2_duty_cycle;
break;
case EPS2_PARAM_ID_HW_VERSION:
*value = eps_data_buff.firmware_version;
*value = eps_data_buff.hardware_version;
break;
case EPS2_PARAM_ID_FW_VERSION:
*value = eps_data_buff.hardware_version;
*value = eps_data_buff.firmware_version;
break;
case EPS2_PARAM_ID_MPPT_1_MODE:
*value = eps_data_buff.mppt_1_mode;
Expand All @@ -533,11 +561,15 @@ int eps_buffer_read(uint8_t id, uint32_t *value)
case EPS2_PARAM_ID_DEVICE_ID:
*value = eps_data_buff.device_id;
break;
case EPS2_PARAM_ID_BEACON_ENABLE:
*value = eps_data_buff.beacon_enable;
break;
default:
sys_log_print_event_from_module(SYS_LOG_ERROR, EPS_DATA_NAME, "Unknown parameter ID!");
sys_log_new_line();
return -1;
}
taskEXIT_CRITICAL();

return 0;
}
Expand Down
14 changes: 8 additions & 6 deletions firmware/app/structs/eps2_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ typedef enum
EPS2_PARAM_ID_BAT_CURRENT = 27,
EPS2_PARAM_ID_BAT_AVERAGE_CURRENT = 28,
EPS2_PARAM_ID_BAT_ACC_CURRENT = 29,
EPS2_PARAM_ID_BAT_CHARGE = 30,
EPS2_PARAM_ID_BAT_CHARGE = 30, /* DEPRECATED PARAMETER! Returns the accumulated current value. */
EPS2_PARAM_ID_BAT_MONITOR_TEMP = 31,
EPS2_PARAM_ID_BAT_MONITOR_STATUS = 32,
EPS2_PARAM_ID_BAT_MONITOR_PROTECT = 33,
Expand All @@ -99,6 +99,7 @@ typedef enum
EPS2_PARAM_ID_DEVICE_ID = 48,
EPS2_PARAM_ID_RESET_EPS = 49,
EPS2_PARAM_ID_PAYLOAD_ENABLE = 50,
EPS2_PARAM_ID_BEACON_ENABLE = 51
} eps2_param_id_e;

/**
Expand Down Expand Up @@ -148,13 +149,13 @@ typedef struct
uint16_t batteries_ma; /**< Batteries current in mA. */
uint16_t batteries_average_ma; /**< Batteries average current in 8 mA measurements. */
uint16_t batteries_accumulated_ma; /**< Batteries accumulated current in mA. */
uint16_t batteries_charge_mah; /**< Batteries charge in mAh. */
uint16_t batteries_charge_mah; /**< Batteries charge in mAh. */ /* DEPRECATED PARAMETER! Returns the accumulated current value. */
uint32_t batteries_rtd0_kelvin; /**< Batteries RTD 0 temperature in kelvin. */
uint32_t batteries_rtd1_kelvin; /**< Batteries RTD 1 temperature in kelvin. */
uint32_t batteries_rtd2_kelvin; /**< Batteries RTD 2 temperature in kelvin. */
uint32_t batteries_rtd3_kelvin; /**< Batteries RTD 3 temperature in kelvin. */
uint8_t heater1_duty_cycle; /**< Batteries heater 1 duty cyle in %. */
uint8_t heater2_duty_cycle; /**< Batteries heater 2 duty cyle in %. */
uint8_t heater1_duty_cycle; /**< Batteries heater 1 duty cyle in %. */
uint8_t heater2_duty_cycle; /**< Batteries heater 2 duty cyle in %. */

/**
* Battery monitor related data.
Expand All @@ -173,8 +174,9 @@ typedef struct
*/
uint32_t firmware_version; /**< Hard-coded firmware version of EPS. */
uint8_t hardware_version; /**< Hard-coded hardware version of EPS. */
uint16_t device_id; /**< Hard-coded device id of EPS. */

uint16_t device_id; /**< Hard-coded device id of EPS. */
uint8_t beacon_enable; /**< Hard-coded hardware version of EPS. */

} eps_data_t;

/**
Expand Down
39 changes: 27 additions & 12 deletions firmware/app/tasks/device_response.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,46 @@ xTaskHandle xTaskDeviceResponseHandle;

void vTaskDeviceResponse(void *pvParameters)
{

uint8_t buf[DEVICE_RESPONSE_BUFFER_SIZE] = {0};
uint32_t val = 0;

/* Wait startup task to finish */
xEventGroupWaitBits(task_startup_status, TASK_STARTUP_DONE, pdFALSE, pdTRUE, pdMS_TO_TICKS(TASK_DEVICE_RESPONSE_INIT_TIMEOUT_MS));

/* Delay before the first cycle */
vTaskDelay(pdMS_TO_TICKS(TASK_DEVICE_RESPONSE_INITIAL_DELAY_MS));

uint8_t beacon_param_list[] = {
BEACON_PARAM_ID_LIST,
};
const uint8_t BEACON_PARAM_LIST_SIZE = sizeof(beacon_param_list) / sizeof(*beacon_param_list);

const uint8_t DEVICE_RESPONSE_BUFFER_SIZE = 1 + 4 * BEACON_PARAM_LIST_SIZE;
uint8_t buf[DEVICE_RESPONSE_BUFFER_SIZE] = {0};
uint32_t val = 0;
uint8_t beacon_flag = 0;

while(1)
{
TickType_t last_cycle = xTaskGetTickCount();

buf[0] = DEVICE_COMMAND_WRITE;
for(uint8_t i = 0, j = 1; i < EPS_DATA_STRUCTURE_SIZE; i++, j+=4)

eps_buffer_read(EPS2_PARAM_ID_BEACON_ENABLE, &beacon_flag);
if(beacon_flag > 0)
{
eps_buffer_read(i, &val);
buf[ j ] = (val >> 24) & 0xFF;
buf[j+1] = (val >> 16) & 0xFF;
buf[j+2] = (val >> 8) & 0xFF;
buf[j+3] = (val >> 0) & 0xFF;
for(uint8_t i = 0, j = 1; i < BEACON_PARAM_LIST_SIZE; i++, j+=4)
{
eps_buffer_read(beacon_param_list[i], &val);
buf[ j ] = (val >> 24) & 0xFF;
buf[j+1] = (val >> 16) & 0xFF;
buf[j+2] = (val >> 8) & 0xFF;
buf[j+3] = (val >> 0) & 0xFF;
}
ttc_answer_long(buf, DEVICE_RESPONSE_BUFFER_SIZE);
}
else
{
sys_log_print_event_from_module(SYS_LOG_INFO, TASK_DEVICE_RESPONSE_NAME, "The beacon is not enabled");
sys_log_new_line();
}

ttc_answer_long(buf, DEVICE_RESPONSE_BUFFER_SIZE);

vTaskDelayUntil(&last_cycle, pdMS_TO_TICKS(TASK_DEVICE_RESPONSE_PERIOD_MS));
}
Expand Down
2 changes: 0 additions & 2 deletions firmware/app/tasks/device_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
#define TASK_DEVICE_RESPONSE_INIT_TIMEOUT_MS 10000UL /**< Wait time to initialize the task in milliseconds. */
#define TASK_DEVICE_RESPONSE_INITIAL_DELAY_MS 10000UL /**< Delay, in milliseconds, before the first execution. */

#define EPS_DATA_STRUCTURE_SIZE 49
#define DEVICE_RESPONSE_BUFFER_SIZE (1 + 4 * EPS_DATA_STRUCTURE_SIZE) /* 1 + (49 * 4) bytes --- CMD + EPS_DATA_STRUCTURE_SIZE in bytes */
#define DEVICE_COMMAND_WRITE 0x03

/**
Expand Down
2 changes: 2 additions & 0 deletions firmware/app/tasks/heartbeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* \brief Heartbeat task implementation.
*
* \author Yan Castro de Azeredo <yan.ufsceel@gmail.com>
* \author João Cláudio Elsen Barcellos <joaoclaudiobarcellos@gmail.com>
* \author Ramon de Araujo Borba <ramonborba97@gmail.com>
*
* \version 0.1.6
*
Expand Down
2 changes: 2 additions & 0 deletions firmware/app/tasks/heartbeat.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* \brief Heartbeat task definition.
*
* \author Yan Castro de Azeredo <yan.ufsceel@gmail.com>
* \author João Cláudio Elsen Barcellos <joaoclaudiobarcellos@gmail.com>
* \author Ramon de Araujo Borba <ramonborba97@gmail.com>
*
* \version 0.1.6
*
Expand Down
4 changes: 3 additions & 1 deletion firmware/app/tasks/heater_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
*
* \author André M. P. de Mattos <andre.mattos@spacelab.ufsc.br>
* \author Gabriel Mariano Marcelino <gabriel.mm8@gmail.com>
* \author João Cláudio Elsen Barcellos <joaoclaudiobarcellos@gmail.com>
* \author Ramon de Araujo Borba <ramonborba97@gmail.com>
*
* \version 0.2.36
*
Expand Down Expand Up @@ -175,4 +177,4 @@ void heater_control(int channel, uint32_t mode, uint32_t duty_cycle)
}
}

/** \} End of heater_controller group */
/** \} End of heater_controller group */
2 changes: 2 additions & 0 deletions firmware/app/tasks/heater_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* \brief Heater controller task definition.
*
* \author André M. P. de Mattos <andre.mattos@spacelab.ufsc.br>
* \author João Cláudio Elsen Barcellos <joaoclaudiobarcellos@gmail.com>
* \author Ramon de Araujo Borba <ramonborba97@gmail.com>
*
* \version 0.2.36
*
Expand Down
Loading

0 comments on commit a696d69

Please sign in to comment.