initial command line and tuyamcu demo to play around with - it's able to send a time (hardcoded) packet to TH06 and the time shows up on the LCD

This commit is contained in:
openshwprojects
2022-03-04 11:31:42 +01:00
parent 40bdb68d13
commit f98e5e79a8
11 changed files with 247 additions and 67 deletions

View File

@ -4,6 +4,7 @@
#include "../new_pins.h"
#include "../new_cfg.h"
#include "../ota/ota.h"
#include "../new_cmd.h"
#ifdef WINDOWS
// nothing
@ -612,75 +613,49 @@ int http_fn_flash_read_tool(http_request_t *request) {
poststr(request, NULL);
return 0;
}
#if PLATFORM_BK7231T | PLATFORM_BK7231N
void test_ty_read_uart_data_to_buffer(int port, void* param)
{
int rc = 0;
while((rc = uart_read_byte(port)) != -1)
{
// if(__ty_uart_read_data_size(port) < (ty_uart[port].buf_len-1))
// {
// ty_uart[port].buf[ty_uart[port].in++] = rc;
/// if(ty_uart[port].in >= ty_uart[port].buf_len){
/// ty_uart[port].in = 0;
/// }
// }
}
}
#endif
#if PLATFORM_BK7231T | PLATFORM_BK7231N
#include "../../beken378/func/user_driver/BkDriverUart.h"
#endif
void TuyaMCU_Bridge_InitUART(int baud) {
#if PLATFORM_BK7231T | PLATFORM_BK7231N
bk_uart_config_t config;
config.baud_rate = 9600;
config.data_width = 0x03;
config.parity = 0; //0:no parity,1:odd,2:even
config.stop_bits = 0; //0:1bit,1:2bit
config.flow_control = 0; //FLOW_CTRL_DISABLED
config.flags = 0;
bk_uart_initialize(0, &config, NULL);
bk_uart_set_rx_callback(0, test_ty_read_uart_data_to_buffer, NULL);
#else
int http_fn_cmd_tool(http_request_t *request) {
int res;
int rem;
int now;
int nowOfs;
int hex;
int i;
char tmpA[128];
char tmpB[64];
http_setup(request, httpMimeTypeHTML);
poststr(request,htmlHeader);
poststr(request,g_header);
poststr(request,"<h4>Command Tool</h4>");
if( http_getArg(request->url,"cmd",tmpA,sizeof(tmpA))) {
i = CMD_ExecuteCommand(tmpA);
if(i == 0) {
poststr(request,"Command not found");
} else {
poststr(request,"Executed");
}
poststr(request,"<br>");
}
poststr(request,"<form action=\"/cmd_tool\">");
poststr(request,"<label for=\"cmd\">cmd:</label><br>\
<input type=\"text\" id=\"cmd\" name=\"cmd\" ");
hprintf128(request,"value=\"%s\">",tmpA);
poststr(request,"<br><br>\
<input type=\"submit\" value=\"Submit\">\
</form> ");
poststr(request,htmlReturnToCfg);
HTTP_AddBuildFooter(request);
poststr(request,htmlEnd);
#endif
}
void TuyaMCU_Bridge_SendUARTByte(byte b) {
#if PLATFORM_BK7231T | PLATFORM_BK7231N
bk_send_byte(0, b);
#elif WINDOWS
// STUB - for testing
printf("%02X", b);
#else
#endif
poststr(request, NULL);
return 0;
}
void TuyaMCU_Send(byte *data, int size) {
int i;
unsigned char check_sum;
TuyaMCU_Bridge_InitUART(9600);
check_sum = 0;
for(i = 0; i < size; i++) {
byte b = data[i];
check_sum += b;
TuyaMCU_Bridge_SendUARTByte(b);
}
TuyaMCU_Bridge_SendUARTByte(check_sum);
printf("\nWe sent %i bytes to Tuya MCU\n",size+1);
}
int http_fn_uart_tool(http_request_t *request) {
char tmpA[256];
byte results[128];
@ -876,7 +851,7 @@ int http_fn_cfg(http_request_t *request) {
poststr(request,"<form action=\"cfg_webapp\"><input type=\"submit\" value=\"Configure Webapp\"/></form>");
poststr(request,"<form action=\"cfg_ha\"><input type=\"submit\" value=\"Generate Home Assistant cfg\"/></form>");
poststr(request,"<form action=\"ota\"><input type=\"submit\" value=\"OTA (update software by WiFi)\"/></form>");
poststr(request,"<form action=\"cmd_single\"><input type=\"submit\" value=\"Execute custom command\"/></form>");
poststr(request,"<form action=\"cmd_tool\"><input type=\"submit\" value=\"Execute custom command\"/></form>");
poststr(request,"<form action=\"flash_read_tool\"><input type=\"submit\" value=\"Flash Read Tool\"/></form>");
poststr(request,"<form action=\"uart_tool\"><input type=\"submit\" value=\"UART Tool\"/></form>");

View File

@ -14,6 +14,7 @@ int http_fn_cfg_loglevel_set(http_request_t *request);
int http_fn_cfg_wifi(http_request_t *request);
int http_fn_cfg_mac(http_request_t *request);
int http_fn_flash_read_tool(http_request_t *request);
int http_fn_cmd_tool(http_request_t *request);
int http_fn_uart_tool(http_request_t *request);
int http_fn_cfg_quick(http_request_t *request);
int http_fn_cfg_ha(http_request_t *request);

View File

@ -511,6 +511,7 @@ int HTTP_ProcessPacket(http_request_t *request) {
if(http_checkUrlBase(urlStr,"flash_read_tool")) return http_fn_flash_read_tool(request);
if(http_checkUrlBase(urlStr,"uart_tool")) return http_fn_uart_tool(request);
if(http_checkUrlBase(urlStr,"cmd_tool")) return http_fn_cmd_tool(request);
if(http_checkUrlBase(urlStr,"config_dump_table")) return http_fn_config_dump_table(request);
if(http_checkUrlBase(urlStr,"cfg_quick")) return http_fn_cfg_quick(request);