*
* return can_event
*/
-static can_event *get_event_of_id(uint32_t id)
+static can_event *get_event_list_of_id(uint32_t id)
{
can_event *current;
static json_object* create_json_from_openxc_CanMessage(event *event)
{
struct json_object *json;
- openxc_CanMessage can_message;
/*
* TODO: process the openxc_CanMessage struct. Should be a call to a
* decoder function relative to that msg
- */
+
+ openxc_CanMessage can_message;
can_message = event->can_message;
+ */
json = json_object_new_object();
json_object_object_add(json, "name", json_object_new_string(event->name));
int maxdlen;
/* Test that socket is really opened */
- if ( socket_test < 0)
+ if ( socket_test() < 0)
{
if (retry(open_can_dev) < 0)
{
if (parse_can_frame(can_message, &canfd_frame, maxdlen))
{
- ERROR(interface, "read_can: Can't parse the can frame. ID: %i, DLC: %i, DATA: %X",
+ ERROR(interface, "read_can: Can't parse the can frame. ID: %i, DLC: %i, DATA: %s",
canfd_frame.can_id, canfd_frame.len, canfd_frame.data);
return -4;
}
* standard CAN frames may have RTR enabled. There are no ERR frames with RTR
if (maxdlen == CAN_MAX_DLEN && canfd_frame->can_id & CAN_RTR_FLAG)
{
- /* print a given CAN 2.0B DLC if it's not zero
+ // print a given CAN 2.0B DLC if it's not zero
if (canfd_frame->len && canfd_frame->len <= CAN_MAX_DLC)
buf[offset++] = hex_asc_upper[canfd_frame->len & 0xF];
/* Doesn't handle real canfd_frame for now
if (maxdlen == CANFD_MAX_DLEN)
{
- /* add CAN FD specific escape char and flags
+ // add CAN FD specific escape char and flags
canfd_frame->flags & 0xF;
} */
return -2;
}
- return NULL;
+ /* You should not reach this return statement */
+ return -3;
}
/*************************************************************************/
*/
static event *get_event(uint32_t id, enum type type)
{
- event *event;
+ event *event_elt;
can_event *list;
/* find the can list by id */
- list = get_event_of_id(id);
+ list = get_event_list_of_id(id);
/* make the new event */
- event = (can_event*)calloc(1, sizeof(can_event));
- event->next = event;
- list->events = event;
- event->name = create_name(id);
- event->afb_event = afb_daemon_make_event(interface->daemon, event->name);
+ event_elt = (event*)calloc(1, sizeof(event));
+ event_elt->next = event_elt;
+ list->events = event_elt;
+ event_elt->name = create_name(id);
+ event_elt->afb_event = afb_daemon_make_event(interface->daemon, event_elt->name);
- return event;
+ return event_elt;
}
/*
static void unsubscribe(struct afb_req req)
{
const char *id;
+ can_event *events_list;
event *event;
id = afb_req_value(req, "id");
afb_req_fail(req, "missing-id", NULL);
else
{
- event = get_event_of_id(atoi(id));
- if (event == NULL)
- afb_req_fail(req, "bad-id", NULL);
- else
+ events_list = get_event_list_of_id((uint32_t)atoi(id));
+ event = events_list->events;
+ while(event)
{
- afb_req_unsubscribe(req, event->afb_event);
- afb_req_success(req, NULL, NULL);
+ if (event == NULL)
+ afb_req_fail(req, "bad-id", NULL);
+ else
+ {
+ afb_req_unsubscribe(req, event->afb_event);
+ afb_req_success(req, NULL, NULL);
+ }
+ event = event->next;
}
}
}