#include "pic_packet.h"
Go to the source code of this file.
Data Structures | |
union | rf_packet |
struct | seen_packet |
struct | sending_item |
Defines | |
#define | PKT_FLAG_DELETED 0xff |
Functions | |
void | pkt_calc_check_byte (rf_packet *packet) |
uns8 | pkt_check_check_byte (rf_packet *packet) |
void | pkt_init (uns16 my_addr, uns16 last_sent_id) |
Initialise packet delivery system. | |
uns8 | pkt_print_packet (rf_packet *my_packet) |
uns8 | pkt_process_rf_data (uns8 *data_in) |
Process received RF data. | |
void | pkt_process_tx_queue () |
Handle queued items. | |
uns8 | pkt_queue_packet (rf_packet *packet, uns8 resend) |
uns8 | pkt_seen (uns16 pkt_id, uns16 source_addr) |
void | pkt_send_packet (rf_packet *packet) |
uns8 | pkt_send_payload (uns16 dest_addr, uns8 *payload, uns8 resend) |
Send a payload via the packet delivery system. | |
Variables | |
uns16 | pkt_my_addr = 0x66 |
uns16 | pkt_my_next_pkt_id = 0 |
static seen_packet | pkt_seen_list [PKT_SEEN_LIST_SIZE] |
uns8 | pkt_seen_list_last = 0 |
static sending_item | pkt_tx_queue [PKT_TX_QUEUE_SIZE] |
#define PKT_FLAG_DELETED 0xff |
Definition at line 78 of file pic_packet.c.
Referenced by pkt_init(), pkt_process_rf_data(), pkt_process_tx_queue(), and pkt_queue_packet().
void pkt_calc_check_byte | ( | rf_packet * | packet | ) |
Definition at line 93 of file pic_packet.c.
References rf_packet::a, rf_packet_det::check_byte, rf_packet::d, PKT_PACKET_SIZE, and uns8.
Referenced by pkt_process_rf_data(), pkt_process_tx_queue(), and pkt_send_payload().
uns8 pkt_check_check_byte | ( | rf_packet * | packet | ) |
Definition at line 104 of file pic_packet.c.
References rf_packet::a, rf_packet_det::check_byte, rf_packet::d, PKT_PACKET_SIZE, and uns8.
Referenced by pkt_process_rf_data().
void pkt_init | ( | uns16 | my_addr, | |
uns16 | last_sent_pkt_id | |||
) |
Initialise the packet delivery system ready for use. This routine clears the transmit queue and seen queue. If you don't store the last_sent_pkt_id (eg, in EEPROM) then set this to 0.
my_addr | The address of this system | |
last_sent_pkt_id | The last pkt_id used by this system. |
Definition at line 423 of file pic_packet.c.
References sending_item::flag, PKT_FLAG_DELETED, pkt_my_addr, pkt_my_next_pkt_id, seen_packet::source_addr, uns16, and uns8.
uns8 pkt_print_packet | ( | rf_packet * | my_packet | ) |
Definition at line 120 of file pic_packet.c.
References rf_packet::d, rf_packet_det::dest_addr, rf_packet_det::payload, rf_packet_det::pkt_id, rf_packet_det::r1_addr, rf_packet_det::r2_addr, rf_packet_det::r3_addr, serial_print_int_hex(), serial_print_spc(), serial_print_str(), rf_packet_det::source_addr, and uns8.
Referenced by pkt_process_rf_data(), pkt_process_tx_queue(), pkt_send_packet(), and pkt_send_payload().
uns8 pkt_process_rf_data | ( | uns8 * | data_in | ) |
Call this routine when your RF device has received a chunk of data from somewhere. The packet delivery system will handle everything including acknowledgements and ignoring packets that it has already seen.
pkt_in | A pointer to the received data. It is assumed that this will point to PKT_PACKET_SIZE bytes of data. |
Definition at line 174 of file pic_packet.c.
References rf_packet::d, rf_packet_det::dest_addr, end_crit_sec, sending_item::flag, sending_item::packet, PKT_BROADCAST_ADDR, pkt_calc_check_byte(), pkt_check_check_byte(), PKT_DIRECT_SEND_ADDR, PKT_FLAG_DELETED, PKT_FLAG_NO_RESEND, seen_packet::pkt_id, rf_packet_det::pkt_id, pkt_my_addr, PKT_PACKET_SIZE, pkt_payload_rx_callback(), pkt_print_packet(), pkt_queue_packet(), pkt_seen(), pkt_seen_list_last, pkt_send_payload(), pkt_send_succeeded_callback(), PKT_STATUS_CHECK_FAIL, PKT_STATUS_DIRECT_SEND, PKT_STATUS_I_AM_SENDER, PKT_STATUS_NEED_TO_REBROADCAST, PKT_STATUS_PKT_FOR_ME_BUT_SEEN, PKT_STATUS_PKT_IS_ACK_FOR_ME, PKT_STATUS_PKT_IS_FACK_FOR_ME, PKT_STATUS_PKT_IS_FOR_ME, PKT_STATUS_PREVIOUS_ROUTED_VIA_ME, PKT_STATUS_ROUTING_FULL, PKT_STATUS_SEEN_BEFORE, serial_print_int(), serial_print_str(), serial_putc(), seen_packet::source_addr, start_crit_sec, uns16, and uns8.
void pkt_process_tx_queue | ( | ) |
Call this routine regularly (as often as possible) in your main loop in order for the packet delivery system to send any queued packets when it is appropriate to do so. It will also remove any packets from the tx queue that have been there too long.
Definition at line 354 of file pic_packet.c.
References rf_packet::d, rf_packet_det::dest_addr, sending_item::flag, sending_item::packet, rf_packet_det::payload, pkt_calc_check_byte(), PKT_FLAG_DELETED, PKT_FLAG_RESEND, rf_packet_det::pkt_id, pkt_print_packet(), pkt_send_callback(), pkt_send_failed_callback(), pkt_send_packet(), rf_packet_det::r1_addr, sending_item::sent_count, serial_print_int(), serial_print_spc(), serial_print_str(), tick_calc_diff(), tick_get_count(), sending_item::tick_sent, uns16, and uns8.
uns8 pkt_queue_packet | ( | rf_packet * | packet, | |
uns8 | resend | |||
) |
Definition at line 144 of file pic_packet.c.
References sending_item::flag, PKT_FLAG_DELETED, PKT_PACKET_SIZE, PKT_STATUS_QUEUED, PKT_STATUS_TX_QUEUE_FULL, sending_item::sent_count, serial_print_int(), serial_print_str(), and uns8.
Referenced by pkt_process_rf_data(), and pkt_send_payload().
uns8 pkt_seen | ( | uns16 | pkt_id, | |
uns16 | source_addr | |||
) |
Definition at line 80 of file pic_packet.c.
References uns8.
Referenced by pkt_process_rf_data().
void pkt_send_packet | ( | rf_packet * | packet | ) | [inline] |
Definition at line 328 of file pic_packet.c.
References rf_packet::a, pic_rf_transmit(), PKT_PACKET_SIZE, pkt_print_packet(), serial_print_str(), tx_buffer, and uns8.
Referenced by pkt_process_tx_queue().
uns8 pkt_send_payload | ( | uns16 | dest_addr, | |
uns8 * | payload, | |||
uns8 | resend | |||
) |
Use this routine to send a payload of data to the destination address. The payload must point to PKT_PAYLOAD_SIZE bytes of data (as defined in your config.h). The packet will be constructed, setting destination address, sender address (set previously in pkt_init) payload, initial routing directions and the check byte calculated. It will then be placed into the tx queue and will actually be sent next time pkt_process_tx_queue is called.
dest_addr | Send payload to this address. Use address of PKT_BROADCAST_ADDR to broadcast to all listening local addresses | |
pay_load | Pointer to PKT_PAYLOAD_SIZE array of bytes | |
resend | Set to PKT_FLAG_RESEND or PKT_FLAG_NO_RESEND |
Definition at line 440 of file pic_packet.c.
References rf_packet::d, rf_packet_det::dest_addr, rf_packet_det::payload, PKT_BROADCAST_ADDR, pkt_calc_check_byte(), PKT_DIRECT_SEND_ADDR, rf_packet_det::pkt_id, pkt_my_addr, pkt_my_next_pkt_id, pkt_print_packet(), pkt_queue_packet(), rf_packet_det::r1_addr, rf_packet_det::r2_addr, rf_packet_det::r3_addr, serial_print_int(), serial_print_str(), rf_packet_det::source_addr, and uns8.
Referenced by pkt_process_rf_data().
uns16 pkt_my_addr = 0x66 |
Definition at line 74 of file pic_packet.c.
Referenced by pkt_init(), pkt_process_rf_data(), and pkt_send_payload().
uns16 pkt_my_next_pkt_id = 0 |
Definition at line 75 of file pic_packet.c.
Referenced by pkt_init(), and pkt_send_payload().
seen_packet pkt_seen_list[PKT_SEEN_LIST_SIZE] [static] |
Definition at line 70 of file pic_packet.c.
uns8 pkt_seen_list_last = 0 |
Definition at line 73 of file pic_packet.c.
Referenced by pkt_process_rf_data().
sending_item pkt_tx_queue[PKT_TX_QUEUE_SIZE] [static] |
Definition at line 71 of file pic_packet.c.