/* 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;
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
#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
#include <afb/afb-binding.h>
#include <afb/afb-service-itf.h>
-#include "ll-can-binding.h"
#include "obd2.h"
/*
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;
}
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;
/*
* 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);
}
}
-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);
}
"NM"
};
-
/*
* A representation of an OBD-II PID.
*
* 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;
* Object to handle obd2 session with pre-scan of supported pid
* then request them regularly
*/
-class Obd2Handler_c {
+class obd2_handler_c {
private:
public:
{ 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