Main Page | Modules | Data Structures | File List | Data Fields

ab.h

00001 /*
00002   Implementation of the alternating bit protocol on top of LNP for
00003   LegOS/BrickOS
00004   Copyright (C) 2004  Bram De Wachter
00005 
00006   This program is free software; you can redistribute it and/or
00007   modify it under the terms of the GNU General Public License
00008   as published by the Free Software Foundation; either version 2
00009   of the License, or (at your option) any later version.
00010   
00011   This program is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014   GNU General Public License for more details.
00015   
00016   You should have received a copy of the GNU General Public License
00017   along with this program; if not, write to the Free Software
00018   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 */
00020 
00021 
00119 /*Alternating Bit Protocol:
00120   1. use init_AB_protocol(portHandler) to initialize the protocol
00121   2. use AB_write(message, length) to send a message
00122 */
00123 
00124 #include <lnp/lnp.h>
00125 #include <unistd.h>
00126 #include <stdlib.h>
00127 #include <string.h>
00128 #include <semaphore.h>
00129 #include <time.h>
00130 
00136 
00138 #define DEBUG     0
00139 
00148 #define WRITE_WAIT_TIME  10 
00149 
00153 #define WRITE_TIMEOUT    100
00154 
00156 
00157 
00162 
00163 #define HEADER_SZ         3
00164 
00167 typedef struct message_struct {
00169   unsigned char* txt;
00170 
00172   unsigned char len;
00173 
00176   sem_t         sem_ack;
00177 
00179   struct message_struct *next;
00180 } msg_s ;
00181 
00182 
00185 typedef struct site_struct {
00187   unsigned char id;
00188 
00192   unsigned char status;
00193 
00196   time_t timeout_wait;
00197 
00199   struct site_struct *next;
00200 
00202   msg_s * head;
00203 } site_s ;
00205 
00206 
00209 
00211 unsigned char ab_source;
00212 
00213 
00224 int ab_awrite(const unsigned char* message, unsigned char length, unsigned char destination);
00225 
00226 
00237 int ab_swrite(const unsigned char* message, unsigned char length, unsigned char destination);
00238 
00246 int init_ab_protocol_8(void (*u_portHandler) (const unsigned char *message, unsigned char length),  
00247                        unsigned char id);
00248 
00267 int init_ab_protocol_16(void (*u_portHandler) (const unsigned char *message, unsigned short length),
00268                         unsigned char id, unsigned char max_id);
00269 
00283 int ab_swrite_16(const unsigned char* message, unsigned short length, unsigned char destination);
00284 

Generated on Sat Mar 12 16:12:58 2005 for Alternating Bit by doxygen 1.3.3