2 * Copyright (C) 2015, 2016 "IoT.bzh"
3 * Author "Romain Forlot" <romain.forlot@iot.bzh>
4 * Author "Loic Collignon" <loic.collignon@iot.bzh>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include <json-c/json.h>
23 #include <sys/timeb.h>
25 #include "openxc.pb.h"
26 #include "../obd2/active-diagnostic-request.hpp"
29 * @brief Build a specific VehicleMessage containing a SimpleMessage.
31 * @param[in] message - simple message to include into openxc_VehicleMessage
33 * @return a vehicle message including simple message that will be convert into
34 * a JSON object before being pushed to the subscribers
36 openxc_VehicleMessage build_VehicleMessage(active_diagnostic_request_t* request, const DiagnosticResponse& response, float parsed_value);
37 openxc_VehicleMessage build_VehicleMessage(const openxc_SimpleMessage& message);
40 * @fn openxc_SimpleMessage build_SimpleMessage(const std::string& name, const openxc_DynamicField& value);
42 * @brief Build an openxc_SimpleMessage associating a name to an openxc_DynamicField
44 * @param[in] name - const string reference name to assign to the created SimpleMessage
45 * this will set has_name member to true and assign name to the name member. Maximum size for name is
47 * @param[in] value - const reference with DynamicField to assign to SimpleMessage
50 * @return an openxc_SimpleMessage struct initialized with name and value provided.
52 openxc_SimpleMessage build_SimpleMessage(const std::string& name, const openxc_DynamicField& value);
55 * @fn openxc_DynamicField build_DynamicField(const std::string& value);
57 * @brief Build an openxc_DynamicField with a string value
59 * @param[in] value - const string reference value to assign to builded
60 * openxc_DynamicField.
62 * @return openxc_DynamicField initialized with a string value.
64 openxc_DynamicField build_DynamicField(const std::string& value);
67 * @fn openxc_DynamicField build_DynamicField(double value);
69 * @brief Build an openxc_DynamicField with a double value
71 * @param[in] value - double value to assign to builded openxc_DynamicField.
73 * @return openxc_DynamicField initialized with a double value.
75 openxc_DynamicField build_DynamicField(double value);
78 * @fn openxc_DynamicField build_DynamicField(bool value);
80 * @brief Build an openxc_DynamicField with a boolean value
82 * @param[in] value - boolean value to assign to builded openxc_DynamicField.
84 * @return openxc_DynamicField initialized with a boolean value.
86 openxc_DynamicField build_DynamicField(bool value);
89 * @fn void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value);
91 * @brief Make a JSON object from a DynamicField
93 * @param[in] field - openxc_DynamicField struct to convert into
95 * @param[out] value - pointer to the object to set up.
97 void jsonify_DynamicField(const openxc_DynamicField& field, json_object* value);
100 * @fn openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg);
102 * @brief Extract the simple message value from an openxc_VehicleMessage
103 * and return it. If there isn't SimpleMessage in the VehicleMessage then
104 * returned value will be a SimpleMessage with all field set at false.
105 * DynamicField from SimpleMessage will be boolean DynamicField set to false too.
107 * @param[in] v_msg - const reference to openxc_VehicleMessage
109 * @return A simpleMessage from the provided VehicleMessage.
111 openxc_SimpleMessage get_simple_message(const openxc_VehicleMessage& v_msg);
114 * @fn json_object* jsonify_simple(const openxc_SimpleMessage& s_msg);
116 * @brief Make a JSON object from a SimpleMessage
118 * @param[in] s_msg - const reference to an openxc_SimpleMessage
119 * struct to convert into a json object.
120 * @param[out] json - pointer with the DynamicField converted into json object
122 * @return True if SimpleMessage has been transformed into json object
123 * and false if not. In such case, a json object is returned { "error": "error msg"}
125 bool jsonify_simple(const openxc_SimpleMessage& s_msg, json_object* json);