void packet_assemble(packet_t* packet) { uint8_t* data_ptr = packet->hw_radio_packet.data + 1; // skip length field for now, we fill this later data_ptr += dll_assemble_packet_header(packet, data_ptr); data_ptr += d7anp_assemble_packet_header(packet, data_ptr); data_ptr += d7atp_assemble_packet_header(packet, data_ptr); // add payload memcpy(data_ptr, packet->payload, packet->payload_length); data_ptr += packet->payload_length; packet->hw_radio_packet.length = data_ptr - packet->hw_radio_packet.data - 1 + 2; // exclude the length byte and add CRC bytes packet->hw_radio_packet.data[0] = packet->hw_radio_packet.length; // TODO network protocol footer // add CRC - SW CRC when using FEC if (!has_hardware_crc || packet->hw_radio_packet.tx_meta.tx_cfg.channel_id.channel_header.ch_coding == PHY_CODING_FEC_PN9) { DPRINT_DATA_DLL(packet->hw_radio_packet.data, packet->hw_radio_packet.length + 1); // TODO tmp uint16_t crc = __builtin_bswap16(crc_calculate(packet->hw_radio_packet.data, packet->hw_radio_packet.length + 1 - 2)); memcpy(data_ptr, &crc, 2); DPRINT_DATA_DLL(packet->hw_radio_packet.data, packet->hw_radio_packet.length + 1); // TODO tmp } }
void packet_assemble(packet_t* packet) { uint8_t* data_ptr = packet->hw_radio_packet.data + 1; // skip length field for now, we fill this later data_ptr += dll_assemble_packet_header(packet, data_ptr); data_ptr += d7anp_assemble_packet_header(packet, data_ptr); data_ptr += d7atp_assemble_packet_header(packet, data_ptr); // add payload memcpy(data_ptr, packet->payload, packet->payload_length); data_ptr += packet->payload_length; packet->hw_radio_packet.length = data_ptr - packet->hw_radio_packet.data - 1 + 2; // exclude the length byte and add CRC bytes // TODO network protocol footer // add CRC uint16_t crc = __builtin_bswap16(crc_calculate(packet->hw_radio_packet.data, packet->hw_radio_packet.length - 2)); memcpy(data_ptr, &crc, 2); }