Skip to content

Commit

Permalink
Added IO-board set commands
Browse files Browse the repository at this point in the history
  • Loading branch information
vedderb committed Feb 16, 2022
1 parent ead2d6a commit 7ba0f8c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
21 changes: 21 additions & 0 deletions comm_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,27 @@ bms_soc_soh_temp_stat *comm_can_get_bms_stat_v_cell_min(void) {
return &bms_stat_v_cell_min;
}

void comm_can_io_board_set_output_digital(int id, int channel, bool on) {
int32_t send_index = 0;
uint8_t buffer[8];

buffer[send_index++] = channel;
buffer[send_index++] = 1;
buffer[send_index++] = on ? 1 : 0;

comm_can_transmit_eid(id | ((uint32_t)CAN_PACKET_IO_BOARD_SET_OUTPUT_DIGITAL << 8), buffer, send_index);
}

void comm_can_io_board_set_output_pwm(int id, int channel, float duty) {
int32_t send_index = 0;
uint8_t buffer[8];

buffer[send_index++] = channel;
buffer_append_float16(buffer, duty, 1e3, &send_index);

comm_can_transmit_eid(id | ((uint32_t)CAN_PACKET_IO_BOARD_SET_OUTPUT_PWM << 8), buffer, send_index);
}

psw_status *comm_can_get_psw_status_index(int index) {
if (index < CAN_STATUS_MSGS_TO_STORE) {
return &psw_stat[index];
Expand Down
6 changes: 6 additions & 0 deletions comm_can.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ can_status_msg_5 *comm_can_get_status_msg_5_id(int id);
bms_soc_soh_temp_stat *comm_can_get_bms_soc_soh_temp_stat_index(int index);
bms_soc_soh_temp_stat *comm_can_get_bms_soc_soh_temp_stat_id(int id);
bms_soc_soh_temp_stat *comm_can_get_bms_stat_v_cell_min(void);

// IO Board
void comm_can_io_board_set_output_digital(int id, int channel, bool on);
void comm_can_io_board_set_output_pwm(int id, int channel, float duty);

// Power switch
psw_status *comm_can_get_psw_status_index(int index);
psw_status *comm_can_get_psw_status_id(int id);
void comm_can_psw_switch(int id, bool is_on, bool plot);
Expand Down
18 changes: 17 additions & 1 deletion commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,23 @@ void commands_process_packet(unsigned char *data, unsigned int len,
chMtxUnlock(&terminal_mutex);
break;

// Power switch
case COMM_IO_BOARD_SET_PWM: {
int32_t ind = 0;
int id = buffer_get_int16(data, &ind);
int channel = buffer_get_int16(data, &ind);
float duty = buffer_get_float32_auto(data, &ind);
comm_can_io_board_set_output_pwm(id, channel, duty);
} break;

case COMM_IO_BOARD_SET_DIGITAL: {
int32_t ind = 0;
int id = buffer_get_int16(data, &ind);
int channel = buffer_get_int16(data, &ind);
bool on = data[ind++];
comm_can_io_board_set_output_digital(id, channel, on);
} break;

// Power switch
case COMM_PSW_GET_STATUS: {
int32_t ind = 0;
bool by_id = data[ind++];
Expand Down
2 changes: 1 addition & 1 deletion conf_general.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define FW_VERSION_MAJOR 6
#define FW_VERSION_MINOR 00
// Set to 0 for building a release and iterate during beta test builds
#define FW_TEST_VERSION_NUMBER 1
#define FW_TEST_VERSION_NUMBER 2

// Init codes for the persistent storage. Change the config code when updating the config struct
// in a way that is not backwards compatible.
Expand Down

0 comments on commit 7ba0f8c

Please sign in to comment.