aboutsummaryrefslogtreecommitdiff
path: root/lib/pbdrv/pb-send.c
blob: b6efd3e9bc9580482dc687f51c103ae772485e3c (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "pb-send.h"
#include "pb-mod.h"
#include "pb-msg.h"

__weak void pb_send_reply(const pb_msg_t * msg, const pb_buf_t * reply) {
	return pb_i2c_send(msg->sender, (uint8_t *) reply->data, reply->size);
}

pb_buf_t pb_send_read_req(uint8_t propid) {
	pb_cmd_prop_t cmd = {
		.propid = propid,
		.value = NULL,
		._value_size = 0,
	};
	pb_msg_t msg = {
		.type = PB_CMD_PROP,
		.action = PB_ACTION_REQ,
		.sender = PB_MOD_ADDR,
		.cmd = &cmd,
	};
	return pb_msg_write(&msg);
}

pb_buf_t pb_send_read_res(uint8_t propid, const uint8_t * value, size_t size) {
	pb_cmd_prop_t cmd = {
		.propid = propid,
		.value = (uint8_t *) value,
		._value_size = size,
	};
	pb_msg_t msg = {
		.type = PB_CMD_PROP,
		.action = PB_ACTION_RES,
		.sender = PB_MOD_ADDR,
		.cmd = &cmd,
	};
	return pb_msg_write(&msg);
}

pb_buf_t pb_send_write_req(uint8_t propid, const uint8_t * value, size_t size) {
	pb_cmd_prop_t cmd = {
		.propid = propid,
		.value = (uint8_t *) value,
		._value_size = size,
	};
	pb_msg_t msg = {
		.type = PB_CMD_PROP,
		.action = PB_ACTION_REQ,
		.sender = PB_MOD_ADDR,
		.cmd = &cmd,
	};
	return pb_msg_write(&msg);
}

pb_buf_t pb_send_state_req() {
	pb_cmd_state_t cmd = {
		.state = pb_hook_mod_state_read(),
	};
	pb_msg_t msg = {
		.type = PB_CMD_STATE,
		.action = PB_ACTION_REQ,
		.sender = PB_MOD_ADDR,
		.cmd = &cmd,
	};
	return pb_msg_write(&msg);
}

pb_buf_t pb_send_state_res() {
	pb_cmd_state_t cmd = {
		.state = pb_hook_mod_state_read(),
	};
	pb_msg_t msg = {
		.type = PB_CMD_STATE,
		.action = PB_ACTION_RES,
		.sender = PB_MOD_ADDR,
		.cmd = &cmd,
	};
	return pb_msg_write(&msg);
}

pb_buf_t pb_send_state_set(pb_global_state_t state) {
	pb_cmd_state_t cmd = {
		.state = state,
	};
	pb_msg_t msg = {
		.type = PB_CMD_STATE,
		.action = PB_ACTION_SET,
		.sender = PB_MOD_ADDR,
		.cmd = &cmd,
	};
	return pb_msg_write(&msg);
}

pb_buf_t pb_send_magic_req() {
	pb_cmd_magic_t cmd = {
		.magic = (char *) &pb_cmd_magic_req[0],
		._magic_size = sizeof(pb_cmd_magic_req),
	};
	pb_msg_t msg = {
		.type = PB_CMD_MAGIC,
		.action = PB_ACTION_REQ,
		.sender = PB_MOD_ADDR,
		.cmd = &cmd,
	};
	return pb_msg_write(&msg);
}

pb_buf_t pb_send_magic_res() {
	pb_cmd_magic_t cmd = {
		.magic = (char *) &pb_cmd_magic_res[0],
		._magic_size = sizeof(pb_cmd_magic_res),
	};
	pb_msg_t msg = {
		.type = PB_CMD_MAGIC,
		.action = PB_ACTION_RES,
		.sender = PB_MOD_ADDR,
		.cmd = &cmd,
	};
	return pb_msg_write(&msg);
}