forked from cauefcr/ControlCam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexternal.h
89 lines (77 loc) · 2.57 KB
/
external.h
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
// missing definitions from time.h in c99, but not in c11 /*
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 199309L
#if __STDC_VERSION__ == 199901L
struct timespec {
time_t tv_sec;
long tv_nsec;
};
#endif
int nanosleep(const struct timespec *req, struct timespec *rem);
#endif
// */
// modified from libcurl example
int curl_rqst(fstr url, ffstr base_headers, ffstr headers){
CURL *curl;
CURLcode res;
curl = curl_easy_init();
struct curl_slist *list = NULL;
if (curl) {
curl_easy_setopt(curl,CURLOPT_URL,url);
// printf("%s,%s\n",curl_url,filename);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
for(int i = 0; base_headers && i < fat_len(fstr,base_headers); i++){
list = curl_slist_append(list, base_headers[i]);
}
for(int i = 0; headers && i < fat_len(fstr,headers);i++){
list = curl_slist_append(list, headers[i]);
}
/* Perform the request, res will get the return code */
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
// printf("url:%s",url);
res = curl_easy_perform(curl);
/* Check for errors */
if (res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
// return -1;
}
/* always cleanup */
curl_easy_cleanup(curl);
curl_slist_free_all(list);
}
// fclose(log);
return 0;
}
// divides sleep automatically, whole part goes to seconds, fractional part goes
// to nanoseconds, as tv_nsec can only hold a value so big
void n_sleep(double sec) {
// printf("sleep:%F",sec);
static double integer;
static struct timespec wt[2] = {{0, 0}, {0, 0}};
// printf("%f\n",sec);
wt[0].tv_nsec = modf(sec, &integer) * 1000000000L;
wt[0].tv_sec = integer;
nanosleep(wt, NULL);
}
// from http://www.linuxmisc.com/9-unix-programmer/e9699aae73de0158.htm
// static struct termios originalTermParam;
// static void set_keypress() {
// struct termios currentTermParam;
// tcgetattr( 0, &originalTermParam );
// memcpy( ¤tTermParam, &originalTermParam, sizeof( struct termios ) );
// /*
// * Disable canonical mode, and set buffer size to 1 byte
// */
// currentTermParam.c_lflag &= ~ICANON;
// currentTermParam.c_lflag &= ~ECHO;
// currentTermParam.c_cc[ VTIME ] = 255;
// currentTermParam.c_cc[VMIN] = 1;
// tcsetattr( 0, TCSANOW, ¤tTermParam );
// return;
// }
// static void reset_keypress() {
// tcsetattr( 0, TCSANOW, &originalTermParam );
// return;
// }
//curl 'http://192.168.1.100/decoder_control.cgi?command=0&user=utfpr&pwd=utfpr'