diff --git a/src/flash_config/flash_config.c b/src/flash_config/flash_config.c index a353d2d71..cb513fc46 100644 --- a/src/flash_config/flash_config.c +++ b/src/flash_config/flash_config.c @@ -87,7 +87,17 @@ int config_get_item(void *container) { return ret; } - +int config_get_tableOffsets(int tableID, int *outStart, int *outLen) { + bk_logic_partition_t *pt; + pt = bk_flash_get_info(tableID); + *outStart = 0; + *outLen = 0; + if(pt == 0) + return 1; + *outStart = pt->partition_start_addr; + *outLen = pt->partition_length; + return 0; +} int config_get_tbl(int readit){ UINT32 ret = 0, status; diff --git a/src/flash_config/flash_config.h b/src/flash_config/flash_config.h index b5a8b5e03..9aaafd161 100644 --- a/src/flash_config/flash_config.h +++ b/src/flash_config/flash_config.h @@ -36,6 +36,8 @@ INFO_ITEM_ST *config_search_item_type(UINT32 type); // list table contetn by type & len to debug int config_dump_table(); +// debug +int config_get_tableOffsets(int tableID, int *outStart, int *outLen); ///////////////////////////////////////// diff --git a/src/httpserver/new_http.c b/src/httpserver/new_http.c index 8e38a320b..71211bc1d 100644 --- a/src/httpserver/new_http.c +++ b/src/httpserver/new_http.c @@ -25,11 +25,13 @@ #elif defined(PLATFORM_BK7231N) // tuya-iotos-embeded-sdk-wifi-ble-bk7231n/sdk/include/tuya_hal_storage.h #include "tuya_hal_storage.h" +#include "BkDriverFlash.h" #else // REALLY? A typo in Tuya SDK? Storge? // tuya-iotos-embeded-sdk-wifi-ble-bk7231t/platforms/bk7231t/tuya_os_adapter/include/driver/tuya_hal_storge.h - +#include "../logging/logging.h" #include "tuya_hal_storge.h" +#include "BkDriverFlash.h" #endif /* @@ -300,6 +302,9 @@ typedef struct template_s { template_t g_templates [] = { { Setup_Device_Empty, "Empty"}, + // BK7231N devices + { Setup_Device_BK7231N_CB2S_QiachipSmartSwitch, "[BK7231N][CB2S] QiaChip Smart Switch"}, + // BK7231T devices { Setup_Device_TuyaWL_SW01_16A, "WL SW01 16A"}, { Setup_Device_TuyaSmartLife4CH10A, "Smart Life 4CH 10A"}, { Setup_Device_IntelligentLife_NF101A, "Intelligent Life NF101A"}, @@ -318,9 +323,23 @@ int g_total_templates = sizeof(g_templates)/sizeof(g_templates[0]); #if PLATFORM_XR809 const char *g_header = "

OpenXR809

[Read more][Support project]

"; -#else -const char *g_header = "

OpenBK7231

[Read more][Support project]

"; +#elif PLATFORM_BK7231N +const char *g_header = "

OpenBK7231N

[Read more][Support project]

"; + +#elif PLATFORM_BK7231T + +const char *g_header = "

OpenBK7231T

[Read more][Support project]

"; + +#elif WINDOWS + +const char *g_header = "

OpenBK7231 [Win test]

[Read more][Support project]

"; + +#else + +const char *g_header = "

error

"; +#error "Platform not supported" +Platform not supported #endif @@ -434,7 +453,7 @@ uint8_t hexbyte( const char* hex ) } int HTTP_ProcessPacket(http_request_t *request) { - int i, j; + int i, j, k; char tmpA[128]; char tmpB[64]; char tmpC[64]; @@ -720,6 +739,37 @@ int HTTP_ProcessPacket(http_request_t *request) { poststr(request,htmlReturnToCfg); HTTP_AddBuildFooter(request); poststr(request,htmlEnd); + } else if(http_checkUrlBase(urlStr,"cfg_loglevel_set")) { + printf("HTTP_ProcessPacket: generating cfg_loglevel_set \r\n"); + + http_setup(request, httpMimeTypeHTML); + poststr(request,htmlHeader); + poststr(request,g_header); + if(http_getArg(recvbuf,"loglevel",tmpA,sizeof(tmpA))) { +#if PLATFORM_BK7231T + loglevel = atoi(tmpA); +#endif + poststr(request,"LOG level changed."); + } + poststr(request,"
\ +
\ +

\ + \ +
"); + + poststr(request,"
"); + poststr(request,"Return to config settings"); + poststr(request,"
"); + poststr(request,htmlReturnToCfg); + HTTP_AddBuildFooter(request); + poststr(request,htmlEnd); } else if(http_checkUrlBase(urlStr,"cfg_wifi")) { // for a test, show password as well... const char *cur_ssid, *cur_pass; @@ -835,10 +885,16 @@ int HTTP_ProcessPacket(http_request_t *request) { int rem; int now; int nowOfs; + int hex; http_setup(request, httpMimeTypeHTML); poststr(request,htmlHeader); poststr(request,g_header); poststr(request,"

Flash Read Tool

"); + if( http_getArg(urlStr,"hex",tmpA,sizeof(tmpA))){ + hex = atoi(tmpA); + } else { + hex = 0; + } if( http_getArg(urlStr,"offset",tmpA,sizeof(tmpA)) && http_getArg(urlStr,"len",tmpB,sizeof(tmpB))) { @@ -870,7 +926,12 @@ int HTTP_ProcessPacket(http_request_t *request) { res = tuya_hal_flash_read (nowOfs, buffer,now); #endif for(i = 0; i < now; i++) { - sprintf(tmpA,"%02X ",buffer[i]); + u8 val = buffer[i]; + if(!hex && isprint(val)) { + sprintf(tmpA,"'%c' ",val); + } else { + sprintf(tmpA,"%02X ",val); + } poststr(request,tmpA); } rem -= now; @@ -882,8 +943,14 @@ int HTTP_ProcessPacket(http_request_t *request) { poststr(request,"
"); } - poststr(request,"
\ -
\ + poststr(request,""); + + poststr(request,"
"); + poststr(request,"
\
",ofs); poststr(request,tmpA); @@ -1026,6 +1093,19 @@ int HTTP_ProcessPacket(http_request_t *request) { poststr(request,"
"); poststr(request,"
"); +#if PLATFORM_BK7231T | PLATFORM_BK7231N + k = config_get_tableOffsets(BK_PARTITION_NET_PARAM,&i,&j); + sprintf(tmpA,"BK_PARTITION_NET_PARAM: bOk %i, at %i, len %i
",k,i,j); + poststr(request,tmpA); + k = config_get_tableOffsets(BK_PARTITION_RF_FIRMWARE,&i,&j); + sprintf(tmpA,"BK_PARTITION_RF_FIRMWARE: bOk %i, at %i, len %i
",k,i,j); + poststr(request,tmpA); + k = config_get_tableOffsets(BK_PARTITION_OTA,&i,&j); + sprintf(tmpA,"BK_PARTITION_OTA: bOk %i, at %i, len %i
",k,i,j); + poststr(request,tmpA); +#endif + + poststr(request,"Launch Web Application
"); poststr(request,htmlReturnToMenu); @@ -1299,4 +1379,4 @@ int HTTP_ProcessPacket(http_request_t *request) { poststr(request, NULL); // nothing more to send return 0; -} \ No newline at end of file +} diff --git a/src/httpserver/rest_interface.c b/src/httpserver/rest_interface.c index c2f158242..2c6e5e2b6 100644 --- a/src/httpserver/rest_interface.c +++ b/src/httpserver/rest_interface.c @@ -584,7 +584,6 @@ static int http_rest_get_info(http_request_t *request){ } - static int http_rest_post_pins(http_request_t *request){ int i; int r; @@ -755,7 +754,7 @@ static int http_rest_post_flash_advanced(http_request_t *request){ int startaddr = 0; int sres; sres = sscanf(params, "%x", &startaddr); - if (sres == 1 && startaddr >= 0x132000){ + if (sres == 1 && startaddr >= START_ADR_OF_BK_PARTITION_OTA){ return http_rest_post_flash(request, startaddr); } return http_rest_error(request, -1, "invalid url"); diff --git a/src/new_builtin_devices.c b/src/new_builtin_devices.c index 3fbe3dc80..1647344fd 100644 --- a/src/new_builtin_devices.c +++ b/src/new_builtin_devices.c @@ -250,6 +250,25 @@ void Setup_Device_EmaxHome_EDU8774() { PIN_SaveToFlash(); } +// TODO - ELEKTRODA LINK +// QiachipSmartSwitch +void Setup_Device_BK7231N_CB2S_QiachipSmartSwitch() { + + + + PIN_ClearPins(); + // Button + PIN_SetPinRoleForPinIndex(7, IOR_Button); + PIN_SetPinChannelForPinIndex(7, 1); + // Relay + PIN_SetPinRoleForPinIndex(8, IOR_Relay); + PIN_SetPinChannelForPinIndex(8, 1); + // Led + + PIN_SaveToFlash(); +} + + // https://www.tokmanni.fi/alypistorasia-home-connect-ip20-6419860720456 // Marked as Smart-PFW02-G // Relay (with npn-transistor) at PWM4 P24 diff --git a/src/new_cfg.c b/src/new_cfg.c index 28eea0e30..f02f9d164 100644 --- a/src/new_cfg.c +++ b/src/new_cfg.c @@ -95,9 +95,15 @@ const char *CFG_GetShortDeviceName(){ #elif PLATFORM_XR809 #define DEVICENAME_PREFIX_FULL "OpenXR809" #define DEVICENAME_PREFIX_SHORT "oxr" -#else +#elif PLATFORM_BK7231N +#define DEVICENAME_PREFIX_FULL "OpenBK7231N" +#define DEVICENAME_PREFIX_SHORT "obk" +#elif PLATFORM_BK7231T #define DEVICENAME_PREFIX_FULL "OpenBK7231T" #define DEVICENAME_PREFIX_SHORT "obk" +#else +#error "You must define a platform.." +This platform is not supported, error! #endif void WiFI_GetMacAddress(char *mac) { diff --git a/src/new_pins.h b/src/new_pins.h index 690526b2d..1a6e8760f 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -65,6 +65,7 @@ void Setup_Device_NedisWIFIPO120FWT_16A(); void Setup_Device_NedisWIFIP130FWT_10A(); void Setup_Device_EmaxHome_EDU8774(); void Setup_Device_TuyaSmartPFW02G(); +void Setup_Device_BK7231N_CB2S_QiachipSmartSwitch(); #endif diff --git a/src/ota/ota.c b/src/ota/ota.c index 2d64919c8..5a663e1a3 100644 --- a/src/ota/ota.c +++ b/src/ota/ota.c @@ -1,4 +1,5 @@ +#include "ota.h" #include "../new_common.h" #include "typedef.h" #include "flash_pub.h" @@ -108,7 +109,8 @@ int myhttpclientcallback(httprequest_t* request){ switch(request->state){ case 0: // start //init_ota(0xff000); - init_ota(0x132000); + + init_ota(START_ADR_OF_BK_PARTITION_OTA); addLog("\r\nmyhttpclientcallback state %d total %d/%d\r\n", request->state, total_bytes, request->client_data.response_content_len); break; case 1: // data diff --git a/src/ota/ota.h b/src/ota/ota.h index 8baf0ebc9..8926bdbf3 100644 --- a/src/ota/ota.h +++ b/src/ota/ota.h @@ -1,5 +1,17 @@ +// NOTE: this offset was taken from BkDriverFlash.c +// search for BK_PARTITION_OTA + +#if PLATFORM_BK7231T +#define START_ADR_OF_BK_PARTITION_OTA 0x132000 +#elif PLATFORM_BK7231N +#define START_ADR_OF_BK_PARTITION_OTA 0x12A000 +#else +// TODO +#define START_ADR_OF_BK_PARTITION_OTA 0x132000 +#endif + // initialise OTA flash starting at startaddr int init_ota(unsigned int startaddr); @@ -7,6 +19,6 @@ int init_ota(unsigned int startaddr); void add_otadata(unsigned char *data, int len); // finalise OTA flash (write last sector if incomplete) -int close_ota(); +void close_ota(); void otarequest(const char *urlin); \ No newline at end of file diff --git a/src/win_stubs.c b/src/win_stubs.c index 6975c8ebe..43562cf23 100644 --- a/src/win_stubs.c +++ b/src/win_stubs.c @@ -5,7 +5,11 @@ int tuya_hal_flash_read(const uint32_t addr, uint8_t *dst, const uint32_t size) { + int i; memset(dst,0,size); + for(i = 0; i < size; i++){ + dst[i] = rand()%128; + } return 0; }