// --------------------------------------------------------------------- size_t AnsiEncoding::encodingChar(const char32_t &bValue, types::byte_t *pBytes) { if (char_is_ascii(bValue)) return char_to_byte(bValue, pBytes); return 0; }
// ---------------------------------------------------------------------------- bool usbcan_decode_message(char *str, uint8_t length) { can_t msg; uint8_t dlc_pos; bool extended; if (str[0] == 'R' || str[0] == 'T') { extended = true; dlc_pos = 9; } else { extended = false; dlc_pos = 4; } if (length < dlc_pos + 1) return false; // get the number of data-bytes for this message msg.length = str[dlc_pos] - '0'; if (msg.length > 8) return false; // too many data-bytes if (str[0] == 'r' || str[0] == 'R') { msg.flags.rtr = true; if (length != (dlc_pos + 1)) return false; } else { msg.flags.rtr = false; if (length != (msg.length * 2 + dlc_pos + 1)) return false; } // read the messge-identifier if (extended) { uint16_t id; uint16_t id2; id = hex_to_byte(&str[1]) << 8; id |= hex_to_byte(&str[3]); id2 = hex_to_byte(&str[5]) << 8; id2 |= hex_to_byte(&str[7]); msg.id = (uint32_t) id << 16 | id2; } else { uint16_t id; id = char_to_byte(&str[1]) << 8; id |= hex_to_byte(&str[2]); msg.id = id; } msg.flags.extended = extended; // read data if the message is no rtr-frame if (!msg.flags.rtr) { char *buf = str + dlc_pos + 1; uint8_t i; for (i=0; i < msg.length; i++) { msg.data[i] = hex_to_byte(buf); buf += 2; } } // finally try to send the message if (can_send_message( &msg )) return true; else return false; }
// --------------------------------------------------------------------- size_t UTF8Encoding::encodingChar(const char32_t &bValue, types::byte_t *pBytes) { return char_to_byte(bValue, pBytes); }
uint8_t hex_to_byte(char *s) { return (char_to_byte(s) << 4) | char_to_byte(s + 1); }