aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-02-16 16:09:08 +0000
committerRomain Forlot <romain.forlot@iot.bzh>2017-02-16 16:10:14 +0000
commitd6d322103eaf1d2d5a1a94a0720a01a692f6a134 (patch)
treed2086d32c7203db7ff9de9984b79f74b4bbb41c3 /src
parent109ba77a295811c5037c2c4dfc618c3f7e047228 (diff)
Changing CanBus_c to can_bus_t class name
Change-Id: Ibf277e36187b78853718f76552ff730d0474a3e6 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r--src/can-signals.cpp2
-rw-r--r--src/can_event_push.cpp2
-rw-r--r--src/can_reader.cpp39
-rw-r--r--src/low-can-binding.cpp13
-rw-r--r--src/obd2.cpp15
-rw-r--r--src/obd2.h34
6 files changed, 56 insertions, 49 deletions
diff --git a/src/can-signals.cpp b/src/can-signals.cpp
index 8e3a1e6..b20c540 100644
--- a/src/can-signals.cpp
+++ b/src/can-signals.cpp
@@ -29,7 +29,7 @@ std::map <CanSignal, struct afb_event>::iterator subscribed_signals_i;
/* Find one or many signals based on its name or id
* passed through openxc_DynamicField.
*/
-void find_signals(openxc_DynamicField *key, std:vector <CanSignal> *signals)
+void find_can_signals(openxc_DynamicField *key, std:vector <CanSignal> *signals)
{
int n_signals, i;
diff --git a/src/can_event_push.cpp b/src/can_event_push.cpp
index db14a44..ccfe6b1 100644
--- a/src/can_event_push.cpp
+++ b/src/can_event_push.cpp
@@ -52,7 +52,7 @@ void jsonify_DynamicField(openxc_DynamicField *field, json_object *value)
else if(field->has_string_value)
json_object_object_add(value, "value", json_object_new_string(field->string_value));
-return value;
+ return value;
}
/* Extract the simple message value from an openxc_VehicleMessage
diff --git a/src/can_reader.cpp b/src/can_reader.cpp
index 6403cfa..8088937 100644
--- a/src/can_reader.cpp
+++ b/src/can_reader.cpp
@@ -23,44 +23,13 @@
#include "can-utils.h"
-void can_reader(CanBus_c *can_bus))
+void can_reader(CanBus_t &can_bus)
{
- ssize_t nbytes;
- int maxdlen;
CanMessage_c can_message;
- canfd_frame canfd_frame;
- /* Test that socket is really opened */
- if ( can_bus->socket < 0)
+ while(can_bus.is_running())
{
- ERROR(interface, "read_can: Socket unavailable");
- return -1;
- }
-
- while(true)
- {
- nbytes = read(can_bus->socket, &canfd_frame, CANFD_MTU);
-
- switch(nbytes)
- {
- case CANFD_MTU:
- DEBUG(interface, "read_can: Got an CAN FD frame with length %d", canfd_frame.len);
- maxdlen = CANFD_MAX_DLEN;
- break;
- case CAN_MTU:
- DEBUG(interface, "read_can: Got a legacy CAN frame with length %d", canfd_frame.len);
- maxdlen = CAN_MAX_DLEN;
- break;
- default:
- if (errno == ENETDOWN)
- ERROR(interface, "read_can: %s interface down", device);
-
- ERROR(interface, "read_can: Error reading CAN bus");
- return -2;
- }
-
- can_message.convert_from_canfd_frame(canfd_frame);
-
- can_message_q.push(can_message);
+ can_message.convert_from_canfd_frame(canbus.read());
+ can_bus.insert_new_can_message(can_message);
}
} \ No newline at end of file
diff --git a/src/low-can-binding.cpp b/src/low-can-binding.cpp
index af86786..18f5a75 100644
--- a/src/low-can-binding.cpp
+++ b/src/low-can-binding.cpp
@@ -40,7 +40,6 @@
#include <afb/afb-binding.h>
#include <afb/afb-service-itf.h>
-#include "ll-can-binding.h"
#include "obd2.h"
/*
@@ -177,7 +176,10 @@ static int subscribe_unsubscribe_name(struct afb_req request, int subscribe, con
if (0 == strcmp(name, "*"))
return subscribe_unsubscribe_all(request, subscribe);
- find_signals(name, sig);
+ if(obd2_handler_c.is_obd2_signal(name))
+
+ else
+ find_can_signals(name, sig);
if (sig == NULL) {
return 0;
}
@@ -246,6 +248,13 @@ const struct afb_binding *afbBindingV1Register (const struct afb_binding_interfa
return &binding_desc;
}
+/**
+ * @brief Initialize the binding.
+ *
+ * @param[in] service Structure which represent the Application Framework Binder.
+ *
+ * @return Exit code, zero if success.
+ */
int afbBindingV1ServiceInit(struct afb_service service)
{
std::ifstream fd_conf;
diff --git a/src/obd2.cpp b/src/obd2.cpp
index 7db5d97..ae2db98 100644
--- a/src/obd2.cpp
+++ b/src/obd2.cpp
@@ -28,7 +28,7 @@ void shims_timer()
/*
* Will scan for supported Obd2 pids
*/
-Obd2Handler::Obd2Handler(afb_binding_interface *itf, CanBus_c cb)
+obd2_handler_c::obd2_handler_c(afb_binding_interface *itf, CanBus_c cb)
{
CanBus_c can_bus = cb;
DiagnosticShims shims = diagnostic_init_shims(shims_logger, can_bus.send_can_message, NULL);
@@ -41,19 +41,26 @@ Obd2Handler::Obd2Handler(afb_binding_interface *itf, CanBus_c cb)
}
}
-Obd2Handler::add_request(int pid)
+void obd2_handler_c::add_request(int pid)
{
DiagnosticRequest request = {
arbitration_id: OBD2_FUNCTIONAL_BROADCAST_ID,
mode: 0x1, has_pid: true, pid: pid};
}
-Obd2Handler::is_obd2_request(DiagnosticRequest* request)
+bool obd2_handler_c::is_obd2_request(DiagnosticRequest* request)
{
return request->mode == 0x1 && request->has_pid && request->pid < 0xff;
}
-Obd2Handler::decode_obd2_response(DiagnosticResponse* responce)
+bool obd2_handler_c::is_obd2_signal(const char *name)
+{
+ if(fnmatch("obd2.*", name, NULL) == 0)
+ return true;
+ return false;
+}
+
+bool obd2_handler_c::decode_obd2_response(DiagnosticResponse* responce)
{
return diagnostic_decode_obd2_pid(response);
}
diff --git a/src/obd2.h b/src/obd2.h
index 61cb70c..cd362c7 100644
--- a/src/obd2.h
+++ b/src/obd2.h
@@ -50,7 +50,6 @@ const char *UNIT_NAMES[10] = {
"NM"
};
-
/*
* A representation of an OBD-II PID.
*
@@ -63,7 +62,6 @@ const char *UNIT_NAMES[10] = {
* when automatic, recurring OBD-II requests are enabled.
* supported - is it supported by the vehicle. Initialized after scan
* event - application framework event handler.
- *
*/
typedef struct _Obd2Pid {
uint8_t pid;
@@ -116,7 +114,7 @@ float handleObd2Pid(const DiagnosticResponse* response, float parsedPayload);
* Object to handle obd2 session with pre-scan of supported pid
* then request them regularly
*/
-class Obd2Handler_c {
+class obd2_handler_c {
private:
public:
@@ -145,7 +143,31 @@ class Obd2Handler_c {
{ pid: 0x63, name: "obd2.engine.torque", min: 0, max: 65535, unit: NM, frequency: 1, supported: false },
};
- Obd2Handler_c();
- bool isObd2Request(request);
-}
+ /* Public: Check if a request is an OBD-II PID request.
+ *
+ * Returns true if the request is a mode 1 request and it has a 1 byte PID.
+ */
+ void find_obd2_pid(const char *name, std::Vector<Obd2Pid> *pids);
+
+ /* Public: Check if a request is an OBD-II PID request.
+ *
+ * Returns true if the request is a mode 1 request and it has a 1 byte PID.
+ */
+ bool is_obd2_request(DiagnosticRequest *request);
+
+ /*
+ * Public: Check if requested signal name is an obd2 pid
+ *
+ * Returns true if name began with ob2.* else false.
+ */
+ bool is_obd2_signal(const char *name);
+
+ /*
+ * Public: pass response to UDS-C library function
+ * diagnostic_decode_obd2_pid()
+ *
+ * Return: float number representing the requested value.
+ */
+ bool decode_obd2_response(DiagnosticResponse* responce);
+} \ No newline at end of file