summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-02-21 17:16:59 +0000
committerRomain Forlot <romain.forlot@iot.bzh>2017-02-22 12:15:12 +0100
commitcddc9c28e3e1a242e55f68c9971d0710ada30e9f (patch)
tree007eff68d56578400ed2ce39b9eec7cbfe7d6850 /src
parentc535c3bb2d73327772c1bb72c9fcca3f8a7f8204 (diff)
Fix: decoder_t class decodeSignal method signature
Change-Id: Id7ef4fe3b8d3f5b14fd447cf05865ba494862792 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r--src/can-decoder.cpp14
-rw-r--r--src/can-decoder.hpp8
-rw-r--r--src/can-signals.hpp2
-rw-r--r--src/openxc-utils.cpp42
-rw-r--r--src/openxc-utils.hpp4
5 files changed, 37 insertions, 33 deletions
diff --git a/src/can-decoder.cpp b/src/can-decoder.cpp
index 0c8c8039..b163011f 100644
--- a/src/can-decoder.cpp
+++ b/src/can-decoder.cpp
@@ -15,10 +15,9 @@
* limitations under the License.
*/
-decoder_t::decoder_t()
- : decoded_value{false, openxc_DynamicField_Type_STRING, false, "", false, 0, false, false}
-{
-}
+#pragma once
+
+#include "can-decoder.hpp"
float decoder_t::parseSignalBitfield(const CanSignal& signal, const CanMessage& message)
{
@@ -75,17 +74,18 @@ openxc_DynamicField decoder_t::stateDecoder(const CanSignal& signal,
}
openxc_DynamicField decoder_t::decodeSignal(const CanSignal& signal,
- float value, const CanSignal& signals, bool* send)
+ float value, const std::vector<CanSignal>& signals, bool* send)
{
SignalDecoder decoder = signal->decoder == NULL ?
- noopDecoder : signal->decoder;
+ noopDecoder : signal->decoder;
openxc_DynamicField decoded_value = decoder(signal, signals,
value, send);
return decoded_value;
}
openxc_DynamicField decoder_t::decodeSignal(const CanSignal& signal,
- const CanMessage& message, const CanSignal& signals, bool* send) {
+ const can_message_t& message, const std::vector<CanSignal>& signals, bool* send)
+{
float value = parseSignalBitfield(signal, message);
return decodeSignal(signal, value, signals, send);
} \ No newline at end of file
diff --git a/src/can-decoder.hpp b/src/can-decoder.hpp
index 1b58ea3c..7f02d610 100644
--- a/src/can-decoder.hpp
+++ b/src/can-decoder.hpp
@@ -22,7 +22,6 @@
class decoder_t
{
private:
- openxc_DynamicField decoded_value;
public:
/* Public: Parse the signal's bitfield from the given data and return the raw
@@ -130,9 +129,8 @@ class decoder_t
* The decoder returns an openxc_DynamicField, which may contain a number,
* string or boolean. If 'send' is false, the return value is undefined.
*/
- openxc_DynamicField decodeSignal(const CanSignal& signal,
- const can_message_t& message, const CanSignal& signals,
- bool* send);
+ openxc_DynamicField decodeSignal(const CanSignal& signal, const can_message_t& message,
+ const std::vector<CanSignal>& signals, bool* send);
/* Public: Decode a transformed, human readable value from an raw CAN signal
* already parsed from a CAN message.
@@ -143,5 +141,5 @@ class decoder_t
* else.
*/
openxc_DynamicField decodeSignal(const CanSignal& signal, float value,
- const CanSignal& signals, bool* send);
+ const std::vector<CanSignal>& signals, bool* send);
}; \ No newline at end of file
diff --git a/src/can-signals.hpp b/src/can-signals.hpp
index 6d15d8b2..d6ec171a 100644
--- a/src/can-signals.hpp
+++ b/src/can-signals.hpp
@@ -64,7 +64,7 @@ CanMessageDefinition* getMessages();
/* Public: Return signals from an signals array filtered on name.
*/
-CanSignal* getSignals(std::string name);
+const std::vector<CanSignal> getSignals();
/* Public: Return an array of all OpenXC CAN commands enabled in the active
* configuration that can write back to CAN with a custom handler.
diff --git a/src/openxc-utils.cpp b/src/openxc-utils.cpp
index bdc772e7..5f001d41 100644
--- a/src/openxc-utils.cpp
+++ b/src/openxc-utils.cpp
@@ -16,19 +16,26 @@
* limitations under the License.
*/
+#include <string>
+#include <json-c/json.h>
+#include <sys/timeb.h>
+
+#include "openxc.pb.h"
+#include "openxc-utils.hpp"
+
openxc_VehicleMessage build_VehicleMessage_with_SimpleMessage(openxc_DynamicField_Type type, const openxc_SimpleMessage& message)
{
struct timeb t_msec;
long long int timestamp_msec;
- openxc_VehicleMessage v = {0};
+ openxc_VehicleMessage v;
- if(!ftime(&t_msec))
+ if(!::ftime(&t_msec))
{
timestamp_msec = ((long long int) t_msec.time) * 1000ll +
(long long int) t_msec.millitm;
- v.has_type = true:
+ v.has_type = true;
v.type = openxc_VehicleMessage_Type::openxc_VehicleMessage_Type_SIMPLE;
v.has_simple_message = true;
v.simple_message = message;
@@ -48,7 +55,7 @@ openxc_VehicleMessage build_VehicleMessage_with_SimpleMessage(openxc_DynamicFiel
openxc_SimpleMessage build_SimpleMessage(const std::string& name, const openxc_DynamicField& value)
{
- openxc_SimpleMessage s = {0};
+ openxc_SimpleMessage s;
s.has_name = true;
::strncpy(s.name, name.c_str(), 100);
@@ -60,41 +67,41 @@ openxc_SimpleMessage build_SimpleMessage(const std::string& name, const openxc_D
openxc_DynamicField build_DynamicField(const std::string& value)
{
- openxc_DynamicField d = {0}
+ openxc_DynamicField d;
d.has_type = true;
d.type = openxc_DynamicField_Type_STRING;
d.has_string_value = true;
- ::strncpy(d.string_value, value.c_tr(), 100);
+ ::strncpy(d.string_value, value.c_str(), 100);
return d;
}
openxc_DynamicField build_DynamicField(double value)
{
- openxc_DynamicField d = {0}
+ openxc_DynamicField d;
d.has_type = true;
d.type = openxc_DynamicField_Type_NUM;
d.has_numeric_value = true;
- d.numeric_value = field;
+ d.numeric_value = value;
return d;
}
openxc_DynamicField build_DynamicField(bool value)
{
- openxc_DynamicField d = {0}
+ openxc_DynamicField d;
d.has_type = true;
d.type = openxc_DynamicField_Type_BOOL;
d.has_boolean_value = true;
- d.boolean_value = field;
+ d.boolean_value = value;
return d;
}
-void jsonify_DynamicField(const openxc_DynamicField& field, const json_object& value)
+void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value)
{
if(field.has_numeric_value)
json_object_object_add(value, "value", json_object_new_double(field.numeric_value));
@@ -102,25 +109,24 @@ void jsonify_DynamicField(const openxc_DynamicField& field, const json_object& v
json_object_object_add(value, "value", json_object_new_boolean(field.boolean_value));
else if(field.has_string_value)
json_object_object_add(value, "value", json_object_new_string(field.string_value));
-
- return value;
}
openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg)
{
- return v_msg.has_simple_message ? v_msg.simple_message : {0};
+ if (v_msg.has_simple_message)
+ return v_msg.simple_message;
}
-json_object jsonify_simple(const openxc_SimpleMessage& s_msg)
+json_object* jsonify_simple(const openxc_SimpleMessage& s_msg)
{
json_object *json;
json = nullptr;
- if(s_msg->has_name)
+ if(s_msg.has_name)
{
json = json_object_new_object();
- json_object_object_add(json, "name", json_object_new_string(s_msg->name));
- jsonify_DynamicField(&s_msg->value, json);
+ json_object_object_add(json, "name", json_object_new_string(s_msg.name));
+ jsonify_DynamicField(s_msg.value, json);
}
return json;
} \ No newline at end of file
diff --git a/src/openxc-utils.hpp b/src/openxc-utils.hpp
index 295e99c5..c2614436 100644
--- a/src/openxc-utils.hpp
+++ b/src/openxc-utils.hpp
@@ -50,7 +50,7 @@ openxc_DynamicField build_DynamicField(double value);
*/
openxc_DynamicField build_DynamicField(bool value);
-void jsonify_DynamicField(const openxc_DynamicField& field, const json_object& value);
+void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value);
/**
* @brief Extract the simple message value from an openxc_VehicleMessage
@@ -58,4 +58,4 @@ void jsonify_DynamicField(const openxc_DynamicField& field, const json_object& v
*/
openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg);
-json_object jsonify_simple(const openxc_SimpleMessage& s_msg); \ No newline at end of file
+json_object* jsonify_simple(const openxc_SimpleMessage& s_msg); \ No newline at end of file