-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcgi.c
More file actions
88 lines (73 loc) · 1.94 KB
/
cgi.c
File metadata and controls
88 lines (73 loc) · 1.94 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
#include <stm32f0xx.h>
#include <stdio.h>
#include <string.h>
#include "contiki-net.h"
#include "httpd.h"
#include "httpd-cgi.h"
#include "httpd-fs.h"
static struct {
int value;
} leds[] = {
{ .value = 0, },
{ .value = 481, },
{ .value = 481, },
{ .value = 481, },
};
static unsigned short
generate_pahka_cgi(void *arg) {
const char *str = (const char *)arg;
const char *cmd = strchr(str, ' ');
if (cmd == NULL)
return 0;
cmd += 1;
const char *led = strchr(cmd, ' ');
if (led == NULL)
return 0;
led += 1;
if (*cmd == 'u') {
/* Return the Unique ID */
return snprintf((char *)uip_appdata, uip_mss(),
"%8.08x%8.08x%8.08x",
*(unsigned int *)(0x1FFFF7AC + 0x08),
*(unsigned int *)(0x1FFFF7AC + 0x04),
*(unsigned int *)(0x1FFFF7AC + 0x00));
}
int lednum = 0;
if (*led == 'r')
lednum = 1;
else if (*led == 'g')
lednum = 2;
else if (*led == 'b')
lednum = 3;
if (*cmd == 'i') {
leds[lednum].value++;
if (leds[lednum].value > 481)
leds[lednum].value = 481;
} else if (*cmd == 'd') {
leds[lednum].value--;
if (leds[lednum].value < 320)
leds[lednum].value = 320;
}
switch (lednum) {
case 1:
TIM16->CCR1 = leds[lednum].value;
break;
case 2:
TIM17->CCR1 = leds[lednum].value;
break;
case 3:
TIM15->CCR1 = leds[lednum].value;
break;
}
return snprintf((char *)uip_appdata, uip_mss(), "%d", leds[lednum].value);
}
PT_THREAD(pahka_cgi_thread(struct httpd_state *s, char *ptr)) {
PSOCK_BEGIN(&s->sout);
PSOCK_GENERATOR_SEND(&s->sout, generate_pahka_cgi, (void *)ptr);
PSOCK_END(&s->sout);
}
HTTPD_CGI_CALL(pahka_cgi, "pahka", pahka_cgi_thread);
void
pahka_cgi_init(void) {
httpd_cgi_add(&pahka_cgi);
}