pocketbus.h
Go to the documentation of this file.00001
00042 #ifndef NET_POCKETBUS_H
00043 #define NET_POCKETBUS_H
00044
00045 #include "cfg/cfg_pocketbus.h"
00046 #include <cfg/compiler.h>
00047
00048 #include <algo/rotating_hash.h>
00049
00050 #include <io/kfile.h>
00051
00056 #define POCKETBUS_STX 0x02 //ASCII STX
00057 #define POCKETBUS_ETX 0x03 //ASCII ETX
00058 #define POCKETBUS_ESC 0x1B //ASCII ESC
00059 #define POCKETBUS_ACK 0x06 //ASCII ACK
00060 #define POCKETBUS_NAK 0x15 //ASCII NAK
00061
00062
00063 #define POCKETBUS_BROADCAST_ADDR 0xFFFF ///< pocketBus broadcast address
00064
00068 typedef uint16_t pocketbus_len_t;
00069
00073 typedef uint16_t pocketbus_addr_t;
00074
00078 typedef struct PocketBusHdr
00079 {
00080 #define POCKETBUS_VER 1
00081 uint8_t ver;
00082 pocketbus_addr_t addr;
00083 } PocketBusHdr;
00084
00088 typedef struct PocketBusCtx
00089 {
00090 uint8_t buf[CONFIG_POCKETBUS_BUFLEN];
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 } PocketBusCtx;
00098
00099 STATIC_ASSERT(offsetof(PocketBusCtx, buf) == 0);
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