summaryrefslogtreecommitdiffstats
path: root/pressure_control/firmware/remote.h
blob: ad6754022dd1169647037a97dfe7b2b3f26c338d (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef REMOTE_H_
#define REMOTE_H_

#include <stdint.h>

#include <avr/pgmspace.h>


enum remote_message_id {
	MSG_INVALID = 0, /* Discard me */
	MSG_ERROR,
	MSG_LOGMESSAGE,
	MSG_PING,
	MSG_PONG,
	MSG_GET_CURRENT_PRESSURE,
	MSG_CURRENT_PRESSURE,
	MSG_GET_DESIRED_PRESSURE,
	MSG_DESIRED_PRESSURE,
	MSG_SET_DESIRED_PRESSURE,
	MSG_GET_HYSTERESIS,
	MSG_HYSTERESIS,
	MSG_SET_HYSTERESIS,
	MSG_GET_CONFIG_FLAGS,
	MSG_CONFIG_FLAGS,
	MSG_SET_CONFIG_FLAGS,
	MSG_SET_VALVE,
};

enum remote_message_error {
	MSG_ERR_NONE = 0,	/* No error */
	MSG_ERR_CHKSUM,		/* Checksum error */
	MSG_ERR_NOCMD,		/* Unknown command */
	MSG_ERR_BUSY,		/* Busy */
	MSG_ERR_INVAL,		/* Invalid argument */
};

enum remote_message_flags {
	MSG_FLAG_REQ_ERRCODE = 0,
};

enum remote_message_config_flags {
	CFG_FLAG_AUTOADJUST_ENABLE = 0,
};

struct remote_message {
	uint8_t id;
	uint8_t flags;

	union {
		struct {
			uint8_t code;
		} __attribute__((packed)) error;
		struct {
			char str[8];
		} __attribute__((packed)) logmessage;
		struct {
			uint16_t mbar;
		} __attribute__((packed)) pressure;
		struct {
			uint32_t flags;
		} __attribute__((packed)) config;
		struct {
			uint8_t nr; /* Valve ID */
			uint8_t state;
		} __attribute__((packed)) valve;

		uint8_t __padding[8];
	} __attribute__((packed));

	uint16_t crc;
} __attribute__((packed));


void print_pgm(const prog_char *msg);
#define print(string_literal)	print_pgm(PSTR(string_literal))

void remote_pressure_change_notification(uint16_t mbar,
					 uint16_t hysteresis);

void remote_work(void);
void remote_init(void);

#endif /* REMOTE_H_ */
bues.ch cgit interface