pocketbus.h
Go to the documentation of this file.00001 00043 #ifndef NET_POCKETBUS_H 00044 #define NET_POCKETBUS_H 00045 00046 #include "cfg/cfg_pocketbus.h" /* for CONFIG_POCKETBUS_BUFLEN */ 00047 #include <cfg/compiler.h> 00048 00049 #include <algo/rotating_hash.h> 00050 00051 #include <kern/kfile.h> 00052 00057 #define POCKETBUS_STX 0x02 //ASCII STX 00058 #define POCKETBUS_ETX 0x03 //ASCII ETX 00059 #define POCKETBUS_ESC 0x1B //ASCII ESC 00060 #define POCKETBUS_ACK 0x06 //ASCII ACK 00061 #define POCKETBUS_NAK 0x15 //ASCII NAK 00062 /*\}*/ 00063 00064 #define POCKETBUS_BROADCAST_ADDR 0xFFFF 00065 00066 00069 typedef uint16_t pocketbus_len_t; 00070 00074 typedef uint16_t pocketbus_addr_t; 00075 00079 typedef struct PocketBusHdr 00080 { 00081 #define POCKETBUS_VER 1 00082 uint8_t ver; 00083 pocketbus_addr_t addr; 00084 } PocketBusHdr; 00085 00089 typedef struct PocketBusCtx 00090 { 00091 struct KFile *fd; 00092 bool sync; 00093 bool escape; 00094 rotating_t in_cks; 00095 rotating_t out_cks; 00096 pocketbus_len_t len; 00097 uint8_t buf[CONFIG_POCKETBUS_BUFLEN]; 00098 } PocketBusCtx; 00099 00103 typedef struct PocketMsg 00104 { 00105 struct PocketBusCtx *ctx; 00106 pocketbus_addr_t addr; 00107 pocketbus_len_t len; 00108 const uint8_t *payload; 00109 } PocketMsg; 00110 00116 STATIC_ASSERT(sizeof(pocketbus_addr_t) == sizeof(uint16_t)); 00117 STATIC_ASSERT(sizeof(rotating_t) == sizeof(uint16_t)); 00118 /*\}*/ 00119 00120 void pocketbus_putchar(struct PocketBusCtx *ctx, uint8_t c); 00121 void pocketbus_begin(struct PocketBusCtx *ctx, pocketbus_addr_t addr); 00122 void pocketbus_write(struct PocketBusCtx *ctx, const void *_data, size_t len); 00123 void pocketbus_end(struct PocketBusCtx *ctx); 00124 00125 void pocketbus_send(struct PocketBusCtx *ctx, pocketbus_addr_t addr, const void *data, size_t len); 00126 bool pocketbus_recv(struct PocketBusCtx *ctx, struct PocketMsg *msg); 00127 void pocketbus_init(struct PocketBusCtx *ctx, struct KFile *fd); 00128 00129 #endif /* NET_POCKETBUS_H */
