This repository has been archived on 2022-09-26. You can view files and clone it, but cannot push or open issues or pull requests.
spyderta/common/msg.h

73 lines
951 B
C

#include "sds.h"
#ifdef WINDOWS
# include <windows.h>
#else
# include <sys/socket.h>
# include <unistd.h>
typedef int SOCKET;
#endif
union msg {
struct {
uint16_t bus;
uint8_t node;
uint64_t addr;
uint8_t tcode;
uint8_t tlabel;
uint8_t extcode;
uint16_t len;
char *buf;
} send_async;
struct {
uint8_t ch;
uint8_t tag;
uint8_t synch;
uint16_t len;
char *buf;
} iso;
struct {
uint64_t start;
uint64_t length;
} allocate;
};
enum {
MSG_SEND_INVALID = -1,
MSG_NOOP = 0,
MSG_SEND_ASYNC = 1,
MSG_SEND_ISO = 2,
MSG_ALLOCATE = 3,
MSG_TYPES_LEN
};
enum parsestate {
PARSE_VERSION_MESSAGE,
PARSE_SEND_ASYNC,
PARSE_SEND_ISO,
PARSE_ALLOCATE
}
typedef void (*msg_exec)(int, union msg *);
struct msg_state {
char *buf;
enum msgtype type;
int msgtype;
union msg msg;
enum parsestate state;
msg_exec on_read[MSG_TYPES_LEN];
};
/* Message Header:
[2 : version][6 : message]
* noop [0]
* (none)
*/