-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcommandmanager.h
More file actions
99 lines (66 loc) · 1.67 KB
/
commandmanager.h
File metadata and controls
99 lines (66 loc) · 1.67 KB
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
//
// commandmanager.h
// pid-controller-server
//
// Created by Andrey Chufyrev on 18.11.2018.
// Copyright © 2018 Andrey Chufyrev. All rights reserved.
//
#ifndef commandmanager_h
#define commandmanager_h
#include <stdio.h>
#include <stdlib.h>
#include <string.h> // for memset()
#include <stdbool.h>
#include <math.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/adc.h"
#include "lwip/sockets.h"
#include "esp_log.h"
#include "pid.h"
// #include "sodium.h"
extern const char *TAG;
extern int sock;
extern struct sockaddr_in6 sourceAddr; // client address
extern socklen_t socklen; // byte size of client's address
enum {
OPCODE_read,
OPCODE_write
};
enum {
VAR_setpoint = 0b0100,
VAR_kP = 0b0101,
VAR_kI = 0b0110,
VAR_kD = 0b0111,
VAR_err_I = 0b1000,
VAR_err_P_limits = 0b1001,
VAR_err_I_limits = 0b1010,
// special
CMD_stream_start = 0b0001,
CMD_stream_stop = 0b0000,
CMD_save_to_eeprom = 0b1011
};
enum {
RESULT_ok,
RESULT_error
};
#define STREAM_PREFIX 0b00000001
typedef struct request {
unsigned char _reserved: 3;
unsigned char var_cmd : 4;
unsigned char opcode : 1;
} request_t;
typedef struct response {
unsigned char _reserved: 2;
unsigned char result : 1;
unsigned char var_cmd : 4;
unsigned char opcode : 1;
} response_t;
// void _print_bin_hex(unsigned char byte);
void error(char *msg);
void _stream_task(void *data);
void stream_start(void);
void stream_stop(void);
int process_request(unsigned char *request_response_buf);
// int process_request(unsigned char *request_buf, unsigned char *response_buf);
#endif /* commandmanager_h */