2 * Copyright (C) 2015, 2016 "IoT.bzh"
3 * Author "Romain Forlot" <romain.forlot@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 #include "can-utils.hpp"
25 openxc_DynamicField decoded_value;
28 /* Public: Parse the signal's bitfield from the given data and return the raw
31 * signal - The signal to parse from the data.
32 * data - The data to parse the signal from.
33 * length - The length of the data array.
35 * Returns the raw value of the signal parsed as a bitfield from the given byte
38 float parseSignalBitfield(const CanSignal& signal, const can_message_t& message);
40 /* Public: Find and return the corresponding string state for a CAN signal's
43 * This is an implementation of the SignalDecoder type signature, and can be
44 * used directly in the CanSignal.decoder field.
46 * signal - The details of the signal that contains the state mapping.
47 * signals - The list of all signals.
48 * signalCount - the length of the signals array.
49 * value - The numerical value that should map to a state.
50 * send - An output argument that will be set to false if the value should
51 * not be sent for any reason.
53 * Returns a DynamicField with a string value if a matching state is found in
54 * the signal. If an equivalent isn't found, send is sent to false and the
55 * return value is undefined.
57 openxc_DynamicField stateDecoder(const CanSignal& signal, const CanSignal& signals,
58 float value, bool* send);
60 /* Public: Coerces a numerical value to a boolean.
62 * This is an implementation of the SignalDecoder type signature, and can be
63 * used directly in the CanSignal.decoder field.
65 * signal - The details of the signal that contains the state mapping.
66 * signals - The list of all signals
67 * signalCount - The length of the signals array
68 * value - The numerical value that will be converted to a boolean.
69 * send - An output argument that will be set to false if the value should
70 * not be sent for any reason.
72 * Returns a DynamicField with a boolean value of false if the raw signal value
73 * is 0.0, otherwise true. The 'send' argument will not be modified as this
74 * decoder always succeeds.
76 openxc_DynamicField booleanDecoder(const CanSignal& signal, const CanSignal& signals,
77 float value, bool* send);
79 /* Public: Update the metadata for a signal and the newly received value.
81 * This is an implementation of the SignalDecoder type signature, and can be
82 * used directly in the CanSignal.decoder field.
84 * This function always flips 'send' to false.
86 * signal - The details of the signal that contains the state mapping.
87 * signals - The list of all signals.
88 * signalCount - The length of the signals array.
89 * value - The numerical value that will be converted to a boolean.
90 * send - This output argument will always be set to false, so the caller will
91 * know not to publish this value to the pipeline.
93 * The return value is undefined.
95 openxc_DynamicField ignoreDecoder(const CanSignal& signal, const CanSignal& signals,
96 float value, bool* send);
98 /* Public: Wrap a raw CAN signal value in a DynamicField without modification.
100 * This is an implementation of the SignalDecoder type signature, and can be
101 * used directly in the CanSignal.decoder field.
103 * signal - The details of the signal that contains the state mapping.
104 * signals - The list of all signals
105 * signalCount - The length of the signals array
106 * value - The numerical value that will be wrapped in a DynamicField.
107 * send - An output argument that will be set to false if the value should
108 * not be sent for any reason.
110 * Returns a DynamicField with the original, unmodified raw CAN signal value as
111 * its numeric value. The 'send' argument will not be modified as this decoder
114 openxc_DynamicField noopDecoder(const CanSignal& signal, const CanSignal& signals,
115 float value, bool* send);
117 /* Public: Parse a signal from a CAN message and apply any required
118 * transforations to get a human readable value.
120 * If the CanSignal has a non-NULL 'decoder' field, the raw CAN signal value
121 * will be passed to the decoder before returning.
123 * signal - The details of the signal to decode and forward.
124 * message - The CAN message that contains the signal.
125 * signals - an array of all active signals.
126 * signalCount - The length of the signals array.
127 * send - An output parameter that will be flipped to false if the value could
130 * The decoder returns an openxc_DynamicField, which may contain a number,
131 * string or boolean. If 'send' is false, the return value is undefined.
133 openxc_DynamicField decodeSignal(const CanSignal& signal,
134 const can_message_t& message, const CanSignal& signals,
137 /* Public: Decode a transformed, human readable value from an raw CAN signal
138 * already parsed from a CAN message.
140 * This is the same as decodeSignal(const CanSignal&, CanMessage*, const CanSignal&, int,
141 * bool*) but you must parse the bitfield value of the signal from the CAN
142 * message yourself. This is useful if you need that raw value for something
145 openxc_DynamicField decodeSignal(const CanSignal& signal, float value,
146 const CanSignal& signals, bool* send);