-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHTTP.h
More file actions
125 lines (112 loc) · 2.96 KB
/
HTTP.h
File metadata and controls
125 lines (112 loc) · 2.96 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
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
/**
* @file HTTP.h
* @author Petr Kucera (kucerp28@fel.cvut.cz)
* @brief The header file defines functions for sampling data into the HTTP data
* structure and serving the web server.
* @version 0.1
* @date 2023-01-10
*
* @copyright Copyright (c) 2023
*
*/
#ifndef HTTP_H_
#define HTTP_H_
#include "UDP.h"
#include "motor.h"
#include <semLib.h>
/**
* @brief The macro defines the HTTP data length.
*
* Note: The graphs should show at least 2 seconds
* of history with time resolution ≤ 5 ms.
*
* We want delay 2 ms -> CYCLE SIZE => 1000
*
*/
#define CYCLE_SIZE 1000
/**
* @brief The structure for sampling data. It is necessary for graphs on the web
* server.
*
*/
typedef struct http_s {
/**
* @brief Mutex for protecting writing to this structure.
*
*/
SEM_ID http_sem;
/**
* @brief Last n motor position values.
*
*/
int motor_position[CYCLE_SIZE];
/**
* @brief Last n requested motor position values.
*
*/
int requested_position[CYCLE_SIZE];
/**
* @brief Last n pwm intensity (speed) values.
*
*/
int pwm_speed[CYCLE_SIZE];
/**
* @brief The value that points to the most recent value's index.
*
*/
int cycle_p;
} HTTP_D;
/**
* @brief The function of running the web server. Web server spawn HTTP
* responses as separate tasks.
*
* @param isEndp The pointer to the global variable for the signalizing program
* end.
* @param http_d The pointer to the HTTP data.
*/
void www(int *isEndp, HTTP_D *http_d);
/**
* @brief The server response renders graphs with motor positions and PWA
* intensity.
*
* @param newFd Web server response file descriptor.
* @param http_d The pointer to the HTTP data.
*/
void serverResponse(int newFd, HTTP_D *http_d);
/**
* @brief The function allocates the HTTP data structure and sets initialization
* values.
*
* @return HTTP_D*
*/
HTTP_D *initHTTPData();
/**
* @brief The function is sampling data for rendering graphs with a specific
* period.
*
* @param udp The pointer to the UDP structure.
* @param my_motor The pointer to the motor structure.
* @param http_d The pointer to the http data strucure.
* @param isEndp The pointer to the global variable for the signalizing program
* end.
*/
void handleHTTPData(UDP *udp, struct psrMotor *my_motor, HTTP_D *http_d,
int *isEndp);
/**
* @brief The local function for saving data into the HTTP Data structure with a
* mutex to prevent damaged data.
*
* @param http_d The pointer to the http data strucure.
* @param motor_position Value of motor position
* @param requested_position Value of requested motor position
* @param pwm_speed Value of pwm intesity (speed)
*/
void saveHTTPData(HTTP_D *http_d, int motor_position, int requested_position,
int pwm_speed);
/**
* @brief Removes allocated data for the HTTP data structure.
*
* @param http_d The pointer to the http data strucure.
*/
void removeHTTPData(HTTP_D *http_d);
#endif /* UDP_H_ */