//delay , then call OTA reboot,3s*level
void ICACHE_FLASH_ATTR
	debug_OtaRebootStart(uint32 t_ms)
{
	os_timer_disarm(&reboot_t);
	os_timer_setfn(&reboot_t,debug_OtaReboot,NULL);

	
	struct ip_info sta_ip;
	wifi_get_ip_info(STATION_IF,&sta_ip);
	uint16 mesh_level = 0;
    #if ESP_MESH_SUPPORT						
		if( espconn_mesh_local_addr(&sta_ip.ip)){
			uint32 mlevel = sta_ip.ip.addr&0xff;
			mesh_level = mlevel;
			ESP_DBG("THIS IS A MESH SUB NODE..level: %d\r\n",mesh_level);
		}else if(sta_ip.ip.addr!= 0){
			ESP_DBG("THIS IS A MESH ROOT..\r\n");
			mesh_level = 1;
		}else{
            //why?
            mesh_level = 1;
		}
    #endif

	os_timer_arm(&reboot_t,t_ms+3000*(mesh_level-1),0);
	ESP_DBG("upgrade reboot in %d ms\r\n",t_ms+3000*mesh_level);
}
/******************************************************************************
 * FunctionName : user_esp_platform_device_action
 * Description  : Execute the actions of minimum wait time
 * Parameters   : pwait_action -- point the list of actions which need execute
 *
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_esp_platform_device_action(struct wait_param *pwait_action)
{
    uint8 i = 0;
    uint16 count = pwait_action->count;
    uint16 action_number = pwait_action->action_number;

    ESP_DBG("there is %d action at the same time\n", pwait_action->action_number);

#if PLUG_DEVICE
    for (i = 0; i < action_number && pwait_action->action[i][0] != '0'; i++) {
        ESP_DBG("%s\n",pwait_action->action[i]);

        if (os_strcmp(pwait_action->action[i], "on_switch", 9) == 0) {
            user_plug_set_status(0x01);
        } else if (os_strcmp(pwait_action->action[i], "off_switch", 10) == 0) {
            user_plug_set_status(0x00);
        } else if (os_strcmp(pwait_action->action[i], "on_off_switch", 13) == 0) {
            if (user_plug_get_status() == 0) {
                user_plug_set_status(0x01);
            } else {
                user_plug_set_status(0x00);
            }
        } else {
            return;
        }
    }
    user_platform_timer_first_start(count);
#endif
}
void ICACHE_FLASH_ATTR
espnow_debug_send(uint8* data,uint16 len)
{
    if(espnow_debug_enable){
        ESP_DBG("espnow send to "MACSTR"\r\n",MAC2STR(debug_target_mac));
		ESP_DBG("data: %s \r\n",data);
		esp_now_send(debug_target_mac,data,len);
    }
//FLASH buf init
void ICACHE_FLASH_ATTR
debug_FlashBufInit(flashDebugBuf* flashDbgBuf,uint32 idx_sec)
{
    //spi_flash_read(idx_sec*0x1000,(uint32*)flashDbgBuf,sizeof(flashDebugBuf));
	config_ParamLoadWithProtect(idx_sec,0,(uint8*)flashDbgBuf,sizeof(flashDebugBuf));

	if(debug_FlashParamCsumCheck(flashDbgBuf) && debug_FlashAddrCheck(flashDbgBuf)){
        ESP_DBG("flash debug check sum ok..\r\n");
    }else{
        ESP_DBG("flash debug info reset...\r\n");
        debug_FlashBufReset(flashDbgBuf,idx_sec);
    }
}
//OTA reboot function
void ICACHE_FLASH_ATTR
	debug_OtaReboot()
{
    #if ESP_MESH_SUPPORT
		ESP_DBG("deinit for OTA\r\n");
		espconn_mesh_disable(NULL);
		wifi_station_disconnect();
		wifi_set_opmode(NULL_MODE);
    #endif

	user_esp_clr_upgrade_finish_flag();//clear flag and reboot
	system_upgrade_flag_set(UPGRADE_FLAG_FINISH);
	ESP_DBG("call system upgrade reboot...\r\n");
    system_upgrade_reboot();
}
//print exception log to Flash
void ICACHE_FLASH_ATTR
stack_dump(struct rst_info *info, uint32 sp)
{
    uint32 i;
	uint8 log_buf[200];
    const char* pad = "    ";
	int len;
    if(info->reason == REASON_WDT_RST || info->reason == REASON_SOFT_WDT_RST
    || info->reason == REASON_EXCEPTION_RST) {

	ets_memset(log_buf,0,sizeof(log_buf));
    ets_sprintf(log_buf,"stack sp is %08x\n",sp);
    len = os_strlen(log_buf);
	if(len%4!=0) ets_memcpy(log_buf+len,pad, 4 - (len%4));
	ESP_DBG("Stack sp is %08x\n",sp);
    debug_DumpToFlash(log_buf,os_strlen(log_buf));

	ets_memset(log_buf,0,sizeof(log_buf));
    ets_sprintf(log_buf,"*** stack dump start ***\n");
    len = os_strlen(log_buf);
	if(len%4!=0) os_memcpy(log_buf+len,pad, 4 - (len%4));
    debug_DumpToFlash(log_buf,os_strlen(log_buf));
	ESP_DBG("*** Stack dump start ***\n");

	ets_memset(log_buf,0,sizeof(log_buf));
    ets_sprintf(log_buf,"PC = 0x%08x\n",info->epc1);
    len = os_strlen(log_buf);
	if(len%4!=0) os_memcpy(log_buf+len,pad, 4 - (len%4));
    debug_DumpToFlash(log_buf,os_strlen(log_buf));
	ESP_DBG("DBG PC = 0x%08x\n",info->epc1);

    for (i = sp; i < 0x40000000; i+=16) {
        uint32 *val = (uint32 *)i;
		ets_memset(log_buf,0,sizeof(log_buf));
        ets_sprintf(log_buf,"%08x: %08x %08x %08x %08x\n", i, *val, *(val + 1), *(val + 2), *(val + 3));
		len = os_strlen(log_buf);
		if(len%4!=0) os_memcpy(log_buf+len,pad, 4 - (len%4));
		debug_DumpToFlash(log_buf,os_strlen(log_buf));
		ESP_DBG("%08x: %08x %08x %08x %08x\n", i, *val, *(val + 1), *(val + 2), *(val + 3));
    }
	ets_memset(log_buf,0,sizeof(log_buf));
    ets_sprintf(log_buf,"*** stack dump end ***\n");
    len = os_strlen(log_buf);
	if(len%4!=0) os_memcpy(log_buf+len,pad, 4 - (len%4));
	debug_DumpToFlash(log_buf,os_strlen(log_buf));
	ESP_DBG("*** Stack dump end ***\n");
    }
//upload debug info to esp-server
void ICACHE_FLASH_ATTR
    debug_UploadExceptionInfo(void* arg)
{
    struct espconn *pespconn = (struct espconn *)arg;
    
    ESP_DBG("reset reason: %x\n", rtc_info_dbg.reason);
    uint8 debug_upload_buf[DEBUG_UPLOAD_BUF_LEN];
    uint8* pInfo = debug_upload_buf;
    os_memset(debug_upload_buf,0,DEBUG_UPLOAD_BUF_LEN);

    uint8 devkey[41];
    os_memset(devkey,0,sizeof(devkey));
    user_esp_platform_get_devkey(devkey);
    
    if (rtc_info_dbg.reason == REASON_WDT_RST ||
        rtc_info_dbg.reason == REASON_EXCEPTION_RST ||
        rtc_info_dbg.reason == REASON_SOFT_WDT_RST) {
        os_sprintf(pInfo,UPLOAD_DEBUG_LOG,rtc_info_dbg.reason,rtc_info_dbg.exccause,rtc_info_dbg.epc1,
                                                  rtc_info_dbg.epc2,rtc_info_dbg.epc3,rtc_info_dbg.excvaddr,
                                                  rtc_info_dbg.depc,FlashDebugBufParam.DebugVersion ,devkey);
    }else{
        return;
    }

    #if ESP_MESH_SUPPORT
    mesh_json_add_elem(pInfo, sizeof(pInfo), (char*)mesh_GetMdevMac(), ESP_MESH_JSON_DEV_MAC_ELEM_LEN);
    #endif

	uint8 *dst = NULL,*src = NULL;
	#if ESP_MESH_SUPPORT
    	uint8 dst_t[6],src_t[6];
		if(pespconn && pespconn->proto.tcp){
            os_memcpy(dst_t,pespconn->proto.tcp->remote_ip,4);
			os_memcpy(dst_t+4,&pespconn->proto.tcp->remote_port,2);
		}
    	wifi_get_macaddr(STATION_IF,src_t);	
		dst = dst_t;
		src = src_t;
	#endif
	
	ESP_DBG("debug Info: %s \r\n",pInfo);
    if(0 == user_JsonDataSend(pespconn, pInfo, os_strlen(pInfo),0,src,dst)){
        debug_DropExceptionInfo();
		ESP_DBG("upload success...\r\n");
    }else{
		ESP_DBG("upload fail...\r\n");
    }
}
//write reset info to flash
void ICACHE_FLASH_ATTR
debug_FlashSvExceptInfo(struct rst_info* pInfo)
{
    debug_FlashBufInit(&FlashDebugBufParam,Flash_DEBUG_INFO_ADDR);
    uint8 InfoBuf[200];
    os_memset(InfoBuf,0,200);
    uint8* ptmp = InfoBuf;
    
    ptmp += os_sprintf(ptmp,"reset reason:%x\n", pInfo->reason);
    
    if (pInfo->reason == REASON_WDT_RST ||
        pInfo->reason == REASON_EXCEPTION_RST ||
        pInfo->reason == REASON_SOFT_WDT_RST) {
        if (pInfo->reason == REASON_EXCEPTION_RST) {
            ptmp += os_sprintf(ptmp,"Fatal exception (%d):\n", pInfo->exccause);
        }
        ptmp+=os_sprintf(ptmp,"debug_version:%d\r\n",FlashDebugBufParam.DebugVersion);
        ptmp+=os_sprintf(ptmp,"epc1=0x%08x, epc2=0x%08x, epc3=0x%08x, excvaddr=0x%08x, depc=0x%08x\r\n",
                pInfo->epc1, pInfo->epc2, pInfo->epc3, pInfo->excvaddr, pInfo->depc);
    }

    int len = os_strlen(InfoBuf);
    uint8 pad_len = 0;
    if(len%4 != 0){
        pad_len = 4 - (len%4);
        os_memcpy(ptmp,"   ",pad_len);
    }
    len += pad_len;
	
    ESP_DBG("============\r\nSV DBUG INFO:\r\n%s\r\n==============\r\n",InfoBuf);
    debug_PrintToFlash(InfoBuf,len,&FlashDebugBufParam,Flash_DEBUG_INFO_ADDR);
}
//write mesh reconn info to flash
void ICACHE_FLASH_ATTR
debug_FlashSvMeshReconInfo(char* time_str,sint8 err)
{

    uint8 reconInfo[200];
	int len;
	os_memset(reconInfo,0,sizeof(reconInfo));
	
    struct ip_info ipconfig;
    wifi_get_ip_info(STATION_IF, &ipconfig);



	len = os_sprintf(reconInfo,"MESH RECONN AT %s,ERR:%d,IP:"IPSTR";\r\n",time_str,err,IP2STR(&(ipconfig.ip)));
	
    //int len = os_strlen(reconInfo);
	char* ptmp = reconInfo + len;
	
    uint8 pad_len = 0;
    if(len%4 != 0){
        pad_len = 4 - (len%4);
        os_memcpy(ptmp,"   ",pad_len);
    }
    len += pad_len;

	
	ESP_DBG("%s\r\n",reconInfo);
    debug_PrintToFlash(reconInfo,len,&FlashDebugBufParam,Flash_DEBUG_INFO_ADDR);


}
void ICACHE_FLASH_ATTR
	debug_FlashPrintParamInit()
{
	//debug_FlashBufInit(&FlashPrintBufParam,FLASH_PRINT_INDEX_ADDR);
	
    //spi_flash_read(idx_sec*0x1000,(uint32*)flashDbgBuf,sizeof(flashDebugBuf));
	config_ParamLoadWithProtect(FLASH_PRINT_INDEX_ADDR,0,(uint8*)&FlashPrintBufParam,sizeof(flashDebugBuf));

	if(debug_FlashParamCsumCheck(&FlashPrintBufParam) && debug_FlashAddrCheck(&FlashPrintBufParam)){
        ESP_DBG("flash debug check sum ok..\r\n");
    }else{
        ESP_DBG("flash debug info reset...\r\n");
        //debug_FlashBufReset(&FlashPrintBufParam,FLASH_PRINT_INDEX_ADDR);
		debug_FlashPrintParamReset();
    }
}
Beispiel #11
0
/*
	串口错误应答
*/
void ICACHE_FLASH_ATTR cus_uart_error_echo(u8 error, u8 id)
{
	ESP_DBG(("cus_uart_error_echo"));

	frame_t frame;

	frame.crc = 0;
	frame.head = FRAME_HEADER;
	frame.crc += frame.head;
	frame.len = FRAME_ERROR_ECHO_DATA_LEN;
	frame.crc += frame.len;
	frame.type = FRAME_CUS_ERRECHO_TYPE;
	frame.crc += frame.type;
	frame.id = id;
	frame.crc += frame.id;

	frame.data[0] = error;
	frame.crc += error;
	frame.data[1] = 0;//保留

	//uart0_tx_buffer((uint8_t *)&frame, frame.len);
	Enqueue(&frame);

	return;
}
//write string to flash
void ICACHE_FLASH_ATTR
debug_DumpToFlash(uint8* data, uint16 len)
{
    if(len%4 != 0){
        ESP_DBG("4Bytes ...\r\n");
        return;
    }
    
    if(FlashDumpBufParam.InPos % 0x1000 ==0)
        spi_flash_erase_sector(FlashDumpBufParam.InPos / 0x1000);

    if(FlashDumpBufParam.InPos+len <  FlashDumpBufParam.StartAddr+FlashDumpBufParam.Size ){
        spi_flash_write(FlashDumpBufParam.InPos,(uint32 *)data,len);
		ESP_DBG("addr: 0x%08x :  %d \r\n",FlashDumpBufParam.InPos,len);
        FlashDumpBufParam.InPos+=len;
    }
}
Beispiel #13
0
/******************************************************************************
 * FunctionName : user_esp_platform_upgrade_cb
 * Description  : Processing the downloaded data from the server
 * Parameters   : pespconn -- the espconn used to connetion with the host
 * Returns      : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
v_user_esp_platform_upgrade_rsp(void *arg)
{
    struct upgrade_server_info *server = arg;
    if (server->upgrade_flag == true) {
    	ESP_DBG("user_esp_platform_upgrade_successful\n");

    } else {
        ESP_DBG("user_esp_platform_upgrade_failed\n");

    }

    os_free(server->url);
    server->url = NULL;
    os_free(server);
    server = NULL;
}
Beispiel #14
0
void ICACHE_FLASH_ATTR user_uart_task(void *pvParameters)
{
	CusUartIntrPtr uartptrData;
	u32 sys_time_value = system_get_time();

	while (1)
	{
		
		if (EmptyQueue() == false && (system_get_time() - sys_time_value) >= 100) {

			ESP_DBG(("***heap_size %d\n", system_get_free_heap_size()));

			frame_t frame;

			if (Dequeue(&frame)) {
				uart0_tx_buffer((uint8_t *)&frame, frame.len);
			}
			sys_time_value = system_get_time();
		}
		
		if (xQueueReceive(xQueueCusUart, (void *)&uartptrData, (portTickType)20/*portMAX_DELAY*/)) // wait about 20msec 
		{
			ESP_DBG(("data uart recv.."));
			debug_print_hex_data(uartptrData.rx_buf, uartptrData.rx_len);

			if (uartptrData.rx_len>0x00) {
				cus_uart_data_handle(uartptrData.rx_buf, uartptrData.rx_len, NULL);
			}
		}
		/*
		if ((system_get_time() - sys_time_value) >= (60 * 1000 * 1000))  //about 1min, send data to uart0, demo beat data
		{
			ESP_DBG(("uart beat data***heap_size %d\n", system_get_free_heap_size()));
			
			//uart0_write_data(uart_beat_data, sizeof(uart_beat_data));//heatbeat sent to MCU
			
			sys_time_value = system_get_time();
		}
		*/
		
	}

	vTaskDelete(NULL);

}
/******************************************************************************
 * FunctionName : user_esp_platform_device_action
 * Description  : Execute the actions of minimum wait time
 * Parameters   : pwait_action -- point the list of actions which need execute
 *
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_esp_platform_device_action(struct wait_param *pwait_action)
{
    uint8 i = 0;
    uint16 count = pwait_action->count;
    uint16 action_number = pwait_action->action_number;

    ESP_DBG("there is %d action at the same time\n", pwait_action->action_number);

}
/******************************************************************************
 * FunctionName : user_platform_timer_start
 * Description  : Processing the message about timer from the server
 * Parameters   : timer_wait_param -- The received data from the server
 *                count -- the espconn used to connetion with the host
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_esp_platform_wait_time_overflow_check(struct wait_param *pwait_action)
{
    ESP_DBG("min_wait_second = %d", min_wait_second);

    if (pwait_action->min_time_backup >= 3600) {
        os_timer_disarm(&device_timer);
        os_timer_setfn(&device_timer, (os_timer_func_t *)user_esp_platform_wait_time_overflow_check, pwait_action);
        os_timer_arm(&device_timer, 3600000, 0);
        ESP_DBG("min_wait_second is extended\n");
    } else {
        os_timer_disarm(&device_timer);
        os_timer_setfn(&device_timer, (os_timer_func_t *)user_esp_platform_device_action, pwait_action);
        os_timer_arm(&device_timer, pwait_action->min_time_backup * 1000, 0);
        ESP_DBG("min_wait_second is = %dms\n", pwait_action->min_time_backup * 1000);
    }

    pwait_action->min_time_backup -= 3600;
}
//save flash debug param
void ICACHE_FLASH_ATTR
    debug_FlashParamSv(flashDebugBuf* flashDbgBuf,uint32 sec_addr)
{
	ESP_DBG("debug_FlashParamSv\r\n");

    debug_FlashParamCsumSet(flashDbgBuf);
	
    //spi_flash_erase_sector(Flash_DEBUG_INFO_ADDR);
    //spi_flash_write(Flash_DEBUG_INFO_ADDR*0x1000,(uint32*)&FlashDebugBufParam,sizeof(FlashDebugBufParam));  
	config_ParamSaveWithProtect(sec_addr,(uint32*)flashDbgBuf,sizeof(flashDebugBuf));
}
Beispiel #18
0
/******************************************************************************
 * FunctionName : user_esp_platform_get_connect_status
 * Description  : get each connection step's status
 * Parameters   : none
 * Returns      : status
*******************************************************************************/
uint8 ICACHE_FLASH_ATTR
user_esp_platform_get_connect_status(void)
{
    uint8 status = wifi_station_get_connect_status();

    if (status == STATION_GOT_IP) {
        status = (device_status == 0) ? DEVICE_CONNECTING : device_status;
    }

    ESP_DBG("status %d\n", status);
    return status;
}
void ICACHE_FLASH_ATTR
	mem_leak_debug_hook(void* buf,uint16_t len)
{
    ESP_DBG("mem_leak_debug_hook\r\n");

    static bool hook_called = false;
    if(hook_called == false){
        debug_DumpBufReset();
		hook_called = true;
    }

	#if 0
    extern uint8 time_stamp_str[32];
	char time_buf[128];
	os_memset(time_buf,' ',sizeof(time_buf));
    if(os_strchr(time_stamp_str,':')){
		//debug_FlashPrint((uint8*)time_stamp_str,32);
		os_sprintf(time_buf,"last time recorded: %s \r\n",time_stamp_str);
    }else{
        os_sprintf(time_buf,"time not recorded\r\n");
    }
	debug_FlashPrint((uint8*)time_buf,sizeof(time_buf));
	#endif

	
    int tmp = 4-len%4;
	int length = len;
    if(tmp != 0){
		int i;
		for(i=0;i<tmp;i++)
            *(((uint8*)buf)+len+i)= ' ';

		length = len+tmp;
    }
	ESP_DBG("len: %d ; length: %d \r\n",len,length);
	debug_FlashPrint((uint8*)buf,length);
	ESP_DBG(
"------------AFTER-------------\r\n");
	
    ESP_DBG("flash debug : CURSEC: %02x\r\n",FlashPrintBufParam.CurrentSec);
    ESP_DBG("flash debug : size: %d\r\n",FlashPrintBufParam.Size);
    ESP_DBG("flash debug : START: %08x\r\n",FlashPrintBufParam.StartAddr);
    ESP_DBG("flash debug : InPos: %08x\r\n",FlashPrintBufParam.InPos);
    ESP_DBG("flash debug : OutPos: %08x\r\n",FlashPrintBufParam.OutPos);
	ESP_DBG("flash debug : length : %d \r\n",debug_GetFlashDebugInfoLen(&FlashPrintBufParam));
Beispiel #20
0
/*
	模块状态查询应答
 */
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;
}
Beispiel #21
0
/******************************************************************************
 * FunctionName : user_esp_platform_ap_change
 * Description  : add the user interface for changing to next ap ID.
 * Parameters   :
 * Returns      : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
user_esp_platform_ap_change(void)
{
    uint8 current_id;
    uint8 i = 0;
    ESP_DBG("user_esp_platform_ap_is_changing\n");

    current_id = wifi_station_get_current_ap_id();
    ESP_DBG("current ap id =%d\n", current_id);

    if (current_id == AP_CACHE_NUMBER - 1) {
       i = 0;
    } else {
       i = current_id + 1;
    }
    while (wifi_station_ap_change(i) != true) {
       i++;
       if (i == AP_CACHE_NUMBER - 1) {
    	   i = 0;
       }
    }

}
//check flash debug info address
bool ICACHE_FLASH_ATTR
    debug_FlashAddrCheck(flashDebugBuf* flashDbgBuf)
{ 
#if 0
    if(FlashDebugBufParam.InPos >= FlashDebugBufParam.OutPos  && 
        FlashDebugBufParam.InPos< FlashDebugBufParam.StartAddr+FlashDebugBufParam.Size &&
        FlashDebugBufParam.InPos>=FlashDebugBufParam.StartAddr){
        ESP_DBG("debug flash addr check ok...\r\n");
        return true;
    }else{
        ESP_DBG("debug flash addr check error...\r\n");
        return false;
    }
#endif

    if((flashDbgBuf->InPos>=flashDbgBuf->StartAddr)&&(flashDbgBuf->InPos<=flashDbgBuf->StartAddr+flashDbgBuf->Size)
		&&(flashDbgBuf->OutPos>=flashDbgBuf->StartAddr)&&(flashDbgBuf->OutPos<=flashDbgBuf->StartAddr+flashDbgBuf->Size)){
		ESP_DBG("debug flash addr check ok...\r\n");
		return true;
	}else{
		ESP_DBG("debug flash addr check error...\r\n");
		return false;
	}	
}
//cal checksum and check
bool ICACHE_FLASH_ATTR
debug_FlashParamCsumCheck(flashDebugBuf* flashDbgBuf)
{
    uint8 csum_cal=0;
    int i ;
    char* tmp = (char*)(flashDbgBuf);
    for(i=1;i<sizeof(flashDebugBuf);i++){
        csum_cal+= *(tmp+i);
    }
    ESP_DBG("flash csum cal: %d ; ori: %d \r\n",csum_cal,flashDbgBuf->csum);
    if(csum_cal==flashDbgBuf->csum)
        return true;
    else
        return false;
}
Beispiel #24
0
/******************************************************************************
 * FunctionName : user_esp_platform_upgrade_begin
 * Description  : Processing the received data from the server
 * Parameters   : pespconn -- the espconn used to connetion with the host
 *                server -- upgrade param
 * Returns      : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
v_user_esp_platform_upgrade_begin(struct espconn *pespconn, struct upgrade_server_info *server)
{
    uint8 user_bin[9] = {0};


    server->pespconn = pespconn;
    server->port = 80;
    server->check_cb = v_user_esp_platform_upgrade_rsp;
    server->check_times = 120000;
    const char esp_server_ip[4] = {52,68,48,85};
    os_memcpy(server->ip, esp_server_ip, 4);

    if (server->url == NULL) {
        server->url = (uint8 *)os_zalloc(512);
    }
#if 0 // in general, we need to check user bin here
    if (system_upgrade_userbin_check() == UPGRADE_FW_BIN1) {
        os_memcpy(user_bin, "user2.bin", 10);
    } else if (system_upgrade_userbin_check() == UPGRADE_FW_BIN2) {
        os_memcpy(user_bin, "user1.bin", 10);
    }
    
    os_sprintf(server->url, "GET /%s HTTP/1.0\r\nHost: "IPSTR":%d\r\n"pheadbuffer"",
           user_bin, IP2STR(server->ip),
           80);
#else

    os_sprintf(server->url, "GET /%s HTTP/1.0\r\nHost: "IPSTR":%d\r\n"pheadbuffer"",
           "download/file/user1.1024.new.bin", IP2STR(server->ip),
           80);


    //http://192.168.31.229/test/user1.1024.new.2.bin

    //52.68.48.85/download/file/user1.1024.new.bin

#endif


    if (system_upgrade_start(server) == false) {

        ESP_DBG("upgrade is already started\n");
    }
}
//dump exception log into Flash
void ICACHE_FLASH_ATTR
system_restart_hook(struct rst_info *info)
{
    register uint32 sp asm("a1");
    uint32 offset = 0;
    #if 0
    if (info->reason == REASON_SOFT_WDT_RST) {
        offset = 0x1c0;
    }
    else if (info->reason == REASON_EXCEPTION_RST) {
        offset = 0x1b0;
    }
	#endif
	debug_DumpBufReset();	
    uint8 InfoBuf[200];
    os_memset(InfoBuf,0,200);
    uint8* ptmp = InfoBuf;
    os_sprintf(ptmp,"reset reason:%x\n", info->reason);
    ptmp+=os_strlen(ptmp);
    if (info->reason == REASON_WDT_RST ||
        info->reason == REASON_EXCEPTION_RST ||
        info->reason == REASON_SOFT_WDT_RST) {
        if (info->reason == REASON_EXCEPTION_RST) {
            os_sprintf(ptmp,"Fatal exception (%d):\n", info->exccause);
            ptmp += os_strlen(ptmp);
        }
        ptmp+=os_strlen(ptmp);
        os_sprintf(ptmp,"epc1=0x%08x, epc2=0x%08x, epc3=0x%08x, excvaddr=0x%08x, depc=0x%08x\r\n",
                info->epc1, info->epc2, info->epc3, info->excvaddr, info->depc);
        ptmp+=os_strlen(ptmp);
    }

    int len = os_strlen(InfoBuf);
    uint8 pad_len = 0;
    if(len%4 != 0){
        pad_len = 4 - (len%4);
        os_memcpy(ptmp,"   ",pad_len);
    }
    len += pad_len;
    ESP_DBG("============\r\nSV DBUG INFO:\r\n%s\r\n==============\r\n",InfoBuf);
    debug_DumpToFlash(InfoBuf,len);
    stack_dump(info, sp + offset);
/******************************************************************************
 * FunctionName : user_platform_timer_start
 * Description  : Processing the message about timer from the server
 * Parameters   : timer_wait_param -- The received data from the server
 *                count -- the espconn used to connetion with the host
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
esp_platform_timer_action(struct esp_platform_wait_timer_param *timer_wait_param, uint16 count)
{
    uint16 i = 0;
    uint16 action_number;
    struct wait_param pwait_action = {0};

    pwait_action.count = count;
    action_number = 0;

    for (i = 0; i < count ; i++) {
        if (timer_wait_param[i].wait_time_second == min_wait_second) {
            os_memcpy(pwait_action.action[action_number], timer_wait_param[i].wait_action, os_strlen(timer_wait_param[i].wait_action));
            ESP_DBG("*****%s*****\n", timer_wait_param[i].wait_action);
            action_number++;
        }
    }

    pwait_action.action_number = action_number;
    pwait_action.min_time_backup = min_wait_second;
    user_esp_platform_wait_time_overflow_check(&pwait_action);
}
//get flash debug info
void ICACHE_FLASH_ATTR
    debug_GetFlashExceptInfo(uint8* buf, uint16 max_len,uint16 offset)
{
    ESP_DBG("flash debug : InPos: %08x\r\n",FlashDebugBufParam.InPos);
    ESP_DBG("flash debug : OutPos: %08x\r\n",FlashDebugBufParam.OutPos);    
    int size = (FlashDebugBufParam.InPos-FlashDebugBufParam.OutPos-offset);
    if(size>max_len) size = max_len;

    offset = offset - offset%4;
    if(size>0){
        //debug_str = (uint8*)os_zalloc(size+1);
        spi_flash_read(FlashDebugBufParam.OutPos+offset,(uint32*)buf,size);
        ESP_DBG("-----------------------\r\n");
        ESP_DBG("FLASH DEBUG INFO: \r\n");
        ESP_DBG("%s\r\n",buf);
        ESP_DBG("-----------------------\r\n");
    }
}
void user_esp_pwm_test_task(void *pvParameters)
{
	uint32 r,g,b,cw,ww,period;

	r = 0;
	g = 0;
	b = 0;
	cw = 0;

	period = 1000;

	while(1)   // a demo test pwm
	{
		ESP_DBG(("*****test****r:%d,g:%d,b:%d,cw:%d,ww:%d",r,g,b,cw,ww));
        light_set_aim(r,g,b,cw,ww,period);

		r+=5;
		g+=5;
		b+=5;
		cw+=5;
		ww+=5;
		
		if(r>100)
			r = 0;
		if(g>100)
			g = 0;
		if(b>100)
			b = 0;
		if(cw>100)
			cw = 0;
		if(ww>100)
			ww = 0;
		vTaskDelay(50);
	}
	vTaskDelete(NULL);
	return;
}
void ICACHE_FLASH_ATTR
    debug_DispFlashExceptInfo(flashDebugBuf* flashDbgBuf)
{
    ESP_DBG("flash debug : version: %d \r\n",flashDbgBuf->DebugVersion);
    ESP_DBG("flash debug : InPos: %08x\r\n",flashDbgBuf->InPos);
    ESP_DBG("flash debug : OutPos: %08x\r\n",flashDbgBuf->OutPos);
    uint8* debug_str = NULL;
    
    int size = (flashDbgBuf->InPos-flashDbgBuf->OutPos);
        
    if(size>0){
        debug_str = (uint8*)os_zalloc(size+1);
        spi_flash_read(flashDbgBuf->OutPos,(uint32*)debug_str,size);
        ESP_DBG("-----------------------\r\n");
        ESP_DBG("FLASH DEBUG INFO: \r\n");
        ESP_DBG("%s\r\n",debug_str);
        ESP_DBG("-----------------------\r\n");
    }
	if(debug_str){
        os_free(debug_str);
		debug_str = NULL;
	}
	
}
/******************************************************************************
 * FunctionName : user_platform_timer_first_start
 * Description  : calculate the wait time of each timer
 * Parameters   : count -- The number of timers given by server
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_platform_timer_first_start(uint16 count)
{
    int i = 0;
    struct esp_platform_wait_timer_param timer_wait_param[100] = {0};

    ESP_DBG("current timestamp= %ds\n", timestamp);

    timestamp = timestamp + min_wait_second;

    for (i = 0 ; i < count ; i++) {
        char *str = timer_splits[i];

        if (indexof(str, "f", 0) == 0) {
            char *fixed_wait[2];

            ESP_DBG("timer is fixed mode\n");

            split(str, "=", fixed_wait);
            os_memcpy(timer_wait_param[i].wait_time_param, fixed_wait[0] + 1, os_strlen(fixed_wait[0]) - 1);
            os_memcpy(timer_wait_param[i].wait_action, fixed_wait[1], os_strlen(fixed_wait[1]));
            timer_wait_param[i].wait_time_second = atoi(timer_wait_param[i].wait_time_param) - timestamp;
            os_free(fixed_wait[0]);
            os_free(fixed_wait[1]);
        }

        else if (indexof(str, "l", 0) == 0) {
            char *loop_wait[2];

            ESP_DBG("timer is loop mode\n");

            split(str, "=", loop_wait);
            os_memcpy(timer_wait_param[i].wait_time_param, loop_wait[0] + 1, os_strlen(loop_wait[0]) - 1);
            os_memcpy(timer_wait_param[i].wait_action, loop_wait[1], os_strlen(loop_wait[1]));
            timer_wait_param[i].wait_time_second = atoi(timer_wait_param[i].wait_time_param) - (timestamp % atoi(timer_wait_param[i].wait_time_param));
            os_free(loop_wait[0]);
            os_free(loop_wait[1]);
        } else if (indexof(str, "w", 0) == 0) {
            char *week_wait[2];
            int monday_wait_time = 0;

            ESP_DBG("timer is weekend mode\n");

            split(str, "=", week_wait);
            os_memcpy(timer_wait_param[i].wait_time_param, week_wait[0] + 1, os_strlen(week_wait[0]) - 1);
            os_memcpy(timer_wait_param[i].wait_action, week_wait[1], os_strlen(week_wait[1]));
            monday_wait_time = (timestamp - 1388937600) % (7 * 24 * 3600);

            ESP_DBG("monday_wait_time == %d", monday_wait_time);

            if (atoi(timer_wait_param[i].wait_time_param) > monday_wait_time) {
                timer_wait_param[i].wait_time_second = atoi(timer_wait_param[i].wait_time_param) - monday_wait_time;
            } else {
                timer_wait_param[i].wait_time_second = 7 * 24 * 3600 - monday_wait_time + atoi(timer_wait_param[i].wait_time_param);
            }

            os_free(week_wait[0]);
            os_free(week_wait[1]);
        }
    }

    esp_platform_find_min_time(timer_wait_param, count);
    if(min_wait_second == 0) {
    	return;
    }

    esp_platform_timer_action(timer_wait_param, count);
}