aboutsummaryrefslogtreecommitdiffstats
path: root/src/can-decoder.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-02-17 09:10:10 +0000
committerRomain Forlot <romain.forlot@iot.bzh>2017-02-20 11:14:55 +0000
commit860d6bd4a829ee5aca50b93122474c9bf68fff9d (patch)
tree9439480025436f103c40ba7e15e9a21bd3a51dfc /src/can-decoder.cpp
parent6f6364f74a4c454d096b0525bdb7563783ee80b7 (diff)
Rename header file to hpp.
Change-Id: I399e0c0f39b18e63e254825b6322faf77896a264 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/can-decoder.cpp')
-rw-r--r--src/can-decoder.cpp44
1 files changed, 21 insertions, 23 deletions
diff --git a/src/can-decoder.cpp b/src/can-decoder.cpp
index 000db2ac..0c8c8039 100644
--- a/src/can-decoder.cpp
+++ b/src/can-decoder.cpp
@@ -15,23 +15,20 @@
* limitations under the License.
*/
-Decoder::Decoder
+decoder_t::decoder_t()
+ : decoded_value{false, openxc_DynamicField_Type_STRING, false, "", false, 0, false, false}
{
- decoded_value = { .has_type = false,
- .has_numeric_value = false,
- .has_boolean_value = false,
- .has_string_value = false };
}
-float Decoder::parseSignalBitfield(CanSignal* signal, const CanMessage* message)
+float decoder_t::parseSignalBitfield(const CanSignal& signal, const CanMessage& message)
{
return bitfield_parse_float(message->data, CAN_MESSAGE_SIZE,
signal->bitPosition, signal->bitSize, signal->factor,
signal->offset);
}
-openxc_DynamicField Decoder::noopDecoder(CanSignal* signal,
- CanSignal* signals, int signalCount, float value, bool* send)
+openxc_DynamicField decoder_t::noopDecoder(const CanSignal& signal,
+ const CanSignal& signals, float value, bool* send)
{
decoded_value = { .has_type = true,
.type = openxc_DynamicField_Type_NUM,
@@ -40,8 +37,8 @@ openxc_DynamicField Decoder::noopDecoder(CanSignal* signal,
return decoded_value;
}
-openxc_DynamicField Decoder::booleanDecoder(CanSignal* signal,
- CanSignal* signals, int signalCount, float value, bool* send)
+openxc_DynamicField decoder_t::booleanDecoder(const CanSignal& signal,
+ const CanSignal& signals, float value, bool* send)
{
decoded_value = { .has_type = true,
.type = openxc_DynamicField_Type_BOOL,
@@ -50,16 +47,18 @@ openxc_DynamicField Decoder::booleanDecoder(CanSignal* signal,
return decoded_value;
}
-openxc_DynamicField Decoder::ignoreDecoder(CanSignal* signal,
- CanSignal* signals, int signalCount, float value, bool* send)
+openxc_DynamicField decoder_t::ignoreDecoder(const CanSignal& signal,
+ const CanSignal& signals, float value, bool* send)
{
- *send = false;
+ if(send)
+ *send = false;
+
openxc_DynamicField decoded_value = {0};
return decoded_value;
}
-openxc_DynamicField Decoder::stateDecoder(CanSignal* signal,
- CanSignal* signals, int signalCount, float value, bool* send)
+openxc_DynamicField decoder_t::stateDecoder(const CanSignal& signal,
+ const CanSignal& signals, float value, bool* send)
{
openxc_DynamicField decoded_value = {0};
decoded_value.has_type = true;
@@ -68,26 +67,25 @@ openxc_DynamicField Decoder::stateDecoder(CanSignal* signal,
const CanSignalState* signalState = lookupSignalState(value, signal);
if(signalState != NULL) {
- strcpy(decoded_value.string_value, signalState->name);
+ ::strcpy(decoded_value.string_value, signalState->name);
} else {
*send = false;
}
return decoded_value;
}
-openxc_DynamicField Decoder::decodeSignal(CanSignal* signal,
- float value, CanSignal* signals, int signalCount, bool* send)
+openxc_DynamicField decoder_t::decodeSignal(const CanSignal& signal,
+ float value, const CanSignal& signals, bool* send)
{
SignalDecoder decoder = signal->decoder == NULL ?
noopDecoder : signal->decoder;
openxc_DynamicField decoded_value = decoder(signal, signals,
- signalCount, value, send);
+ value, send);
return decoded_value;
}
-openxc_DynamicField Decoder::decodeSignal(CanSignal* signal,
- const CanMessage* message, CanSignal* signals, int signalCount,
- bool* send) {
+openxc_DynamicField decoder_t::decodeSignal(const CanSignal& signal,
+ const CanMessage& message, const CanSignal& signals, bool* send) {
float value = parseSignalBitfield(signal, message);
- return decodeSignal(signal, value, signals, signalCount, send);
+ return decodeSignal(signal, value, signals, send);
} \ No newline at end of file