kopia lustrzana https://github.com/SP8EBC/ParaTNC
65 wiersze
2.0 KiB
C
65 wiersze
2.0 KiB
C
/*
|
|
* kiss_did.c
|
|
*
|
|
* Implementation of all arrays defining data source for DIDs and function
|
|
* which generate raw binary data to be returned to a tester
|
|
*
|
|
* Created on: Jun 27, 2023
|
|
* Author: mateusz
|
|
*/
|
|
|
|
#include <etc/kiss_did_configuration.h>
|
|
#include <etc/kiss_configuation.h>
|
|
|
|
//!< Dummy variable used only as end of definition marker in tables
|
|
char did_dummy_data;
|
|
|
|
//!< Structure to define a DID which return numeric data
|
|
typedef struct kiss_did_numeric_definition_t {
|
|
uint16_t identifier;
|
|
void* first_data;
|
|
uint8_t first_data_size;
|
|
void* second_data;
|
|
uint8_t second_data_size;
|
|
void* third_data;
|
|
uint8_t third_data_size;
|
|
}kiss_did_numeric_definition_t;
|
|
|
|
//!< Definition of all DIDs with numeric data
|
|
const static kiss_did_numeric_definition_t kiss_did_def[] = {
|
|
DIDS_NUMERIC(DID_NUMERIC_DEFINITION_EXPANDER)
|
|
};
|
|
|
|
/**
|
|
* Creates a response for DID request into specified buffer. Please take into account
|
|
* that this function cannot use full size of this buffer. The exact content of the
|
|
* response is: FEND, NONSTANDARD, KISS_READ_DID_RESP, DID LSB, DID MSB, data, FEND.
|
|
* So in practice payload data may use only buffer_ln - 6 bytes of data.
|
|
*
|
|
* @param identifier
|
|
* @param output_buffer pointer to buffer where response will be generated into
|
|
* @param buffer_ln a size of this buffer, please be aware of note about available buffer!
|
|
*/
|
|
void kiss_did_response(uint16_t identifier, uint8_t * output_buffer, uint16_t buffer_ln) {
|
|
|
|
// iterator to go through DID definition
|
|
int i = 0;
|
|
|
|
// data of a did found in configuration
|
|
kiss_did_numeric_definition_t found = {.identifier = 0xFFFFu};
|
|
|
|
// iterate through DID definition and check if this id exist there
|
|
do {
|
|
// check if current position is the DID we're looking for
|
|
if (kiss_did_def[i].identifier == identifier) {
|
|
// if yes copy this data and exit the loop
|
|
found = kiss_did_def[i];
|
|
}
|
|
else {
|
|
// if no, go to the next DID definition
|
|
i++;
|
|
}
|
|
} while (kiss_did_def[i].identifier != 0xFFFFU);
|
|
|
|
}
|