int do_http_post(int sd, char *req, int rlen) { int BUFSIZE = 1024; char buf[BUFSIZE]; int len = 0, n; char *p; if (is_cmd_led(req)) { n = toggle_leds(); len = generate_http_header(buf, "txt", 1); p = buf + len; *p++ = n?'1':'0'; *p = 0; len++; xil_printf("http POST: ledstatus: %x\r\n", n); } else if (is_cmd_switch(req)) { unsigned s = get_switch_state(); int n_switches = 8; xil_printf("http POST: switch state: %x\r\n", s); len = generate_http_header(buf, "txt", n_switches); p = buf + len; for (n = 0; n < n_switches; n++) { *p++ = '0' + (s & 0x1); s >>= 1; } *p = 0; len += n_switches; } else {
int do_http_post(struct tcp_pcb *pcb, char *req, int rlen) { int BUFSIZE = 1024; char buf[BUFSIZE]; int len, n; char *p; if (is_cmd_led(req)) { n = toggle_leds(); len = generate_http_header(buf, "js", 1); p = buf + len; *p++ = n?'1':'0'; *p = 0; len++; xil_printf("http POST: ledstatus: %x\r\n", n); } else if (is_cmd_switch(req)) { unsigned s = get_switch_state(); int n_switches = 8; //char *json_response = "{\"status\":\"10101011\"}"; xil_printf("http POST: switch state: %x\r\n", s); len = generate_http_header(buf, "js", n_switches); //len = generate_http_header(buf, "js", strlen(json_response)); p = buf + len; #if 1 for (n = 0; n < n_switches; n++, p++) { *p = '0' + (s & 0x1); s >>= 1; } *p = 0; len += n_switches; #else strcpy(p, json_response); len += strlen(json_response); #endif } if (tcp_write(pcb, buf, len, 1) != ERR_OK) { xil_printf("error writing http POST response to socket\n\r"); xil_printf("http header = %s\r\n", buf); return -1; } return 0; }
int do_http_post(struct tcp_pcb* pcb, char* req, int rlen) { int BUFSIZE = 1024; unsigned char buf[BUFSIZE]; int len, n; char* p; if (is_cmd_led(req)) { n = toggle_leds(); len = generate_http_header((char*)buf, "js", 1); p = (char*)buf + len; *p++ = n ? '1':'0'; *p = 0; len++; xil_printf("http POST: ledstatus: %x\r\n", n); } else if (is_cmd_switch(req)) { unsigned s = get_switch_state(); int n_switches = 4; xil_printf("http POST: switch state: %x\r\n", s); len = generate_http_header((char*)buf, "js", n_switches); p = (char*)buf + len; for (n=0; n<n_switches; n++, p++) { *p = '0' + (s & 0x1); s >>= 1; } *p = 0; len += n_switches; } if (tcp_write(pcb, buf, len, 1) != ERR_OK) { xil_printf("error writing http POST response to socket\r\n"); xil_printf("http header = %s\r\n", buf); return -1; } return 0; }