pic_packet.h File Reference

Pic meshed packed network library. More...

#include "pic_utils.h"
#include "pic_serial.h"
#include "pic_tick.h"
#include "config.h"
#include <memory.h>
#include "pic_rf_2401a.h"

Include dependency graph for pic_packet.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _rf_packet_det

Defines

#define PKT_BROADCAST_ADDR   0xfffe
#define PKT_CONFIG_ADDR   0xfffd
#define PKT_DIRECT_SEND_ADDR   0xffff
#define PKT_FLAG_BROADCAST   2
#define PKT_FLAG_NO_RESEND   0
#define PKT_FLAG_RESEND   1
#define PKT_PACKET_SIZE   sizeof(rf_packet_det)
#define PKT_STATUS_CHECK_FAIL   12
#define PKT_STATUS_DIRECT_SEND   6
#define PKT_STATUS_I_AM_SENDER   2
#define PKT_STATUS_NEED_TO_REBROADCAST   9
#define PKT_STATUS_PKT_FOR_ME_BUT_SEEN   13
#define PKT_STATUS_PKT_IS_ACK_FOR_ME   4
#define PKT_STATUS_PKT_IS_FACK_FOR_ME   5
#define PKT_STATUS_PKT_IS_FOR_ME   3
#define PKT_STATUS_PREVIOUS_ROUTED_VIA_ME   7
#define PKT_STATUS_QUEUED   10
#define PKT_STATUS_ROUTING_FULL   8
#define PKT_STATUS_SEEN_BEFORE   1
#define PKT_STATUS_TX_QUEUE_FULL   11
#define RF_RX_BUFFER_SIZE   PKT_PACKET_SIZE

Typedefs

typedef struct _rf_packet_det rf_packet_det

Functions

void pkt_init (uns16 my_addr, uns16 last_sent_pkt_id)
 Initialise packet delivery system.
void pkt_payload_rx_callback (uns16 source_addr, uns16 pkt_id, uns8 *payload)
 Called when a packet has been received.
uns8 pkt_process_rf_data (uns8 *data_in)
 Process received RF data.
void pkt_process_tx_queue ()
 Handle queued items.
void pkt_send_callback (uns16 dest_addr, uns16 pkt_id)
void pkt_send_failed_callback (uns16 dest_addr, uns16 pkt_id)
uns8 pkt_send_payload (uns16 dest_addr, uns8 *payload, uns8 resend)
 Send a payload via the packet delivery system.
void pkt_send_succeeded_callback (uns16 dest_addr, uns16 pkt_id)


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 you use it'd be nice to get an email" license. Oh, and if it breaks, you get to keep both pieces.

Definition in file pic_packet.h.


Define Documentation

#define PKT_BROADCAST_ADDR   0xfffe

Send to anyone that will listen

Definition at line 143 of file pic_packet.h.

Referenced by pkt_process_rf_data(), and pkt_send_payload().

#define PKT_CONFIG_ADDR   0xfffd

Magic config packet address

Definition at line 140 of file pic_packet.h.

#define PKT_DIRECT_SEND_ADDR   0xffff

Router address for direct send only (no routing)

Definition at line 146 of file pic_packet.h.

Referenced by pkt_process_rf_data(), and pkt_send_payload().

#define PKT_FLAG_BROADCAST   2

Packet should be broadcast to anyone on the network

Definition at line 136 of file pic_packet.h.

#define PKT_FLAG_NO_RESEND   0

Packet should not be resent if it fails to reach destination

Definition at line 130 of file pic_packet.h.

Referenced by pkt_process_rf_data().

#define PKT_FLAG_RESEND   1

Packet should be resent if it fails to reach destination

Definition at line 133 of file pic_packet.h.

Referenced by pkt_process_tx_queue().

#define PKT_PACKET_SIZE   sizeof(rf_packet_det)

#define PKT_STATUS_CHECK_FAIL   12

Packet is corrupt, ignoring

Definition at line 122 of file pic_packet.h.

Referenced by pkt_process_rf_data().

#define PKT_STATUS_DIRECT_SEND   6

Packet is direct send, but not for me, ignoring

Definition at line 104 of file pic_packet.h.

Referenced by pkt_process_rf_data().

#define PKT_STATUS_I_AM_SENDER   2

I have sent this packet, so ignoring

Definition at line 92 of file pic_packet.h.

Referenced by pkt_process_rf_data().

#define PKT_STATUS_NEED_TO_REBROADCAST   9

Packet is not for me, but protocol states I need to rebroadcast it

Definition at line 113 of file pic_packet.h.

Referenced by pkt_process_rf_data().

#define PKT_STATUS_PKT_FOR_ME_BUT_SEEN   13

Packet is for me but seen previously

Definition at line 125 of file pic_packet.h.

Referenced by pkt_process_rf_data().

#define PKT_STATUS_PKT_IS_ACK_FOR_ME   4

Packet is ACK for me, but didn't find in my transmit queue

Definition at line 98 of file pic_packet.h.

Referenced by pkt_process_rf_data().

#define PKT_STATUS_PKT_IS_FACK_FOR_ME   5

Packet is ACK for me, found in and removed from transmit queue (successful send)

Definition at line 101 of file pic_packet.h.

Referenced by pkt_process_rf_data().

#define PKT_STATUS_PKT_IS_FOR_ME   3

Packet is for me

Definition at line 95 of file pic_packet.h.

Referenced by pkt_process_rf_data().

#define PKT_STATUS_PREVIOUS_ROUTED_VIA_ME   7

Packet has my address in the router list, ignoring

Definition at line 107 of file pic_packet.h.

Referenced by pkt_process_rf_data().

#define PKT_STATUS_QUEUED   10

Packet queued for transmition

Definition at line 116 of file pic_packet.h.

Referenced by pkt_queue_packet().

#define PKT_STATUS_ROUTING_FULL   8

Packet not retransmitted since its routing list is full

Definition at line 110 of file pic_packet.h.

Referenced by pkt_process_rf_data().

#define PKT_STATUS_SEEN_BEFORE   1

Packet is already in seen list, ignoring

Definition at line 89 of file pic_packet.h.

Referenced by pkt_process_rf_data().

#define PKT_STATUS_TX_QUEUE_FULL   11

Packet has not been queued for transmition since my transmit queue is full

Definition at line 119 of file pic_packet.h.

Referenced by pkt_queue_packet().

#define RF_RX_BUFFER_SIZE   PKT_PACKET_SIZE

Definition at line 175 of file pic_packet.h.


Typedef Documentation

typedef struct _rf_packet_det rf_packet_det


Function Documentation

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 400 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.

void pkt_payload_rx_callback ( uns16  source_addr,
uns16  pkt_id,
uns8 *  payload 
)

Once a packet has been received, if it has not been seen before and it is destined to this address (set using pkt_init), then this routine will be called. You must have this routine defined in your own code.

Parameters:
source_addr The address of the system that sent the packet
pkt_id The ID of the packet (the source_addr and pkt_id are used to uniquely identify the packet
payload A pointer to PKT_PACKET_SIZE bytes received

Referenced by pkt_process_rf_data().

Here is the caller graph for this function:

uns8 pkt_process_rf_data ( uns8 *  data_in  ) 

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 331 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.

Here is the call graph for this function:

void pkt_send_callback ( uns16  dest_addr,
uns16  pkt_id 
)

Referenced by pkt_process_tx_queue().

Here is the caller graph for this function:

void pkt_send_failed_callback ( uns16  dest_addr,
uns16  pkt_id 
)

Referenced by pkt_process_tx_queue().

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 417 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:

void pkt_send_succeeded_callback ( uns16  dest_addr,
uns16  pkt_id 
)

Referenced by pkt_process_rf_data().

Here is the caller graph for this function:


Generated on Tue Jul 22 09:32:17 2008 for Pic Pack by  doxygen 1.5.5