pic_packet.c File Reference

Pic meshed packed network library. More...

#include "pic_packet.h"

Include dependency graph for pic_packet.c:

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

Typedefs

typedef union _rf_packet rf_packet
typedef struct _seen_packet seen_packet
typedef struct _sending_item sending_item

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]


Detailed Description

Assumes either nrf2401a or nrf24l01 library

Ian Harris 2008 imharris [at] gmail.com

Released under the "do whatever you like with this but if it breaks, you get to keep both pieces" license.

Definition in file pic_packet.c.


Define Documentation

#define PKT_FLAG_DELETED   0xff

Definition at line 55 of file pic_packet.c.

Referenced by pkt_init(), pkt_process_rf_data(), pkt_process_tx_queue(), and pkt_queue_packet().


Typedef Documentation

typedef union _rf_packet rf_packet

typedef struct _seen_packet seen_packet

typedef struct _sending_item sending_item


Function Documentation

void pkt_calc_check_byte ( rf_packet packet  ) 

Definition at line 70 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(), and pkt_send_payload().

Here is the caller graph for this function:

uns8 pkt_check_check_byte ( rf_packet packet  ) 

Definition at line 81 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().

Here is the caller graph for this function:

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.

Parameters:
my_addr The address of this system
last_sent_pkt_id The last pkt_id used by this system.

Definition at line 373 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  ) 

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.

Parameters:
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 151 of file pic_packet.c.

References _rf_packet::d, _rf_packet_det::dest_addr, _sending_item::flag, _sending_item::packet, pkt_calc_check_byte(), pkt_check_check_byte(), 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_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_str(), _seen_packet::source_addr, uns16, and uns8.

Here is the call graph for this function:

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 318 of file pic_packet.c.

References _rf_packet::d, _rf_packet_det::dest_addr, _sending_item::flag, _sending_item::packet, PKT_FLAG_DELETED, PKT_FLAG_NO_RESEND, _rf_packet_det::pkt_id, pkt_print_packet(), 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.

Here is the call graph for this function:

uns8 pkt_queue_packet ( rf_packet packet,
uns8  resend 
)

Definition at line 121 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().

Here is the call graph for this function:

Here is the caller graph for this function:

uns8 pkt_seen ( uns16  pkt_id,
uns16  source_addr 
)

Definition at line 57 of file pic_packet.c.

References uns8.

Referenced by pkt_process_rf_data().

Here is the caller graph for this function:

void pkt_send_packet ( rf_packet packet  )  [inline]

Definition at line 292 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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
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 390 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().

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

uns16 pkt_my_addr = 0x66

Definition at line 51 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 52 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 47 of file pic_packet.c.

Definition at line 50 of file pic_packet.c.

Referenced by pkt_process_rf_data().

sending_item pkt_tx_queue[PKT_TX_QUEUE_SIZE] [static]

Definition at line 48 of file pic_packet.c.


Generated on Fri May 16 12:19:02 2008 for Pic Pack by  doxygen 1.5.5