00001 /* 00002 00003 Copyright (c) 2010, Embedded Adventures, www.embeddedadventures.com 00004 All rights reserved. 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions are met: 00008 00009 - Redistributions of source code must retain the above copyright notice, 00010 this list of conditions and the following disclaimer. 00011 00012 - Redistributions in binary form must reproduce the above copyright 00013 notice, this list of conditions and the following disclaimer in the 00014 documentation and/or other materials provided with the distribution. 00015 00016 - Neither the name of Embedded Adventures nor the names of its contributors 00017 may be used to endorse or promote products derived from this software 00018 without specific prior written permission. 00019 00020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00021 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00022 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00024 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00025 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00026 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00029 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 00030 THE POSSIBILITY OF SUCH DAMAGE. 00031 00032 Contact us at admin@embeddedadventures.com 00033 00034 */ 00035 00036 00045 // You'll need to define this routine in your own code: 00046 00047 /* 00048 void pkt_payload_rx_callback(uns16 source_addr, uns16 pkt_id, uns8 *payload) {} 00049 */ 00050 00051 // This will get called when a packet is received 00052 00053 // Put this in your config.h: 00054 00055 /* 00056 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 00057 // pic_packet defines 00058 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 00059 00060 #define PKT_TX_QUEUE_SIZE 5 00061 #define PKT_SEEN_LIST_SIZE 5 00062 #define PKT_SEND_MAX_TRIES 10 00063 #define PKT_RESEND_TICK_DELAY 500 00064 00065 #define PKT_PAYLOAD_SIZE 8 00066 00067 // Define if you want to get a callback on send failure 00068 // #define PKT_CALLBACK_ON_SEND_FAILED 00069 // if you define it, you'll need to include this routine in your code: 00070 // void pkt_send_failed_callback(uns16 dest_addr, uns16 pkt_id) { 00071 // } 00072 00073 // Define if you want to get a callback on send success 00074 // #define PKT_CALLBACK_ON_SEND_SUCCEEDED 00075 // if you define it, you'll need to include this routine in your code: 00076 // void pkt_send_succeeded_callback(uns16 dest_addr, uns16 pkt_id) { 00077 // } 00078 00079 // Define if you want to get a callback RF send 00080 // #define PKT_CALLBACK_ON_SEND 00081 // if you define it, you'll need to include this routine in your code: 00082 // void pkt_sendcallback(uns16 dest_addr, uns16 pkt_id) { 00083 // } 00084 00085 00086 // define one or other of these: 00087 #define PKT_USE_2401A 00088 //#define PKT_USE_24L01 00089 00090 // define if you want debug 00091 //#define PKT_DEBUG 00092 00093 // define if you want high amounts of debug 00094 //#define PKT_DEBUG_HIGH 00095 00096 00097 00098 00099 */ 00100 00101 00102 00103 #ifndef __pic_packet_h 00104 #define __pic_packet_h 00105 00106 #include "pic_utils.h" 00107 #include "pic_serial.h" 00108 #include "pic_tick.h" 00109 #include "pic_serial.h" 00110 #include "pic_tick.h" 00111 00112 #include "config.h" 00113 00114 #include <memory.h> 00115 00116 // Status results 00118 #define PKT_STATUS_SEEN_BEFORE 1 00119 00121 #define PKT_STATUS_I_AM_SENDER 2 00122 00124 #define PKT_STATUS_PKT_IS_FOR_ME 3 00125 00127 #define PKT_STATUS_PKT_IS_ACK_FOR_ME 4 00128 00130 #define PKT_STATUS_PKT_IS_FACK_FOR_ME 5 00131 00133 #define PKT_STATUS_DIRECT_SEND 6 00134 00136 #define PKT_STATUS_PREVIOUS_ROUTED_VIA_ME 7 00137 00139 #define PKT_STATUS_ROUTING_FULL 8 00140 00142 #define PKT_STATUS_NEED_TO_REBROADCAST 9 00143 00145 #define PKT_STATUS_QUEUED 10 00146 00148 #define PKT_STATUS_TX_QUEUE_FULL 11 00149 00151 #define PKT_STATUS_CHECK_FAIL 12 00152 00154 #define PKT_STATUS_PKT_FOR_ME_BUT_SEEN 13 00155 00156 // flags 00157 00159 #define PKT_FLAG_NO_RESEND 0 00160 00162 #define PKT_FLAG_RESEND 1 00163 00165 #define PKT_FLAG_BROADCAST 2 00166 00167 00169 #define PKT_CONFIG_ADDR 0xfffd 00170 00172 #define PKT_BROADCAST_ADDR 0xfffe 00173 00175 #define PKT_DIRECT_SEND_ADDR 0xffff 00176 00177 #ifdef PKT_USE_24L01 00178 #include "pic_rf_24l01.h" 00179 #else 00180 #include "pic_rf_2401a.h" 00181 #endif 00182 00183 #ifdef PKT_DEBUG_HIGH 00184 #ifndef PKT_DEBUG 00185 #define PKT_DEBUG 00186 #endif 00187 #endif 00188 00190 typedef struct _rf_packet_det { // 21 bytes 00191 uns16 source_addr; 00192 uns16 pkt_id; 00193 uns16 dest_addr; 00194 uns16 r1_addr; 00195 uns16 r2_addr; 00196 uns16 r3_addr; 00197 uns8 payload[PKT_PAYLOAD_SIZE]; 00198 uns8 check_byte; 00199 } rf_packet_det; 00200 00201 00202 #define PKT_PACKET_SIZE sizeof(rf_packet_det) 00203 00204 #define RF_RX_BUFFER_SIZE PKT_PACKET_SIZE 00205 00218 void pkt_init(uns16 my_addr, uns16 last_sent_pkt_id); 00219 00220 00232 uns8 pkt_process_rf_data(uns8* data_in); 00242 void pkt_process_tx_queue(); 00243 00260 uns8 pkt_send_payload(uns16 dest_addr, uns8 *payload, uns8 resend); 00261 00274 void pkt_payload_rx_callback(uns16 source_addr, uns16 pkt_id, uns8 *payload); 00275 00276 00277 void pkt_send_failed_callback(uns16 dest_addr, uns16 pkt_id); 00278 void pkt_send_succeeded_callback(uns16 dest_addr, uns16 pkt_id); 00279 void pkt_send_callback(uns16 dest_addr, uns16 pkt_id); 00280 00281 00282 #endif