2020-02-23 17:22:37 +00:00
|
|
|
/*
|
|
|
|
* umb_status_request.c
|
|
|
|
*
|
|
|
|
* Created on: 23.02.2020
|
|
|
|
* Author: mateusz
|
|
|
|
*/
|
|
|
|
|
2023-06-30 21:01:36 +00:00
|
|
|
#include <stored_configuration_nvm/config_data.h>
|
2020-02-23 17:22:37 +00:00
|
|
|
#include "../umb_master/umb_master.h"
|
2020-02-29 21:12:08 +00:00
|
|
|
#include "../umb_master/umb_0x26_status.h"
|
2020-03-20 21:53:24 +00:00
|
|
|
#include "main.h"
|
2020-02-23 17:22:37 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2021-04-05 19:48:23 +00:00
|
|
|
umb_retval_t umb_0x26_status_request(umb_frame_t* frame, umb_context_t* ctx, const config_data_umb_t * const config_umb) {
|
2020-02-23 17:22:37 +00:00
|
|
|
|
2020-03-18 20:56:02 +00:00
|
|
|
if (ctx->state != UMB_STATUS_IDLE && ctx->state != UMB_STATUS_ERROR) {
|
2020-02-23 17:22:37 +00:00
|
|
|
return UMB_BUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame->command_id = 0x26;
|
2021-04-05 19:48:23 +00:00
|
|
|
frame->slave_class = (uint8_t)(config_umb->slave_class & 0xFF);
|
|
|
|
frame->slave_id = (uint8_t)(config_umb->slave_id & 0xFF);
|
2020-02-23 17:22:37 +00:00
|
|
|
frame->lenght = 0;
|
|
|
|
|
|
|
|
memset(frame->payload, 0x00, UMB_FRAME_MAX_PAYLOAD_LN);
|
|
|
|
|
2020-03-07 18:13:24 +00:00
|
|
|
ctx->state = UMB_STATUS_READY_TO_SEND;
|
2020-03-18 20:56:02 +00:00
|
|
|
ctx->current_routine = 0x26;
|
2020-02-23 17:22:37 +00:00
|
|
|
|
|
|
|
return UMB_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-29 21:12:08 +00:00
|
|
|
umb_retval_t umb_0x26_status_callback(umb_frame_t* frame, umb_context_t* ctx) {
|
2020-02-23 17:22:37 +00:00
|
|
|
|
2020-03-18 20:56:02 +00:00
|
|
|
// return value
|
|
|
|
umb_retval_t output = UMB_OK;
|
|
|
|
|
|
|
|
// first byte of the response is always 0x00 then one or more error code is transmitted
|
|
|
|
uint8_t error_codes_amount = frame->lenght - 1;
|
|
|
|
|
|
|
|
uint8_t first_errc = frame->payload[1];
|
|
|
|
|
|
|
|
// error code set to 0x00 means just that device operates normally and there are no errors
|
|
|
|
if (first_errc == 0x00) {
|
|
|
|
// so just do nothing and then return from the function
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// copy error codes to context
|
|
|
|
for (int i = 0; i < error_codes_amount && i < UMB_CONTEXT_ERR_HISTORY_LN; i++) {
|
|
|
|
|
|
|
|
// copy current error code to the buffer
|
|
|
|
ctx->nok_error_codes[ctx->nok_error_it] = frame->payload[1 + i];
|
|
|
|
|
|
|
|
// move the iterator through the buffer
|
2020-03-23 20:41:01 +00:00
|
|
|
ctx->nok_error_it++;
|
|
|
|
|
|
|
|
// check if and end of the buffer is reach here
|
|
|
|
ctx->nok_error_it %= UMB_CONTEXT_ERR_HISTORY_LN;
|
2020-03-18 20:56:02 +00:00
|
|
|
}
|
2020-03-20 21:53:24 +00:00
|
|
|
|
|
|
|
// storing the time when last error code will be stored
|
2020-04-11 19:37:01 +00:00
|
|
|
ctx->time_of_last_nok = main_get_master_time();
|
2020-04-10 20:54:30 +00:00
|
|
|
|
|
|
|
// trigger the status message with a content of fault store
|
|
|
|
ctx->trigger_status_msg = 1;
|
2020-03-18 20:56:02 +00:00
|
|
|
}
|
2020-02-23 17:22:37 +00:00
|
|
|
|
2020-02-29 21:12:08 +00:00
|
|
|
ctx->state = UMB_STATUS_IDLE;
|
2020-02-23 17:22:37 +00:00
|
|
|
|
2020-03-18 20:56:02 +00:00
|
|
|
return output;
|
2020-02-23 17:22:37 +00:00
|
|
|
}
|
2020-02-29 21:12:08 +00:00
|
|
|
|