aboutsummaryrefslogtreecommitdiff
path: root/app.h
blob: 0f8429625bb5b53065c3c768d22d3f1a921e1f26 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef APP_H
#define APP_H

#include "config-check.h"
#include <stdint.h>
#include <Arduino.h>

#define SENSOR_NAME_LEN 10

// TODO: Randomize these numbers. There are no reason why they should be in order.

enum sm_cmd_code {
  SM_CMD_GET_SENSOR_COUNT    = 1,
  // Used to be 2
  SM_CMD_GET_VALUE           = 8,
  SM_CMD_SET_WARNING_VALUE   = 3,
  SM_CMD_GET_WARNING_VALUE   = 4,
  SM_CMD_SET_SENSOR_NAME     = 5,
  SM_CMD_GET_SENSOR_NAME     = 6,
  SM_CMD_SET_UPDATE_INTERVAL = 7,
  // 8 is used
  SM_CMD_FAIL                = 255,
};

struct sm_get_sensor_count_req {
};

struct sm_get_sensor_count_res {
  uint8_t count;
};

struct sm_get_value_req {
  uint8_t sensor;
};

/**
 * This includes the sensor id because it can be used as a notification too
 */
struct sm_get_value_res {
  uint8_t  sensor;
  uint16_t value;
};

struct sm_set_warning_value_req {
  uint8_t  sensor;
  uint16_t warning_value;
};

struct sm_set_warning_value_res {
};

struct sm_get_warning_value_req {
  uint8_t sensor;
};

struct sm_get_warning_value_res {
  uint16_t warning_value;
};

struct sm_set_sensor_name_req {
  uint8_t sensor;
  uint8_t length;
  uint8_t name[SENSOR_NAME_LEN];
};

struct sm_set_sensor_name_res {
};

struct sm_get_sensor_name_req {
  uint8_t sensor;
};

struct sm_get_sensor_name_res {
  uint8_t length;
  uint8_t name[SENSOR_NAME_LEN];
};

struct sm_set_update_interval_req {
  uint8_t sensor;
  uint8_t interval_in_seconds;
};

struct sm_set_update_interval_res {
};

struct sm_req {
  uint8_t code;
  union {
    struct sm_get_sensor_count_req    get_sensor_count;
    struct sm_get_value_req           get_value;
    struct sm_set_warning_value_req   set_warning_value;
    struct sm_get_warning_value_req   get_warning_value;
    struct sm_set_sensor_name_req     set_sensor_name;
    struct sm_get_sensor_name_req     get_sensor_name;
    struct sm_set_update_interval_req set_update_interval;
  };
};

// len + code
#define SM_RES_HEADER_SIZE 1

struct sm_res {
  // header
  uint8_t code;

  // body
  union {
    struct sm_get_sensor_count_res    get_sensor_count;
    struct sm_get_value_res           get_value;
    struct sm_set_warning_value_res   set_warning_value;
    struct sm_get_warning_value_res   get_warning_value;
    struct sm_set_sensor_name_res     set_sensor_name;
    struct sm_get_sensor_name_res     get_sensor_name;
    struct sm_set_update_interval_res set_update_interval;
  };
};

void sm_loop();
void sm_setup();
void sm_on_connect();
void sm_on_disconnect();

//boolean tx_soil_moisture(struct sm_res& res);
void notify_soil_moisture(const struct sm_res &res, uint8_t body_len);
void notify_battery_level(uint8_t value);

void on_soil_moisture_ctrl(uint8_t *data, uint8_t len);

#ifdef SM_DEBUG
void write_req(struct sm_req const &req);
void write_res(struct sm_res const &res);
#endif

#endif

// vim: set ft=arduino: