chiark / gitweb /
hostside: hidrawconv: break out dispatch()
[trains.git] / hostside / hidrawconv.h
1 #ifndef HIDRAWCONV_H
2 #define HIDRAWCONV_H
3
4 #include <stdio.h>
5 #include <stdint.h>
6
7 #include "common.h"
8
9 #define MAXREPORTLEN 256
10 #define MAXREPORTS 256
11
12 typedef struct { int len; uint8_t *msg; } Last;
13 typedef struct { Last lasts[MAXREPORTS]; } LastReports;
14 typedef void ProcessReport(const uint8_t *msg, int msglen, const uint8_t *last);
15
16 extern const char *const descriptor;
17 extern ProcessReport *const report_processors[MAXREPORTS];
18
19 typedef struct {
20   const char *str;
21   int pos;
22   uint8_t mask;
23 } KeyBit;
24
25 typedef struct {
26   const char *str;
27   int pos, rshift, sign; /* mask is applied before rshift */
28   uint8_t mask, zero;
29 } ValLoc;
30
31 void reportbits(const uint8_t msg[], const uint8_t last[],
32                 int len, const KeyBit bits[]);
33
34 void reportlocs(const uint8_t msg[], const uint8_t last[],
35                 int len, const ValLoc locs[]);
36
37 void dispatch(LastReports *lasts, const char *message_prefix,
38               ProcessReport *const report_processors[MAXREPORTS],
39               const uint8_t *msg, int l);
40
41 #endif /*HIDRAWCONV_H*/