mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-07 20:17:04 +03:00
httpd implementation - wip
This commit is contained in:
@@ -21,6 +21,6 @@ COMPONENT_ADD_LDFLAGS=-l$(COMPONENT_NAME) \
|
||||
#$(COMPONENT_PATH)/lib/libesp-tremor.a
|
||||
#$(COMPONENT_PATH)/lib/libesp-ogg-container.a
|
||||
|
||||
|
||||
COMPONENT_ADD_INCLUDEDIRS := /inc
|
||||
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ void config_set_entry_changed_flag(cJSON * entry, cJSON_bool flag);
|
||||
#if RECOVERY_APPLICATION==0
|
||||
static void * malloc_fn(size_t sz){
|
||||
|
||||
void * ptr = heap_caps_malloc(sz, MALLOC_CAP_SPIRAM);
|
||||
void * ptr = heap_caps_malloc(sz, MALLOC_CAP_SPIRAM |MALLOC_CAP_8BIT);
|
||||
if(ptr==NULL){
|
||||
ESP_LOGE(TAG,"malloc_fn: unable to allocate memory!");
|
||||
}
|
||||
@@ -681,7 +681,7 @@ char * config_alloc_get_json(bool bFormatted){
|
||||
config_unlock();
|
||||
return json_buffer;
|
||||
}
|
||||
esp_err_t config_set_value(nvs_type_t nvs_type, const char *key, void * value){
|
||||
esp_err_t config_set_value(nvs_type_t nvs_type, const char *key, const void * value){
|
||||
esp_err_t result = ESP_OK;
|
||||
if(!config_lock(LOCK_MAX_WAIT/portTICK_PERIOD_MS)){
|
||||
ESP_LOGE(TAG, "Unable to lock config after %d ms",LOCK_MAX_WAIT);
|
||||
|
||||
@@ -39,6 +39,6 @@ void config_set_default(nvs_type_t type, const char *key, void * default_value,
|
||||
void * config_alloc_get(nvs_type_t nvs_type, const char *key) ;
|
||||
bool wait_for_commit();
|
||||
char * config_alloc_get_json(bool bFormatted);
|
||||
esp_err_t config_set_value(nvs_type_t nvs_type, const char *key, void * value);
|
||||
esp_err_t config_set_value(nvs_type_t nvs_type, const char *key, const void * value);
|
||||
nvs_type_t config_get_item_type(cJSON * entry);
|
||||
void * config_safe_alloc_get_entry_value(nvs_type_t nvs_type, cJSON * entry);
|
||||
|
||||
1
components/esp-dsp
Submodule
1
components/esp-dsp
Submodule
Submodule components/esp-dsp added at de39220fb4
@@ -11,3 +11,5 @@ CFLAGS += -fstack-usage\
|
||||
-I$(PROJECT_PATH)/components/tools \
|
||||
-I$(PROJECT_PATH)/components/codecs/inc/alac \
|
||||
-I$(PROJECT_PATH)/main/
|
||||
COMPONENT_ADD_INCLUDEDIRS := .
|
||||
COMPONENT_SRCDIRS := .
|
||||
@@ -19,56 +19,107 @@
|
||||
*/
|
||||
|
||||
const static char tag[] = "messaging";
|
||||
|
||||
typedef struct {
|
||||
struct messaging_list_t * next;
|
||||
char * subscriber_name;
|
||||
size_t max_count;
|
||||
RingbufHandle_t buf_handle;
|
||||
} messaging_list_t;
|
||||
static messaging_list_t top;
|
||||
|
||||
|
||||
messaging_list_t * get_struct_ptr(messaging_handle_t handle){
|
||||
return (messaging_list_t *)handle;
|
||||
}
|
||||
messaging_handle_t get_handle_ptr(messaging_list_t * handle){
|
||||
return (messaging_handle_t )handle;
|
||||
}
|
||||
RingbufHandle_t messaging_create_ring_buffer(uint8_t max_count){
|
||||
RingbufHandle_t buf_handle = NULL;
|
||||
StaticRingbuffer_t *buffer_struct = (StaticRingbuffer_t *)heap_caps_malloc(sizeof(StaticRingbuffer_t), MALLOC_CAP_SPIRAM);
|
||||
StaticRingbuffer_t *buffer_struct = malloc(sizeof(StaticRingbuffer_t));
|
||||
if (buffer_struct != NULL) {
|
||||
size_t buf_size = (size_t )(sizeof(single_message_t)+8)*(size_t )(max_count>0?max_count:5); // no-split buffer requires an additional 8 bytes
|
||||
uint8_t *buffer_storage = (uint8_t *)heap_caps_malloc(buf_size, MALLOC_CAP_SPIRAM);
|
||||
uint8_t *buffer_storage = (uint8_t *)heap_caps_malloc(buf_size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if (buffer_storage== NULL) {
|
||||
ESP_LOGE(tag,"Failed to allocate memory for messaging ring buffer !");
|
||||
ESP_LOGE(tag,"buff alloc failed");
|
||||
}
|
||||
else {
|
||||
buf_handle = xRingbufferCreateStatic(buf_size, RINGBUF_TYPE_NOSPLIT, buffer_storage, buffer_struct);
|
||||
if (buf_handle == NULL) {
|
||||
ESP_LOGE(tag,"Failed to create messaging ring buffer !");
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ESP_LOGE(tag,"Failed to create ring buffer for messaging!");
|
||||
ESP_LOGE(tag,"ringbuf alloc failed");
|
||||
}
|
||||
return buf_handle;
|
||||
}
|
||||
void messaging_fill_messages(messaging_list_t * target_subscriber){
|
||||
single_message_t * message=NULL;
|
||||
UBaseType_t uxItemsWaiting;
|
||||
|
||||
RingbufHandle_t messaging_register_subscriber(uint8_t max_count, char * name){
|
||||
vRingbufferGetInfo(top.buf_handle, NULL, NULL, NULL, NULL, &uxItemsWaiting);
|
||||
for(size_t i=0;i<uxItemsWaiting;i++){
|
||||
message= messaging_retrieve_message(top.buf_handle);
|
||||
if(message){
|
||||
//re-post to original queue so it is available to future subscribers
|
||||
messaging_post_to_queue(get_handle_ptr(&top), message, sizeof(single_message_t));
|
||||
// post to new subscriber
|
||||
messaging_post_to_queue(get_handle_ptr(target_subscriber) , message, sizeof(single_message_t));
|
||||
FREE_AND_NULL(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
messaging_handle_t messaging_register_subscriber(uint8_t max_count, char * name){
|
||||
messaging_list_t * cur=⊤
|
||||
while(cur->next){
|
||||
cur = cur->next;
|
||||
cur = get_struct_ptr(cur->next);
|
||||
}
|
||||
cur->next=heap_caps_malloc(sizeof(messaging_list_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
cur->next=heap_caps_malloc(sizeof(messaging_list_t), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if(!cur->next){
|
||||
ESP_LOGE(tag,"Failed to allocate messaging subscriber entry!");
|
||||
ESP_LOGE(tag,"subscriber alloc failed");
|
||||
return NULL;
|
||||
}
|
||||
memset(cur->next,0x00,sizeof(messaging_list_t));
|
||||
cur = cur->next;
|
||||
cur = get_struct_ptr(cur->next);
|
||||
cur->max_count=max_count;
|
||||
cur->subscriber_name=strdup(name);
|
||||
cur->buf_handle = messaging_create_ring_buffer(max_count);
|
||||
strncpy(cur->subscriber_name,name,sizeof(cur->subscriber_name));
|
||||
|
||||
if(cur->buf_handle){
|
||||
messaging_fill_messages(cur);
|
||||
}
|
||||
return cur->buf_handle;
|
||||
}
|
||||
esp_err_t messaging_service_init(){
|
||||
void messaging_service_init(){
|
||||
size_t max_count=15;
|
||||
top.buf_handle = messaging_create_ring_buffer(max_count);
|
||||
if(!top.buf_handle){
|
||||
ESP_LOGE(tag, "messaging service init failed.");
|
||||
}
|
||||
strncpy(top.subscriber_name,"messaging");
|
||||
return (top.buf_handle!=NULL);
|
||||
else {
|
||||
top.max_count = max_count;
|
||||
top.subscriber_name = strdup("messaging");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const char * messaging_get_type_desc(messaging_types msg_type){
|
||||
switch (msg_type) {
|
||||
CASE_TO_STR(MESSAGING_INFO);
|
||||
CASE_TO_STR(MESSAGING_WARNING);
|
||||
CASE_TO_STR(MESSAGING_ERROR);
|
||||
default:
|
||||
return "Unknown";
|
||||
break;
|
||||
}
|
||||
}
|
||||
const char * messaging_get_class_desc(messaging_classes msg_class){
|
||||
switch (msg_class) {
|
||||
CASE_TO_STR(MESSAGING_CLASS_OTA);
|
||||
CASE_TO_STR(MESSAGING_CLASS_SYSTEM);
|
||||
default:
|
||||
return "Unknown";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cJSON * messaging_retrieve_messages(RingbufHandle_t buf_handle){
|
||||
single_message_t * message=NULL;
|
||||
@@ -81,12 +132,13 @@ cJSON * messaging_retrieve_messages(RingbufHandle_t buf_handle){
|
||||
message = (single_message_t *)xRingbufferReceive(buf_handle, &item_size, pdMS_TO_TICKS(50));
|
||||
//Check received data
|
||||
if (message== NULL) {
|
||||
ESP_LOGE(tag,"Failed to receive message from buffer!");
|
||||
ESP_LOGE(tag,"received null ptr");
|
||||
}
|
||||
else {
|
||||
json_message = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(json_message, "message", message->message);
|
||||
cJSON_AddStringToObject(json_message, "type", message->message);
|
||||
cJSON_AddStringToObject(json_message, "type", messaging_get_type_desc(message->type));
|
||||
cJSON_AddStringToObject(json_message, "class", messaging_get_class_desc(message->msg_class));
|
||||
cJSON_AddNumberToObject(json_message,"sent_time",message->sent_time);
|
||||
cJSON_AddNumberToObject(json_message,"current_time",esp_timer_get_time() / 1000);
|
||||
cJSON_AddItemToArray(json_messages,json_message);
|
||||
@@ -95,19 +147,55 @@ cJSON * messaging_retrieve_messages(RingbufHandle_t buf_handle){
|
||||
}
|
||||
return json_messages;
|
||||
}
|
||||
|
||||
void messaging_release_message(RingbufHandle_t buf_handle, single_message_t * message){
|
||||
|
||||
single_message_t * messaging_retrieve_message(RingbufHandle_t buf_handle){
|
||||
single_message_t * message=NULL;
|
||||
single_message_t * message_copy=NULL;
|
||||
size_t item_size;
|
||||
UBaseType_t uxItemsWaiting;
|
||||
vRingbufferGetInfo(buf_handle, NULL, NULL, NULL, NULL, &uxItemsWaiting);
|
||||
if(uxItemsWaiting>0){
|
||||
message = (single_message_t *)xRingbufferReceive(buf_handle, &item_size, pdMS_TO_TICKS(50));
|
||||
if(item_size!=sizeof(single_message_t)){
|
||||
ESP_LOGE(tag,"Invalid message length!");
|
||||
}
|
||||
else {
|
||||
message_copy = heap_caps_malloc(item_size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
if(message_copy){
|
||||
memcpy(message_copy,message,item_size);
|
||||
}
|
||||
}
|
||||
vRingbufferReturnItem(buf_handle, (void *)message);
|
||||
}
|
||||
return message_copy;
|
||||
}
|
||||
esp_err_t messageing_post_to_queue(messaging_list_t * subscriber, single_message_t * message){
|
||||
UBaseType_t res = xRingbufferSend(subscriber->buf_handle, message, sizeof(message), pdMS_TO_TICKS(1000));
|
||||
|
||||
esp_err_t messaging_post_to_queue(messaging_handle_t subscriber_handle, single_message_t * message, size_t message_size){
|
||||
UBaseType_t uxItemsWaiting=0;
|
||||
size_t item_size=0;
|
||||
messaging_list_t * subscriber=get_struct_ptr(subscriber_handle);
|
||||
if(!subscriber->buf_handle){
|
||||
ESP_LOGE(tag,"post failed: null buffer for %s", str_or_unknown(subscriber->subscriber_name));
|
||||
return ESP_FAIL;
|
||||
}
|
||||
vRingbufferGetInfo(subscriber->buf_handle,NULL,NULL,NULL,NULL,&uxItemsWaiting);
|
||||
if(uxItemsWaiting>=subscriber->max_count){
|
||||
ESP_LOGW(tag,"messaged dropped for %s",str_or_unknown(subscriber->subscriber_name));
|
||||
single_message_t * dummy = (single_message_t *)xRingbufferReceive(subscriber->buf_handle, &item_size, pdMS_TO_TICKS(50));
|
||||
if (dummy== NULL) {
|
||||
ESP_LOGE(tag,"receive from buffer failed");
|
||||
}
|
||||
else {
|
||||
vRingbufferReturnItem(subscriber->buf_handle, (void *)dummy);
|
||||
}
|
||||
}
|
||||
UBaseType_t res = xRingbufferSend(subscriber->buf_handle, message, message_size, pdMS_TO_TICKS(1000));
|
||||
if (res != pdTRUE) {
|
||||
ESP_LOGE(tag,"Failed to post message to subscriber %s",subscriber->subscriber_name);
|
||||
ESP_LOGE(tag,"post to %s failed",str_or_unknown(subscriber->subscriber_name));
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
void messaging_post_message(messaging_types type, char *fmt, ...){
|
||||
void messaging_post_message(messaging_types type,messaging_classes msg_class, char *fmt, ...){
|
||||
single_message_t message={};
|
||||
messaging_list_t * cur=⊤
|
||||
va_list va;
|
||||
@@ -115,10 +203,11 @@ void messaging_post_message(messaging_types type, char *fmt, ...){
|
||||
vsnprintf(message.message, sizeof(message.message), fmt, va);
|
||||
va_end(va);
|
||||
message.type = type;
|
||||
message.msg_class = msg_class;
|
||||
message.sent_time = esp_timer_get_time() / 1000;
|
||||
while(cur->next){
|
||||
messageing_post_to_queue(cur, &message);
|
||||
cur = cur->next;
|
||||
while(cur){
|
||||
messaging_post_to_queue(get_handle_ptr(cur), &message, sizeof(single_message_t));
|
||||
cur = get_struct_ptr(cur->next);
|
||||
}
|
||||
return;
|
||||
|
||||
|
||||
@@ -7,19 +7,24 @@ typedef enum {
|
||||
MESSAGING_WARNING,
|
||||
MESSAGING_ERROR
|
||||
} messaging_types;
|
||||
typedef struct {
|
||||
void * next;
|
||||
char subscriber_name[21];
|
||||
RingbufHandle_t buf_handle;
|
||||
} messaging_list_t;
|
||||
typedef enum {
|
||||
MESSAGING_CLASS_OTA,
|
||||
MESSAGING_CLASS_SYSTEM
|
||||
} messaging_classes;
|
||||
|
||||
typedef struct messaging_list_t *messaging_handle_t;
|
||||
|
||||
typedef struct {
|
||||
time_t sent_time;
|
||||
messaging_types type;
|
||||
char message[101];
|
||||
messaging_classes msg_class;
|
||||
char message[151];
|
||||
} single_message_t;
|
||||
|
||||
cJSON * messaging_retrieve_messages(RingbufHandle_t buf_handle);
|
||||
RingbufHandle_t messaging_register_subscriber(uint8_t max_count, char * name);
|
||||
|
||||
void messaging_post_message(messaging_types type, char * fmt, ...);
|
||||
messaging_handle_t messaging_register_subscriber(uint8_t max_count, char * name);
|
||||
esp_err_t messaging_post_to_queue(messaging_handle_t subscriber_handle, single_message_t * message, size_t message_size);
|
||||
void messaging_post_message(messaging_types type,messaging_classes msg_class, char * fmt, ...);
|
||||
cJSON * messaging_retrieve_messages(RingbufHandle_t buf_handle);
|
||||
single_message_t * messaging_retrieve_message(RingbufHandle_t buf_handle);
|
||||
void messaging_service_init();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "monitor.h"
|
||||
#include "globdefs.h"
|
||||
#include "accessors.h"
|
||||
#include "messaging.h"
|
||||
|
||||
extern void battery_svc_init(void);
|
||||
extern void monitor_svc_init(void);
|
||||
@@ -52,6 +53,7 @@ void set_power_gpio(int gpio, char *value) {
|
||||
*/
|
||||
void services_init(void) {
|
||||
messaging_service_init();
|
||||
messaging_post_message(MESSAGING_INFO,MESSAGING_CLASS_SYSTEM, "Initializing services");
|
||||
gpio_install_isr_service(0);
|
||||
|
||||
#ifdef CONFIG_I2C_LOCKED
|
||||
|
||||
@@ -83,26 +83,36 @@ void _printMemStats(){
|
||||
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
|
||||
}
|
||||
void sendMessaging(messaging_types type,char * fmt, ...){
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
messaging_post_message(type, fmt, args);
|
||||
va_end(args);
|
||||
_printMemStats();
|
||||
}
|
||||
const char * ota_get_status(){
|
||||
if(!ota_status.bInitialized)
|
||||
{
|
||||
memset(ota_status.status_text, 0x00,sizeof(ota_status.status_text));
|
||||
ota_status.bInitialized = true;
|
||||
}
|
||||
return ota_status.status_text;
|
||||
}
|
||||
uint8_t ota_get_pct_complete(){
|
||||
return ota_status.total_image_len==0?0:
|
||||
(uint8_t)((float)ota_status.actual_image_len/(float)ota_status.total_image_len*100.0f);
|
||||
}
|
||||
|
||||
void sendMessaging(messaging_types type,const char * fmt, ...){
|
||||
va_list args;
|
||||
cJSON * msg = cJSON_CreateObject();
|
||||
size_t str_len=0;
|
||||
char * msg_str=NULL;
|
||||
|
||||
va_start(args, fmt);
|
||||
str_len = vsnprintf(NULL,0,fmt,args);
|
||||
if(str_len>0){
|
||||
msg_str = malloc(str_len);
|
||||
vsnprintf(msg_str,str_len,fmt,args);
|
||||
}
|
||||
va_end(args);
|
||||
|
||||
cJSON_AddStringToObject(msg,"ota_dsc",msg_str);
|
||||
free(msg_str);
|
||||
cJSON_AddNumberToObject(msg,"ota_pct", ota_get_pct_complete() );
|
||||
char * json_msg = cJSON_PrintUnformatted(msg);
|
||||
messaging_post_message(type, MESSAGING_CLASS_OTA, json_msg);
|
||||
free(json_msg);
|
||||
cJSON_free(msg);
|
||||
_printMemStats();
|
||||
}
|
||||
|
||||
|
||||
static void __attribute__((noreturn)) task_fatal_error(void)
|
||||
{
|
||||
ESP_LOGE(TAG, "Exiting task due to fatal error...");
|
||||
@@ -206,7 +216,7 @@ esp_err_t init_config(ota_thread_parms_t * p_ota_thread_parms){
|
||||
ota_config.skip_cert_common_name_check = false;
|
||||
ota_config.url = strdup(ota_status.current_url);
|
||||
ota_config.max_redirection_count = 3;
|
||||
ota_write_data = heap_caps_malloc(ota_config.buffer_size+1 , MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
ota_write_data = heap_caps_malloc(ota_config.buffer_size+1 , MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
//ota_write_data = malloc(ota_config.buffer_size+1);
|
||||
if(ota_write_data== NULL){
|
||||
ESP_LOGE(TAG,"Error allocating the ota buffer");
|
||||
@@ -324,7 +334,7 @@ static esp_err_t _http_handle_response_code(esp_http_client_handle_t http_client
|
||||
}
|
||||
ESP_LOGD(TAG, "Redirection done, checking if we need to read the data. ");
|
||||
if (process_again(status_code)) {
|
||||
char * local_buff = heap_caps_malloc(ota_config.buffer_size+1, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
char * local_buff = heap_caps_malloc(ota_config.buffer_size+1, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
//char * local_buff = malloc(ota_config.buffer_size+1);
|
||||
if(local_buff==NULL){
|
||||
ESP_LOGE(TAG,"Failed to allocate internal memory buffer for http processing");
|
||||
|
||||
@@ -37,7 +37,5 @@
|
||||
#define OTA_TASK_PRIOTITY 6
|
||||
|
||||
esp_err_t start_ota(const char * bin_url, char * bin_buffer, uint32_t length);
|
||||
const char * ota_get_status();
|
||||
uint8_t ota_get_pct_complete();
|
||||
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ static ssize_t stdout_write(int fd, const void * data, size_t size);
|
||||
static char *eventToString(telnet_event_type_t type);
|
||||
static void handle_telnet_conn();
|
||||
static void process_logs( UBaseType_t bytes);
|
||||
|
||||
static bool bMirrorToUART=false;
|
||||
struct telnetUserData {
|
||||
int sockfd;
|
||||
telnet_t *tnHandle;
|
||||
@@ -79,11 +79,14 @@ struct telnetUserData {
|
||||
|
||||
void init_telnet(){
|
||||
char *val= get_nvs_value_alloc(NVS_TYPE_STR, "telnet_enable");
|
||||
if (!val || strlen(val) == 0 || !strcasestr("YX",val) ) {
|
||||
if (!val || strlen(val) == 0 || !strcasestr("YXD",val) ) {
|
||||
ESP_LOGI(tag,"Telnet support disabled");
|
||||
if(val) free(val);
|
||||
return;
|
||||
}
|
||||
bMirrorToUART = strcasestr("D",val)!=NULL;
|
||||
|
||||
FREE_AND_NULL(val);
|
||||
val=get_nvs_value_alloc(NVS_TYPE_STR, "telnet_block");
|
||||
if(val){
|
||||
send_chunk=atol(val);
|
||||
@@ -100,8 +103,8 @@ void init_telnet(){
|
||||
vSemaphoreCreateBinary( xSemaphore );
|
||||
|
||||
// Redirect the output to our telnet handler as soon as possible
|
||||
StaticRingbuffer_t *buffer_struct = (StaticRingbuffer_t *)heap_caps_malloc(sizeof(StaticRingbuffer_t), MALLOC_CAP_SPIRAM);
|
||||
uint8_t *buffer_storage = (uint8_t *)heap_caps_malloc(sizeof(uint8_t)*log_buf_size, MALLOC_CAP_SPIRAM);
|
||||
StaticRingbuffer_t *buffer_struct = (StaticRingbuffer_t *)heap_caps_malloc(sizeof(StaticRingbuffer_t), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
uint8_t *buffer_storage = (uint8_t *)heap_caps_malloc(sizeof(uint8_t)*log_buf_size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
buf_handle = xRingbufferCreateStatic(log_buf_size, RINGBUF_TYPE_BYTEBUF, buffer_storage, buffer_struct);
|
||||
if (buf_handle == NULL) {
|
||||
ESP_LOGE(tag,"Failed to create ring buffer for telnet!");
|
||||
@@ -117,7 +120,9 @@ void init_telnet(){
|
||||
.close = &stdout_close,
|
||||
.read = &stdout_read,
|
||||
};
|
||||
uart_fd=open("/dev/uart/0", O_RDWR);
|
||||
if(bMirrorToUART){
|
||||
uart_fd=open("/dev/uart/0", O_RDWR);
|
||||
}
|
||||
ESP_ERROR_CHECK(esp_vfs_register("/dev/pkspstdout", &vfs, NULL));
|
||||
freopen("/dev/pkspstdout", "w", stdout);
|
||||
freopen("/dev/pkspstdout", "w", stderr);
|
||||
@@ -125,7 +130,7 @@ void init_telnet(){
|
||||
}
|
||||
void start_telnet(void * pvParameter){
|
||||
static bool isStarted=false;
|
||||
StaticTask_t *xTaskBuffer = (StaticTask_t*) heap_caps_malloc(sizeof(StaticTask_t), MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
StaticTask_t *xTaskBuffer = (StaticTask_t*) heap_caps_malloc(sizeof(StaticTask_t), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
StackType_t *xStack = malloc(TELNET_STACK_SIZE);
|
||||
|
||||
if(!isStarted && bIsEnabled) {
|
||||
@@ -228,7 +233,9 @@ void process_received_data(const char * buffer, size_t size){
|
||||
command[size]='\0';
|
||||
if(command[0]!='\r' && command[0]!='\n'){
|
||||
// echo the command buffer out to uart and run
|
||||
write(uart_fd, command, size);
|
||||
if(bMirrorToUART){
|
||||
write(uart_fd, command, size);
|
||||
}
|
||||
run_command((char *)command);
|
||||
}
|
||||
free(command);
|
||||
@@ -317,7 +324,7 @@ static void handle_telnet_conn() {
|
||||
struct telnetUserData *pTelnetUserData = (struct telnetUserData *)malloc(sizeof(struct telnetUserData));
|
||||
tnHandle = telnet_init(my_telopts, handle_telnet_events, 0, pTelnetUserData);
|
||||
|
||||
pTelnetUserData->rxbuf = (char *) heap_caps_malloc(TELNET_RX_BUF, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
|
||||
pTelnetUserData->rxbuf = (char *) heap_caps_malloc(TELNET_RX_BUF, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
||||
pTelnetUserData->tnHandle = tnHandle;
|
||||
pTelnetUserData->sockfd = partnerSocket;
|
||||
|
||||
@@ -374,7 +381,7 @@ static ssize_t stdout_write(int fd, const void * data, size_t size) {
|
||||
// We could not obtain the semaphore and can therefore not access
|
||||
// the shared resource safely.
|
||||
}
|
||||
return write(uart_fd, data, size);
|
||||
return bMirrorToUART?write(uart_fd, data, size):true;
|
||||
}
|
||||
|
||||
static ssize_t stdout_read(int fd, void* data, size_t size) {
|
||||
|
||||
@@ -648,6 +648,7 @@ function refreshAPHTML(data){
|
||||
function getMessages() {
|
||||
$.getJSON("/messages.json", function(data) {
|
||||
data.forEach(function(msg) {
|
||||
message: "{"ota_dsc":"Erasing flash complete","ota_pct":0}"
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
@@ -50,9 +50,9 @@ function to process requests, decode URLs, serve files, etc. etc.
|
||||
#include "esp_vfs.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "messaging.h"
|
||||
#include "platform_esp32.h"
|
||||
|
||||
#define HTTP_STACK_SIZE (5*1024)
|
||||
#define FREE_AND_NULL(p) if(p!=NULL){ free(p); p=NULL;}
|
||||
const char str_na[]="N/A";
|
||||
#define STR_OR_NA(s) s?s:str_na
|
||||
/* @brief tag used for ESP serial console messages */
|
||||
|
||||
@@ -75,7 +75,7 @@ Contains the freeRTOS task and all necessary support
|
||||
#endif
|
||||
|
||||
#define STR_OR_BLANK(p) p==NULL?"":p
|
||||
#define FREE_AND_NULL(p) if(p!=NULL){ free(p); p=NULL;}
|
||||
|
||||
/* objects used to manipulate the main queue of events */
|
||||
QueueHandle_t wifi_manager_queue;
|
||||
SemaphoreHandle_t wifi_manager_json_mutex = NULL;
|
||||
@@ -89,7 +89,7 @@ char *ip_info_json = NULL;
|
||||
char * release_url=NULL;
|
||||
cJSON * ip_info_cjson=NULL;
|
||||
wifi_config_t* wifi_manager_config_sta = NULL;
|
||||
static update_reason_code_t last_update_reason_code=0;
|
||||
|
||||
|
||||
static int32_t total_connected_time=0;
|
||||
static int64_t last_connected=0;
|
||||
@@ -208,9 +208,6 @@ bool isGroupBitSet(uint8_t bit){
|
||||
EventBits_t uxBits= xEventGroupGetBits(wifi_manager_event_group);
|
||||
return (uxBits & bit);
|
||||
}
|
||||
void wifi_manager_refresh_ota_json(){
|
||||
wifi_manager_send_message(EVENT_REFRESH_OTA, NULL);
|
||||
}
|
||||
|
||||
void wifi_manager_scan_async(){
|
||||
wifi_manager_send_message(ORDER_START_WIFI_SCAN, NULL);
|
||||
@@ -455,8 +452,6 @@ cJSON * wifi_manager_get_basic_info(cJSON **old){
|
||||
cJSON_AddItemToObject(root, "version", cJSON_CreateString(desc->version));
|
||||
if(release_url !=NULL) cJSON_AddItemToObject(root, "release_url", cJSON_CreateString(release_url));
|
||||
cJSON_AddNumberToObject(root,"recovery", RECOVERY_APPLICATION );
|
||||
cJSON_AddItemToObject(root, "ota_dsc", cJSON_CreateString(ota_get_status()));
|
||||
cJSON_AddNumberToObject(root,"ota_pct", ota_get_pct_complete() );
|
||||
cJSON_AddItemToObject(root, "Jack", cJSON_CreateString(jack_inserted_svc() ? "1" : "0"));
|
||||
cJSON_AddNumberToObject(root,"Voltage", battery_value_svc());
|
||||
cJSON_AddNumberToObject(root,"disconnect_count", num_disconnect );
|
||||
@@ -485,12 +480,6 @@ void wifi_manager_generate_ip_info_json(update_reason_code_t update_reason_code)
|
||||
wifi_config_t *config = wifi_manager_get_wifi_sta_config();
|
||||
ip_info_cjson = wifi_manager_get_basic_info(&ip_info_cjson);
|
||||
|
||||
if(update_reason_code == UPDATE_OTA) {
|
||||
update_reason_code = last_update_reason_code;
|
||||
}
|
||||
else {
|
||||
last_update_reason_code = update_reason_code;
|
||||
}
|
||||
cJSON_AddNumberToObject(ip_info_cjson, "urc", update_reason_code);
|
||||
if(config){
|
||||
cJSON_AddItemToObject(ip_info_cjson, "ssid", cJSON_CreateString((char *)config->sta.ssid));
|
||||
@@ -1144,12 +1133,6 @@ void wifi_manager( void * pvParameters ){
|
||||
ESP_LOGD(TAG, "Done Invoking SCAN DONE callback");
|
||||
}
|
||||
break;
|
||||
case EVENT_REFRESH_OTA:
|
||||
if(wifi_manager_lock_json_buffer( portMAX_DELAY )){
|
||||
wifi_manager_generate_ip_info_json( UPDATE_OTA );
|
||||
wifi_manager_unlock_json_buffer();
|
||||
}
|
||||
break;
|
||||
|
||||
case ORDER_START_WIFI_SCAN:
|
||||
ESP_LOGD(TAG, "MESSAGE: ORDER_START_WIFI_SCAN");
|
||||
@@ -1445,7 +1428,7 @@ void wifi_manager( void * pvParameters ){
|
||||
if(cb_ptr_arr[msg.code]) (*cb_ptr_arr[msg.code])(NULL);
|
||||
break;
|
||||
case UPDATE_CONNECTION_OK:
|
||||
/* refresh JSON with the new ota data */
|
||||
/* refresh JSON */
|
||||
if(wifi_manager_lock_json_buffer( portMAX_DELAY )){
|
||||
/* generate the connection info with success */
|
||||
wifi_manager_generate_ip_info_json( UPDATE_CONNECTION_OK );
|
||||
|
||||
@@ -198,12 +198,11 @@ typedef enum message_code_t {
|
||||
EVENT_STA_DISCONNECTED = 12,
|
||||
EVENT_SCAN_DONE = 13,
|
||||
EVENT_STA_GOT_IP = 14,
|
||||
EVENT_REFRESH_OTA = 15,
|
||||
ORDER_RESTART_OTA = 16,
|
||||
ORDER_RESTART_RECOVERY = 17,
|
||||
ORDER_RESTART_OTA_URL = 18,
|
||||
ORDER_RESTART = 19,
|
||||
MESSAGE_CODE_COUNT = 20 /* important for the callback array */
|
||||
ORDER_RESTART_OTA = 15,
|
||||
ORDER_RESTART_RECOVERY = 16,
|
||||
ORDER_RESTART_OTA_URL = 17,
|
||||
ORDER_RESTART = 18,
|
||||
MESSAGE_CODE_COUNT = 19 /* important for the callback array */
|
||||
|
||||
}message_code_t;
|
||||
|
||||
@@ -226,8 +225,7 @@ typedef enum update_reason_code_t {
|
||||
UPDATE_CONNECTION_OK = 0,
|
||||
UPDATE_FAILED_ATTEMPT = 1,
|
||||
UPDATE_USER_DISCONNECT = 2,
|
||||
UPDATE_LOST_CONNECTION = 3,
|
||||
UPDATE_OTA=4
|
||||
UPDATE_LOST_CONNECTION = 3
|
||||
}update_reason_code_t;
|
||||
|
||||
typedef enum connection_request_made_by_code_t{
|
||||
|
||||
Reference in New Issue
Block a user