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.
24 openxc_DynamicField decoded_value;
27 /* Public: Parse the signal's bitfield from the given data and return the raw
30 * signal - The signal to parse from the data.
31 * data - The data to parse the signal from.
32 * length - The length of the data array.
34 * Returns the raw value of the signal parsed as a bitfield from the given byte
37 float parseSignalBitfield(CanSignal* signal, const CanMessage* message);
39 /* Public: Find and return the corresponding string state for a CAN signal's
42 * This is an implementation of the SignalDecoder type signature, and can be
43 * used directly in the CanSignal.decoder field.
45 * signal - The details of the signal that contains the state mapping.
46 * signals - The list of all signals.
47 * signalCount - the length of the signals array.
48 * value - The numerical value that should map to a state.
49 * send - An output argument that will be set to false if the value should
50 * not be sent for any reason.
52 * Returns a DynamicField with a string value if a matching state is found in
53 * the signal. If an equivalent isn't found, send is sent to false and the
54 * return value is undefined.
56 openxc_DynamicField stateDecoder(CanSignal* signal, CanSignal* signals,
57 int signalCount, float value, bool* send);
59 /* Public: Coerces a numerical value to a boolean.
61 * This is an implementation of the SignalDecoder type signature, and can be
62 * used directly in the CanSignal.decoder field.
64 * signal - The details of the signal that contains the state mapping.
65 * signals - The list of all signals
66 * signalCount - The length of the signals array
67 * value - The numerical value that will be converted to a boolean.
68 * send - An output argument that will be set to false if the value should
69 * not be sent for any reason.
71 * Returns a DynamicField with a boolean value of false if the raw signal value
72 * is 0.0, otherwise true. The 'send' argument will not be modified as this
73 * decoder always succeeds.
75 openxc_DynamicField booleanDecoder(CanSignal* signal, CanSignal* signals,
76 int signalCount, float value, bool* send);
78 /* Public: Update the metadata for a signal and the newly received value.
80 * This is an implementation of the SignalDecoder type signature, and can be
81 * used directly in the CanSignal.decoder field.
83 * This function always flips 'send' to false.
85 * signal - The details of the signal that contains the state mapping.
86 * signals - The list of all signals.
87 * signalCount - The length of the signals array.
88 * value - The numerical value that will be converted to a boolean.
89 * send - This output argument will always be set to false, so the caller will
90 * know not to publish this value to the pipeline.
92 * The return value is undefined.
94 openxc_DynamicField ignoreDecoder(CanSignal* signal, CanSignal* signals,
95 int signalCount, float value, bool* send);
97 /* Public: Wrap a raw CAN signal value in a DynamicField without modification.
99 * This is an implementation of the SignalDecoder type signature, and can be
100 * used directly in the CanSignal.decoder field.
102 * signal - The details of the signal that contains the state mapping.
103 * signals - The list of all signals
104 * signalCount - The length of the signals array
105 * value - The numerical value that will be wrapped in a DynamicField.
106 * send - An output argument that will be set to false if the value should
107 * not be sent for any reason.
109 * Returns a DynamicField with the original, unmodified raw CAN signal value as
110 * its numeric value. The 'send' argument will not be modified as this decoder
113 openxc_DynamicField noopDecoder(CanSignal* signal, CanSignal* signals,
114 int signalCount, float value, bool* send);
116 /* Public: Parse a signal from a CAN message and apply any required
117 * transforations to get a human readable value.
119 * If the CanSignal has a non-NULL 'decoder' field, the raw CAN signal value
120 * will be passed to the decoder before returning.
122 * signal - The details of the signal to decode and forward.
123 * message - The CAN message that contains the signal.
124 * signals - an array of all active signals.
125 * signalCount - The length of the signals array.
126 * send - An output parameter that will be flipped to false if the value could
129 * The decoder returns an openxc_DynamicField, which may contain a number,
130 * string or boolean. If 'send' is false, the return value is undefined.
132 openxc_DynamicField decodeSignal(CanSignal* signal,
133 const CanMessage* message, CanSignal* signals, int signalCount,
136 /* Public: Decode a transformed, human readable value from an raw CAN signal
137 * already parsed from a CAN message.
139 * This is the same as decodeSignal(CanSignal*, CanMessage*, CanSignal*, int,
140 * bool*) but you must parse the bitfield value of the signal from the CAN
141 * message yourself. This is useful if you need that raw value for something
144 openxc_DynamicField decodeSignal(CanSignal* signal, float value,
145 CanSignal* signals, int signalCount, bool* send);