forked from j3d1/fiatlux
stash
This commit is contained in:
parent
be01d6b985
commit
9de089083c
8 changed files with 191 additions and 144 deletions
|
|
@ -30,7 +30,6 @@ using namespace fiatlux;
|
|||
|
||||
#define vTaskDelayMs(ms) vTaskDelay((ms) / portTICK_PERIOD_MS)
|
||||
|
||||
|
||||
uint16_t voltage_val;
|
||||
|
||||
struct {
|
||||
|
|
@ -44,7 +43,7 @@ void websocket_task(void *pvParameter) {
|
|||
auto *pcb = (struct tcp_pcb *) pvParameter;
|
||||
|
||||
size_t connstarttime = xTaskGetTickCount();
|
||||
has_changed = {true, true, true};
|
||||
has_changed = {true, true, true, true};
|
||||
syslog_attach();
|
||||
unsigned local_log_tail = syslog_current_tail();
|
||||
|
||||
|
|
@ -73,7 +72,7 @@ void websocket_task(void *pvParameter) {
|
|||
}
|
||||
|
||||
//Global Info
|
||||
if(false && has_changed.global) {
|
||||
if(has_changed.global) {
|
||||
timeval tv{};
|
||||
gettimeofday(&tv, nullptr);
|
||||
size_t uptime = xTaskGetTickCount() * portTICK_PERIOD_MS / 1000;
|
||||
|
|
@ -95,6 +94,11 @@ void websocket_task(void *pvParameter) {
|
|||
frame.msg.flashsize = flash_size;
|
||||
//frame.msg. = ; // hostname
|
||||
|
||||
LOCK_TCPIP_CORE();
|
||||
websocket_write(pcb, (unsigned char *) &frame, sizeof(frame), WS_BIN_MODE);
|
||||
has_changed.global = false;
|
||||
UNLOCK_TCPIP_CORE();
|
||||
|
||||
free(hostname);
|
||||
/*LOCK_TCPIP_CORE();
|
||||
websocket_write(pcb, (uint8_t * ) &frame, sizeof(frame), WS_BIN_MODE);
|
||||
|
|
@ -107,13 +111,13 @@ void websocket_task(void *pvParameter) {
|
|||
gettimeofday(&tv, nullptr);
|
||||
size_t connuptime = (xTaskGetTickCount() - connstarttime) * portTICK_PERIOD_MS / 1000;
|
||||
|
||||
printf("conn %d: %d.%.%.%d <-> %d.%d.&d.%d \n", pcb->netif_idx, IP2STR(&pcb->local_ip),
|
||||
printf("conn %d: %d.%d.%d.%d <-> %d.%d.%d.%d \n", pcb->netif_idx, IP2STR(&pcb->local_ip),
|
||||
IP2STR(&pcb->remote_ip));
|
||||
char response[192];
|
||||
size_t
|
||||
len = snprintf(response, sizeof(response), "{\"connage\" : \"%d\"," "\"clientip\" : \""
|
||||
IPSTR
|
||||
"\"" "}", connuptime, IP2STR(&pcb->remote_ip));
|
||||
IPSTR
|
||||
"\"" "}", connuptime, IP2STR(&pcb->remote_ip));
|
||||
if(len < sizeof(response)) {
|
||||
LOCK_TCPIP_CORE();
|
||||
websocket_write(pcb, (unsigned char *) response, len, WS_TEXT_MODE);
|
||||
|
|
@ -213,7 +217,7 @@ void websocket_task(void *pvParameter) {
|
|||
res.ret = OK;
|
||||
res.cmd = (messages::id) 'V';
|
||||
LOCK_TCPIP_CORE();
|
||||
websocket_write(pcb, (uint8_t * ) & res, sizeof(res), WS_BIN_MODE);
|
||||
websocket_write(pcb, (uint8_t *) &res, sizeof(res), WS_BIN_MODE);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
taskYIELD();
|
||||
} else {
|
||||
|
|
@ -257,7 +261,7 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
|
|||
res.ret = OK;
|
||||
} else if(data[0] == 'B') {
|
||||
// Disable LED
|
||||
uint32_t val = data[4] | (data[5] << 8) | (data[6] << 16) | (data[7] << 24);
|
||||
uint32_t val = data[7] | (data[6] << 8) | (data[5] << 16) | (data[4] << 24);
|
||||
bottom_color.r = data[7];
|
||||
bottom_color.g = data[6];
|
||||
bottom_color.b = data[5];
|
||||
|
|
@ -270,17 +274,28 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
|
|||
res.val = 1;
|
||||
} else if(data[0] == 'T') {
|
||||
// Disable LED
|
||||
uint32_t val = data[4] | (data[5] << 8) | (data[6] << 16) | (data[7] << 24);
|
||||
uint32_t val = data[7] | (data[6] << 8) | (data[5] << 16) | (data[4] << 24);
|
||||
top_color.r = data[7];
|
||||
top_color.g = data[6];
|
||||
top_color.b = data[5];
|
||||
syslog("B");
|
||||
syslog("T");
|
||||
syslog_i32(val);
|
||||
syslog("\n");
|
||||
//signal_led(false);
|
||||
res.cmd = (messages::id) 'T';
|
||||
res.ret = OK;
|
||||
res.val = 1;
|
||||
} else if(data[0] == 'J') {
|
||||
// Disable LED
|
||||
uint32_t val = data[7] | (data[6] << 8) | (data[5] << 16) | (data[4] << 24);
|
||||
light_value = data[7] | (data[6] << 8);
|
||||
syslog("J");
|
||||
syslog_i32(val);
|
||||
syslog("\n");
|
||||
//signal_led(false);
|
||||
res.cmd = (messages::id) 'J';
|
||||
res.ret = OK;
|
||||
res.val = 1;
|
||||
} else if(data[0] == 'D') {
|
||||
// Disable LED
|
||||
syslog("G\n");
|
||||
|
|
@ -358,7 +373,7 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
|
|||
}
|
||||
|
||||
LOCK_TCPIP_CORE();
|
||||
websocket_write(pcb, (uint8_t * ) & res, sizeof(res), WS_BIN_MODE);
|
||||
websocket_write(pcb, (uint8_t *) &res, sizeof(res), WS_BIN_MODE);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
|
||||
if(res.ret == OK) {
|
||||
|
|
@ -418,9 +433,15 @@ extern "C" void httpd_task(void *pvParameters) {
|
|||
websocket_register_callbacks((tWsOpenHandler) websocket_open_cb, (tWsHandler) websocket_cb);
|
||||
httpd_init();
|
||||
|
||||
uint16_t last_voltage = 0;
|
||||
while (1) {
|
||||
voltage_val = sdk_system_adc_read();
|
||||
has_changed.voltage = true;
|
||||
vTaskDelayMs(1000);
|
||||
uint16_t voltage = sdk_system_adc_read();
|
||||
if(false && voltage != last_voltage) {
|
||||
last_voltage = voltage;
|
||||
voltage_val = voltage;
|
||||
has_changed.voltage = true;
|
||||
}
|
||||
//has_changed.global = true;
|
||||
vTaskDelayMs(5000);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue