-
Notifications
You must be signed in to change notification settings - Fork 1
/
fht.h
55 lines (45 loc) · 1.13 KB
/
fht.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* fhz2mqtt, a FHZ to MQTT bridge
*
* Copyright (c) Ralf Ramsauer, 2018
*
* Authors:
* Ralf Ramsauer <[email protected]>
*
* This work is licensed under the terms of the GNU GPL, version 2. See
* the COPYING file in the top-level directory.
*/
#include <ctype.h>
#include <errno.h>
#include <string.h>
struct payload;
struct hauscode {
unsigned char upper;
unsigned char lower;
} __attribute__((packed));
struct fht_message {
enum {STATUS, ACK} type;
struct hauscode hauscode;
struct {
char topic[16];
char value[16];
} report[2];
};
static inline int hauscode_from_string(const char *string,
struct hauscode *hauscode)
{
int i;
if (strlen(string) != 4)
return -EINVAL;
for (i = 0; i < 4; i++)
if (!isdigit(string[i]))
return -EINVAL;
hauscode->upper = (string[0] - '0') * 10;
hauscode->upper += (string[1] - '0') * 1;
hauscode->lower = (string[2] - '0') * 10;
hauscode->lower += (string[3] - '0') * 1;
return 0;
}
int fht_decode(const struct payload *payload, struct fht_message *message);
int fht_set(int fd, const struct hauscode *hauscode,
const char *command, const char *payload);