This class is to encode and decode DCDT format data which is used between VIVIWARE Cell App, Core, and Branch.
More...
#include <VivicoreSerialDataCode.h>
|
| DataCodeTranslator (void) |
|
| DataCodeTranslator (const dcInfo_t *dc_info, const uint8_t dc_num, bool *initialized) |
|
uint8_t | getDcNum (void) |
|
const dcInfo_t * | getDcInfo (void) |
|
bool | hasBinary (void) |
|
bool | hasError (void) |
|
bool | hasFatalError (void) |
|
bool | init (const dcInfo_t *dc_info, const uint8_t dc_num) |
|
bool | encode (const int16_t *encoding_values, data_pkt *out) |
|
bool | encode (const int16_t *encoding_values, const bool *is_set, data_pkt *out, const bool is_initial_data=false) |
|
bool | decode (const data_pkt *in, int16_t *values, uint8_t *dc_nums, uint8_t *dc_nums_count) |
|
This class is to encode and decode DCDT format data which is used between VIVIWARE Cell App, Core, and Branch.
◆ DataCodeTranslator() [1/2]
DataCodeTranslator::DataCodeTranslator |
( |
void |
| ) |
|
|
inline |
Constructor which does not call init. Caller needs to call init by itself.
◆ DataCodeTranslator() [2/2]
DataCodeTranslator::DataCodeTranslator |
( |
const dcInfo_t * |
dc_info, |
|
|
const uint8_t |
dc_num, |
|
|
bool * |
initialized |
|
) |
| |
Constructor which calls init internally. Caller does not need to call init by itself.
- Parameters
-
[in] | dc_info | Pointer to dcInfo_t array buffer |
[in] | dc_num | dc_info array buffer's length |
[out] | initialized | true if init succeeded. false in another case. |
◆ decode()
bool DataCodeTranslator::decode |
( |
const data_pkt * |
in, |
|
|
int16_t * |
values, |
|
|
uint8_t * |
dc_nums, |
|
|
uint8_t * |
dc_nums_count |
|
) |
| |
This API decodes DC format data and corresponding DC numbers which is received from core. This API does nothing and returns false if hasFatalError returns true, but can be used even if hasError returns true. This API returns false if there is at least one of the following errors in encoding process for each DC.
- Parameters
-
[in] | in | Data to be decoded. The first 2 bytes should be DC flags. |
[out] | values | Array of values decoded from in data. The length of array should be less or equal to the number of DC info array specified to init. |
[out] | dc_nums | Array of DC numbers decoded from in data. The length of array should be less or equal to the number of DC info array specified to init. |
[out] | dc_nums_count | Actual number of DC stored in dc_nums. |
- Returns
- true if all DC data in the input data is valid. false in another case.
- Warning
- It is better for caller of this method to check if no error in DC info by using hasError method.
-
This method cannot decode data if any of the following errors was included in input data.
- Data for DC over the maximum number specified in DC info at init
- Invalid or unknown DC type is included in DC info.
◆ encode() [1/2]
bool DataCodeTranslator::encode |
( |
const int16_t * |
encoding_values, |
|
|
const bool * |
is_set, |
|
|
data_pkt * |
out, |
|
|
const bool |
is_initial_data = false |
|
) |
| |
This API encodes data in encoding_values to be sent to core which are set as true in is_set. This API does nothing and returns false if hasFatalError returns true, but can be used even if hasError returns true. This API returns false if there is at least one of the following errors in encoding process for each DC.
- Encoding value is out of range between min and max which are specified in DC info at init
- DC nature is DC_NATURE_IN (Skip this error checking if is_initial_data is true)
- DC type is DC_TYPE_BINARY (Skip this error checking if is_initial_data is true)
- Parameters
-
[in] | encoding_values | Array of values to be encoded as DC. The length of array should be less or equal to the number of DC info array specified to init. |
[in] | is_set | Array of true/false flag to be encoded to DC in encoding_array. The length of array should be less or equal to the number of DC info array specified to init. |
[out] | out | DC format data to be sent to core. |
[in] | is_initial_data | Set true to encode DC min/max/ini. |
- Returns
- true if no error. false in another case.
- Warning
- It is better for caller of this method to check if no error in DC info by using hasError method.
◆ encode() [2/2]
bool DataCodeTranslator::encode |
( |
const int16_t * |
encoding_values, |
|
|
data_pkt * |
out |
|
) |
| |
This API encodes all of data in encoding_values to be sent to core. This API does nothing and returns false if hasFatalError returns true, but can be used even if hasError returns true. This API returns false if there is at least one of the following errors in encoding process for each DC.
- Encoding value is out of range between min and max which are specified in DC info at init
- Parameters
-
[in] | encoding_values | Array of values to be encoded as DC. The length of array should be equal to the number of DC info array specified to init. |
[out] | out | DC format data to be sent to core. |
- Returns
- true if no error. false in another case.
- Warning
- It is better for caller of this method to check if no error in DC info by using hasError method.
◆ getDcInfo()
const dcInfo_t* DataCodeTranslator::getDcInfo |
( |
void |
| ) |
|
|
inline |
This API returns the pointer to DC info array. It is necessary to be called after init.
- Returns
- Pointer to DC info array.
◆ getDcNum()
uint8_t DataCodeTranslator::getDcNum |
( |
void |
| ) |
|
|
inline |
This API returns the number of DC. It is necessary to be called after init.
- Returns
- Number of DC.
◆ hasBinary()
bool DataCodeTranslator::hasBinary |
( |
void |
| ) |
|
|
inline |
This API returns if DC info has binary type. It is necessary to be called after init.
- Returns
- true if DC info has binary type. false in another case.
◆ hasError()
bool DataCodeTranslator::hasError |
( |
void |
| ) |
|
|
inline |
Return true if DC info has any of errors in the following.
- The number of DC is less or equal to maximum value NUM_MAX_DC
- Calculated maximum packet size is less or equal to maximum value NUM_MAX_PKT_BODY_DATA_DC
- DC min and max are correct as logical and meets range of data type
- DC ini of DC_NATURE_IN meets range of min and max
- DC of binary is only a DC definition if it exists
- Returns
- true if any error of above conditions. false in another case.
◆ hasFatalError()
bool DataCodeTranslator::hasFatalError |
( |
void |
| ) |
|
|
inline |
Return true if DC info has any of errors in the following.
- All DC type meets DcType_t
- Returns
- true if any error of above conditions. false in another case.
◆ init()
bool DataCodeTranslator::init |
( |
const dcInfo_t * |
dc_info, |
|
|
const uint8_t |
dc_num |
|
) |
| |
Initialize the class instance
- Parameters
-
[in] | dc_info | Pointer to dcInfo_t array buffer |
[in] | dc_num | dc_info array length |
- Returns
- true if no error in DC. false if DC has any of the errors in hasFatalError or hasError.
The documentation for this class was generated from the following files: