2018-12-16 15:26:40 +00:00
|
|
|
/*
|
2022-11-11 09:44:56 +00:00
|
|
|
xdrv_127_debug.ino - debug support for Tasmota
|
2018-12-16 15:26:40 +00:00
|
|
|
|
2021-01-01 12:44:04 +00:00
|
|
|
Copyright (C) 2021 Theo Arends
|
2018-12-16 15:26:40 +00:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//#define USE_DEBUG_DRIVER
|
|
|
|
|
|
|
|
#ifdef DEBUG_THEO
|
|
|
|
#ifndef USE_DEBUG_DRIVER
|
|
|
|
#define USE_DEBUG_DRIVER
|
|
|
|
#endif // USE_DEBUG_DRIVER
|
|
|
|
#endif // DEBUG_THEO
|
|
|
|
|
|
|
|
#ifdef USE_DEBUG_DRIVER
|
|
|
|
/*********************************************************************************************\
|
|
|
|
* Virtual debugging support - Part1
|
|
|
|
*
|
|
|
|
* Needs file zzzz_debug.ino due to DEFINE processing
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2022-11-11 09:44:56 +00:00
|
|
|
#define XDRV_127 127
|
2018-12-16 15:26:40 +00:00
|
|
|
|
|
|
|
#ifndef CPU_LOAD_CHECK
|
|
|
|
#define CPU_LOAD_CHECK 1 // Seconds between each CPU_LOAD log
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*********************************************************************************************\
|
|
|
|
* Debug commands
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2022-01-03 13:02:18 +00:00
|
|
|
#define D_CMND_MEMDUMP "MemDump"
|
2018-12-16 15:26:40 +00:00
|
|
|
#define D_CMND_CFGDUMP "CfgDump"
|
|
|
|
#define D_CMND_CFGPEEK "CfgPeek"
|
2019-08-05 15:45:13 +01:00
|
|
|
#define D_CMND_CFGPOKE "CfgPoke"
|
2022-11-11 09:44:56 +00:00
|
|
|
#define D_CMND_SHOWHEAP "ShowHeap"
|
2018-12-16 15:26:40 +00:00
|
|
|
#define D_CMND_CFGXOR "CfgXor"
|
|
|
|
#define D_CMND_CPUCHECK "CpuChk"
|
|
|
|
#define D_CMND_EXCEPTION "Exception"
|
2019-08-05 15:45:13 +01:00
|
|
|
#define D_CMND_FLASHDUMP "FlashDump"
|
|
|
|
#define D_CMND_FLASHMODE "FlashMode"
|
2018-12-16 15:26:40 +00:00
|
|
|
#define D_CMND_FREEMEM "FreeMem"
|
|
|
|
#define D_CMND_HELP "Help"
|
2019-08-05 15:45:13 +01:00
|
|
|
#define D_CMND_RTCDUMP "RtcDump"
|
2019-10-06 15:39:11 +01:00
|
|
|
#define D_CMND_I2CWRITE "I2CWrite"
|
|
|
|
#define D_CMND_I2CREAD "I2CRead"
|
|
|
|
#define D_CMND_I2CSTRETCH "I2CStretch"
|
|
|
|
#define D_CMND_I2CCLOCK "I2CClock"
|
2020-05-11 14:27:29 +01:00
|
|
|
#define D_CMND_SERBUFF "SerBufSize"
|
2023-03-17 20:05:51 +00:00
|
|
|
#define D_CMND_SOSET "SOSet"
|
2018-12-16 15:26:40 +00:00
|
|
|
|
2019-08-11 17:12:18 +01:00
|
|
|
const char kDebugCommands[] PROGMEM = "|" // No prefix
|
2022-01-03 13:02:18 +00:00
|
|
|
D_CMND_MEMDUMP "|" D_CMND_CFGDUMP "|" D_CMND_CFGPEEK "|" D_CMND_CFGPOKE "|"
|
2022-11-11 09:44:56 +00:00
|
|
|
#ifdef ESP8266
|
|
|
|
#ifdef UMM_INLINE_METRICS
|
|
|
|
D_CMND_SHOWHEAP "|"
|
|
|
|
#endif
|
|
|
|
#endif
|
2019-08-03 14:25:16 +01:00
|
|
|
#ifdef USE_WEBSERVER
|
|
|
|
D_CMND_CFGXOR "|"
|
|
|
|
#endif
|
2020-05-11 14:27:29 +01:00
|
|
|
D_CMND_CPUCHECK "|" D_CMND_SERBUFF "|"
|
2019-08-03 14:25:16 +01:00
|
|
|
#ifdef DEBUG_THEO
|
|
|
|
D_CMND_EXCEPTION "|"
|
|
|
|
#endif
|
2021-07-14 13:20:50 +01:00
|
|
|
D_CMND_FLASHDUMP "|" D_CMND_FLASHMODE "|" D_CMND_FREEMEM"|" D_CMND_HELP "|" D_CMND_RTCDUMP "|"
|
2019-11-19 22:15:44 +00:00
|
|
|
#ifdef USE_I2C
|
2023-03-17 20:05:51 +00:00
|
|
|
D_CMND_I2CWRITE "|" D_CMND_I2CREAD "|" D_CMND_I2CSTRETCH "|" D_CMND_I2CCLOCK "|"
|
2019-11-19 22:15:44 +00:00
|
|
|
#endif
|
2023-03-17 20:05:51 +00:00
|
|
|
D_CMND_SOSET
|
2019-11-19 22:15:44 +00:00
|
|
|
;
|
2019-08-03 14:25:16 +01:00
|
|
|
|
|
|
|
void (* const DebugCommand[])(void) PROGMEM = {
|
2022-01-03 13:02:18 +00:00
|
|
|
&CmndMemDump, &CmndCfgDump, &CmndCfgPeek, &CmndCfgPoke,
|
2022-11-11 09:44:56 +00:00
|
|
|
#ifdef ESP8266
|
|
|
|
#ifdef UMM_INLINE_METRICS
|
|
|
|
&CmndShowHeap,
|
|
|
|
#endif
|
|
|
|
#endif
|
2019-08-03 14:25:16 +01:00
|
|
|
#ifdef USE_WEBSERVER
|
|
|
|
&CmndCfgXor,
|
|
|
|
#endif
|
2020-05-11 14:27:29 +01:00
|
|
|
&CmndCpuCheck, &CmndSerBufSize,
|
2019-08-03 14:25:16 +01:00
|
|
|
#ifdef DEBUG_THEO
|
|
|
|
&CmndException,
|
|
|
|
#endif
|
2021-07-14 13:20:50 +01:00
|
|
|
&CmndFlashDump, &CmndFlashMode, &CmndFreemem, &CmndHelp, &CmndRtcDump,
|
2019-11-19 22:15:44 +00:00
|
|
|
#ifdef USE_I2C
|
2023-03-17 20:05:51 +00:00
|
|
|
&CmndI2cWrite, &CmndI2cRead, &CmndI2cStretch, &CmndI2cClock,
|
2019-11-19 22:15:44 +00:00
|
|
|
#endif
|
2023-03-17 20:05:51 +00:00
|
|
|
&CmndSoSet
|
2019-11-19 22:15:44 +00:00
|
|
|
};
|
2018-12-16 15:26:40 +00:00
|
|
|
|
|
|
|
uint32_t CPU_loops = 0;
|
|
|
|
uint32_t CPU_last_millis = 0;
|
|
|
|
uint32_t CPU_last_loop_time = 0;
|
|
|
|
uint8_t CPU_load_check = 0;
|
|
|
|
uint8_t CPU_show_freemem = 0;
|
|
|
|
|
|
|
|
/*******************************************************************************************/
|
|
|
|
|
|
|
|
#ifdef DEBUG_THEO
|
2019-01-28 13:08:33 +00:00
|
|
|
void ExceptionTest(uint8_t type)
|
2018-12-16 15:26:40 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
Exception (28):
|
|
|
|
epc1=0x4000bf64 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000007 depc=0x00000000
|
|
|
|
|
|
|
|
ctx: cont
|
|
|
|
sp: 3fff1f30 end: 3fff2840 offset: 01a0
|
|
|
|
|
|
|
|
>>>stack>>>
|
|
|
|
3fff20d0: 202c3573 756f7247 2c302070 646e4920
|
|
|
|
3fff20e0: 40236a6e 7954202c 45206570 00454358
|
|
|
|
3fff20f0: 00000010 00000007 00000000 3fff2180
|
|
|
|
3fff2100: 3fff2190 40107bfc 3fff3e4c 3fff22c0
|
|
|
|
3fff2110: 40261934 000000f0 3fff22c0 401004d8
|
|
|
|
3fff2120: 40238fcf 00000050 3fff2100 4021fc10
|
|
|
|
3fff2130: 3fff32bc 4021680c 3ffeade1 4021ff7d
|
|
|
|
3fff2140: 3fff2190 3fff2180 0000000c 7fffffff
|
|
|
|
3fff2150: 00000019 00000000 00000000 3fff21c0
|
|
|
|
3fff2160: 3fff23f3 3ffe8e08 00000000 4021ffb4
|
|
|
|
3fff2170: 3fff2190 3fff2180 0000000c 40201118
|
|
|
|
3fff2180: 3fff21c0 0000003c 3ffef840 00000007
|
|
|
|
3fff2190: 00000000 00000000 00000000 40201128
|
|
|
|
3fff21a0: 3fff23f3 000000f1 3fff23ec 4020fafb
|
|
|
|
3fff21b0: 3fff23f3 3fff21c0 3fff21d0 3fff23f6
|
|
|
|
3fff21c0: 00000000 3fff23fb 4022321b 00000000
|
|
|
|
|
|
|
|
Exception 28: LoadProhibited: A load referenced a page mapped with an attribute that does not permit loads
|
|
|
|
Decoding 14 results
|
|
|
|
0x40236a6e: ets_vsnprintf at ?? line ?
|
|
|
|
0x40107bfc: vsnprintf at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/libc_replacements.c line 387
|
|
|
|
0x40261934: bignum_exptmod at ?? line ?
|
|
|
|
0x401004d8: malloc at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266\umm_malloc/umm_malloc.c line 1664
|
|
|
|
0x40238fcf: wifi_station_get_connect_status at ?? line ?
|
|
|
|
0x4021fc10: operator new[](unsigned int) at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/abi.cpp line 57
|
|
|
|
0x4021680c: ESP8266WiFiSTAClass::status() at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi\src/ESP8266WiFiSTA.cpp line 569
|
|
|
|
0x4021ff7d: vsnprintf_P(char*, unsigned int, char const*, __va_list_tag) at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/pgmspace.cpp line 146
|
|
|
|
0x4021ffb4: snprintf_P(char*, unsigned int, char const*, ...) at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/pgmspace.cpp line 146
|
|
|
|
0x40201118: atol at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_noniso.c line 45
|
|
|
|
0x40201128: atoi at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_noniso.c line 45
|
|
|
|
|
2019-11-03 14:37:33 +00:00
|
|
|
00:00:08 MQTT: tele/tasmota/INFO3 = {"Started":"Fatal exception:28 flag:2 (EXCEPTION) epc1:0x4000bf64 epc2:0x00000000 epc3:0x00000000 excvaddr:0x00000007 depc:0x00000000"}
|
2018-12-16 15:26:40 +00:00
|
|
|
*/
|
|
|
|
if (1 == type) {
|
|
|
|
char svalue[10];
|
|
|
|
snprintf_P(svalue, sizeof(svalue), PSTR("%s"), 7); // Exception 28 as number in string (7 in excvaddr)
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
14:50:52 osWatch: FreeRam 25896, rssi 68, last_run 0
|
|
|
|
14:51:02 osWatch: FreeRam 25896, rssi 58, last_run 0
|
|
|
|
14:51:03 CMND: exception 2
|
|
|
|
14:51:12 osWatch: FreeRam 25360, rssi 60, last_run 8771
|
|
|
|
14:51:22 osWatch: FreeRam 25360, rssi 62, last_run 18771
|
|
|
|
14:51:32 osWatch: FreeRam 25360, rssi 62, last_run 28771
|
|
|
|
14:51:42 osWatch: FreeRam 25360, rssi 62, last_run 38771
|
|
|
|
14:51:42 osWatch: Warning, loop blocked. Restart now
|
|
|
|
*/
|
|
|
|
if (2 == type) {
|
|
|
|
while(1) delay(1000); // this will trigger the os watch
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG_THEO
|
|
|
|
|
|
|
|
/*******************************************************************************************/
|
|
|
|
|
|
|
|
void CpuLoadLoop(void)
|
|
|
|
{
|
|
|
|
CPU_last_loop_time = millis();
|
|
|
|
if (CPU_load_check && CPU_last_millis) {
|
|
|
|
CPU_loops ++;
|
|
|
|
if ((CPU_last_millis + (CPU_load_check *1000)) <= CPU_last_loop_time) {
|
|
|
|
#if defined(F_CPU) && (F_CPU == 160000000L)
|
2020-10-29 15:16:34 +00:00
|
|
|
int CPU_load = 100 - ( (CPU_loops*(1 + 30*TasmotaGlobal.sleep)) / (CPU_load_check *800) );
|
2018-12-16 15:26:40 +00:00
|
|
|
CPU_loops = CPU_loops / CPU_load_check;
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "FreeRam %d, CPU %d%%(160MHz), Loops/sec %d"), ESP.getFreeHeap(), CPU_load, CPU_loops);
|
2018-12-16 15:26:40 +00:00
|
|
|
#else
|
2020-10-29 15:16:34 +00:00
|
|
|
int CPU_load = 100 - ( (CPU_loops*(1 + 30*TasmotaGlobal.sleep)) / (CPU_load_check *400) );
|
2018-12-16 15:26:40 +00:00
|
|
|
CPU_loops = CPU_loops / CPU_load_check;
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "FreeRam %d, CPU %d%%(80MHz), Loops/sec %d"), ESP.getFreeHeap(), CPU_load, CPU_loops);
|
2018-12-16 15:26:40 +00:00
|
|
|
#endif
|
|
|
|
CPU_last_millis = CPU_last_loop_time;
|
|
|
|
CPU_loops = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************************/
|
|
|
|
|
2020-04-16 13:59:01 +01:00
|
|
|
#ifdef ESP8266
|
2018-12-16 15:26:40 +00:00
|
|
|
// All version from core 2.4.2
|
|
|
|
// https://github.com/esp8266/Arduino/pull/5018
|
|
|
|
// https://github.com/esp8266/Arduino/pull/4553
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <cont.h>
|
|
|
|
extern cont_t* g_pcont;
|
|
|
|
}
|
|
|
|
|
2023-03-17 20:05:51 +00:00
|
|
|
void DebugFreeMem(void) {
|
2018-12-16 15:26:40 +00:00
|
|
|
register uint32_t *sp asm("a1");
|
|
|
|
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "FreeRam %d, FreeStack %d (%s)"), ESP.getFreeHeap(), 4 * (sp - g_pcont->stack), XdrvMailbox.data);
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 20:05:51 +00:00
|
|
|
uint32_t FreeStack(void) {
|
|
|
|
register uint32_t *sp asm("a1");
|
|
|
|
return 4 * (sp - g_pcont->stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddLogMem(const char* function) {
|
|
|
|
register uint32_t *sp asm("a1");
|
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "== %s FreeRam %d, FreeStack %d"), function, ESP.getFreeHeap(), 4 * (sp - g_pcont->stack));
|
|
|
|
}
|
|
|
|
|
2020-11-28 15:39:15 +00:00
|
|
|
#endif // ESP8266
|
|
|
|
#ifdef ESP32
|
2020-04-16 13:59:01 +01:00
|
|
|
|
2023-03-17 20:05:51 +00:00
|
|
|
void DebugFreeMem(void) {
|
2020-04-16 15:29:33 +01:00
|
|
|
register uint8_t *sp asm("a1");
|
|
|
|
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "FreeRam %d, FreeStack %d (%s)"), ESP.getFreeHeap(), sp - pxTaskGetStackStart(NULL), XdrvMailbox.data);
|
2020-04-16 13:59:01 +01:00
|
|
|
}
|
|
|
|
|
2023-03-17 20:05:51 +00:00
|
|
|
uint32_t FreeStack(void) {
|
|
|
|
register uint8_t *sp asm("a1");
|
|
|
|
return sp - pxTaskGetStackStart(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddLogMem(const char* function) {
|
|
|
|
register uint8_t *sp asm("a1");
|
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "== %s FreeRam %d, FreeStack %d"), function, ESP.getFreeHeap(), sp - pxTaskGetStackStart(NULL));
|
|
|
|
}
|
|
|
|
|
2020-04-16 13:59:01 +01:00
|
|
|
#endif // ESP8266 - ESP32
|
|
|
|
|
2021-03-28 13:38:16 +01:00
|
|
|
/*******************************************************************************************/
|
|
|
|
/*
|
|
|
|
Usage:
|
|
|
|
|
|
|
|
DebugTimer(1);
|
|
|
|
|
|
|
|
Code snippit to time
|
|
|
|
|
|
|
|
DebugTimer(0);
|
|
|
|
*/
|
|
|
|
|
|
|
|
void DebugTimer(bool start) {
|
|
|
|
static uint32_t timer = 0;
|
|
|
|
|
|
|
|
if (start) {
|
|
|
|
timer = micros();
|
|
|
|
} else {
|
|
|
|
timer = ((int32_t)(micros() - timer));
|
|
|
|
AddLog(LOG_LEVEL_DEBUG, PSTR("DBG: ExecTime %d uS"), timer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 15:26:40 +00:00
|
|
|
/*******************************************************************************************/
|
|
|
|
|
|
|
|
void DebugRtcDump(char* parms)
|
|
|
|
{
|
2020-04-16 13:59:01 +01:00
|
|
|
#ifdef ESP8266
|
2020-12-23 17:26:15 +00:00
|
|
|
uint32_t CFG_COLS = 16;
|
2018-12-16 15:26:40 +00:00
|
|
|
|
|
|
|
uint16_t idx;
|
|
|
|
uint16_t maxrow;
|
|
|
|
uint16_t row;
|
|
|
|
uint16_t col;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
// |<--SDK data (256 bytes)-->|<--User data (512 bytes)-->|
|
|
|
|
// 000 - 0FF: SDK
|
|
|
|
// 000 - 01B: SDK rst_info
|
|
|
|
// 100 - 2FF: User
|
|
|
|
// 280 - 283: Tasmota RtcReboot (Offset 100 (x 4bytes) - sizeof(RTCRBT) (x 4bytes))
|
|
|
|
// 290 - 2EB: Tasmota RtcSettings (Offset 100 (x 4bytes))
|
|
|
|
|
|
|
|
uint8_t buffer[768];
|
|
|
|
// ESP.rtcUserMemoryRead(0, (uint32_t*)&buffer, sizeof(buffer));
|
|
|
|
system_rtc_mem_read(0, (uint32_t*)&buffer, sizeof(buffer));
|
|
|
|
|
|
|
|
maxrow = ((sizeof(buffer)+CFG_COLS)/CFG_COLS);
|
|
|
|
|
|
|
|
uint16_t srow = strtol(parms, &p, 16) / CFG_COLS;
|
|
|
|
uint16_t mrow = strtol(p, &p, 10);
|
|
|
|
|
2021-01-23 16:10:06 +00:00
|
|
|
// AddLog(LOG_LEVEL_DEBUG, PSTR("Cnfg: Parms %s, Start row %d, rows %d"), parms, srow, mrow);
|
2018-12-16 15:26:40 +00:00
|
|
|
|
|
|
|
if (0 == mrow) { // Default only 8 lines
|
|
|
|
mrow = 8;
|
|
|
|
}
|
|
|
|
if (srow > maxrow) {
|
|
|
|
srow = maxrow - mrow;
|
|
|
|
}
|
|
|
|
if (mrow < (maxrow - srow)) {
|
|
|
|
maxrow = srow + mrow;
|
|
|
|
}
|
|
|
|
|
2021-01-02 11:23:30 +00:00
|
|
|
char log_data[100]; // 020: C7 2B 2E AB 70 E8 09 AE C8 88 3D EA 7C FF 48 2F | +. p = | H/|
|
2018-12-16 15:26:40 +00:00
|
|
|
for (row = srow; row < maxrow; row++) {
|
|
|
|
idx = row * CFG_COLS;
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%03X:"), idx);
|
2018-12-16 15:26:40 +00:00
|
|
|
for (col = 0; col < CFG_COLS; col++) {
|
|
|
|
if (!(col%4)) {
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data);
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, buffer[idx + col]);
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s |"), log_data);
|
2018-12-16 15:26:40 +00:00
|
|
|
for (col = 0; col < CFG_COLS; col++) {
|
|
|
|
// if (!(col%4)) {
|
2020-12-23 17:26:15 +00:00
|
|
|
// snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data);
|
2018-12-16 15:26:40 +00:00
|
|
|
// }
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' ');
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data);
|
|
|
|
AddLogData(LOG_LEVEL_INFO, log_data);
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
2020-04-16 13:59:01 +01:00
|
|
|
#endif // ESP8266
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************************/
|
|
|
|
|
2020-11-28 15:39:15 +00:00
|
|
|
void DebugDump(uint32_t start, uint32_t size) {
|
|
|
|
uint32_t CFG_COLS = 32;
|
|
|
|
|
|
|
|
uint32_t idx;
|
|
|
|
uint32_t maxrow;
|
|
|
|
uint32_t row;
|
|
|
|
uint32_t col;
|
|
|
|
char *p;
|
|
|
|
|
2022-01-03 13:02:18 +00:00
|
|
|
uint8_t *buffer = (uint8_t *)(start);
|
|
|
|
maxrow = ((size + CFG_COLS) / CFG_COLS);
|
2020-11-28 15:39:15 +00:00
|
|
|
|
|
|
|
uint32_t srow = 0;
|
|
|
|
uint32_t mrow = maxrow;
|
|
|
|
|
2021-01-23 16:10:06 +00:00
|
|
|
// AddLog(LOG_LEVEL_DEBUG, PSTR("Cnfg: Parms %s, Start row %d, rows %d"), parms, srow, mrow);
|
2020-11-28 15:39:15 +00:00
|
|
|
|
|
|
|
if (0 == mrow) { // Default only 8 lines
|
|
|
|
mrow = 8;
|
|
|
|
}
|
|
|
|
if (srow > maxrow) {
|
|
|
|
srow = maxrow - mrow;
|
|
|
|
}
|
|
|
|
if (mrow < (maxrow - srow)) {
|
|
|
|
maxrow = srow + mrow;
|
|
|
|
}
|
|
|
|
|
2021-01-02 11:23:30 +00:00
|
|
|
char log_data[150]; // 020: C7 2B 2E AB 70 E8 09 AE C8 88 3D EA 7C FF 48 2F 0E A7 D7 BF 02 0E D7 7D C9 6F B9 3A 1D 01 3F 28 | +. p = | H/ } o : ?(|
|
2020-11-28 15:39:15 +00:00
|
|
|
for (row = srow; row < maxrow; row++) {
|
|
|
|
idx = row * CFG_COLS;
|
2022-01-03 13:02:18 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%08X:"), start + idx);
|
2020-11-28 15:39:15 +00:00
|
|
|
for (col = 0; col < CFG_COLS; col++) {
|
|
|
|
if (!(col%4)) {
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data);
|
2020-11-28 15:39:15 +00:00
|
|
|
}
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, buffer[idx + col]);
|
2020-11-28 15:39:15 +00:00
|
|
|
}
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s |"), log_data);
|
2020-11-28 15:39:15 +00:00
|
|
|
for (col = 0; col < CFG_COLS; col++) {
|
|
|
|
// if (!(col%4)) {
|
2020-12-23 17:26:15 +00:00
|
|
|
// snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data);
|
2020-11-28 15:39:15 +00:00
|
|
|
// }
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' ');
|
2020-11-28 15:39:15 +00:00
|
|
|
}
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data);
|
|
|
|
AddLogData(LOG_LEVEL_INFO, log_data);
|
2020-11-28 15:39:15 +00:00
|
|
|
delay(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 15:26:40 +00:00
|
|
|
void DebugCfgDump(char* parms)
|
|
|
|
{
|
2020-12-23 17:26:15 +00:00
|
|
|
uint32_t CFG_COLS = 16;
|
2018-12-16 15:26:40 +00:00
|
|
|
|
|
|
|
uint16_t idx;
|
|
|
|
uint16_t maxrow;
|
|
|
|
uint16_t row;
|
|
|
|
uint16_t col;
|
|
|
|
char *p;
|
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
uint8_t *buffer = (uint8_t *) Settings;
|
|
|
|
maxrow = ((sizeof(TSettings)+CFG_COLS)/CFG_COLS);
|
2018-12-16 15:26:40 +00:00
|
|
|
|
|
|
|
uint16_t srow = strtol(parms, &p, 16) / CFG_COLS;
|
|
|
|
uint16_t mrow = strtol(p, &p, 10);
|
|
|
|
|
2021-01-23 16:10:06 +00:00
|
|
|
// AddLog(LOG_LEVEL_DEBUG, PSTR("Cnfg: Parms %s, Start row %d, rows %d"), parms, srow, mrow);
|
2018-12-16 15:26:40 +00:00
|
|
|
|
|
|
|
if (0 == mrow) { // Default only 8 lines
|
|
|
|
mrow = 8;
|
|
|
|
}
|
|
|
|
if (srow > maxrow) {
|
|
|
|
srow = maxrow - mrow;
|
|
|
|
}
|
|
|
|
if (mrow < (maxrow - srow)) {
|
|
|
|
maxrow = srow + mrow;
|
|
|
|
}
|
|
|
|
|
2021-01-02 11:23:30 +00:00
|
|
|
char log_data[100]; // 020: 6D 75 73 31 3A 38 30 2F 61 70 69 2F 61 72 64 75 |mus1:80/api/ardu|
|
2018-12-16 15:26:40 +00:00
|
|
|
for (row = srow; row < maxrow; row++) {
|
|
|
|
idx = row * CFG_COLS;
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%03X:"), idx);
|
2018-12-16 15:26:40 +00:00
|
|
|
for (col = 0; col < CFG_COLS; col++) {
|
|
|
|
if (!(col%4)) {
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data);
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, buffer[idx + col]);
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s |"), log_data);
|
2018-12-16 15:26:40 +00:00
|
|
|
for (col = 0; col < CFG_COLS; col++) {
|
|
|
|
// if (!(col%4)) {
|
2020-12-23 17:26:15 +00:00
|
|
|
// snprintf_P(log_data, sizeof(log_data), PSTR("%s "), log_data);
|
2018-12-16 15:26:40 +00:00
|
|
|
// }
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' ');
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data);
|
|
|
|
AddLogData(LOG_LEVEL_INFO, log_data);
|
2018-12-16 15:26:40 +00:00
|
|
|
delay(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugCfgPeek(char* parms)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
uint16_t address = strtol(parms, &p, 16);
|
2021-06-11 17:14:12 +01:00
|
|
|
if (address > sizeof(TSettings)) address = sizeof(TSettings) -4;
|
2018-12-16 15:26:40 +00:00
|
|
|
address = (address >> 2) << 2;
|
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
uint8_t *buffer = (uint8_t *) Settings;
|
2018-12-16 15:26:40 +00:00
|
|
|
uint8_t data8 = buffer[address];
|
|
|
|
uint16_t data16 = (buffer[address +1] << 8) + buffer[address];
|
|
|
|
uint32_t data32 = (buffer[address +3] << 24) + (buffer[address +2] << 16) + data16;
|
|
|
|
|
2021-01-02 11:23:30 +00:00
|
|
|
char log_data[100]; // 000: 09 12 00 10 | | 0x09 (9), 0x1209 (4617), 0x10001209 (268440073)
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%03X:"), address);
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < 4; i++) {
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s %02X"), log_data, buffer[address +i]);
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s |"), log_data);
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < 4; i++) {
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[address +i] > 0x20) && (buffer[address +i] < 0x7F)) ? (char)buffer[address +i] : ' ');
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
2020-12-23 17:26:15 +00:00
|
|
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s| 0x%02X (%d), 0x%04X (%d), 0x%0LX (%lu)"), log_data, data8, data8, data16, data16, data32, data32);
|
|
|
|
AddLogData(LOG_LEVEL_INFO, log_data);
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DebugCfgPoke(char* parms)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
uint16_t address = strtol(parms, &p, 16);
|
2021-06-11 17:14:12 +01:00
|
|
|
if (address > sizeof(TSettings)) address = sizeof(TSettings) -4;
|
2018-12-16 15:26:40 +00:00
|
|
|
address = (address >> 2) << 2;
|
|
|
|
|
|
|
|
uint32_t data = strtol(p, &p, 16);
|
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
uint8_t *buffer = (uint8_t *) Settings;
|
2018-12-16 15:26:40 +00:00
|
|
|
uint32_t data32 = (buffer[address +3] << 24) + (buffer[address +2] << 16) + (buffer[address +1] << 8) + buffer[address];
|
|
|
|
|
|
|
|
uint8_t *nbuffer = (uint8_t *) &data;
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < 4; i++) { buffer[address +i] = nbuffer[+i]; }
|
2018-12-16 15:26:40 +00:00
|
|
|
|
|
|
|
uint32_t ndata32 = (buffer[address +3] << 24) + (buffer[address +2] << 16) + (buffer[address +1] << 8) + buffer[address];
|
|
|
|
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("%03X: 0x%0LX (%lu) poked to 0x%0LX (%lu)"), address, data32, data32, ndata32, ndata32);
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetFlashMode(uint8_t mode)
|
|
|
|
{
|
2020-04-16 13:59:01 +01:00
|
|
|
#ifdef ESP8266
|
2018-12-16 15:26:40 +00:00
|
|
|
uint8_t *_buffer;
|
|
|
|
uint32_t address;
|
|
|
|
|
|
|
|
address = 0;
|
|
|
|
_buffer = new uint8_t[FLASH_SECTOR_SIZE];
|
|
|
|
|
|
|
|
if (ESP.flashRead(address, (uint32_t*)_buffer, FLASH_SECTOR_SIZE)) {
|
|
|
|
if (_buffer[2] != mode) { // DOUT
|
|
|
|
_buffer[2] = mode;
|
2019-08-03 14:25:16 +01:00
|
|
|
if (ESP.flashEraseSector(address / FLASH_SECTOR_SIZE)) {
|
|
|
|
ESP.flashWrite(address, (uint32_t*)_buffer, FLASH_SECTOR_SIZE);
|
|
|
|
}
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
delete[] _buffer;
|
2020-04-16 13:59:01 +01:00
|
|
|
#endif // ESP8266
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
|
|
|
|
2019-08-03 14:25:16 +01:00
|
|
|
/*********************************************************************************************\
|
|
|
|
* Commands
|
|
|
|
\*********************************************************************************************/
|
2018-12-16 15:26:40 +00:00
|
|
|
|
2019-08-03 14:25:16 +01:00
|
|
|
void CmndHelp(void)
|
2018-12-16 15:26:40 +00:00
|
|
|
{
|
2021-06-05 10:47:09 +01:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("HLP: %s"), kDebugCommands);
|
2019-08-03 14:25:16 +01:00
|
|
|
ResponseCmndDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndRtcDump(void)
|
|
|
|
{
|
|
|
|
DebugRtcDump(XdrvMailbox.data);
|
|
|
|
ResponseCmndDone();
|
|
|
|
}
|
|
|
|
|
2022-01-03 13:02:18 +00:00
|
|
|
void CmndMemDump(void) {
|
|
|
|
// MemDump 0x3fff1aa8 200
|
|
|
|
if (XdrvMailbox.payload >= 0) {
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
uint32_t start = strtol(XdrvMailbox.data, &p, 16);
|
|
|
|
uint32_t size = strtol(p, &p, 10);
|
|
|
|
if (0 == size) { size = 32; }
|
|
|
|
DebugDump(start, size);
|
|
|
|
}
|
|
|
|
ResponseCmndDone();
|
|
|
|
}
|
|
|
|
|
2019-08-03 14:25:16 +01:00
|
|
|
void CmndCfgDump(void)
|
|
|
|
{
|
|
|
|
DebugCfgDump(XdrvMailbox.data);
|
|
|
|
ResponseCmndDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndCfgPeek(void)
|
|
|
|
{
|
|
|
|
DebugCfgPeek(XdrvMailbox.data);
|
|
|
|
ResponseCmndDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndCfgPoke(void)
|
|
|
|
{
|
|
|
|
DebugCfgPoke(XdrvMailbox.data);
|
|
|
|
ResponseCmndDone();
|
|
|
|
}
|
2018-12-16 15:26:40 +00:00
|
|
|
|
2022-11-11 09:44:56 +00:00
|
|
|
#ifdef ESP8266
|
|
|
|
#ifdef UMM_INLINE_METRICS
|
|
|
|
void CmndShowHeap(void) {
|
|
|
|
system_show_malloc();
|
|
|
|
ResponseCmndDone();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2018-12-16 15:26:40 +00:00
|
|
|
#ifdef USE_WEBSERVER
|
2019-08-03 14:25:16 +01:00
|
|
|
void CmndCfgXor(void)
|
|
|
|
{
|
|
|
|
if (XdrvMailbox.data_len > 0) {
|
2021-05-24 15:52:59 +01:00
|
|
|
config_xor_on_set = XdrvMailbox.payload;
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
2020-05-19 10:15:31 +01:00
|
|
|
char temp[10];
|
2021-05-24 15:52:59 +01:00
|
|
|
snprintf_P(temp, sizeof(temp), PSTR("0x%02X"), config_xor_on_set);
|
2020-05-19 10:15:31 +01:00
|
|
|
ResponseCmndChar(temp);
|
2019-08-03 14:25:16 +01:00
|
|
|
}
|
2018-12-16 15:26:40 +00:00
|
|
|
#endif // USE_WEBSERVER
|
2019-08-03 14:25:16 +01:00
|
|
|
|
2018-12-16 15:26:40 +00:00
|
|
|
#ifdef DEBUG_THEO
|
2019-08-03 14:25:16 +01:00
|
|
|
void CmndException(void)
|
|
|
|
{
|
|
|
|
if (XdrvMailbox.data_len > 0) { ExceptionTest(XdrvMailbox.payload); }
|
|
|
|
ResponseCmndDone();
|
|
|
|
}
|
2018-12-16 15:26:40 +00:00
|
|
|
#endif // DEBUG_THEO
|
2019-08-03 14:25:16 +01:00
|
|
|
|
|
|
|
void CmndCpuCheck(void)
|
|
|
|
{
|
|
|
|
if (XdrvMailbox.data_len > 0) {
|
|
|
|
CPU_load_check = XdrvMailbox.payload;
|
|
|
|
CPU_last_millis = CPU_last_loop_time;
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
2019-08-03 14:25:16 +01:00
|
|
|
ResponseCmndNumber(CPU_load_check);
|
|
|
|
}
|
|
|
|
|
2020-05-11 14:27:29 +01:00
|
|
|
void CmndSerBufSize(void)
|
|
|
|
{
|
|
|
|
if (XdrvMailbox.data_len > 0) {
|
|
|
|
Serial.setRxBufferSize(XdrvMailbox.payload);
|
|
|
|
}
|
|
|
|
#ifdef ESP8266
|
|
|
|
ResponseCmndNumber(Serial.getRxBufferSize());
|
2020-11-28 15:39:15 +00:00
|
|
|
#endif // ESP8266
|
|
|
|
#ifdef ESP32
|
2020-05-11 14:27:29 +01:00
|
|
|
ResponseCmndDone();
|
2020-11-28 15:39:15 +00:00
|
|
|
#endif // ESP32
|
2020-05-11 14:27:29 +01:00
|
|
|
}
|
|
|
|
|
2019-08-03 14:25:16 +01:00
|
|
|
void CmndFreemem(void)
|
|
|
|
{
|
|
|
|
if (XdrvMailbox.data_len > 0) {
|
|
|
|
CPU_show_freemem = XdrvMailbox.payload;
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
2019-08-03 14:25:16 +01:00
|
|
|
ResponseCmndNumber(CPU_show_freemem);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndFlashMode(void)
|
|
|
|
{
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 3)) {
|
|
|
|
SetFlashMode(XdrvMailbox.payload);
|
|
|
|
}
|
|
|
|
ResponseCmndNumber(ESP.getFlashChipMode());
|
2018-12-16 15:26:40 +00:00
|
|
|
}
|
|
|
|
|
2019-08-05 15:45:13 +01:00
|
|
|
uint32_t DebugSwap32(uint32_t x) {
|
|
|
|
return ((x << 24) & 0xff000000 ) |
|
|
|
|
((x << 8) & 0x00ff0000 ) |
|
|
|
|
((x >> 8) & 0x0000ff00 ) |
|
|
|
|
((x >> 24) & 0x000000ff );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndFlashDump(void)
|
|
|
|
{
|
2020-04-16 13:59:01 +01:00
|
|
|
#ifdef ESP8266
|
2019-08-05 15:45:13 +01:00
|
|
|
// FlashDump
|
|
|
|
// FlashDump 0xFF000
|
|
|
|
// FlashDump 0xFC000 10
|
|
|
|
const uint32_t flash_start = 0x40200000; // Start address flash
|
|
|
|
const uint8_t bytes_per_cols = 0x20;
|
2021-01-22 10:54:15 +00:00
|
|
|
const uint32_t max = (EEPROM_LOCATION + 5) * SPI_FLASH_SEC_SIZE; // 0x100000 for 1M flash, 0x400000 for 4M flash
|
2019-08-05 15:45:13 +01:00
|
|
|
|
|
|
|
uint32_t start = flash_start;
|
|
|
|
uint32_t rows = 8;
|
|
|
|
|
|
|
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= (max - bytes_per_cols))) {
|
|
|
|
start += (XdrvMailbox.payload &0x7FFFFFFC); // Fix exception as flash access is only allowed on 4 byte boundary
|
|
|
|
|
|
|
|
char *p;
|
|
|
|
uint32_t is_payload = strtol(XdrvMailbox.data, &p, 16);
|
|
|
|
rows = strtol(p, &p, 10);
|
|
|
|
if (0 == rows) { rows = 8; }
|
|
|
|
}
|
|
|
|
uint32_t end = start + (rows * bytes_per_cols);
|
|
|
|
if ((end - flash_start) > max) {
|
|
|
|
end = flash_start + max;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t pos = start; pos < end; pos += bytes_per_cols) {
|
|
|
|
uint32_t* values = (uint32_t*)(pos);
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("%06X: %08X %08X %08X %08X %08X %08X %08X %08X"), pos - flash_start,
|
2019-08-05 15:45:13 +01:00
|
|
|
DebugSwap32(values[0]), DebugSwap32(values[1]), DebugSwap32(values[2]), DebugSwap32(values[3]),
|
|
|
|
DebugSwap32(values[4]), DebugSwap32(values[5]), DebugSwap32(values[6]), DebugSwap32(values[7]));
|
|
|
|
}
|
|
|
|
ResponseCmndDone();
|
2020-04-16 13:59:01 +01:00
|
|
|
#endif // ESP8266
|
2019-08-05 15:45:13 +01:00
|
|
|
}
|
|
|
|
|
2019-11-19 22:15:44 +00:00
|
|
|
#ifdef USE_I2C
|
2019-10-06 15:39:11 +01:00
|
|
|
void CmndI2cWrite(void)
|
|
|
|
{
|
|
|
|
// I2cWrite <address>,<data>..
|
2020-10-30 11:29:48 +00:00
|
|
|
if (TasmotaGlobal.i2c_enabled) {
|
2019-10-06 15:39:11 +01:00
|
|
|
char* parms = XdrvMailbox.data;
|
|
|
|
uint8_t buffer[100];
|
|
|
|
uint32_t index = 0;
|
|
|
|
|
|
|
|
char *p;
|
|
|
|
char *data = strtok_r(parms, " ,", &p);
|
|
|
|
while (data != NULL && index < sizeof(buffer)) {
|
|
|
|
buffer[index++] = strtol(data, nullptr, 16);
|
|
|
|
data = strtok_r(nullptr, " ,", &p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index > 1) {
|
2022-11-11 10:47:11 +00:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("DBG: CmndI2cWrite %*_H"), index, buffer);
|
2019-10-06 15:39:11 +01:00
|
|
|
|
|
|
|
Wire.beginTransmission(buffer[0]);
|
|
|
|
for (uint32_t i = 1; i < index; i++) {
|
|
|
|
Wire.write(buffer[i]);
|
|
|
|
}
|
|
|
|
int result = Wire.endTransmission();
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("I2C: Result %d"), result);
|
2019-10-06 15:39:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ResponseCmndDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndI2cRead(void)
|
|
|
|
{
|
|
|
|
// I2cRead <address>,<size>
|
2020-10-30 11:29:48 +00:00
|
|
|
if (TasmotaGlobal.i2c_enabled) {
|
2019-10-06 15:39:11 +01:00
|
|
|
char* parms = XdrvMailbox.data;
|
|
|
|
uint8_t buffer[100];
|
|
|
|
uint32_t index = 0;
|
|
|
|
|
|
|
|
char *p;
|
|
|
|
char *data = strtok_r(parms, " ,", &p);
|
|
|
|
while (data != NULL && index < sizeof(buffer)) {
|
|
|
|
buffer[index++] = strtol(data, nullptr, 16);
|
|
|
|
data = strtok_r(nullptr, " ,", &p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index > 0) {
|
|
|
|
uint8_t size = 1;
|
|
|
|
if (index > 1) {
|
|
|
|
size = buffer[1];
|
|
|
|
}
|
|
|
|
Wire.requestFrom(buffer[0], size);
|
|
|
|
index = 0;
|
|
|
|
while (Wire.available() && index < sizeof(buffer)) {
|
|
|
|
buffer[index++] = Wire.read();
|
|
|
|
}
|
|
|
|
if (index > 0) {
|
2022-11-11 10:47:11 +00:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("DBG: CmndI2cRead %*_H"), index, buffer);
|
2019-10-06 15:39:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ResponseCmndDone();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CmndI2cStretch(void)
|
|
|
|
{
|
2020-04-16 13:59:01 +01:00
|
|
|
#ifdef ESP8266
|
2020-10-30 11:29:48 +00:00
|
|
|
if (TasmotaGlobal.i2c_enabled && (XdrvMailbox.payload > 0)) {
|
2019-10-06 15:39:11 +01:00
|
|
|
Wire.setClockStretchLimit(XdrvMailbox.payload);
|
|
|
|
}
|
|
|
|
ResponseCmndDone();
|
2020-04-16 13:59:01 +01:00
|
|
|
#endif // ESP8266
|
2019-10-06 15:39:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CmndI2cClock(void)
|
|
|
|
{
|
2020-10-30 11:29:48 +00:00
|
|
|
if (TasmotaGlobal.i2c_enabled && (XdrvMailbox.payload > 0)) {
|
2019-10-06 15:39:11 +01:00
|
|
|
Wire.setClock(XdrvMailbox.payload);
|
|
|
|
}
|
|
|
|
ResponseCmndDone();
|
|
|
|
}
|
2019-11-19 22:15:44 +00:00
|
|
|
#endif // USE_I2C
|
2019-10-06 15:39:11 +01:00
|
|
|
|
2023-03-17 20:05:51 +00:00
|
|
|
void CmndSoSet(void) {
|
|
|
|
// Set option data as 32-bit hex value
|
|
|
|
// SoSet1 0x5400401B
|
|
|
|
if ((XdrvMailbox.index >= 1) && (XdrvMailbox.index <= 5)) {
|
|
|
|
uint32_t option = XdrvMailbox.index;
|
|
|
|
uint32_t data;
|
|
|
|
switch (option) {
|
|
|
|
case 1:
|
|
|
|
data = Settings->flag.data; // SetOption0 .. 31
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
data = Settings->flag3.data; // SetOption50 .. 81
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
data = Settings->flag4.data; // SetOption82 .. 113
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
data = Settings->flag5.data; // SetOption114 .. 145
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
data = Settings->flag6.data; // SetOption146 .. 177
|
|
|
|
}
|
|
|
|
if (XdrvMailbox.data_len > 0) {
|
|
|
|
char *p;
|
|
|
|
data = strtoul(XdrvMailbox.data, &p, 0); // decimal, octal (0) or hex (0x)
|
|
|
|
switch (option) {
|
|
|
|
case 1:
|
|
|
|
Settings->flag.data = data; // SetOption0 .. 31
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
Settings->flag3.data = data; // SetOption50 .. 81
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
Settings->flag4.data = data; // SetOption82 .. 113
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
Settings->flag5.data = data; // SetOption114 .. 145
|
|
|
|
break;
|
|
|
|
case 5: Settings->flag6.data = data; // SetOption146 .. 177
|
|
|
|
}
|
|
|
|
// TasmotaGlobal.restart_flag = 2; // Activate some SetOptions
|
|
|
|
}
|
|
|
|
Response_P(PSTR("{\"%s%d\":\"%08X\"}"), XdrvMailbox.command, XdrvMailbox.index, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 15:26:40 +00:00
|
|
|
/*********************************************************************************************\
|
|
|
|
* Interface
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2022-11-11 09:44:56 +00:00
|
|
|
bool Xdrv127(uint32_t function)
|
2018-12-16 15:26:40 +00:00
|
|
|
{
|
2019-01-28 13:08:33 +00:00
|
|
|
bool result = false;
|
2018-12-16 15:26:40 +00:00
|
|
|
|
|
|
|
switch (function) {
|
|
|
|
case FUNC_LOOP:
|
|
|
|
CpuLoadLoop();
|
|
|
|
break;
|
2019-08-03 14:25:16 +01:00
|
|
|
case FUNC_FREE_MEM:
|
|
|
|
if (CPU_show_freemem) { DebugFreeMem(); }
|
|
|
|
break;
|
2019-03-30 12:03:45 +00:00
|
|
|
case FUNC_PRE_INIT:
|
|
|
|
CPU_last_millis = millis();
|
|
|
|
break;
|
2018-12-16 15:26:40 +00:00
|
|
|
case FUNC_COMMAND:
|
2019-08-03 14:25:16 +01:00
|
|
|
result = DecodeCommand(kDebugCommands, DebugCommand);
|
2018-12-16 15:26:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_DEBUG_DRIVER
|