diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-02-14 18:20:22 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-02-14 18:22:04 +0100 |
commit | b162907a78a1846d99f0951a052d6d721eb96f08 (patch) | |
tree | 2980ae6ad7ccf126e034c28a4635167f647f857c | |
parent | b59d45196f14f2401e148bbe37c04b514850d859 (diff) |
Implement CanMessage_c method to navigate through
can_message queue (get/set)
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r-- | src/can-utils.cpp | 23 | ||||
-rw-r--r-- | src/can-utils.h | 26 | ||||
-rw-r--r-- | src/can_reader.cpp | 2 |
3 files changed, 32 insertions, 19 deletions
diff --git a/src/can-utils.cpp b/src/can-utils.cpp index 6721410..09f4947 100644 --- a/src/can-utils.cpp +++ b/src/can-utils.cpp @@ -128,6 +128,29 @@ int CanBus_c::send_can_message(CanMessage_c can_msg) return 0; } +/* + * Get a CanMessage from can_message_q and return it + * then point to the next CanMessage in queue. + * + * Return the next queue element or NULL if queue is empty. + */ +CanMessage_c* CanBus_c::next_can_message() +{ + if(! can_message_q.empty()) + { + CanMessage_c can_msg = can_message_q.front(); + can_message_q.pop() + return &can_msg; + } + + return NULL; +} + +void CanBus_c::insert_new_can_message(CanMessage_c *can_msg) +{ + can_message_q.push(can_msg); +} + /******************************************************************************** * * CanMessage method implementation diff --git a/src/can-utils.h b/src/can-utils.h index 8c850e6..a760af1 100644 --- a/src/can-utils.h +++ b/src/can-utils.h @@ -99,8 +99,9 @@ class CanBus_c { std::thread th_reading; std::thread th_decoding; std::thread th_pushing; + std::queue <CanMessage_c> can_message_q; - std::queue <openxc_VehicleMessage> VehicleMessage_q; + std::queue <openxc_VehicleMessage> vehicle_message_q; public: int open(); @@ -108,6 +109,9 @@ class CanBus_c { void start_threads(); int send_can_message(CanMessage_c can_msg); + + CanMessage_c* next_can_message(); + void insert_new_can_message(CanMessage_c *can_msg); }; /* A compact representation of a single CAN message, meant to be used in in/out @@ -165,17 +169,12 @@ typedef enum CanMessageFormat CanMessageFormat; * * 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. * @@ -299,7 +298,8 @@ 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 { + */ + typedef struct { uint8_t index; const char* name; uint8_t busCount; @@ -307,16 +307,6 @@ 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. * diff --git a/src/can_reader.cpp b/src/can_reader.cpp index d9b3e67..6403cfa 100644 --- a/src/can_reader.cpp +++ b/src/can_reader.cpp @@ -63,4 +63,4 @@ void can_reader(CanBus_c *can_bus)) can_message_q.push(can_message); } -} +}
\ No newline at end of file |