// print various Wifi information into json buffer int ICACHE_FLASH_ATTR printWifiInfo(char *buff) { int len; struct station_config stconf; wifi_station_get_config(&stconf); uint8_t op = wifi_get_opmode() & 0x3; char *mode = wifiMode[op]; char *status = "unknown"; int st = wifi_station_get_connect_status(); if (st > 0 && st < sizeof(connStatuses)) status = connStatuses[st]; int p = wifi_get_phy_mode(); char *phy = wifiPhy[p&3]; char *warn = wifiWarn[op]; sint8 rssi = wifi_station_get_rssi(); if (rssi > 0) rssi = 0; uint8 mac_addr[6]; wifi_get_macaddr(0, mac_addr); len = os_sprintf(buff, "\"mode\": \"%s\", \"ssid\": \"%s\", \"status\": \"%s\", \"phy\": \"%s\", " "\"rssi\": \"%ddB\", \"warn\": \"%s\", \"passwd\": \"%s\", " "\"mac\":\"%02x:%02x:%02x:%02x:%02x:%02x\"", mode, (char*)stconf.ssid, status, phy, rssi, warn, (char*)stconf.password, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); struct ip_info info; if (wifi_get_ip_info(0, &info)) { len += os_sprintf(buff+len, ", \"ip\": \"%d.%d.%d.%d\"", (info.ip.addr>>0)&0xff, (info.ip.addr>>8)&0xff, (info.ip.addr>>16)&0xff, (info.ip.addr>>24)&0xff); } else {
//--------------------------------------------------------------------------------- //-- Send Radio Status void MavESP8266GCS::_sendRadioStatus() { linkStatus* st = _forwardTo->getStatus(); uint8_t rssi = 0; if(wifi_get_opmode() == STATION_MODE) { rssi = (uint8_t)wifi_station_get_rssi(); } //-- Build message mavlink_message_t msg; mavlink_msg_radio_status_pack( _forwardTo->systemID(), MAV_COMP_ID_UDP_BRIDGE, &msg, rssi, // RSSI Only valid in STA mode 0, // We don't have access to Remote RSSI st->queue_status, // UDP queue status 0, // We don't have access to noise data (uint16_t)((st->packets_lost * 100) / st->packets_received), // Percent of lost messages from Vehicle (UART) (uint16_t)((_status.packets_lost * 100) / _status.packets_received), // Percent of lost messages from GCS (UDP) 0 // We don't fix anything ); _sendSingleUdpMessage(&msg); _status.radio_status_sent++; }
void ICACHE_FLASH_ATTR tcpserver_init(void) { int8_t res; tcp_server.type = ESPCONN_TCP; tcp_server.state = ESPCONN_NONE; tcp_server.proto.tcp = &tcp_config; tcp_server.proto.tcp->local_port = TCP_SERVER_LOCAL_PORT; espconn_regist_connectcb(&tcp_server, incoming_connection_callback); espconn_tcp_set_max_con_allow(&tcp_server, 1); //Allow 1 connection max res = espconn_accept(&tcp_server); if(res == 0) os_printf("Created TCP server on port %d, running on ROM %d, AP RSSI: %ddBm, WiFi mode: %d.\r\n", tcp_server.proto.tcp->local_port, system_upgrade_userbin_check(), wifi_station_get_rssi(), wifi_get_phy_mode()); else os_printf("Failed to create TCP server, error code: %d.\r\n", res); }
int ICACHE_FLASH_ATTR mqttStatusMsg(char *buf) { sint8 rssi = wifi_station_get_rssi(); if (rssi > 0) rssi = 0; // not connected or other error //os_printf("timer rssi=%d\n", rssi); // compose MQTT message return os_sprintf(buf, "{\"rssi\":%d, \"heap_free\":%ld}", rssi, (unsigned long)system_get_free_heap_size()); }
void ICACHE_FLASH_ATTR publishData(MQTT_Client* client) { if (mqttConnected) { char topic[100]; char data[100]; os_sprintf(topic, (const char*) "/Raw/%s/0/info", sysCfg.device_id); os_sprintf(data, (const char*) "{\"Type\":\"RSSI\", \"Value\":%d}", wifi_station_get_rssi()); MQTT_Publish(client, topic, data, strlen(data), 0, false); os_printf("%s=>%s\n", topic, data); } }
// print various Wifi information into json buffer int ICACHE_FLASH_ATTR printWifiInfo(char *buff) { int len; //struct station_config stconf; wifi_station_get_config(&stconf); //struct softap_config apconf; wifi_softap_get_config(&apconf); uint8_t op = wifi_get_opmode() & 0x3; char *mode = wifiMode[op]; char *status = "unknown"; int st = wifi_station_get_connect_status(); if (st >= 0 && st < sizeof(connStatuses)) status = connStatuses[st]; int p = wifi_get_phy_mode(); char *phy = wifiPhy[p&3]; char *warn = wifiWarn[op]; if (op == 3) op = 4; // Done to let user switch to AP only mode from Soft-AP settings page, using only one set of warnings char *apwarn = wifiWarn[op]; char *apauth = apAuthMode[apconf.authmode]; sint8 rssi = wifi_station_get_rssi(); if (rssi > 0) rssi = 0; uint8 mac_addr[6]; uint8 apmac_addr[6]; wifi_get_macaddr(0, mac_addr); wifi_get_macaddr(1, apmac_addr); uint8_t chan = wifi_get_channel(); len = os_sprintf(buff, "\"mode\": \"%s\", \"modechange\": \"%s\", \"ssid\": \"%s\", \"status\": \"%s\", " "\"phy\": \"%s\", \"rssi\": \"%ddB\", \"warn\": \"%s\", \"apwarn\": \"%s\", " "\"mac\":\"%02x:%02x:%02x:%02x:%02x:%02x\", \"chan\":\"%d\", \"apssid\": \"%s\", " "\"appass\": \"%s\", \"apchan\": \"%d\", \"apmaxc\": \"%d\", \"aphidd\": \"%s\", " "\"apbeac\": \"%d\", \"apauth\": \"%s\",\"apmac\":\"%02x:%02x:%02x:%02x:%02x:%02x\"", mode, MODECHANGE, (char*)stconf.ssid, status, phy, rssi, warn, apwarn, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5], chan, (char*)apconf.ssid, (char*)apconf.password, apconf.channel, apconf.max_connection, apconf.ssid_hidden?"enabled":"disabled", apconf.beacon_interval, apauth,apmac_addr[0], apmac_addr[1], apmac_addr[2], apmac_addr[3], apmac_addr[4], apmac_addr[5]); struct ip_info info; if (wifi_get_ip_info(0, &info)) { len += os_sprintf(buff+len, ", \"ip\": \"%d.%d.%d.%d\"", IP2STR(&info.ip.addr)); len += os_sprintf(buff+len, ", \"netmask\": \"%d.%d.%d.%d\"", IP2STR(&info.netmask.addr)); len += os_sprintf(buff+len, ", \"gateway\": \"%d.%d.%d.%d\"", IP2STR(&info.gw.addr)); len += os_sprintf(buff+len, ", \"hostname\": \"%s\"", flashConfig.hostname); } else { len += os_sprintf(buff+len, ", \"ip\": \"-none-\""); } len += os_sprintf(buff+len, ", \"staticip\": \"%d.%d.%d.%d\"", IP2STR(&flashConfig.staticip)); len += os_sprintf(buff+len, ", \"dhcp\": \"%s\"", flashConfig.staticip > 0 ? "off" : "on"); return len; }
/* 模块状态查询应答 */ void ICACHE_FLASH_ATTR cus_uart_data_echo() { ESP_DBG((" ")); uint8_t i; frame_t frame; for (i = 0; i < FRAME_STATUS_ECHO_DATA_LEN - 5; i++) frame.data[i] = 0; frame.crc = 0; frame.head = FRAME_HEADER; frame.crc += frame.head; frame.len = FRAME_STATUS_ECHO_DATA_LEN; frame.crc += frame.len; frame.type = FRAME_CUS_QUERY_TYPE; frame.crc += frame.type; frame.id = _ID++; frame.crc += frame.id; i = 0; frame.data[i] = FRAME_CMD_STATUS_QUERY; //work model, 01:STA,02:AP,03:STA+AP frame.crc += frame.data[i++]; //add mode status frame.data[i] = wifi_get_opmode(); //work model, 01:STA,02:AP,03:STA+AP frame.crc += frame.data[i++]; //add AP connected status if (wifi_station_get_connect_status()) { frame.data[i] = 0x01; } else { frame.data[i] = 0x02; } frame.crc += frame.data[i++]; //add CLOUD connected status frame.data[i] = cloud_connect_status; frame.crc += frame.data[i++]; //add RSSI int rssi = wifi_station_get_rssi(); frame.data[i] = ((128 + rssi) / 128.0 * 4 + 1); frame.crc += frame.data[i++]; frame.data[i++] = 0;//保留 frame.data[i] = frame.crc; uint8_t *p = (uint8_t *)&frame; //uart0_tx_buffer(p, frame.len); Enqueue(&frame); return; }
void ICACHE_FLASH_ATTR publishDeviceInfo(char *version, char *mode, uint8 wifiChannel, uint16 wifiConnectTime, char *bestSSID, uint16 vcc) { if (mqttIsConnected()) { char *topic = (char *) os_zalloc(50); char *data = (char *) os_zalloc(500); int idx; struct ip_info ipConfig; if (topic == NULL || data == NULL) { ERRORP("malloc err %s/%s\n", topic, data); startFlash(-1, 50, 50); // fast return; } wifi_get_ip_info(STATION_IF, &ipConfig); os_sprintf(topic, "/Raw/%10s/info", sysCfg.device_id); os_sprintf(data, "{\"Name\":\"%s\", \"Location\":\"%s\", \"Version\":\"%s(%s)\", " "\"Updates\":%d, \"Inputs\":%d, \"Outputs\":%d, " "\"RSSI\":%d, \"Channel\": %d, \"ConnectTime\": %d, \"Vcc\": %d, ", sysCfg.deviceName, sysCfg.deviceLocation, version, mode, sysCfg.updates, #ifdef INPUTS sysCfg.inputs, #else 0, #endif #ifdef OUTPUTS sysCfg.outputs, #else 0, #endif wifi_station_get_rssi(), wifiChannel, wifiConnectTime, vcc); os_sprintf(data + os_strlen(data), "\"IPaddress\":\"%d.%d.%d.%d\"", IP2STR(&ipConfig.ip.addr)); os_sprintf(data + os_strlen(data), ", \"AP\":\"%s\"", bestSSID); os_sprintf(data + os_strlen(data), ", \"Settings\":["); for (idx = 0; idx < SETTINGS_SIZE; idx++) { if (idx != 0) os_sprintf(data + os_strlen(data), ", "); os_sprintf(data + os_strlen(data), "%d", sysCfg.settings[idx]); } os_sprintf(data + os_strlen(data), "]}"); if (!MQTT_Publish(mqttClient, topic, data, os_strlen(data), 0, true)) printMQTTstate(); INFOP("%s=>%s\n", topic, data); checkMinHeap(); os_free(topic); os_free(data); } }
void ICACHE_FLASH_ATTR get_wifi2_status(const int8_t cid, const GetWifi2Status *data) { gw2sr.header = data->header; gw2sr.header.length = sizeof(GetWifi2StatusReturn); struct ip_info info; wifi_get_ip_info(STATION_IF, &info); gw2sr.client_ip[0] = ip4_addr1(&info.ip); gw2sr.client_ip[1] = ip4_addr2(&info.ip); gw2sr.client_ip[2] = ip4_addr3(&info.ip); gw2sr.client_ip[3] = ip4_addr4(&info.ip); gw2sr.client_subnet_mask[0] = ip4_addr1(&info.netmask); gw2sr.client_subnet_mask[1] = ip4_addr2(&info.netmask); gw2sr.client_subnet_mask[2] = ip4_addr3(&info.netmask); gw2sr.client_subnet_mask[3] = ip4_addr4(&info.netmask); gw2sr.client_gateway[0] = ip4_addr1(&info.gw); gw2sr.client_gateway[1] = ip4_addr2(&info.gw); gw2sr.client_gateway[2] = ip4_addr3(&info.gw); gw2sr.client_gateway[3] = ip4_addr4(&info.gw); wifi_get_ip_info(SOFTAP_IF, &info); gw2sr.ap_ip[0] = ip4_addr1(&info.ip); gw2sr.ap_ip[1] = ip4_addr2(&info.ip); gw2sr.ap_ip[2] = ip4_addr3(&info.ip); gw2sr.ap_ip[3] = ip4_addr4(&info.ip); gw2sr.ap_subnet_mask[0] = ip4_addr1(&info.netmask); gw2sr.ap_subnet_mask[1] = ip4_addr2(&info.netmask); gw2sr.ap_subnet_mask[2] = ip4_addr3(&info.netmask); gw2sr.ap_subnet_mask[3] = ip4_addr4(&info.netmask); gw2sr.ap_gateway[0] = ip4_addr1(&info.gw); gw2sr.ap_gateway[1] = ip4_addr2(&info.gw); gw2sr.ap_gateway[2] = ip4_addr3(&info.gw); gw2sr.ap_gateway[3] = ip4_addr4(&info.gw); wifi_get_macaddr(STATION_IF, gw2sr.client_mac_address); wifi_get_macaddr(SOFTAP_IF, gw2sr.ap_mac_address); gw2sr.client_enabled = configuration_current.client_enable; gw2sr.ap_enabled = configuration_current.ap_enable; gw2sr.client_rssi = wifi_station_get_rssi(); gw2sr.client_status = wifi_station_get_connect_status(); gw2sr.ap_connected_count = wifi_softap_get_station_num(); com_send(&gw2sr, sizeof(GetWifi2StatusReturn), cid); }
int ICACHE_FLASH_ATTR alink_get_debuginfo(info_type type, char *status) { int used; switch (type) { case MEMUSED: used = 100 - ((system_get_free_heap_size() * 100) / (96 * 1024)); sprintf(status, "%d%%", used); break; case WIFISTRENGTH: sprintf(status, "%ddB", wifi_station_get_rssi()); break; default: status[0] = '\0'; break; } return 0; }
// print various Wifi information into json buffer int ICACHE_FLASH_ATTR printWifiInfo(char *buff) { int len; struct station_config stconf; wifi_station_get_config(&stconf); uint8_t op = wifi_get_opmode() & 0x3; char *mode = wifiMode[op]; char *status = "unknown"; int st = wifi_station_get_connect_status(); if (st >= 0 && st < sizeof(connStatuses)) status = connStatuses[st]; int p = wifi_get_phy_mode(); char *phy = wifiPhy[p&3]; char *warn = wifiWarn[op]; sint8 rssi = wifi_station_get_rssi(); if (rssi > 0) rssi = 0; uint8 mac_addr[6]; wifi_get_macaddr(0, mac_addr); uint8_t chan = wifi_get_channel(); len = os_sprintf(buff, "\"mode\": \"%s\", \"modechange\": \"%s\", \"ssid\": \"%s\", \"status\": \"%s\", \"phy\": \"%s\", " "\"rssi\": \"%ddB\", \"warn\": \"%s\", \"mac\":\"%02x:%02x:%02x:%02x:%02x:%02x\", \"chan\":%d", mode, MODECHANGE, (char*)stconf.ssid, status, phy, rssi, warn, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5], chan); struct ip_info info; if (wifi_get_ip_info(0, &info)) { len += os_sprintf(buff+len, ", \"ip\": \"%d.%d.%d.%d\"", IP2STR(&info.ip.addr)); len += os_sprintf(buff+len, ", \"netmask\": \"%d.%d.%d.%d\"", IP2STR(&info.netmask.addr)); len += os_sprintf(buff+len, ", \"gateway\": \"%d.%d.%d.%d\"", IP2STR(&info.gw.addr)); len += os_sprintf(buff+len, ", \"hostname\": \"%s\"", flashConfig.hostname); } else { len += os_sprintf(buff+len, ", \"ip\": \"-none-\""); } len += os_sprintf(buff+len, ", \"staticip\": \"%d.%d.%d.%d\"", IP2STR(&flashConfig.staticip)); len += os_sprintf(buff+len, ", \"dhcp\": \"%s\"", flashConfig.staticip > 0 ? "off" : "on"); return len; }
/** * Return the current network RSSI. * @return RSSI value */ int32_t ESP8266WiFiSTAClass::RSSI(void) { return wifi_station_get_rssi(); }
irom void stats_generate(uint16_t size, char *dst) { const struct rst_info *rst_info; struct station_config sc_default, sc_current; uint32_t system_time; system_time = system_get_time(); rst_info = system_get_rst_info(); wifi_station_get_config_default(&sc_default); wifi_station_get_config(&sc_current); snprintf(dst, size, "> firmware version date: %s\n" "> system id: %u\n" "> spi flash id: %u\n" "> cpu frequency: %u\n" "> flash map: %s\n" "> reset cause: %s\n" ">\n" "> heap free: %u bytes\n" "> system clock: %u.%06u s\n" "> uptime: %u %02d:%02d:%02d\n" "> real time: %u %02d:%02d:%02d\n" "> size of config: %u\n" ">\n" "> int uart rx: %u\n" "> int uart tx: %u\n" "> timer_fast fired: %u\n" "> timer_slow fired: %u\n" "> timer_second fired: %u\n" "> background task: %u\n" ">\n" "> default ssid: %s, passwd: %s\n" "> current ssid: %s, passwd: %s\n" "> phy mode: %s\n" "> sleep mode: %s\n" "> channel: %u\n" "> signal strength: %d dB\n", __DATE__ " " __TIME__, system_get_chip_id(), spi_flash_get_id(), system_get_cpu_freq(), flash_map[system_get_flash_size_map()], reset_map[rst_info->reason], system_get_free_heap_size(), system_time / 1000000, system_time % 1000000, ut_days, ut_hours, ut_mins, ut_secs, rt_days, rt_hours, rt_mins, rt_secs, sizeof(config_t), stat_uart_rx_interrupts, stat_uart_tx_interrupts, stat_timer_fast, stat_timer_slow, stat_timer_second, stat_background_task, sc_default.ssid, sc_default.password, sc_current.ssid, sc_current.password, phy[wifi_get_phy_mode()], slp[wifi_get_sleep_type()], wifi_get_channel(), wifi_station_get_rssi()); }
int http_wifi_api_get_info(http_connection *c) { CGI_WIFI_DBG("http_wifi_api_get_info\n"); //wait for whole body if(c->state <HTTPD_STATE_BODY_END) { return HTTPD_CGI_MORE; } api_cgi_status * status = c->cgi.data; if(status==NULL) { //first call, send headers status = (api_cgi_status*)os_malloc(sizeof(api_cgi_status)); status->state=1; c->cgi.data=status; http_SET_HEADER(c,HTTP_CONTENT_TYPE,JSON_CONTENT_TYPE); http_response_OK(c); return HTTPD_CGI_MORE; } else if(status->state==1) { //json data char mac[20]; wifi_station_get_config(&wifi_status.station_config); char *wifistatus = "unknown"; uint8_t c_status = wifi_station_get_connect_status(); if (c_status >= 0 && c_status < sizeof(connStatuses)) wifistatus = connStatuses[c_status]; int p = wifi_get_phy_mode(); char *phy = wifiPhy[p&3]; sint8 rssi = wifi_station_get_rssi(); if (rssi > 0) rssi = 0; uint8_t op = wifi_get_opmode() & 0x3; char *warn = wifiWarn[op]; uint8 mac_addr[6]; wifi_get_macaddr(0, mac_addr); uint8_t chan = wifi_get_channel(); char *hostname = wifi_station_get_hostname(); os_sprintf(mac,"%02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); cJSON *root = cJSON_CreateObject(); cJSON_AddNumberToObject(root,"mode",wifi_get_opmode()); cJSON_AddStringToObject(root,"modechange", MODECHANGE); cJSON_AddStringToObject(root,"ssid", (const char *)wifi_status.station_config.ssid); cJSON_AddStringToObject(root,"status", (const char *)wifistatus); cJSON_AddStringToObject(root,"phy", (const char *)phy); cJSON_AddNumberToObject(root,"rssi", rssi); cJSON_AddStringToObject(root,"warn", (const char *)warn); cJSON_AddStringToObject(root,"mac", (const char *)mac); cJSON_AddNumberToObject(root,"chan", chan); cJSON_AddStringToObject(root,"hostname", (const char *)hostname); cJSON_AddStringToObject(root,"domain", (const char *)INTERFACE_DOMAIN); // got ip if(c_status==5) { struct ip_info ip; wifi_get_ip_info(0x0,&ip); char *ip_str = (char*)ipaddr_ntoa(&ip.ip); cJSON_AddStringToObject(root,"ip",ip_str); } else { cJSON_AddStringToObject(root,"ip",""); } http_write_json(c,root); cJSON_Delete(root); status->state=99; return HTTPD_CGI_MORE; } else { os_free(c->cgi.data); return HTTPD_CGI_DONE; } }
/*JSON{ "type" : "staticmethod", "class" : "ESP8266WiFi", "name" : "getRSSI", "generate" : "jswrap_ESP8266WiFi_getRSSI", "return" : ["JsVar","An integer representing the signal strength."] }*/ JsVar *jswrap_ESP8266WiFi_getRSSI() { int rssi = wifi_station_get_rssi(); return jsvNewFromInteger(rssi); }
/** @brief test task Runs corrected cube demo from Sem Optionally wireframe Earh viewer @return void */ LOCAL void user_task(void) { uint32_t time1,time2; uint8_t red, blue,green; long timer = 0; uint16 system_adc_read(void); extern uint8_t ip_msg[]; time_t sec; char buffer[256]; #ifdef WIRECUBE V.x = degree; V.y = degree; V.z = degree; // Cube points were defined with sides of 1.0 // We want a scale of +/- w/2 wire_draw(windemo, cube_points, cube_edges, &V, windemo->w/2, windemo->h/2, dscale, 0); //wire_draw(windemo, cube_points, cube_edges, &V, windemo->w/2, windemo->h/2, dscale, 0); #endif #ifdef CIRCLE rad = dscale; // +/- 90 tft_drawCircle(windemo, windemo->w/2, windemo->h/2, rad ,0); Display bounding circle that changes color around the cube if(dscale_inc < 0.0) { red = 255; blue = 0; green = 0; } else { red = 0; blue = 255; green = 0; } // RGB - YELLOW tft_drawCircle(windemo, windemo->w/2, windemo->h/2, dscale, tft_color565(red,green,blue)); #endif degree += deg_inc; dscale += dscale_inc; if(degree <= -360) deg_inc = 4; if(degree >= 360) deg_inc = -4; if(dscale < dscale_max/2) { dscale_inc = -dscale_inc; } if(dscale > dscale_max) { dscale_inc = -dscale_inc; } #ifdef WIRECUBE V.x = degree; V.y = degree; V.z = degree; //time1 = system_get_time(); wire_draw(windemo, cube_points, cube_edges, &V, windemo->w/2, windemo->h/2, dscale, ILI9341_WHITE); //wire_draw(windemo, cube_points, cube_edges, &V, windemo->w/2, windemo->h/2, dscale, ILI9341_WHITE); //time2 = system_get_time(); #endif // Get system voltage 33 = 3.3 volts adc_sum += system_adc_read(); //adc_sum += system_get_vdd33(); // FIXME atomic access if(++adc_count == 10) { voltage = ((double) adc_sum / 100.0); adc_count = 0; adc_sum = 0; } // DEBUG_PRINTF("Degree: %d \r\n",(int)degree); // cube redraw count count += 1; tft_set_font(winstats,0); tft_setpos(winstats,ip_xpos,ip_ypos); tft_printf(winstats,"%-26s\n", ip_msg); if(!signal_loop--) { signal_loop = 100; tft_printf(winstats,"CH:%02d, DB:-%02d\n", wifi_get_channel(), wifi_station_get_rssi()); signal_loop = 0; } tft_setpos(winstats,xpos,ypos); tft_printf(winstats,"Heap: %d\n", system_get_free_heap_size()); tft_printf(winstats,"Iter:% 9ld, %+7.2f\n", count, degree); // NTP state machine ntp_setup(); // get current time time(&sec); tft_printf(winstats,"Volt:%2.2f\n%s\n", (float)voltage, ctime(&sec)); #ifdef NETWORK_TEST poll_network_message(wintest); #endif // Buffered get line uses interrupts and queues if(uart0_gets(buffer,255)) { DEBUG_PRINTF("Command:%s\n",buffer); if(!fatfs_tests(buffer)) { if(!user_tests(buffer)) { DEBUG_PRINTF("unknow command: %s\n", buffer); } } } }
// main task loop called by yield code void user_loop(void) { extern int connections; uint32_t time1,time2; long t; #ifdef DISPLAY char time_tmp[32]; uint8_t red, blue,green; int touched; uint16_t X,Y; #endif // getinfo.ip.addr, getinfo.gw.addr, getinfo.netmask.addr struct ip_info getinfo; char *ptr; // ======================================================== // Run all remaining tasks once every 1mS t = ms_read(); if((t - last_time10) < 1U) return; last_time10 = t; // ======================================================== // Tasks that must run very fast , once every millisecond should be at the top #ifdef ADF4351 ADF4351_task(); #endif #ifdef XPT2046 XPT2046_task(); #endif // ======================================================== // Only run every 50mS t = ms_read(); if((t - last_time50) < 50U) return; last_time50 = t; // ======================================================== user_tasks(); // NTP state machine ntp_setup(); #ifdef DISPLAY #ifdef XPT2046 if(tft_is_calibrated) { touched = tft_touch_key(master,(uint16_t *)&X, (uint16_t *)&Y); #if XPT2046_DEBUG if(touched) tft_printf(winmsg,"X:%d,Y:%d\n",(int)X,(int)Y); #endif } #endif #ifdef NETWORK_TEST servertest_message(winmsg); #endif #ifdef DEBUG_STATS #ifdef VOLTAGE_TEST #ifdef DEBUG_STATS // Do NOT run adc_read() every millisecond as system_adc_read() blocks WIFI tft_set_textpos(wintop, 0,2); tft_printf(wintop,"Volt:%2.2f\n", (float)adc_read()); #endif #endif // VOLTAGE_TEST count += 1; tft_set_textpos(wintop, 0,0); tft_set_font(wintop,0); tft_font_fixed(wintop); tft_printf(wintop,"Iter:% 10ld, %+7.2f\n", count, degree); #endif #ifdef CIRCLE rad = dscale; // +/- 90 tft_drawCircle(wincube, wincube->w/2, wincube->h/2, rad ,wincube->bg); // RGB #endif // reset cube to background #ifdef WIRECUBE V.x = degree; V.y = degree; V.z = degree; // Cube points were defined with sides of 1.0 // We want a scale of +/- w/2 wire_draw(wincube, cube_points, cube_edges, &V, wincube->w/2, wincube->h/2, dscale, wincube->bg); #endif degree += deg_inc; dscale += dscale_inc; if(degree <= -360) deg_inc = 4; if(degree >= 360) deg_inc = -4; if(dscale < dscale_max/2) { dscale_inc = -dscale_inc; } if(dscale > dscale_max) { dscale_inc = -dscale_inc; } #ifdef WIRECUBE V.x = degree; V.y = degree; V.z = degree; wire_draw(wincube, cube_points, cube_edges, &V, wincube->w/2, wincube->h/2, dscale, ILI9341_WHITE); #endif #ifdef CIRCLE // Display bounding circle that changes color around the cube if(dscale_inc < 0.0) { red = 255; blue = 0; green = 0; } else { red = 0; blue = 0; green = 255; } rad = dscale; // +/- 90 tft_drawCircle(wincube, wincube->w/2, wincube->h/2, rad, tft_RGBto565(red,green,blue)); #endif #endif // DISPLAY // ======================================================== // Tasks run only once every second go after this time(&sec); if(sec == seconds) return; seconds=sec; // ======================================================== #ifdef DISPLAY // ======================================================== // TIME tft_set_textpos(winbottom, 0,0); //Tue May 17 18:56:01 2016 strncpy(time_tmp,ctime(&sec),31); time_tmp[19] = 0; tft_printf(winbottom," %s", time_tmp); tft_cleareol(winbottom); tft_set_textpos(winbottom, 0,1); // ======================================================== // CONNECTION status //tft_printf(winbottom," %s", ip_msg); // IP and disconnected connection state only if(wifi_get_ip_info(0, &getinfo)) tft_printf(winbottom," %s", ipv4_2str(getinfo.ip.addr)); else tft_printf(winbottom," Disconnected"); tft_cleareol(winbottom); #ifdef DEBUG_STATS // ======================================================== // HEAP size tft_set_textpos(wintop, 0,1); tft_printf(wintop,"Heap: %d, Conn:%d\n", system_get_free_heap_size(), connections); // ======================================================== // WIFI status tft_set_textpos(wintop, 0,3); tft_printf(wintop,"CH:%02d, DB:%+02d\n", wifi_get_channel(), wifi_station_get_rssi()); #endif // DEBUG_STATS #endif //DISPLAY }