#include <cstdio>
#include <string>
#include <thread>
+#include <fcntl.h>
+#include <unistd.h>
+#include <net/if.h>
+#include <sys/ioctl.h>
#include <linux/can.h>
+#include <sys/socket.h>
+#include <json-c/json.h>
+#include <linux/can/raw.h>
#include "timer.hpp"
#include "openxc.pb.h"
+extern "C"
+{
+ #include <afb/afb-binding.h>
+ #include <afb/afb-service-itf.h>
+}
+
// TODO actual max is 32 but dropped to 24 for memory considerations
#define MAX_ACCEPTANCE_FILTERS 24
// TODO this takes up a ton of memory
*/
class can_message_t {
private:
- const struct afb_binding_interface *interface_;
+ const struct afb_binding_interface* interface_;
uint32_t id_;
CanMessageFormat format_;
- uint8_t data_[CAN_MESSAGE_SIZE];
+ uint8_t data_;
uint8_t length_;
public:
+ can_message_t(const struct afb_binding_interface* interface);
+
uint32_t get_id() const;
int get_format() const;
- uint8_t get_data() const;
- uint8_t get_lenght() const;
+ const uint8_t* get_data() const;
+ uint8_t get_length() const;
- void set_id(uint32_t id);
- void set_format(CanMessageFormat format);
- void set_data(uint8_t data);
- void set_lenght(uint8_t length);
+ void set_id(const uint32_t new_id);
+ void set_format(const CanMessageFormat format);
+ void set_data(const uint8_t new_data);
+ void set_length(const uint8_t new_length);
- void convert_from_canfd_frame(canfd_frame frame);
+ void convert_from_canfd_frame(const canfd_frame& frame);
canfd_frame convert_to_canfd_frame();
};
public:
can_bus_dev_t(const std::string& dev_name);
- int open();
+ int open(const struct afb_binding_interface* interface);
int close();
bool is_running();
+ void start_reading();
+ canfd_frame read(const struct afb_binding_interface *interface);
- can_message_t* next_can_message();
+ can_message_t next_can_message(const struct afb_binding_interface* interface);
void push_new_can_message(const can_message_t& can_msg);
bool has_can_message() const;
+
+ int send_can_message(can_message_t& can_msg, const struct afb_binding_interface* interface);
};
/**
void start_threads();
- int send_can_message(can_message_t can_msg);
-
- openxc_VehicleMessage& next_vehicle_message();
+ openxc_VehicleMessage next_vehicle_message();
void push_new_vehicle_message(const openxc_VehicleMessage& v_msg);
bool has_vehicle_message() const;
};
* @param[in] format - the format of the message's ID.
* @param[in] 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.
+ * handlers to retriec++ if ? syntaxve.
* @param[in] forceSendChanged - If true, regardless of the frequency, it will send CAN
* message if it has changed when using raw passthrough.
* @param[in] lastValue - The last received value of the message. Defaults to undefined.
};
typedef struct CanMessageDefinition CanMessageDefinition;
-/* Private: An entry in the list of acceptance filters for each CanBus.
- *
- * This struct is meant to be used with a LIST type from <sys/queue.h>.
- *
- * filter - the value for the CAN acceptance filter.
- * activeUserCount - The number of active consumers of this filter's messages.
- * When 0, this filter can be removed.
- * format - the format of the ID for the filter.
-struct AcceptanceFilterListEntry {
- uint32_t filter;
- uint8_t activeUserCount;
- CanMessageFormat format;
- LIST_ENTRY(AcceptanceFilterListEntry) entries;
-};
- */
-
-/* Private: A type of list containing CAN acceptance filters.
-LIST_HEAD(AcceptanceFilterList, AcceptanceFilterListEntry);
-
-struct CanMessageDefinitionListEntry {
- CanMessageDefinition definition;
- LIST_ENTRY(CanMessageDefinitionListEntry) entries;
-};
-LIST_HEAD(CanMessageDefinitionList, CanMessageDefinitionListEntry);
- */
-
/**
* @brief A parent wrapper for a particular set of CAN messages and associated
* CAN buses(e.g. a vehicle or program).
* @param[in] buses - An array of all CAN buses.
* @param[in] int busCount - The length of the buses array.
*/
-void pre_initialize(can_bus_dev_t* bus, bool writable, CanBus* buses, const int busCount);
+void pre_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount);
/* Post-initialize actions made after CAN bus initialization and before the
* event loop connection.
* buses - An array of all CAN buses.
* busCount - The length of the buses array.
*/
-void post_initialize(can_bus_dev_t* bus, bool writable, CanBus* buses, const int busCount);
+void post_initialize(can_bus_dev_t* bus, bool writable, can_bus_dev_t* buses, const int busCount);
/* Public: Check if the device is connected to an active CAN bus, i.e. it's
* received a message in the recent past.
* buses - an array of active CAN buses.
* busCount - the length of the buses array.
*/
-void logBusStatistics(CanBus* buses, const int busCount);
+void logBusStatistics(can_bus_dev_t* buses, const int busCount);
+
+/**
+ * @brief Function representing thread activated by can bus objects
+ */
+void can_reader(can_bus_dev_t& can_bus);
+void can_decode_message(can_bus_t& can_bus);
+void can_event_push(can_bus_t& can_bus);
\ No newline at end of file