Allow uploading sensors wholesale

This commit is contained in:
Neale Pickett 2014-07-29 21:48:56 +00:00
parent 97f29f389a
commit 4d15d84856
1 changed files with 28 additions and 13 deletions

View File

@ -32,11 +32,22 @@ struct {
"name", 20}, { "name", 20}, {
"author", 80}, { "author", 80}, {
"color", 10}, { "color", 10}, {
"sensor0", 16}, {
"sensor1", 16}, {
"sensor2", 16}, {
"sensor3", 16}, {
"sensor4", 16}, {
"sensor5", 16}, {
"sensor6", 16}, {
"sensor7", 16}, {
"sensor8", 16}, {
"sensor9", 16}, {
"program", 16384}, { "program", 16384}, {
NULL, 0} NULL, 0}
}; };
size_t inlen; size_t inlen;
int int
@ -166,7 +177,7 @@ croak(int code, char *msg)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int sensor[10][4]; int sensor[10][5];
char key[20]; char key[20];
char token[40]; char token[40];
size_t len; size_t len;
@ -214,18 +225,19 @@ main(int argc, char *argv[])
} }
i = atoi(val); i = atoi(val);
sensor[n][0] = 1;
switch (key[2]) { switch (key[2]) {
case 'r': case 'r':
p = 0;
break;
case 'a':
p = 1; p = 1;
break; break;
case 'w': case 'a':
p = 2; p = 2;
break; break;
default: case 'w':
p = 3; p = 3;
break;
default:
p = 4;
i = (val[0] != '\0'); i = (val[0] != '\0');
break; break;
} }
@ -285,15 +297,18 @@ main(int argc, char *argv[])
for (i = 0; i < 10; i += 1) { for (i = 0; i < 10; i += 1) {
FILE *f; FILE *f;
if (sensor[i][0]) {
snprintf(dest, sizeof(dest), "%s%s/sensor%d", BASE_PATH, token, i); snprintf(dest, sizeof(dest), "%s%s/sensor%d", BASE_PATH, token, i);
f = fopen(dest, "w"); f = fopen(dest, "w");
if (!f) if (!f) {
break; break;
}
fprintf(f, "%d %d %d %d\n", sensor[i][0], sensor[i][1], sensor[i][2], sensor[i][3]); fprintf(f, "%d %d %d %d\n", sensor[i][1], sensor[i][2], sensor[i][3], sensor[i][4]);
fclose(f); fclose(f);
} }
} }
}
printf("Content-type: text/plain\n"); printf("Content-type: text/plain\n");
printf("\n"); printf("\n");