+/*
+ * Parse the CAN frame data payload as a CAN packet
+ * TODO: parse as an OpenXC Can Message. Don't translate as ASCII and put bytes
+ * directly into openxc_CanMessage
+ */
+static int parse_can_frame(openxc_CanMessage *can_message, struct canfd_frame *canfd_frame, int maxdlen)
+{
+ int i, len;
+ //size_t n_msg;
+
+ len = (canfd_frame->len > maxdlen) ? maxdlen : canfd_frame->len;
+
+ can_message->has_id = true;
+ if (canfd_frame->can_id & CAN_ERR_FLAG)
+ can_message->id = canfd_frame->can_id & (CAN_ERR_MASK|CAN_ERR_FLAG);
+ else if (canfd_frame->can_id & CAN_EFF_FLAG)
+ {
+ can_message->has_frame_format = true;
+ can_message->frame_format = openxc_CanMessage_FrameFormat_EXTENDED;
+ can_message->id = canfd_frame->can_id & CAN_EFF_MASK;
+ } else
+ {
+ can_message->has_frame_format = true;
+ can_message->frame_format = openxc_CanMessage_FrameFormat_STANDARD;
+ can_message->id = canfd_frame->can_id & CAN_SFF_MASK;
+ }
+
+ /* Don't know what to do with that for now as we haven't
+ * len fields in openxc_CanMessage struct
+
+ * 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
+ if (canfd_frame->len && canfd_frame->len <= CAN_MAX_DLC)
+ buf[offset++] = hex_asc_upper[canfd_frame->len & 0xF];
+
+ buf[offset] = 0;
+ return NULL;
+ }
+ */
+
+ /* Doesn't handle real canfd_frame for now
+ if (maxdlen == CANFD_MAX_DLEN)
+ {
+ // add CAN FD specific escape char and flags
+ canfd_frame->flags & 0xF;
+ } */
+
+ if (sizeof(canfd_frame->data) <= sizeof(can_message->data.bytes))
+ {
+ for (i = 0; i < len; i++)
+ can_message->data.bytes[i] = canfd_frame->data[i];
+ return 0;
+ } else if (sizeof(canfd_frame->data) <= CAN_MAX_DLEN)
+ {
+ ERROR(interface, "parse_can_frame: can_frame data too long to be stored into openxc_CanMessage data field");
+ return -1;
+ /* TODO create as many as needed openxc_CanMessage into an array to store all data from canfd_frame
+ n_msg = CAN_MAX_DLEN / sizeof(canfd_frame->data.bytes);
+ for (i = 0; i < len; i++)
+ can_message->data.bytes[i] = canfd_frame->data[i]; */
+ } else
+ {
+ ERROR(interface, "parse_can_frame: can_frame is really too long here. Size of data greater than canfd maximum 64bytes size. Is it a CAN message ?");
+ return -2;
+ }
+
+ /* You should not reach this return statement */
+ return -3;
+}
+
+