-
/*
* Copyright (C) 2015, 2016 "IoT.bzh"
* Author "Romain Forlot" <romain.forlot@iot.bzh>
* signal - The CAN signal that we are decoding.
* signals - The list of all signals.
* signalCount - The length of the signals array.
- * pipeline - you may want to generate arbitrary additional messages for
- * publishing.
* value - The CAN signal parsed from the message as a raw floating point
* value.
* send - An output parameter. If the decoding failed or the CAN signal should
* Returns a decoded value in an openxc_DynamicField struct.
*/
typedef openxc_DynamicField (*SignalDecoder)(struct CanSignal* signal,
- CanSignal* signals, int signalCount,
- openxc::pipeline::Pipeline* pipeline, float value, bool* send);
+ CanSignal* signals, int signalCount, float value, bool* send);
/* Public: The type signature for a CAN signal encoder.
*
* A SignalEncoder transforms a number, string or boolean into a raw floating
* point value that fits in the CAN signal.
*
- * signal - The CAN signal to encode.
+ * signal - The CAN signal to encode.
* value - The dynamic field to encode.
* send - An output parameter. If the encoding failed or the CAN signal should
* not be encoded for some other reason, this will be flipped to false.
typedef uint64_t (*SignalEncoder)(struct CanSignal* signal,
openxc_DynamicField* value, bool* send);
-/* CanBus represent a can device definition get from configuraiton file */
-class CanBus {
+/*
+ * CanBus represent a can device definition gotten from configuraiton file
+ */
+class CanBus_c {
private:
/* Got from conf file */
std::string deviceName;
bool is_fdmode_on;
struct sockaddr_can txAddress;
+ std::thread th_reading;
+ std::thread th_decoding;
+ std::thread th_pushing;
+
public:
int open();
int close();
+
+ void start_threads();
};
/* Public: The ID format for a CAN message.
* STANDARD - standard 11-bit CAN arbitration ID.
* EXTENDED - an extended frame, with a 29-bit arbitration ID.
*/
-enum CanMessageFormat {
+enum CanMessageFormat_c {
STANDARD,
EXTENDED,
};
-typedef enum CanMessageFormat CanMessageFormat;
+typedef enum CanMessageFormat_c CanMessageFormat;
/* Public: A state encoded (SED) signal's mapping from numerical values to
* OpenXC state names.
*
* value - The integer value of the state on the CAN bus.
* name - The corresponding string name for the state in OpenXC.
- */
struct CanSignalState {
const int value;
const char* name;
};
typedef struct CanSignalState CanSignalState;
+ */
+ class CanSignalState_c {
+ private:
+ const int value;
+ const char *name;
+};
/* Public: A CAN signal to decode from the bus and output over USB.
*
* received - True if this signal has ever been received.
* lastValue - The last received value of the signal. If 'received' is false,
* this value is undefined.
- */
struct CanSignal {
struct CanMessageDefinition* message;
const char* genericName;
float lastValue;
};
typedef struct CanSignal CanSignal;
+ */
+
+class CanSignal_c {
+ private:
+ CanMessageDefinition *message;
+ const char *generic_name;
+ uint8_t bit_position;
+ uint8_t bit_size;
+ float factor;
+ float offset;
+ float min_value;
+ float max_value;
+ FrequencyClock_t clock;
+ bool send_same;
+ bool force_send_changed;
+ const CanSignalState *states;
+ uint8_t state_count;
+ bool writable;
+ SignalDecoder decoder;
+ SignalEncoder encoder;
+ bool received;
+ float last_value;
+};
/* Public: The definition of a CAN message. This includes a lot of metadata, so
* to save memory this struct should not be used for storing incoming and
* bus - A pointer to the bus this message is on.
* id - The ID of the message.
* format - the format of the message's ID.
- * frequencyClock - an optional frequency clock to control the output of this
+ * clock - an optional frequency clock to control the output of this
* message, if sent raw, or simply to mark the max frequency for custom
* handlers to retrieve.
* forceSendChanged - If true, regardless of the frequency, it will send CAN
* lastValue - The last received value of the message. Defaults to undefined.
* This is required for the forceSendChanged functionality, as the stack
* needs to compare an incoming CAN message with the previous frame.
- */
struct CanMessageDefinition {
struct CanBus* bus;
uint32_t id;
uint8_t lastValue[CAN_MESSAGE_SIZE];
};
typedef struct CanMessageDefinition CanMessageDefinition;
+ */
+ class CanMessageDefinition_c {
+ private:
+ CanBus *bus
+ uint32_t id;
+ CanMessageFormat format;
+ FrequencyClock_t clock;
+ bool force_send_changed;
+ uint8_t last_value[CAN_MESSAGE_SIZE];
+ };
/* A compact representation of a single CAN message, meant to be used in in/out
* buffers.
* format - the format of the message's ID.
* data - The message's data field.
* length - the length of the data array (max 8).
- */
struct CanMessage {
uint32_t id;
CanMessageFormat format;
uint8_t length;
};
typedef struct CanMessage CanMessage;
+*/
+class CanMessage_c {
+ private:
+ uint32_t id;
+ CanMessageFormat format;
+ uint8_t data[CAN_MESSAGE_SIZE];
+ uint8_t length;
+
+ public:
+ uint32_t get_id();
+ int get_format();
+ uint8_t get_data();
+ uint8_t get_lenght();
+
+ void set_id(uint32_t id);
+ void set_format(CanMessageFormat format);
+ void set_data(uint8_t data);
+ void set_lenght(uint8_t length);
-QUEUE_DECLARE(CanMessage, 8);
+ void convert_canfd_frame_to_CanMessage(canfd_frame frame);
+};
+
+QUEUE_DECLARE(CanMessage_c, 8);
/* Private: An entry in the list of acceptance filters for each CanBus.
*
* signalCount - The number of CAN signals (across all messages) defined for
* this message set.
* commandCount - The number of CanCommmands defined for this message set.
- */
typedef struct {
uint8_t index;
const char* name;
unsigned short signalCount;
unsigned short commandCount;
} CanMessageSet;
+ */
+class CanMessageSet_c {
+ private:
+ uint8_t index;
+ const char * name;
+ uint8_t busCount;
+ unsigned short messageCount;
+ unsigned short signalCount;
+ unsigned short commandCount;
+};
/* Public: The type signature for a function to handle a custom OpenXC command.
*
* genericName - The name of the command.
* handler - An function to process the received command's data and perform some
* action.
- */
typedef struct {
const char* genericName;
CommandHandler handler;
} CanCommand;
+ */
+
+class CanCommand_c {
+ private:
+ const char* genericName;
+ CommandHandler handler;
+};
/* Pre initialize actions made before CAN bus initialization
*