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"
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 uint8_t buf[CONFIG_POCKETBUS_BUFLEN];
00092 struct KFile *fd;
00093 bool sync;
00094 bool escape;
00095 rotating_t in_cks;
00096 rotating_t out_cks;
00097 pocketbus_len_t len;
00098 } PocketBusCtx;
00099
00100 STATIC_ASSERT(offsetof(PocketBusCtx, buf) == 0);
00104 typedef struct PocketMsg
00105 {
00106 struct PocketBusCtx *ctx;
00107 pocketbus_addr_t addr;
00108 pocketbus_len_t len;
00109 const uint8_t *payload;
00110 } PocketMsg;
00111
00117 STATIC_ASSERT(sizeof(pocketbus_addr_t) == sizeof(uint16_t));
00118 STATIC_ASSERT(sizeof(rotating_t) == sizeof(uint16_t));
00119
00120
00121 void pocketbus_putchar(struct PocketBusCtx *ctx, uint8_t c);
00122 void pocketbus_begin(struct PocketBusCtx *ctx, pocketbus_addr_t addr);
00123 void pocketbus_write(struct PocketBusCtx *ctx, const void *_data, size_t len);
00124 void pocketbus_end(struct PocketBusCtx *ctx);
00125
00126 void pocketbus_send(struct PocketBusCtx *ctx, pocketbus_addr_t addr, const void *data, size_t len);
00127 bool pocketbus_recv(struct PocketBusCtx *ctx, struct PocketMsg *msg);
00128 void pocketbus_init(struct PocketBusCtx *ctx, struct KFile *fd);
00129
00130 #endif