pocketbus.h

Go to the documentation of this file.
00001 
00014 #ifndef NET_POCKETBUS_H
00015 #define NET_POCKETBUS_H
00016 
00017 #include <algos/rotating_hash.h>
00018 #include <drv/ser.h>
00019 #include <kern/kfile.h>
00020 #include <cfg/compiler.h>
00021 #include "appconfig.h" //for CONFIG_POCKETBUS_BUFLEN
00022 
00027 #define POCKETBUS_STX 0x02 //ASCII STX
00028 #define POCKETBUS_ETX 0x03 //ASCII ETX
00029 #define POCKETBUS_ESC 0x1B //ASCII ESC
00030 #define POCKETBUS_ACK 0x06 //ASCII ACK
00031 #define POCKETBUS_NAK 0x15 //ASCII NAK
00032 /*\}*/
00033 
00034 #define POCKETBUS_BROADCAST_ADDR 0xFFFF 
00035 
00036 
00039 typedef uint16_t pocketbus_len_t;
00040 
00044 typedef uint16_t pocketbus_addr_t;
00045 
00049 typedef struct PocketBusHdr
00050 {
00051     #define POCKETBUS_VER 1 
00052     uint8_t ver;   
00053     pocketbus_addr_t addr; 
00054 } PocketBusHdr;
00055 
00059 typedef struct PocketBusCtx
00060 {
00061     struct KFile *fd;   
00062     bool sync;           
00063     bool escape;         
00064     rotating_t in_cks;   
00065     rotating_t out_cks;  
00066     pocketbus_len_t len; 
00067     uint8_t buf[CONFIG_POCKETBUS_BUFLEN]; 
00068 } PocketBusCtx;
00069 
00073 typedef struct PocketMsg
00074 {
00075     struct PocketBusCtx *ctx; 
00076     pocketbus_addr_t addr;    
00077     pocketbus_len_t len;      
00078     const uint8_t *payload;   
00079 } PocketMsg;
00080 
00086 STATIC_ASSERT(sizeof(pocketbus_addr_t) == sizeof(uint16_t));
00087 STATIC_ASSERT(sizeof(rotating_t) == sizeof(uint16_t));
00088 /*\}*/
00089 
00090 void pocketbus_putchar(struct PocketBusCtx *ctx, uint8_t c);
00091 void pocketbus_begin(struct PocketBusCtx *ctx, pocketbus_addr_t addr);
00092 void pocketbus_write(struct PocketBusCtx *ctx, const void *_data, size_t len);
00093 void pocketbus_end(struct PocketBusCtx *ctx);
00094 
00095 void pocketbus_send(struct PocketBusCtx *ctx, pocketbus_addr_t addr, const void *data, size_t len);
00096 bool pocketbus_recv(struct PocketBusCtx *ctx, struct PocketMsg *msg);
00097 void pocketbus_init(struct PocketBusCtx *ctx, struct KFile *fd);
00098 
00099 #endif /* NET_POCKETBUS_H */