X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=can-utils.h;h=4b5102cb82c83db41fc357b3519fd2b680f6cf09;hb=e28b4da3cf2042695e0c0a99b9448eb3a548e0f5;hp=55408cb431ef9a0e98e85e5609a19e22a4854a6b;hpb=398f2aafbe3927bd6f4e961e2f5f090a2770d6d1;p=apps%2Flow-level-can-service.git diff --git a/can-utils.h b/can-utils.h index 55408cb..4b5102c 100644 --- a/can-utils.h +++ b/can-utils.h @@ -1,4 +1,3 @@ - /* * Copyright (C) 2015, 2016 "IoT.bzh" * Author "Romain Forlot" @@ -60,8 +59,6 @@ void queue_##type##_snapshot(queue_##type* queue, type* snapshot, int max); * 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 @@ -70,15 +67,14 @@ void queue_##type##_snapshot(queue_##type* queue, type* snapshot, int max); * 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. @@ -86,8 +82,10 @@ typedef openxc_DynamicField (*SignalDecoder)(struct CanSignal* signal, 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; @@ -96,9 +94,15 @@ class CanBus { 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. @@ -106,23 +110,28 @@ class CanBus { * 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. * @@ -157,7 +166,6 @@ typedef struct CanSignalState CanSignalState; * 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; @@ -179,6 +187,29 @@ struct CanSignal { 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 @@ -187,7 +218,7 @@ typedef struct CanSignal CanSignal; * 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 @@ -195,7 +226,6 @@ typedef struct CanSignal CanSignal; * 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; @@ -205,6 +235,16 @@ struct CanMessageDefinition { 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. @@ -213,7 +253,6 @@ typedef struct CanMessageDefinition CanMessageDefinition; * 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; @@ -221,8 +260,29 @@ struct CanMessage { 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. * @@ -262,7 +322,6 @@ LIST_HEAD(CanMessageDefinitionList, CanMessageDefinitionListEntry); * 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; @@ -271,6 +330,16 @@ typedef struct { 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. * @@ -301,11 +370,17 @@ typedef void (*CommandHandler)(const char* name, openxc_DynamicField* value, * 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 *