mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-05 06:45:40 +00:00
fix EOL whitespace
This commit is contained in:
@ -17,10 +17,10 @@ static int CMD_SetChannel(const void *context, const char *cmd, const char *args
|
||||
ADDLOG_INFO(LOG_FEATURE_CMD, "CMD_SetChannel: command requires 2 arguments");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
ch = Tokenizer_GetArgInteger(0);
|
||||
val = Tokenizer_GetArgInteger(1);
|
||||
|
||||
|
||||
CHANNEL_Set(ch,val, false);
|
||||
|
||||
return 1;
|
||||
@ -37,7 +37,7 @@ static int CMD_AddChannel(const void *context, const char *cmd, const char *args
|
||||
ADDLOG_INFO(LOG_FEATURE_CMD, "CMD_AddChannel: command requires 2 arguments (next 2, min and max, are optionsl)");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
ch = Tokenizer_GetArgInteger(0);
|
||||
val = Tokenizer_GetArgInteger(1);
|
||||
if(Tokenizer_GetArgsCount() == 4) {
|
||||
@ -50,7 +50,7 @@ static int CMD_AddChannel(const void *context, const char *cmd, const char *args
|
||||
} else {
|
||||
CHANNEL_Add(ch,val);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -66,11 +66,11 @@ static int CMD_ClampChannel(const void *context, const char *cmd, const char *ar
|
||||
ADDLOG_INFO(LOG_FEATURE_CMD, "CMD_ClampChannel: command requires 3 arguments");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
ch = Tokenizer_GetArgInteger(0);
|
||||
min = Tokenizer_GetArgInteger(1);
|
||||
max = Tokenizer_GetArgInteger(2);
|
||||
|
||||
|
||||
CHANNEL_AddClamped(ch,0, min, max);
|
||||
|
||||
return 1;
|
||||
@ -89,10 +89,10 @@ static int CMD_SetPinRole(const void *context, const char *cmd, const char *args
|
||||
ADDLOG_INFO(LOG_FEATURE_CMD, "CMD_SetPinRole: command requires 2 arguments");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
pin = Tokenizer_GetArgInteger(0);
|
||||
role = Tokenizer_GetArg(1);
|
||||
|
||||
|
||||
roleIndex = PIN_ParsePinRoleName(role);
|
||||
if(roleIndex == IOR_Total_Options) {
|
||||
ADDLOG_INFO(LOG_FEATURE_CMD, "CMD_SetPinRole: This role is not known");
|
||||
@ -114,10 +114,10 @@ static int CMD_SetPinChannel(const void *context, const char *cmd, const char *a
|
||||
ADDLOG_INFO(LOG_FEATURE_CMD, "CMD_SetPinChannel: command requires 2 arguments");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
pin = Tokenizer_GetArgInteger(0);
|
||||
ch = Tokenizer_GetArgInteger(1);
|
||||
|
||||
|
||||
PIN_SetPinChannelForPinIndex(pin,ch);
|
||||
|
||||
return 1;
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
// addEventHandler OnClick 5 setChannel 4 1
|
||||
// This will set event handler for event name "OnClick" for pin number 5, and the executed event command will be "setChannel 4 1"
|
||||
// addEventHandler OnHold 5 addChannel 4 10
|
||||
// addEventHandler OnHold 5 addChannel 4 10
|
||||
// As above, but it will require a button hold and it will add value 10 to channel 4 (it will add a value to PWM, PWM channels are <0,100> range)
|
||||
|
||||
//
|
||||
@ -35,18 +35,18 @@ setPinChannel 11 0
|
||||
setPinRole 26 PWM
|
||||
setPinChannel 26 1
|
||||
addEventHandler OnClick 10 setChannel 1 100
|
||||
addEventHandler OnHold 10 addChannel 1 10
|
||||
addEventHandler OnHold 10 addChannel 1 10
|
||||
addEventHandler OnClick 11 setChannel 1 0
|
||||
addEventHandler OnHold 11 addChannel 1 -10
|
||||
addEventHandler OnHold 11 addChannel 1 -10
|
||||
|
||||
//
|
||||
// On change listeners
|
||||
// On change listeners
|
||||
// Full example of on change listeners:
|
||||
// addChangeHandler Channel0 < 50 echo value is low
|
||||
// addChangeHandler Current > 100 setChannel 0 0
|
||||
// addChangeHandler Power > 40 setChannel 1 0
|
||||
//
|
||||
//
|
||||
//
|
||||
// LCD demo:
|
||||
// backlog startDriver I2C; addI2CDevice_LCD_PCF8574 I2C1 0x23 0 0 0
|
||||
// addChangeHandler Channel1 != 0 backlog lcd_clearAndGoto I2C1 0x23 1 1; lcd_print I2C1 0x23 Enabled
|
||||
@ -179,7 +179,7 @@ void EventHandlers_ProcessVariableChange_Integer(byte eventCode, int oldValue, i
|
||||
struct eventHandler_s *ev;
|
||||
|
||||
ev = g_eventHandlers;
|
||||
|
||||
|
||||
while(ev) {
|
||||
if(eventCode==ev->eventCode) {
|
||||
if(EVENT_EvaluateChangeCondition(ev->eventType, ev->requiredArgument, oldValue, newValue)) {
|
||||
@ -206,7 +206,7 @@ void EventHandlers_FireEvent(byte eventCode, int argument) {
|
||||
struct eventHandler_s *ev;
|
||||
|
||||
ev = g_eventHandlers;
|
||||
|
||||
|
||||
while(ev) {
|
||||
if(eventCode==ev->eventCode) {
|
||||
if(argument == ev->requiredArgument) {
|
||||
@ -216,7 +216,7 @@ void EventHandlers_FireEvent(byte eventCode, int argument) {
|
||||
}
|
||||
ev = ev->next;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static int CMD_AddEventHandler(const void *context, const char *cmd, const char *args, int cmdFlags){
|
||||
@ -234,17 +234,17 @@ static int CMD_AddEventHandler(const void *context, const char *cmd, const char
|
||||
ADDLOG_INFO(LOG_FEATURE_EVENT, "CMD_AddEventHandler: command requires 3 arguments");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
eventName = Tokenizer_GetArg(0);
|
||||
reqArg = Tokenizer_GetArgInteger(1);
|
||||
cmdToCall = Tokenizer_GetArgFrom(2);
|
||||
|
||||
|
||||
eventCode = EVENT_ParseEventName(eventName);
|
||||
if(eventCode == CMD_EVENT_NONE) {
|
||||
ADDLOG_INFO(LOG_FEATURE_EVENT, "CMD_AddEventHandler: %s is not a valid event",eventName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
ADDLOG_INFO(LOG_FEATURE_EVENT, "CMD_AddEventHandler: added %s with cmd %s",eventName,cmdToCall);
|
||||
EventHandlers_AddEventHandler_Integer(eventCode,EVENT_DEFAULT,reqArg,cmdToCall);
|
||||
|
||||
@ -268,7 +268,7 @@ static int CMD_AddChangeHandler(const void *context, const char *cmd, const char
|
||||
ADDLOG_INFO(LOG_FEATURE_EVENT, "CMD_AddChangeHandler: command requires 4 arguments");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
eventName = Tokenizer_GetArg(0);
|
||||
relation = Tokenizer_GetArg(1);
|
||||
reqArg = Tokenizer_GetArgInteger(2);
|
||||
@ -285,8 +285,8 @@ static int CMD_AddChangeHandler(const void *context, const char *cmd, const char
|
||||
ADDLOG_INFO(LOG_FEATURE_EVENT, "CMD_AddChangeHandler: %s is not a valid event",eventName);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ADDLOG_INFO(LOG_FEATURE_EVENT, "CMD_AddChangeHandler: added %s with cmd %s",eventName,cmdToCall);
|
||||
EventHandlers_AddEventHandler_Integer(eventCode,relationCode,reqArg,cmdToCall);
|
||||
|
||||
@ -299,9 +299,9 @@ static int CMD_ListEvents(const void *context, const char *cmd, const char *args
|
||||
|
||||
ev = g_eventHandlers;
|
||||
c = 0;
|
||||
|
||||
|
||||
while(ev) {
|
||||
|
||||
|
||||
ADDLOG_INFO(LOG_FEATURE_EVENT, "Event %i has code %i and command %s",c,ev->eventCode,ev->command);
|
||||
ev = ev->next;
|
||||
c++;
|
||||
@ -314,7 +314,7 @@ void EventHandlers_Init() {
|
||||
CMD_RegisterCommand("AddEventHandler", "", CMD_AddEventHandler, "qqqqq0", NULL);
|
||||
CMD_RegisterCommand("AddChangeHandler", "", CMD_AddChangeHandler, "qqqqq0", NULL);
|
||||
CMD_RegisterCommand("listEvents", "", CMD_ListEvents, "qqqqq0", NULL);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ static int CMD_Restart(const void *context, const char *cmd, const char *args, i
|
||||
} else {
|
||||
delaySeconds = atoi(args);
|
||||
}
|
||||
|
||||
|
||||
ADDLOG_INFO(LOG_FEATURE_CMD, "CMD_Restart: will reboot in %i",delaySeconds);
|
||||
|
||||
RESET_ScheduleModuleReset(delaySeconds);
|
||||
@ -62,7 +62,7 @@ void CMD_ListAllCommands(void *userData, void (*callback)(command_t *cmd, void *
|
||||
newCmd = newCmd->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void CMD_RegisterCommand(const char *name, const char *args, commandHandler_t handler, const char *userDesc, void *context) {
|
||||
int hash;
|
||||
@ -134,7 +134,7 @@ int CMD_ExecuteCommandArgs(const char *cmd, const char *args, int cmdFlags) {
|
||||
// not found, so...
|
||||
char nonums[32];
|
||||
// get the complete string up to numbers.
|
||||
//len =
|
||||
//len =
|
||||
get_cmd(cmd, nonums, 32, 1);
|
||||
newCmd = CMD_Find(nonums);
|
||||
if (!newCmd) {
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
// NOTE: there are 2 customization commands
|
||||
// They are not storing the config in flash, if you use them,
|
||||
// please put them in autoexec.bat from LittleFS.
|
||||
// Command 1: led_brightnessMult [floatVal]
|
||||
// Command 1: led_brightnessMult [floatVal]
|
||||
// It sets the multipler for the dimming
|
||||
// Command 2: g_cfg_colorScaleToChannel [floatVal]
|
||||
// It sets the multipler for converting 0-255 range RGB to 0-100 channel value
|
||||
@ -40,7 +40,7 @@
|
||||
int parsePowerArgument(const char *s);
|
||||
|
||||
// In general, LED can be in two modes:
|
||||
// - Temperature (Cool and Warm LEDs are on)
|
||||
// - Temperature (Cool and Warm LEDs are on)
|
||||
// - RGB (R G B LEDs are on)
|
||||
// This is just like in Tuya.
|
||||
// The third mode, "All", was added by me for testing.
|
||||
@ -81,7 +81,7 @@ void apply_smart_light() {
|
||||
|
||||
for(i = 0; i < 5; i++) {
|
||||
float raw, final;
|
||||
|
||||
|
||||
raw = baseColors[i];
|
||||
|
||||
if(g_lightEnableAll) {
|
||||
@ -97,7 +97,7 @@ void apply_smart_light() {
|
||||
final = 0;
|
||||
}
|
||||
} else if(g_lightMode == Light_RGB) {
|
||||
// skip channels 3, 4
|
||||
// skip channels 3, 4
|
||||
if(i >= 3)
|
||||
{
|
||||
final = 0;
|
||||
@ -125,8 +125,8 @@ static int temperature(const void *context, const char *cmd, const char *args, i
|
||||
tmp = atoi(args);
|
||||
|
||||
g_lightMode = Light_Temperature;
|
||||
// the slider control in the UI emits values
|
||||
//in the range from 154-500 (defined
|
||||
// the slider control in the UI emits values
|
||||
//in the range from 154-500 (defined
|
||||
//in homeassistant/util/color.py as HASS_COLOR_MIN and HASS_COLOR_MAX).
|
||||
|
||||
f = (tmp - 154);
|
||||
|
||||
@ -37,7 +37,7 @@ enum EventCode {
|
||||
|
||||
|
||||
// must be lower than 256
|
||||
CMD_EVENT_MAX_TYPES
|
||||
CMD_EVENT_MAX_TYPES
|
||||
};
|
||||
|
||||
// cmd_tokenizer.c
|
||||
|
||||
@ -30,9 +30,9 @@ static int power(const void *context, const char *cmd, const char *args, int cmd
|
||||
channel = atoi(cmd+5);
|
||||
}
|
||||
#if 0
|
||||
// it seems that my Home Assistant expects RGB etc light bulbs to be turned off entirely
|
||||
// it seems that my Home Assistant expects RGB etc light bulbs to be turned off entirely
|
||||
// with this commands with no arguments, so... no arguments = set all channels?
|
||||
else
|
||||
else
|
||||
{
|
||||
CHANNEL_SetAll(iVal, false);
|
||||
return 1;
|
||||
@ -223,4 +223,4 @@ int taslike_commands_init(){
|
||||
CMD_RegisterCommand("backlog", "", cmnd_backlog, "run a sequence of ; separated commands", NULL);
|
||||
CMD_RegisterCommand("exec", "", cmnd_lfsexec, "exec <file> - run autoexec.bat or other file from LFS if present", NULL);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,9 +48,9 @@ static int addcmd(const void * context, const char *cmd, const char *args, int c
|
||||
os_free(names[index]);
|
||||
}
|
||||
cmds[index] = os_malloc(strlen(args)+1);
|
||||
|
||||
|
||||
strcpy(cmds[index], args);
|
||||
//len =
|
||||
//len =
|
||||
get_cmd(args, cmd, 32, 1);
|
||||
names[index] = os_malloc(strlen(cmd)+1);
|
||||
strcpy(names[index], cmd);
|
||||
|
||||
@ -21,8 +21,8 @@
|
||||
|
||||
|
||||
int GPIO_NRG_SEL = 24; // pwm4
|
||||
int GPIO_HLW_CF = 7;
|
||||
int GPIO_NRG_CF1 = 8;
|
||||
int GPIO_HLW_CF = 7;
|
||||
int GPIO_NRG_CF1 = 8;
|
||||
|
||||
bool g_sel = true;
|
||||
uint32_t res_v = 0;
|
||||
@ -118,12 +118,12 @@ int BL0937_CurrentSet(const void *context, const char *cmd, const char *args, in
|
||||
return 0;
|
||||
}
|
||||
void BL0937_Init() {
|
||||
|
||||
|
||||
HAL_PIN_Setup_Output(GPIO_NRG_SEL);
|
||||
HAL_PIN_SetOutputValue(GPIO_NRG_SEL, g_sel);
|
||||
|
||||
HAL_PIN_Setup_Input_Pullup(GPIO_NRG_CF1);
|
||||
|
||||
|
||||
gpio_int_enable(GPIO_NRG_CF1,IRQ_TRIGGER_FALLING_EDGE,HlwCf1Interrupt);
|
||||
|
||||
HAL_PIN_Setup_Input_Pullup(GPIO_HLW_CF);
|
||||
|
||||
@ -85,12 +85,12 @@ int BL0942_TryToGetNextBL0942Packet() {
|
||||
return 1;
|
||||
}
|
||||
//startDriver BL0942
|
||||
raw_unscaled_current = (UART_GetNextByte(3) << 16) | (UART_GetNextByte(2) << 8) | UART_GetNextByte(1);
|
||||
raw_unscaled_voltage = (UART_GetNextByte(6) << 16) | (UART_GetNextByte(5) << 8) | UART_GetNextByte(4);
|
||||
raw_unscaled_power = (UART_GetNextByte(12) << 24) | (UART_GetNextByte(11) << 16) | (UART_GetNextByte(10) << 8);
|
||||
raw_unscaled_current = (UART_GetNextByte(3) << 16) | (UART_GetNextByte(2) << 8) | UART_GetNextByte(1);
|
||||
raw_unscaled_voltage = (UART_GetNextByte(6) << 16) | (UART_GetNextByte(5) << 8) | UART_GetNextByte(4);
|
||||
raw_unscaled_power = (UART_GetNextByte(12) << 24) | (UART_GetNextByte(11) << 16) | (UART_GetNextByte(10) << 8);
|
||||
raw_unscaled_power = (raw_unscaled_power >> 8);
|
||||
|
||||
raw_unscaled_freq = (UART_GetNextByte(17) << 8) | UART_GetNextByte(16);
|
||||
raw_unscaled_freq = (UART_GetNextByte(17) << 8) | UART_GetNextByte(16);
|
||||
|
||||
// those are not values like 230V, but unscaled
|
||||
//addLogAdv(LOG_INFO, LOG_FEATURE_BL0942,"Unscaled current %d, voltage %d, power %d, freq %d\n", raw_unscaled_current, raw_unscaled_voltage,raw_unscaled_power,raw_unscaled_freq);
|
||||
@ -116,7 +116,7 @@ int BL0942_TryToGetNextBL0942Packet() {
|
||||
#endif
|
||||
|
||||
UART_ConsumeBytes(BL0942_PACKET_LEN);
|
||||
|
||||
|
||||
return BL0942_PACKET_LEN;
|
||||
}
|
||||
|
||||
|
||||
@ -20,9 +20,9 @@ enum {
|
||||
OBK_NUM_MEASUREMENTS,
|
||||
};
|
||||
|
||||
// Current values
|
||||
// Current values
|
||||
float lastReadings[OBK_NUM_MEASUREMENTS];
|
||||
//
|
||||
//
|
||||
// Variables below are for optimization
|
||||
// We can't send a full MQTT update every second.
|
||||
// It's too much for Beken, and it's too much for LWIP 2 MQTT library,
|
||||
@ -35,13 +35,13 @@ float lastSentValues[OBK_NUM_MEASUREMENTS];
|
||||
// how much update frames has passed without sending MQTT update of read values?
|
||||
int noChangeFrames[OBK_NUM_MEASUREMENTS];
|
||||
// how much of value have to change in order to be send over MQTT again?
|
||||
int changeSendThresholds[OBK_NUM_MEASUREMENTS] = {
|
||||
int changeSendThresholds[OBK_NUM_MEASUREMENTS] = {
|
||||
0.25f, // voltage - OBK_VOLTAGE
|
||||
0.002f, // current - OBK_CURRENT
|
||||
0.25f, // power - OBK_POWER
|
||||
};
|
||||
// how are they called in MQTT
|
||||
const char *mqttNames[OBK_NUM_MEASUREMENTS] = {
|
||||
const char *mqttNames[OBK_NUM_MEASUREMENTS] = {
|
||||
"voltage",
|
||||
"current",
|
||||
"power"
|
||||
|
||||
@ -22,13 +22,13 @@ typedef struct driver_s {
|
||||
|
||||
// startDriver BL0937
|
||||
static driver_t g_drivers[] = {
|
||||
{ "TuyaMCU", TuyaMCU_Init, TuyaMCU_RunFrame, NULL, false },
|
||||
{ "NTP", NTP_Init, NTP_OnEverySecond, NULL, false },
|
||||
{ "I2C", DRV_I2C_Init, DRV_I2C_EverySecond, NULL, false },
|
||||
{ "BL0942", BL0942_Init, BL0942_RunFrame, BL0942_AppendInformationToHTTPIndexPage, false },
|
||||
{ "BL0937", BL0937_Init, BL0937_RunFrame, NULL, false },
|
||||
{ "TuyaMCU", TuyaMCU_Init, TuyaMCU_RunFrame, NULL, false },
|
||||
{ "NTP", NTP_Init, NTP_OnEverySecond, NULL, false },
|
||||
{ "I2C", DRV_I2C_Init, DRV_I2C_EverySecond, NULL, false },
|
||||
{ "BL0942", BL0942_Init, BL0942_RunFrame, BL0942_AppendInformationToHTTPIndexPage, false },
|
||||
{ "BL0937", BL0937_Init, BL0937_RunFrame, NULL, false },
|
||||
#if PLATFORM_BEKEN
|
||||
{ "DGR", DRV_DGR_Init, DRV_DGR_RunFrame, NULL, false },
|
||||
{ "DGR", DRV_DGR_Init, DRV_DGR_RunFrame, NULL, false },
|
||||
#endif
|
||||
};
|
||||
static int g_numDrivers = sizeof(g_drivers)/sizeof(g_drivers[0]);
|
||||
@ -55,7 +55,7 @@ int DRV_Start(const void *context, const char *cmd, const char *args, int cmdFla
|
||||
|
||||
for(i = 0; i < g_numDrivers; i++) {
|
||||
if(!stricmp(g_drivers[i].name,name)) {
|
||||
if(g_drivers[i].bLoaded){
|
||||
if(g_drivers[i].bLoaded){
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_NTP,"Drv %s is already loaded.\n",name);
|
||||
return 1;
|
||||
|
||||
@ -89,14 +89,14 @@ void DRV_AppendInformationToHTTPIndexPage(http_request_t *request) {
|
||||
int c_active = 0;
|
||||
|
||||
for(i = 0; i < g_numDrivers; i++) {
|
||||
if(g_drivers[i].bLoaded){
|
||||
if(g_drivers[i].bLoaded){
|
||||
c_active++;
|
||||
if(g_drivers[i].appendInformationToHTTPIndexPage) {
|
||||
g_drivers[i].appendInformationToHTTPIndexPage(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
hprintf128(request,"<h5>%i drivers active, total %i</h5>",c_active,g_numDrivers);
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
// NTP client
|
||||
// Based on my previous work here:
|
||||
// Based on my previous work here:
|
||||
// https://www.elektroda.pl/rtvforum/topic3712112.html
|
||||
|
||||
#include "../new_common.h"
|
||||
@ -74,7 +74,7 @@ void NTP_Init() {
|
||||
|
||||
unsigned int NTP_GetCurrentTime() {
|
||||
return g_time;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NTP_Shutdown() {
|
||||
@ -166,7 +166,7 @@ void NTP_CheckForReceive() {
|
||||
#else
|
||||
recv_len = recv(g_ntp_socket, ptr, i, 0);
|
||||
#endif
|
||||
|
||||
|
||||
if(recv_len < 0){
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_NTP,"NTP_CheckForReceive: Error while receiving server's msg\n");
|
||||
return;
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/inet.h"
|
||||
|
||||
const char* group = "239.255.250.250";
|
||||
const char* group = "239.255.250.250";
|
||||
int port = 4447;
|
||||
//
|
||||
//int DRV_DGR_CreateSocket_Send() {
|
||||
@ -52,11 +52,11 @@ void DRV_DGR_CreateSocket_Receive() {
|
||||
return ;
|
||||
}
|
||||
|
||||
if(broadcast)
|
||||
if(broadcast)
|
||||
{
|
||||
|
||||
iResult = setsockopt(g_dgr_socket, SOL_SOCKET, SO_BROADCAST, (char *)&flag, sizeof(flag));
|
||||
if (iResult != 0)
|
||||
if (iResult != 0)
|
||||
{
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_DGR,"failed to do setsockopt SO_BROADCAST\n");
|
||||
return ;
|
||||
@ -93,7 +93,7 @@ void DRV_DGR_CreateSocket_Receive() {
|
||||
// return 1;
|
||||
//}
|
||||
|
||||
if(broadcast)
|
||||
if(broadcast)
|
||||
{
|
||||
|
||||
}
|
||||
@ -121,7 +121,7 @@ void DRV_DGR_CreateSocket_Receive() {
|
||||
}
|
||||
void DRV_DGR_RunFrame() {
|
||||
struct sockaddr_in addr;
|
||||
|
||||
|
||||
if(g_dgr_socket==0) {
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_DGR,"no sock\n");
|
||||
return ;
|
||||
@ -165,12 +165,12 @@ void DRV_DGR_RunFrame() {
|
||||
// OSStatus err = kNoErr;
|
||||
//
|
||||
//
|
||||
// err = rtos_create_thread( &g_dgr_thread, BEKEN_APPLICATION_PRIORITY,
|
||||
// "DGR_server",
|
||||
// err = rtos_create_thread( &g_dgr_thread, BEKEN_APPLICATION_PRIORITY,
|
||||
// "DGR_server",
|
||||
// (beken_thread_function_t)DRV_DGR_Thread,
|
||||
// 0x100,
|
||||
// (beken_thread_arg_t)0 );
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
||||
void DRV_DGR_Init()
|
||||
@ -179,7 +179,7 @@ void DRV_DGR_Init()
|
||||
DRV_DGR_StartThread();
|
||||
#else
|
||||
DRV_DGR_CreateSocket_Receive();
|
||||
|
||||
|
||||
lwip_fcntl(g_dgr_socket, F_SETFL,O_NONBLOCK);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -190,7 +190,7 @@ int UART_TryToGetNextTuyaPacket(byte *out, int maxSize) {
|
||||
byte a, b, version, command, lena, lenb;
|
||||
char printfSkipDebug[256];
|
||||
char buffer2[8];
|
||||
|
||||
|
||||
printfSkipDebug[0] = 0;
|
||||
|
||||
cs = UART_GetDataSize();
|
||||
@ -435,7 +435,7 @@ int TuyaMCU_Send_Hex(const void *context, const char *cmd, const char *args, int
|
||||
while(*args) {
|
||||
byte b;
|
||||
b = hexbyte(args);
|
||||
|
||||
|
||||
UART_SendByte(b);
|
||||
|
||||
args += 2;
|
||||
@ -449,7 +449,7 @@ int TuyaMCU_LinkTuyaMCUOutputToChannel(const void *context, const char *cmd, con
|
||||
int dpType;
|
||||
int channelID;
|
||||
|
||||
// linkTuyaMCUOutputToChannel dpId varType channelID
|
||||
// linkTuyaMCUOutputToChannel dpId varType channelID
|
||||
Tokenizer_TokenizeString(args);
|
||||
|
||||
if(Tokenizer_GetArgsCount() < 3) {
|
||||
@ -698,7 +698,7 @@ void TuyaMCU_ParseStateMessage(const byte *data, int len) {
|
||||
int dataType;
|
||||
|
||||
ofs = 0;
|
||||
|
||||
|
||||
while(ofs + 4 < len) {
|
||||
sectorLen = data[ofs + 2] << 8 | data[ofs + 3];
|
||||
fnId = data[ofs];
|
||||
@ -713,7 +713,7 @@ void TuyaMCU_ParseStateMessage(const byte *data, int len) {
|
||||
// apply to channels
|
||||
TuyaMCU_ApplyMapping(fnId,iVal);
|
||||
}
|
||||
if(sectorLen == 4) {
|
||||
if(sectorLen == 4) {
|
||||
int iVal = data[ofs + 4] << 24 | data[ofs + 5] << 16 | data[ofs + 6] << 8 | data[ofs + 7];
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_TUYAMCU,"TuyaMCU_ParseStateMessage: raw data 4 int: %i\n",iVal);
|
||||
// apply to channels
|
||||
@ -848,7 +848,7 @@ void TuyaMCU_Init()
|
||||
// https://github.com/esphome/feature-requests/issues/497
|
||||
/// 55AA 00 08 000C 00 02 02 02 02 02 02 01 01 0001 01 23
|
||||
/// head vr id size FL YY MM DD HH MM SS ID TP SIZE VL CK
|
||||
/// 55AA 00 08 000C 00 01 01 01 01 01 01 03 04 0001 02 23
|
||||
/// 55AA 00 08 000C 00 01 01 01 01 01 01 03 04 0001 02 23
|
||||
// TP = 0x01 bool 1 Value range: 0x00/0x01.
|
||||
// TP = 0x04 enum 1 Enumeration type, ranging from 0 to 255.
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ int UART_GetDataSize()
|
||||
}else {
|
||||
remain_buf_size = g_recvBufIn + g_recvBufSize - g_recvBufOut;
|
||||
}
|
||||
|
||||
|
||||
return remain_buf_size;
|
||||
}
|
||||
byte UART_GetNextByte(int index) {
|
||||
@ -56,7 +56,7 @@ void UART_ConsumeBytes(int idx) {
|
||||
}
|
||||
|
||||
void UART_AppendByteToCircularBuffer(int rc) {
|
||||
if(UART_GetDataSize() < (g_recvBufSize-1))
|
||||
if(UART_GetDataSize() < (g_recvBufSize-1))
|
||||
{
|
||||
g_recvBuf[g_recvBufIn++] = rc;
|
||||
if(g_recvBufIn >= g_recvBufSize){
|
||||
@ -68,7 +68,7 @@ void UART_AppendByteToCircularBuffer(int rc) {
|
||||
void test_ty_read_uart_data_to_buffer(int port, void* param)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
|
||||
while((rc = uart_read_byte(port)) != -1)
|
||||
{
|
||||
UART_AppendByteToCircularBuffer(rc);
|
||||
|
||||
@ -63,7 +63,7 @@ int bekken_hal_flash_read(const unsigned int addr, void *dst, const unsigned int
|
||||
flash_handle = ddev_open(FLASH_DEV_NAME, &status, 0);
|
||||
ddev_read(flash_handle, dst, size, addr);
|
||||
ddev_close(flash_handle);
|
||||
|
||||
|
||||
hal_flash_unlock();
|
||||
|
||||
return 0;
|
||||
@ -87,7 +87,7 @@ int HAL_Configuration_SaveConfigMemory(void *src, int dataLen){
|
||||
|
||||
if (dataLen > flashlen){
|
||||
ADDLOG_ERROR(LOG_FEATURE_CFG, "HAL_Configuration_SaveConfigMemory - table too big - can't save");
|
||||
if (taken == pdTRUE)
|
||||
if (taken == pdTRUE)
|
||||
xSemaphoreGive( config_mutex );
|
||||
return 0;
|
||||
}
|
||||
@ -102,7 +102,7 @@ int HAL_Configuration_SaveConfigMemory(void *src, int dataLen){
|
||||
|
||||
if (taken == pdTRUE)
|
||||
xSemaphoreGive( config_mutex );
|
||||
|
||||
|
||||
ADDLOG_DEBUG(LOG_FEATURE_CFG, "HAL_Configuration_SaveConfigMemory: saved %d bytes to %d", dataLen, flashaddr);
|
||||
return dataLen;
|
||||
}
|
||||
|
||||
@ -4,9 +4,9 @@
|
||||
Design:
|
||||
variables to be small - we want as many writes between erases as possible.
|
||||
sector will be all FF (erased), and data added into it.
|
||||
reading consists of searching the first non FF byte from the end, then
|
||||
reading consists of searching the first non FF byte from the end, then
|
||||
reading the preceding bytes as the variables.
|
||||
last byte of data is len (!== 0xFF!)
|
||||
last byte of data is len (!== 0xFF!)
|
||||
|
||||
*/
|
||||
|
||||
@ -47,13 +47,13 @@ int flash_vars_read(FLASH_VARS_STRUCTURE *data);
|
||||
|
||||
//#define TEST_MODE
|
||||
//#define debug_delay(x) rtos_delay_milliseconds(x)
|
||||
#define debug_delay(x)
|
||||
#define debug_delay(x)
|
||||
|
||||
#define FLASH_VARS_MAGIC 0xfefefefe
|
||||
// NOTE: Changed below according to partitions in SDK!!!!
|
||||
static unsigned int flash_vars_start = 0x1e3000; //0x1e1000 + 0x1000 + 0x1000; // after netconfig and mystery SSID
|
||||
static unsigned int flash_vars_len = 0x2000; // two blocks in BK7231
|
||||
static unsigned int flash_vars_sector_len = 0x1000; // erase size in BK7231
|
||||
static unsigned int flash_vars_len = 0x2000; // two blocks in BK7231
|
||||
static unsigned int flash_vars_sector_len = 0x1000; // erase size in BK7231
|
||||
|
||||
FLASH_VARS_STRUCTURE flash_vars;
|
||||
int flash_vars_offset = 0; // offset to first FF in our area
|
||||
@ -110,8 +110,8 @@ int flash_vars_init(){
|
||||
// there is an EXTRA sctor used for some form of wifi?
|
||||
// on T variety, this is 0x1e3000
|
||||
flash_vars_start = pt->partition_start_addr + pt->partition_length + 0x1000;
|
||||
flash_vars_len = 0x2000; // two blocks in BK7231
|
||||
flash_vars_sector_len = 0x1000; // erase size in BK7231
|
||||
flash_vars_len = 0x2000; // two blocks in BK7231
|
||||
flash_vars_sector_len = 0x1000; // erase size in BK7231
|
||||
#endif
|
||||
//ADDLOG_DEBUG(LOG_FEATURE_CFG, "got part info");
|
||||
debug_delay(200);
|
||||
@ -137,7 +137,7 @@ static int flash_vars_valid(){
|
||||
//uint32_t i;
|
||||
//uint32_t param;
|
||||
UINT32 status;
|
||||
#ifndef TEST_MODE
|
||||
#ifndef TEST_MODE
|
||||
DD_HANDLE flash_hdl;
|
||||
#endif
|
||||
uint32_t start_addr;
|
||||
@ -146,7 +146,7 @@ static int flash_vars_valid(){
|
||||
//ADDLOG_DEBUG(LOG_FEATURE_CFG, "flash_vars_valid()");
|
||||
debug_delay(200);
|
||||
|
||||
#ifndef TEST_MODE
|
||||
#ifndef TEST_MODE
|
||||
flash_hdl = ddev_open(FLASH_DEV_NAME, &status, 0);
|
||||
ASSERT(DD_HANDLE_UNVALID != flash_hdl);
|
||||
bk_flash_enable_security(FLASH_PROTECT_NONE);
|
||||
@ -156,7 +156,7 @@ static int flash_vars_valid(){
|
||||
//ADDLOG_DEBUG(LOG_FEATURE_CFG, "flash_vars_valid() flash open");
|
||||
debug_delay(200);
|
||||
|
||||
#ifdef TEST_MODE
|
||||
#ifdef TEST_MODE
|
||||
os_memcpy(&tmp, &test_flash_area[start_addr - flash_vars_start], sizeof(tmp));
|
||||
#else
|
||||
GLOBAL_INT_DISABLE();
|
||||
@ -187,7 +187,7 @@ static int flash_vars_write_magic(){
|
||||
//uint32_t i;
|
||||
//uint32_t param;
|
||||
UINT32 status;
|
||||
#ifndef TEST_MODE
|
||||
#ifndef TEST_MODE
|
||||
DD_HANDLE flash_hdl;
|
||||
#endif
|
||||
uint32_t start_addr;
|
||||
@ -208,7 +208,7 @@ static int flash_vars_write_magic(){
|
||||
debug_delay(200);
|
||||
return -1;
|
||||
}
|
||||
#ifdef TEST_MODE
|
||||
#ifdef TEST_MODE
|
||||
os_memcpy(&test_flash_area[start_addr - flash_vars_start], &tmp, sizeof(tmp));
|
||||
#else
|
||||
bk_flash_enable_security(FLASH_PROTECT_NONE);
|
||||
@ -248,7 +248,7 @@ int flash_vars_read(FLASH_VARS_STRUCTURE *data){
|
||||
//uint32_t i;
|
||||
//uint32_t param;
|
||||
UINT32 status;
|
||||
#ifndef TEST_MODE
|
||||
#ifndef TEST_MODE
|
||||
DD_HANDLE flash_hdl;
|
||||
#endif
|
||||
uint32_t start_addr;
|
||||
@ -269,7 +269,7 @@ int flash_vars_read(FLASH_VARS_STRUCTURE *data){
|
||||
}
|
||||
debug_delay(200);
|
||||
|
||||
#ifndef TEST_MODE
|
||||
#ifndef TEST_MODE
|
||||
flash_hdl = ddev_open(FLASH_DEV_NAME, &status, 0);
|
||||
ASSERT(DD_HANDLE_UNVALID != flash_hdl);
|
||||
bk_flash_enable_security(FLASH_PROTECT_NONE);
|
||||
@ -278,7 +278,7 @@ int flash_vars_read(FLASH_VARS_STRUCTURE *data){
|
||||
|
||||
do {
|
||||
start_addr -= sizeof(tmp);
|
||||
#ifdef TEST_MODE
|
||||
#ifdef TEST_MODE
|
||||
os_memcpy(&tmp, &test_flash_area[start_addr - flash_vars_start], sizeof(tmp));
|
||||
#else
|
||||
GLOBAL_INT_DISABLE();
|
||||
@ -300,7 +300,7 @@ int flash_vars_read(FLASH_VARS_STRUCTURE *data){
|
||||
os_memset(data, 0, sizeof(*data));
|
||||
// set the len to the latest revision's len
|
||||
data->len = sizeof(*data);
|
||||
#ifndef TEST_MODE
|
||||
#ifndef TEST_MODE
|
||||
ddev_close(flash_hdl);
|
||||
bk_flash_enable_security(FLASH_PROTECT_ALL);
|
||||
#endif
|
||||
@ -319,7 +319,7 @@ int flash_vars_read(FLASH_VARS_STRUCTURE *data){
|
||||
|
||||
if (len > sizeof(*data)){
|
||||
ADDLOG_ERROR(LOG_FEATURE_CFG, "len (%d) in flash_var greater than current structure len (%d)", len, sizeof(*data));
|
||||
#ifndef TEST_MODE
|
||||
#ifndef TEST_MODE
|
||||
ddev_close(flash_hdl);
|
||||
bk_flash_enable_security(FLASH_PROTECT_ALL);
|
||||
#endif
|
||||
@ -330,7 +330,7 @@ int flash_vars_read(FLASH_VARS_STRUCTURE *data){
|
||||
// clear result.
|
||||
os_memset(data, 0, sizeof(*data));
|
||||
// read the DATA portion into the structure
|
||||
#ifdef TEST_MODE
|
||||
#ifdef TEST_MODE
|
||||
os_memcpy(data, &test_flash_area[start_addr - flash_vars_start], len-1);
|
||||
#else
|
||||
GLOBAL_INT_DISABLE();
|
||||
@ -376,8 +376,8 @@ int flash_vars_write(){
|
||||
flash_vars_offset += data->len;
|
||||
alignOffset(&flash_vars_offset);
|
||||
|
||||
ADDLOG_DEBUG(LOG_FEATURE_CFG, "new offset %d, boot_count %d, success count %d",
|
||||
flash_vars_offset,
|
||||
ADDLOG_DEBUG(LOG_FEATURE_CFG, "new offset %d, boot_count %d, success count %d",
|
||||
flash_vars_offset,
|
||||
data->boot_count,
|
||||
data->boot_success_count
|
||||
);
|
||||
@ -394,14 +394,14 @@ int _flash_vars_write(void *data, unsigned int off_set, unsigned int size){
|
||||
//uint32_t i;
|
||||
//uint32_t param;
|
||||
UINT32 status;
|
||||
#ifndef TEST_MODE
|
||||
#ifndef TEST_MODE
|
||||
DD_HANDLE flash_hdl;
|
||||
#endif
|
||||
uint32_t start_addr;
|
||||
GLOBAL_INT_DECLARATION();
|
||||
//ADDLOG_DEBUG(LOG_FEATURE_CFG, "_flash vars write offset %d, size %d", off_set, size);
|
||||
|
||||
#ifndef TEST_MODE
|
||||
#ifndef TEST_MODE
|
||||
flash_hdl = ddev_open(FLASH_DEV_NAME, &status, 0);
|
||||
ASSERT(DD_HANDLE_UNVALID != flash_hdl);
|
||||
bk_flash_enable_security(FLASH_PROTECT_NONE);
|
||||
@ -421,7 +421,7 @@ int _flash_vars_write(void *data, unsigned int off_set, unsigned int size){
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef TEST_MODE
|
||||
#ifdef TEST_MODE
|
||||
os_memcpy(&test_flash_area[start_addr - flash_vars_start], data, size);
|
||||
#else
|
||||
GLOBAL_INT_DISABLE();
|
||||
@ -443,14 +443,14 @@ int flash_vars_erase(unsigned int off_set, unsigned int size){
|
||||
uint32_t i;
|
||||
uint32_t param;
|
||||
UINT32 status;
|
||||
#ifndef TEST_MODE
|
||||
#ifndef TEST_MODE
|
||||
DD_HANDLE flash_hdl;
|
||||
#endif
|
||||
uint32_t start_sector, end_sector;
|
||||
GLOBAL_INT_DECLARATION();
|
||||
ADDLOG_DEBUG(LOG_FEATURE_CFG, "flash vars erase at offset %d len %d", off_set, size);
|
||||
|
||||
#ifndef TEST_MODE
|
||||
#ifndef TEST_MODE
|
||||
flash_hdl = ddev_open(FLASH_DEV_NAME, &status, 0);
|
||||
ASSERT(DD_HANDLE_UNVALID != flash_hdl);
|
||||
bk_flash_enable_security(FLASH_PROTECT_NONE);
|
||||
@ -463,7 +463,7 @@ int flash_vars_erase(unsigned int off_set, unsigned int size){
|
||||
param = flash_vars_start + (i << 12);
|
||||
if (param < flash_vars_start){
|
||||
ADDLOG_ERROR(LOG_FEATURE_CFG, "flash vars erase invalid addr 0x%X < 0x%X", param, flash_vars_start);
|
||||
#ifndef TEST_MODE
|
||||
#ifndef TEST_MODE
|
||||
ddev_close(flash_hdl);
|
||||
bk_flash_enable_security(FLASH_PROTECT_ALL);
|
||||
#endif
|
||||
@ -471,14 +471,14 @@ int flash_vars_erase(unsigned int off_set, unsigned int size){
|
||||
}
|
||||
if (param + flash_vars_sector_len > flash_vars_start + flash_vars_len){
|
||||
ADDLOG_ERROR(LOG_FEATURE_CFG, "flash vars erase invalid addr 0x%X+0x%X > 0x%X", param, flash_vars_sector_len, flash_vars_start + flash_vars_len);
|
||||
#ifndef TEST_MODE
|
||||
#ifndef TEST_MODE
|
||||
ddev_close(flash_hdl);
|
||||
bk_flash_enable_security(FLASH_PROTECT_ALL);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
ADDLOG_DEBUG(LOG_FEATURE_CFG, "flash vars erase block at addr 0x%X", param);
|
||||
#ifdef TEST_MODE
|
||||
#ifdef TEST_MODE
|
||||
os_memset(&test_flash_area[param - flash_vars_start], 0xff, 0x1000);
|
||||
#else
|
||||
GLOBAL_INT_DISABLE();
|
||||
@ -486,7 +486,7 @@ int flash_vars_erase(unsigned int off_set, unsigned int size){
|
||||
GLOBAL_INT_RESTORE();
|
||||
#endif
|
||||
}
|
||||
#ifndef TEST_MODE
|
||||
#ifndef TEST_MODE
|
||||
ddev_close(flash_hdl);
|
||||
bk_flash_enable_security(FLASH_PROTECT_ALL);
|
||||
#endif
|
||||
@ -511,9 +511,9 @@ void HAL_FlashVars_IncreaseBootCount(){
|
||||
flash_vars_write();
|
||||
|
||||
flash_vars_read(&data);
|
||||
ADDLOG_DEBUG(LOG_FEATURE_CFG, "re-read - offset %d, boot count %d, boot success %d, bootfailures %d",
|
||||
flash_vars_offset,
|
||||
data.boot_count,
|
||||
ADDLOG_DEBUG(LOG_FEATURE_CFG, "re-read - offset %d, boot count %d, boot success %d, bootfailures %d",
|
||||
flash_vars_offset,
|
||||
data.boot_count,
|
||||
data.boot_success_count,
|
||||
data.boot_count - data.boot_success_count );
|
||||
#endif
|
||||
@ -530,9 +530,9 @@ void HAL_FlashVars_SaveBootComplete(){
|
||||
flash_vars_write();
|
||||
|
||||
flash_vars_read(&data);
|
||||
ADDLOG_DEBUG(LOG_FEATURE_CFG, "re-read - offset %d, boot count %d, boot success %d, bootfailures %d",
|
||||
flash_vars_offset,
|
||||
data.boot_count,
|
||||
ADDLOG_DEBUG(LOG_FEATURE_CFG, "re-read - offset %d, boot count %d, boot success %d, bootfailures %d",
|
||||
flash_vars_offset,
|
||||
data.boot_count,
|
||||
data.boot_success_count,
|
||||
data.boot_count - data.boot_success_count );
|
||||
#endif
|
||||
@ -552,4 +552,4 @@ int HAL_FlashVars_GetBootCount(){
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -30,7 +30,7 @@ const char *HAL_GetMyIPString(){
|
||||
} else {
|
||||
bk_wlan_get_ip_status(&ipStatus, STATION);
|
||||
}
|
||||
|
||||
|
||||
strcpy(g_IP, ipStatus.ip);
|
||||
return g_IP;
|
||||
}
|
||||
@ -69,10 +69,10 @@ void HAL_PrintNetworkInfo(){
|
||||
|
||||
os_memset(&ipStatus, 0x0, sizeof(IPStatusTypedef));
|
||||
bk_wlan_get_ip_status(&ipStatus, STATION);
|
||||
|
||||
|
||||
char *fmt = "dhcp=%d ip=%s gate=%s mask=%s mac=" MACSTR "\r\n";
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL, fmt ,
|
||||
ipStatus.dhcp, ipStatus.ip, ipStatus.gate,
|
||||
ipStatus.dhcp, ipStatus.ip, ipStatus.gate,
|
||||
ipStatus.mask, MAC2STR((unsigned char*)ipStatus.mac));
|
||||
|
||||
// print wifi state
|
||||
@ -84,7 +84,7 @@ void HAL_PrintNetworkInfo(){
|
||||
#else
|
||||
bk_printf("sta: %d, softap: %d, b/g\r\n",sta_ip_is_start(),uap_ip_is_start());
|
||||
#endif
|
||||
|
||||
|
||||
if( sta_ip_is_start() )
|
||||
{
|
||||
os_memset(&linkStatus, 0x0, sizeof(LinkStatusTypeDef));
|
||||
@ -119,7 +119,7 @@ void HAL_PrintNetworkInfo(){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( uap_ip_is_start() )
|
||||
{
|
||||
os_memset(&ap_info, 0x0, sizeof(network_InitTypeDef_ap_st));
|
||||
@ -152,9 +152,9 @@ void HAL_PrintNetworkInfo(){
|
||||
break;
|
||||
}
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL,"ip=%s,gate=%s,mask=%s,dns=%s\r\n",
|
||||
ap_info.local_ip_addr,
|
||||
ap_info.gateway_ip_addr,
|
||||
ap_info.net_mask,
|
||||
ap_info.local_ip_addr,
|
||||
ap_info.gateway_ip_addr,
|
||||
ap_info.net_mask,
|
||||
ap_info.dns_server_ip_addr);
|
||||
}
|
||||
|
||||
@ -190,13 +190,13 @@ void wl_status( void *ctxt ){
|
||||
g_wifiStatusCallback(WIFI_STA_AUTH_FAILED);
|
||||
}
|
||||
break;
|
||||
case RW_EVT_STA_CONNECTED: /* authentication success */
|
||||
case RW_EVT_STA_GOT_IP:
|
||||
case RW_EVT_STA_CONNECTED: /* authentication success */
|
||||
case RW_EVT_STA_GOT_IP:
|
||||
if(g_wifiStatusCallback!=0) {
|
||||
g_wifiStatusCallback(WIFI_STA_CONNECTED);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
/* for softap mode */
|
||||
case RW_EVT_AP_CONNECTED: /* a client association success */
|
||||
if(g_wifiStatusCallback!=0) {
|
||||
@ -233,12 +233,12 @@ void HAL_ConnectToWiFi(const char *oob_ssid,const char *connect_key)
|
||||
network_InitTypeDef_adv_st wNetConfigAdv;
|
||||
|
||||
os_memset( &wNetConfigAdv, 0x0, sizeof(network_InitTypeDef_adv_st) );
|
||||
|
||||
|
||||
os_strcpy((char*)wNetConfigAdv.ap_info.ssid, oob_ssid);
|
||||
hwaddr_aton("48:ee:0c:48:93:12", (unsigned char *)wNetConfigAdv.ap_info.bssid);
|
||||
wNetConfigAdv.ap_info.security = SECURITY_TYPE_WPA2_MIXED;
|
||||
wNetConfigAdv.ap_info.channel = 5;
|
||||
|
||||
|
||||
os_strcpy((char*)wNetConfigAdv.key, connect_key);
|
||||
wNetConfigAdv.key_len = os_strlen(connect_key);
|
||||
wNetConfigAdv.dhcp_mode = DHCP_CLIENT;
|
||||
@ -247,7 +247,7 @@ void HAL_ConnectToWiFi(const char *oob_ssid,const char *connect_key)
|
||||
bk_wlan_start_sta_adv(&wNetConfigAdv);
|
||||
#else
|
||||
network_InitTypeDef_st network_cfg;
|
||||
|
||||
|
||||
os_memset(&network_cfg, 0x0, sizeof(network_InitTypeDef_st));
|
||||
|
||||
os_strcpy((char *)network_cfg.wifi_ssid, oob_ssid);
|
||||
@ -258,7 +258,7 @@ void HAL_ConnectToWiFi(const char *oob_ssid,const char *connect_key)
|
||||
network_cfg.wifi_retry_interval = 100;
|
||||
|
||||
ADDLOGF_INFO("ssid:%s key:%s\r\n", network_cfg.wifi_ssid, network_cfg.wifi_key);
|
||||
|
||||
|
||||
bk_wlan_start(&network_cfg);
|
||||
#endif
|
||||
}
|
||||
@ -269,25 +269,25 @@ int HAL_SetupWiFiOpenAccessPoint(const char *ssid)
|
||||
#define APP_DRONE_DEF_NET_IP "192.168.4.1"
|
||||
#define APP_DRONE_DEF_NET_MASK "255.255.255.0"
|
||||
#define APP_DRONE_DEF_NET_GW "192.168.4.1"
|
||||
#define APP_DRONE_DEF_CHANNEL 1
|
||||
|
||||
#define APP_DRONE_DEF_CHANNEL 1
|
||||
|
||||
general_param_t general;
|
||||
ap_param_t ap_info;
|
||||
network_InitTypeDef_st wNetConfig;
|
||||
int len;
|
||||
unsigned char *mac;
|
||||
|
||||
|
||||
os_memset(&general, 0, sizeof(general_param_t));
|
||||
os_memset(&ap_info, 0, sizeof(ap_param_t));
|
||||
os_memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_st));
|
||||
|
||||
os_memset(&ap_info, 0, sizeof(ap_param_t));
|
||||
os_memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_st));
|
||||
|
||||
general.role = 1,
|
||||
general.dhcp_enable = 1,
|
||||
|
||||
os_strcpy((char *)wNetConfig.local_ip_addr, APP_DRONE_DEF_NET_IP);
|
||||
os_strcpy((char *)wNetConfig.net_mask, APP_DRONE_DEF_NET_MASK);
|
||||
os_strcpy((char *)wNetConfig.dns_server_ip_addr, APP_DRONE_DEF_NET_GW);
|
||||
|
||||
|
||||
|
||||
ADDLOGF_INFO("no flash configuration, use default\r\n");
|
||||
mac = (unsigned char*)&ap_info.bssid.array;
|
||||
@ -298,10 +298,10 @@ int HAL_SetupWiFiOpenAccessPoint(const char *ssid)
|
||||
ap_info.cipher_suite = 0;
|
||||
//memcpy(ap_info.ssid.array, APP_DRONE_DEF_SSID, os_strlen(APP_DRONE_DEF_SSID));
|
||||
memcpy(ap_info.ssid.array, ssid, os_strlen(ssid));
|
||||
|
||||
|
||||
ap_info.key_len = 0;
|
||||
os_memset(&ap_info.key, 0, 65);
|
||||
|
||||
os_memset(&ap_info.key, 0, 65);
|
||||
|
||||
|
||||
bk_wlan_ap_set_default_channel(ap_info.chann);
|
||||
|
||||
@ -309,18 +309,18 @@ int HAL_SetupWiFiOpenAccessPoint(const char *ssid)
|
||||
|
||||
os_strncpy((char *)wNetConfig.wifi_ssid, (char *)ap_info.ssid.array, sizeof(wNetConfig.wifi_ssid));
|
||||
os_strncpy((char *)wNetConfig.wifi_key, (char *)ap_info.key, sizeof(wNetConfig.wifi_key));
|
||||
|
||||
|
||||
wNetConfig.wifi_mode = SOFT_AP;
|
||||
wNetConfig.dhcp_mode = DHCP_SERVER;
|
||||
wNetConfig.wifi_retry_interval = 100;
|
||||
|
||||
|
||||
if(1) {
|
||||
ADDLOGF_INFO("set ip info: %s,%s,%s\r\n",
|
||||
wNetConfig.local_ip_addr,
|
||||
wNetConfig.net_mask,
|
||||
wNetConfig.dns_server_ip_addr);
|
||||
}
|
||||
|
||||
|
||||
if(1) {
|
||||
ADDLOGF_INFO("ssid:%s key:%s mode:%d\r\n", wNetConfig.wifi_ssid, wNetConfig.wifi_key, wNetConfig.wifi_mode);
|
||||
}
|
||||
@ -343,6 +343,6 @@ int HAL_SetupWiFiOpenAccessPoint(const char *ssid)
|
||||
//dhcp_server_start(0);
|
||||
//dhcp_server_stop(void);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ void HAL_PIN_Setup_Output(int index) {
|
||||
|
||||
void HAL_PIN_PWM_Stop(int index) {
|
||||
int pwm;
|
||||
|
||||
|
||||
pwm = BL_FindPWMForPin(index);
|
||||
|
||||
if(pwm == -1) {
|
||||
@ -55,13 +55,13 @@ void HAL_PIN_PWM_Stop(int index) {
|
||||
|
||||
void HAL_PIN_PWM_Start(int index) {
|
||||
int pwm;
|
||||
|
||||
|
||||
pwm = BL_FindPWMForPin(index);
|
||||
|
||||
if(pwm == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//addLogAdv(LOG_INFO, LOG_FEATURE_MAIN,"HAL_PIN_PWM_Start: pin %i chose pwm %i\r\n",index,pwm);
|
||||
// Frequency must be between 2000 and 800000
|
||||
bl_pwm_init(pwm, index, 2000);
|
||||
|
||||
@ -31,12 +31,12 @@ void HAL_ConnectToWiFi(const char *ssid, const char *psk)
|
||||
g_bAccessPointMode = 0;
|
||||
}
|
||||
int HAL_SetupWiFiOpenAccessPoint(const char *ssid) {
|
||||
|
||||
|
||||
uint8_t hidden_ssid = 0;
|
||||
int channel;
|
||||
wifi_interface_t wifi_interface;
|
||||
struct netif *net;
|
||||
|
||||
|
||||
wifi_interface = wifi_mgmr_ap_enable();
|
||||
/*no password when only one param*/
|
||||
wifi_mgmr_ap_start(wifi_interface, ssid, hidden_ssid, NULL, 1);
|
||||
@ -188,4 +188,4 @@ const char *HAL_GetMACStr(char *macstr) {
|
||||
return macstr;
|
||||
}
|
||||
|
||||
#endif // PLATFORM_BL602
|
||||
#endif // PLATFORM_BL602
|
||||
|
||||
@ -102,7 +102,7 @@ int HAL_Configuration_SaveConfigMemory(void *src, int dataLen){
|
||||
ADDLOG_DEBUG(LOG_FEATURE_CFG, "HAL_Configuration_SaveConfigMemory: fdcm write failed\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
ADDLOG_DEBUG(LOG_FEATURE_CFG, "HAL_Configuration_SaveConfigMemory: saved %d bytes", dataLen);
|
||||
return dataLen;
|
||||
}
|
||||
|
||||
@ -128,5 +128,5 @@ void HAL_PIN_PWM_Update(int index, int value) {
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@ -608,7 +608,7 @@ int httpclient_retrieve_content_old(httpclient_t *client, char *data, int len, u
|
||||
http_wr_to_flash(data,len);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
b_data = os_malloc((TCP_LEN_MAX+1) * sizeof(char));
|
||||
//bk_http_ptr->do_data = 1;
|
||||
//bk_http_ptr->http_total = readLen - len;
|
||||
@ -620,7 +620,7 @@ int httpclient_retrieve_content_old(httpclient_t *client, char *data, int len, u
|
||||
os_memcpy(client_data->response_buf+count, data, templen);
|
||||
client_data->response_buf_filled = count;
|
||||
client_data->response_buf[count] = '\0';
|
||||
client_data->retrieve_len -= templen;
|
||||
client_data->retrieve_len -= templen;
|
||||
} else {
|
||||
client_data->response_buf[client_data->response_buf_len - 1] = '\0';
|
||||
client_data->response_buf_filled = client_data->response_buf_len - 1;
|
||||
@ -653,11 +653,11 @@ int httpclient_retrieve_content_old(httpclient_t *client, char *data, int len, u
|
||||
}
|
||||
}
|
||||
} while (readLen);
|
||||
|
||||
|
||||
//bk_http_ptr->do_data = 0;
|
||||
os_free(b_data);
|
||||
b_data = NULL;
|
||||
|
||||
|
||||
if (client_data->is_chunked) {
|
||||
if (len < 2) {
|
||||
int new_trf_len, ret;
|
||||
@ -873,7 +873,7 @@ iotx_err_t httpclient_recv_response(httpclient_t *client, uint32_t timeout_ms, h
|
||||
|
||||
|
||||
// if is_more is true, we just need to get more data
|
||||
// this will fill response_buf
|
||||
// this will fill response_buf
|
||||
if (client_data->is_more) {
|
||||
client_data->response_buf[0] = '\0';
|
||||
client_data->response_buf_filled = 0;
|
||||
@ -882,9 +882,9 @@ iotx_err_t httpclient_recv_response(httpclient_t *client, uint32_t timeout_ms, h
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
ret = httpclient_retrieve_content(client,
|
||||
buf,
|
||||
reclen,
|
||||
ret = httpclient_retrieve_content(client,
|
||||
buf,
|
||||
reclen,
|
||||
iotx_time_left(&timer), client_data);
|
||||
}
|
||||
|
||||
@ -1131,8 +1131,8 @@ exit:
|
||||
// our async stuff
|
||||
int HTTPClient_Async_SendGeneric(httprequest_t *request){
|
||||
OSStatus err = kNoErr;
|
||||
err = rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY,
|
||||
"httprequest",
|
||||
err = rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY,
|
||||
"httprequest",
|
||||
(beken_thread_function_t)httprequest_thread,
|
||||
0x800,
|
||||
(beken_thread_arg_t)request );
|
||||
@ -1197,10 +1197,10 @@ int HTTPClient_Async_SendGet(const char *url_in){
|
||||
client_data->post_buf = ""; //Sets the user data to be posted.
|
||||
client_data->post_buf_len = 0; //Sets the post data length.
|
||||
client_data->post_content_type = "text/csv"; //Sets the content type.
|
||||
request->data_callback = 0;
|
||||
request->data_callback = 0;
|
||||
request->port = 80;//HTTP_PORT;
|
||||
request->url = url;
|
||||
request->method = HTTPCLIENT_GET;
|
||||
request->method = HTTPCLIENT_GET;
|
||||
request->timeout = 10000;
|
||||
HTTPClient_Async_SendGeneric(request);
|
||||
|
||||
|
||||
@ -134,15 +134,15 @@ typedef struct httprequest_t_tag{
|
||||
* client_data->post_content_type = content_type; //Sets the content type.
|
||||
* request->port = HTTPS_PORT;
|
||||
* request->url = url;
|
||||
* request->method = HTTPCLIENT_POST;
|
||||
* request->method = HTTPCLIENT_POST;
|
||||
* request->timeout = 10000;
|
||||
* request->data_callback = mydatacallback;
|
||||
* request->data_callback = mydatacallback;
|
||||
* HTTPClient_Async_SendGeneric(request);
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* int mydatacallback(httprequest_t *request){
|
||||
* addLog("httpclient callback state %d", request->state);
|
||||
*
|
||||
*
|
||||
* //to terminate, return 1
|
||||
* return 0
|
||||
* }
|
||||
|
||||
@ -202,7 +202,7 @@ int32_t HAL_TCP_Read(uintptr_t fd, char *buf, uint32_t len, uint32_t timeout_ms)
|
||||
|
||||
timeout.tv_sec = t_left / 1000;
|
||||
timeout.tv_usec = (t_left % 1000) * 1000;
|
||||
|
||||
|
||||
ret = select(fd + 1, &sets, NULL, NULL, NULL);
|
||||
if ( FD_ISSET( fd, &sets ) )
|
||||
{
|
||||
@ -217,7 +217,7 @@ int32_t HAL_TCP_Read(uintptr_t fd, char *buf, uint32_t len, uint32_t timeout_ms)
|
||||
// {
|
||||
// http_data_process(buf,ret);
|
||||
// }
|
||||
|
||||
|
||||
len_recv += ret;
|
||||
} else if (0 == ret) {
|
||||
ADDLOG_ERROR(LOG_FEATURE_HTTP_CLIENT,"connection is closed");
|
||||
|
||||
@ -46,5 +46,5 @@ int iotx_net_disconnect(utils_network_pt pNetwork);
|
||||
int iotx_net_connect(utils_network_pt pNetwork);
|
||||
int iotx_net_init(utils_network_pt pNetwork, const char *host, uint16_t port, const char *ca_crt);
|
||||
extern void http_data_process(char *buf, uint32_t len);
|
||||
|
||||
|
||||
#endif /* IOTX_COMMON_NET_H */
|
||||
|
||||
@ -73,7 +73,7 @@ template_t g_templates [] = {
|
||||
int g_total_templates = sizeof(g_templates)/sizeof(g_templates[0]);
|
||||
|
||||
unsigned char hexdigit( char hex ) {
|
||||
return (hex <= '9') ? hex - '0' :
|
||||
return (hex <= '9') ? hex - '0' :
|
||||
toupper((unsigned char)hex) - 'A' + 10 ;
|
||||
}
|
||||
|
||||
@ -333,7 +333,7 @@ int http_fn_cfg_mqtt(http_request_t *request) {
|
||||
poststr(request,"<form action=\"/cfg_mqtt_set\">\
|
||||
<label for=\"host\">Host:</label><br>\
|
||||
<input type=\"text\" id=\"host\" name=\"host\" value=\"");
|
||||
|
||||
|
||||
poststr(request,CFG_GetMQTTHost());
|
||||
poststr(request,"\"><br>\
|
||||
<label for=\"port\">Port:</label><br>\
|
||||
@ -343,7 +343,7 @@ int http_fn_cfg_mqtt(http_request_t *request) {
|
||||
poststr(request,"\"><br><br>\
|
||||
<label for=\"port\">Client:</label><br>\
|
||||
<input type=\"text\" id=\"client\" name=\"client\" value=\"");
|
||||
|
||||
|
||||
poststr(request,CFG_GetMQTTBrokerName());
|
||||
poststr(request,"\"><br>\
|
||||
<label for=\"user\">User:</label><br>\
|
||||
@ -388,7 +388,7 @@ int http_fn_cfg_mqtt_set(http_request_t *request) {
|
||||
CFG_Save_SetupTimer();
|
||||
|
||||
poststr(request,"Please wait for module to connect... if there is problem, restart it from Index html page...");
|
||||
|
||||
|
||||
poststr(request,"<br>");
|
||||
poststr(request,"<a href=\"cfg_mqtt\">Return to MQTT settings</a>");
|
||||
poststr(request,"<br>");
|
||||
@ -410,7 +410,7 @@ int http_fn_cfg_webapp(http_request_t *request) {
|
||||
poststr(request,"<h2> Use this to set the URL of the Webapp</h2>");
|
||||
poststr(request,"<form action=\"/cfg_webapp_set\">\
|
||||
<label for=\"url\">Url:</label><br>\
|
||||
<input type=\"text\" id=\"url\" name=\"url\" value=\"");
|
||||
<input type=\"text\" id=\"url\" name=\"url\" value=\"");
|
||||
poststr(request,CFG_GetWebappRoot());
|
||||
poststr(request,"\"><br>\
|
||||
<input type=\"submit\" value=\"Submit\">\
|
||||
@ -437,7 +437,7 @@ int http_fn_cfg_webapp_set(http_request_t *request) {
|
||||
} else {
|
||||
poststr(request,"Webapp url not set because you didn't specify the argument.");
|
||||
}
|
||||
|
||||
|
||||
poststr(request,"<br>");
|
||||
poststr(request,htmlReturnToCfg);
|
||||
HTTP_AddBuildFooter(request);
|
||||
@ -502,7 +502,7 @@ int http_fn_cfg_ping(http_request_t *request) {
|
||||
<input type=\"text\" id=\"host\" name=\"host\" value=\"");
|
||||
tmp = CFG_GetPingHost();
|
||||
poststr(request,tmp);
|
||||
|
||||
|
||||
/* poststr(request, "\"><br>\
|
||||
<label for=\"pass\">Interval (s) between pings:</label><br>\
|
||||
<input type=\"number\" id=\"interval\" name=\"interval\" value=\"");
|
||||
@ -514,7 +514,7 @@ int http_fn_cfg_ping(http_request_t *request) {
|
||||
<input type=\"number\" id=\"disconnectTime\" name=\"disconnectTime\" value=\"");
|
||||
i = CFG_GetPingDisconnectedSecondsToRestart();
|
||||
hprintf128(request,"%i",i);
|
||||
|
||||
|
||||
poststr(request,"\"><br><br>\
|
||||
<input type=\"submit\" value=\"Submit\" onclick=\"return confirm('Are you sure?')\">\
|
||||
</form> ");
|
||||
@ -562,7 +562,7 @@ int http_fn_cfg_wifi(http_request_t *request) {
|
||||
|
||||
AP_IF_S *ar;
|
||||
uint32_t num;
|
||||
|
||||
|
||||
bk_printf("Scan begin...\r\n");
|
||||
tuya_hal_wifi_all_ap_scan(&ar,&num);
|
||||
bk_printf("Scan returned %i networks\r\n",num);
|
||||
@ -603,13 +603,13 @@ int http_fn_cfg_wifi(http_request_t *request) {
|
||||
<input type=\"text\" id=\"ssid\" name=\"ssid\" value=\"");
|
||||
cur_ssid = CFG_GetWiFiSSID();
|
||||
poststr(request,cur_ssid);
|
||||
|
||||
|
||||
poststr(request, "\"><br>\
|
||||
<label for=\"pass\">Pass:</label><br>\
|
||||
<input type=\"text\" id=\"pass\" name=\"pass\" value=\"");
|
||||
cur_pass = CFG_GetWiFiPass();
|
||||
poststr(request,cur_pass);
|
||||
|
||||
|
||||
poststr(request,"\"><br><br>\
|
||||
<input type=\"submit\" value=\"Submit\" onclick=\"return confirm('Are you sure? Please check SSID and pass twice?')\">\
|
||||
</form> ");
|
||||
@ -629,7 +629,7 @@ int http_fn_cfg_name(http_request_t *request) {
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
poststr(request,htmlHeader);
|
||||
poststr(request,g_header);
|
||||
|
||||
|
||||
poststr(request,"<h2> Change device names for display. </h2> Remember that short name is used by MQTT.<br>");
|
||||
if(http_getArg(request->url,"shortName",tmpA,sizeof(tmpA))) {
|
||||
CFG_SetShortDeviceName(tmpA);
|
||||
@ -643,13 +643,13 @@ int http_fn_cfg_name(http_request_t *request) {
|
||||
<input type=\"text\" id=\"shortName\" name=\"shortName\" value=\"");
|
||||
shortName = CFG_GetShortDeviceName();
|
||||
poststr(request,shortName);
|
||||
|
||||
|
||||
poststr(request, "\"><br>\
|
||||
<label for=\"name\">Full Name:</label><br>\
|
||||
<input type=\"text\" id=\"name\" name=\"name\" value=\"");
|
||||
name = CFG_GetDeviceName();
|
||||
poststr(request,name);
|
||||
|
||||
|
||||
poststr(request,"\"><br><br>\
|
||||
<input type=\"submit\" value=\"Submit\" onclick=\"return confirm('Are you sure? Short name might be used by MQTT, so you will have to reconfig some stuff.')\">\
|
||||
</form> ");
|
||||
@ -684,14 +684,14 @@ int http_fn_cfg_wifi_set(http_request_t *request) {
|
||||
|
||||
poststr(request,"Please wait for module to reset...");
|
||||
RESET_ScheduleModuleReset(3);
|
||||
|
||||
|
||||
poststr(request,"<br>");
|
||||
poststr(request,"<a href=\"cfg_wifi\">Return to WiFi settings</a>");
|
||||
poststr(request,"<br>");
|
||||
poststr(request,htmlReturnToCfg);
|
||||
HTTP_AddBuildFooter(request);
|
||||
poststr(request,htmlEnd);
|
||||
|
||||
|
||||
poststr(request, NULL);
|
||||
return 0;
|
||||
}
|
||||
@ -712,7 +712,7 @@ int http_fn_cfg_loglevel_set(http_request_t *request) {
|
||||
loglevel = atoi(tmpA);
|
||||
#endif
|
||||
poststr(request,"LOG level changed.");
|
||||
}
|
||||
}
|
||||
poststr(request,"<form action=\"/cfg_loglevel_set\">\
|
||||
<label for=\"loglevel\">loglevel:</label><br>\
|
||||
<input type=\"text\" id=\"loglevel\" name=\"loglevel\" value=\"");
|
||||
@ -724,7 +724,7 @@ int http_fn_cfg_loglevel_set(http_request_t *request) {
|
||||
poststr(request,"\"><br><br>\
|
||||
<input type=\"submit\" value=\"Submit\" >\
|
||||
</form> ");
|
||||
|
||||
|
||||
poststr(request,"<br>");
|
||||
poststr(request,"<a href=\"cfg\">Return to config settings</a>");
|
||||
poststr(request,"<br>");
|
||||
@ -848,7 +848,7 @@ int http_fn_flash_read_tool(http_request_t *request) {
|
||||
poststr(request,"<br>");
|
||||
}
|
||||
poststr(request,"<form action=\"/flash_read_tool\">");
|
||||
|
||||
|
||||
poststr(request,"<input type=\"checkbox\" id=\"hex\" name=\"hex\" value=\"1\"");
|
||||
if(hex){
|
||||
poststr(request," checked");
|
||||
@ -935,7 +935,7 @@ int http_fn_startup_command(http_request_t *request) {
|
||||
cmd = CFG_GetShortStartupCommand();
|
||||
|
||||
poststr(request,"<form action=\"/startup_command\">");
|
||||
|
||||
|
||||
poststr(request,"<label for=\"data\">Startup command:</label><br>\
|
||||
<input type=\"text\" id=\"data\" name=\"data\"");
|
||||
hprintf128(request," value=\"%s\" size=\"120\"><br>",cmd);
|
||||
@ -988,7 +988,7 @@ int http_fn_uart_tool(http_request_t *request) {
|
||||
}
|
||||
|
||||
poststr(request,"<form action=\"/uart_tool\">");
|
||||
|
||||
|
||||
poststr(request,"<label for=\"data\">data:</label><br>\
|
||||
<input type=\"text\" id=\"data\" name=\"data\"");
|
||||
hprintf128(request," value=\"%s\" size=\"40\"><br>",tmpA);
|
||||
@ -1029,20 +1029,20 @@ int http_fn_cfg_quick(http_request_t *request) {
|
||||
poststr(request,htmlHeader);
|
||||
poststr(request,g_header);
|
||||
poststr(request,"<h4>Quick Config</h4>");
|
||||
|
||||
|
||||
if(http_getArg(request->url,"dev",tmpA,sizeof(tmpA))) {
|
||||
j = atoi(tmpA);
|
||||
hprintf128(request,"<h3>Set dev %i!</h3>",j);
|
||||
g_templates[j].setter();
|
||||
}
|
||||
poststr(request,"<form action=\"cfg_quick\">");
|
||||
poststr(request,"<form action=\"cfg_quick\">");
|
||||
poststr(request, "<select name=\"dev\">");
|
||||
for(j = 0; j < g_total_templates; j++) {
|
||||
hprintf128(request, "<option value=\"%i\">%s</option>",j,g_templates[j].name);
|
||||
}
|
||||
poststr(request,"</select>");
|
||||
poststr(request,"<input type=\"submit\" value=\"Set\"/></form>");
|
||||
|
||||
|
||||
poststr(request,htmlReturnToCfg);
|
||||
HTTP_AddBuildFooter(request);
|
||||
poststr(request,htmlEnd);
|
||||
@ -1068,7 +1068,7 @@ int http_fn_cfg_ha(http_request_t *request) {
|
||||
poststr(request,"<h4>Paste this to configuration yaml</h4>");
|
||||
poststr(request,"<h5>Make sure that you have \"switch:\" keyword only once! Home Assistant doesn't like dup keywords.</h5>");
|
||||
poststr(request,"<h5>You can also use \"switch MyDeviceName:\" to avoid keyword duplication!</h5>");
|
||||
|
||||
|
||||
poststr(request,"<textarea rows=\"40\" cols=\"50\">");
|
||||
|
||||
for(i = 0; i < PLATFORM_GPIO_MAX; i++) {
|
||||
@ -1139,7 +1139,7 @@ http://<ip>/cm?user=admin&password=joker&cmnd=Power%20Toggle
|
||||
// System responds with state
|
||||
int http_fn_cm(http_request_t *request) {
|
||||
char tmpA[128];
|
||||
|
||||
|
||||
http_setup(request, httpMimeTypeJson);
|
||||
if( http_getArg(request->url,"cmnd",tmpA,sizeof(tmpA))) {
|
||||
CMD_ExecuteCommand(tmpA,COMMAND_FLAG_SOURCE_HTTP);
|
||||
@ -1303,8 +1303,8 @@ int http_fn_cfg_pins(http_request_t *request) {
|
||||
}
|
||||
poststr(request, "</select>");
|
||||
hprintf128(request, "<input name=\"r%i\" type=\"text\" value=\"%i\"/>",i,ch);
|
||||
|
||||
if(si == IOR_Button || si == IOR_Button_n)
|
||||
|
||||
if(si == IOR_Button || si == IOR_Button_n)
|
||||
{
|
||||
// extra param. For button, is relay index to toggle on double click
|
||||
hprintf128(request, "<input name=\"e%i\" type=\"text\" value=\"%i\"/>",i,ch2);
|
||||
|
||||
@ -28,8 +28,8 @@ void HTTPServer_Start()
|
||||
{
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
err = rtos_create_thread( &g_http_thread, BEKEN_APPLICATION_PRIORITY,
|
||||
"TCP_server",
|
||||
err = rtos_create_thread( &g_http_thread, BEKEN_APPLICATION_PRIORITY,
|
||||
"TCP_server",
|
||||
(beken_thread_function_t)tcp_server_thread,
|
||||
0x800,
|
||||
(beken_thread_arg_t)0 );
|
||||
@ -51,7 +51,7 @@ static void tcp_client_thread( beken_thread_arg_t arg )
|
||||
{
|
||||
OSStatus err = kNoErr;
|
||||
int fd = (int) arg;
|
||||
//fd_set readfds, errfds, readfds2;
|
||||
//fd_set readfds, errfds, readfds2;
|
||||
char *buf = NULL;
|
||||
char *reply = NULL;
|
||||
int replyBufferSize = 10000;
|
||||
@ -62,7 +62,7 @@ static void tcp_client_thread( beken_thread_arg_t arg )
|
||||
|
||||
reply = (char*) os_malloc( replyBufferSize );
|
||||
buf = (char*) os_malloc( 1026 );
|
||||
|
||||
|
||||
if ( buf == 0 || reply == 0)
|
||||
{
|
||||
ADDLOG_ERROR(LOG_FEATURE_HTTP, "TCP Client failed to malloc buffer" );
|
||||
@ -101,12 +101,12 @@ static void tcp_client_thread( beken_thread_arg_t arg )
|
||||
rtos_delay_milliseconds(10);
|
||||
|
||||
exit:
|
||||
if ( err != kNoErr )
|
||||
if ( err != kNoErr )
|
||||
ADDLOG_ERROR(LOG_FEATURE_HTTP, "TCP client thread exit with err: %d", err );
|
||||
|
||||
if ( buf != NULL )
|
||||
if ( buf != NULL )
|
||||
os_free( buf );
|
||||
if ( reply != NULL )
|
||||
if ( reply != NULL )
|
||||
os_free( reply );
|
||||
|
||||
lwip_close( fd );;
|
||||
@ -134,9 +134,9 @@ static void tcp_server_thread( beken_thread_arg_t arg )
|
||||
server_addr.sin_addr.s_addr = INADDR_ANY;/* Accept conenction request on all network interface */
|
||||
server_addr.sin_port = htons( HTTP_SERVER_PORT );/* Server listen on port: 20000 */
|
||||
err = bind( tcp_listen_fd, (struct sockaddr *) &server_addr, sizeof(server_addr) );
|
||||
|
||||
|
||||
err = listen( tcp_listen_fd, 0 );
|
||||
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
FD_ZERO( &readfds );
|
||||
@ -164,7 +164,7 @@ static void tcp_server_thread( beken_thread_arg_t arg )
|
||||
tcp_client_thread((beken_thread_arg_t)client_fd);
|
||||
#else
|
||||
// Create separate thread for client
|
||||
if ( kNoErr !=
|
||||
if ( kNoErr !=
|
||||
#if PLATFORM_XR809
|
||||
OS_ThreadCreate(&clientThreadUnused,
|
||||
"HTTP Client",
|
||||
@ -174,14 +174,14 @@ static void tcp_server_thread( beken_thread_arg_t arg )
|
||||
0x400)
|
||||
|
||||
#else
|
||||
rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY,
|
||||
rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY,
|
||||
"HTTP Client",
|
||||
(beken_thread_function_t)tcp_client_thread,
|
||||
0x800,
|
||||
0x800,
|
||||
(beken_thread_arg_t)client_fd )
|
||||
|
||||
|
||||
#endif
|
||||
)
|
||||
)
|
||||
{
|
||||
ADDLOG_DEBUG(LOG_FEATURE_HTTP, "TCP Client %s:%d thread creation failed! fd: %d", client_ip_str, client_addr.sin_port, client_fd );
|
||||
lwip_close( client_fd );
|
||||
@ -191,10 +191,10 @@ static void tcp_server_thread( beken_thread_arg_t arg )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( err != kNoErr )
|
||||
|
||||
if ( err != kNoErr )
|
||||
ADDLOG_ERROR(LOG_FEATURE_HTTP, "Server listerner thread exit with err: %d", err );
|
||||
|
||||
|
||||
lwip_close( tcp_listen_fd );
|
||||
|
||||
rtos_delete_thread( NULL );
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
#include "../new_common.h"
|
||||
#include "../logging/logging.h"
|
||||
#include "ctype.h"
|
||||
#include "ctype.h"
|
||||
#include "new_http.h"
|
||||
#include "http_fns.h"
|
||||
#include "../new_pins.h"
|
||||
@ -86,7 +86,7 @@ int HTTP_RegisterCallback( const char *url, int method, http_callback_fn callbac
|
||||
strcpy(callbacks[numCallbacks]->url, url);
|
||||
callbacks[numCallbacks]->callback = callback;
|
||||
callbacks[numCallbacks]->method = method;
|
||||
|
||||
|
||||
numCallbacks++;
|
||||
|
||||
// success
|
||||
@ -94,7 +94,7 @@ int HTTP_RegisterCallback( const char *url, int method, http_callback_fn callbac
|
||||
}
|
||||
|
||||
int my_strnicmp(char *a, char *b, int len){
|
||||
int i;
|
||||
int i;
|
||||
for (i = 0; i < len; i++){
|
||||
char x = *a;
|
||||
char y = *b;
|
||||
@ -490,7 +490,7 @@ int HTTP_ProcessPacket(http_request_t *request) {
|
||||
} while(1);
|
||||
|
||||
request->bodystart = p;
|
||||
request->bodylen = request->receivedLen - (p - request->received);
|
||||
request->bodylen = request->receivedLen - (p - request->received);
|
||||
|
||||
// look for a callback with this URL and method, or HTTP_ANY
|
||||
for (i = 0; i < numCallbacks; i++){
|
||||
@ -513,7 +513,7 @@ int HTTP_ProcessPacket(http_request_t *request) {
|
||||
if(http_checkUrlBase(urlStr,"cfg_mqtt_set")) return http_fn_cfg_mqtt_set(request);
|
||||
|
||||
if(http_checkUrlBase(urlStr,"cfg_webapp")) return http_fn_cfg_webapp(request);
|
||||
if(http_checkUrlBase(urlStr,"cfg_webapp_set")) return http_fn_cfg_webapp_set(request);
|
||||
if(http_checkUrlBase(urlStr,"cfg_webapp_set")) return http_fn_cfg_webapp_set(request);
|
||||
|
||||
if(http_checkUrlBase(urlStr,"cfg_wifi")) return http_fn_cfg_wifi(request);
|
||||
if(http_checkUrlBase(urlStr,"cfg_name")) return http_fn_cfg_name(request);
|
||||
|
||||
@ -22,7 +22,7 @@ extern const char *g_build_str;
|
||||
|
||||
|
||||
|
||||
#define MAX_QUERY 16
|
||||
#define MAX_QUERY 16
|
||||
#define MAX_HEADERS 16
|
||||
typedef struct http_request_tag {
|
||||
char *received; // partial or whole received data, up to 1024
|
||||
@ -75,4 +75,4 @@ typedef int (*http_callback_fn)(http_request_t *request);
|
||||
// urls must be unique (i.e. you can't have /about and /aboutme or /about/me)
|
||||
int HTTP_RegisterCallback( const char *url, int method, http_callback_fn callback);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -76,7 +76,7 @@ void init_rest(){
|
||||
HTTP_RegisterCallback( "/favicon.ico", HTTP_GET, http_favicon);
|
||||
}
|
||||
|
||||
const char *apppage1 =
|
||||
const char *apppage1 =
|
||||
"<!DOCTYPE html>"
|
||||
"<html>"
|
||||
" <head>"
|
||||
@ -116,7 +116,7 @@ const char * apppage4 = "startup.js\"></script>"
|
||||
|
||||
static int http_rest_get(http_request_t *request){
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "GET of %s", request->url);
|
||||
|
||||
|
||||
if (!strcmp(request->url, "api/channels")){
|
||||
return http_rest_get_channels(request);
|
||||
}
|
||||
@ -164,9 +164,9 @@ static int http_rest_get(http_request_t *request){
|
||||
if (!strncmp(request->url, "api/testflashvars", 17)){
|
||||
return http_rest_get_flash_vars_test(request);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
http_setup(request, httpMimeTypeHTML);
|
||||
poststr(request, "GET of ");
|
||||
@ -210,7 +210,7 @@ static int http_rest_post(http_request_t *request){
|
||||
if (!strcmp(request->url, "api/cmnd")){
|
||||
return http_rest_post_cmd(request);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef BK_LITTLEFS
|
||||
if (!strcmp(request->url, "api/fsblock")){
|
||||
@ -306,7 +306,7 @@ static int http_rest_get_lfs_file(http_request_t *request){
|
||||
memset(file, 0, sizeof(lfs_file_t));
|
||||
|
||||
strcpy(fpath, request->url + strlen("api/lfs/"));
|
||||
|
||||
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "LFS read of %s", fpath);
|
||||
lfsres = lfs_file_open(&lfs, file, fpath, LFS_O_RDONLY);
|
||||
|
||||
@ -334,12 +334,12 @@ static int http_rest_get_lfs_file(http_request_t *request){
|
||||
lfsres = lfs_dir_read(&lfs, dir, &info);
|
||||
if (lfsres > 0){
|
||||
if (count) poststr(request, ",");
|
||||
hprintf128(request, "{\"name\":\"%s\",\"type\":%d,\"size\":%d}",
|
||||
hprintf128(request, "{\"name\":\"%s\",\"type\":%d,\"size\":%d}",
|
||||
info.name, info.type, info.size);
|
||||
} else {
|
||||
if (lfsres < 0){
|
||||
if (count) poststr(request, ",");
|
||||
hprintf128(request, "{\"error\":%d}", lfsres);
|
||||
hprintf128(request, "{\"error\":%d}", lfsres);
|
||||
}
|
||||
}
|
||||
count++;
|
||||
@ -456,7 +456,7 @@ static int http_rest_post_lfs_file(http_request_t *request){
|
||||
towrite = request->contentLength;
|
||||
}
|
||||
//ADDLOG_DEBUG(LOG_FEATURE_API, "bodylen %d, contentlen %d", request->bodylen, request->contentLength);
|
||||
|
||||
|
||||
if (writelen < 0){
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "ABORTED: %d bytes to write", writelen);
|
||||
lfs_file_close(&lfs, file);
|
||||
@ -807,7 +807,7 @@ static int http_rest_post_flash(http_request_t *request, int startaddr){
|
||||
if (request->contentLength >= 0){
|
||||
towrite = request->contentLength;
|
||||
}
|
||||
|
||||
|
||||
if (writelen < 0 || (startaddr + writelen > 0x200000)){
|
||||
ADDLOG_DEBUG(LOG_FEATURE_API, "ABORTED: %d bytes to write", writelen);
|
||||
return http_rest_error(request, -20, "writelen < 0 or end > 0x200000");
|
||||
@ -847,7 +847,7 @@ static int http_rest_post_reboot(http_request_t *request){
|
||||
|
||||
static int http_rest_get_flash_advanced(http_request_t *request){
|
||||
char *params = request->url + 10;
|
||||
int startaddr = 0;
|
||||
int startaddr = 0;
|
||||
int len = 0;
|
||||
int sres;
|
||||
sres = sscanf(params, "%x-%x", &startaddr, &len);
|
||||
@ -859,7 +859,7 @@ static int http_rest_get_flash_advanced(http_request_t *request){
|
||||
|
||||
static int http_rest_post_flash_advanced(http_request_t *request){
|
||||
char *params = request->url + 10;
|
||||
int startaddr = 0;
|
||||
int startaddr = 0;
|
||||
int sres;
|
||||
sres = sscanf(params, "%x", &startaddr);
|
||||
if (sres == 1 && startaddr >= START_ADR_OF_BK_PARTITION_OTA){
|
||||
@ -913,7 +913,7 @@ static int http_rest_get_dumpconfig(http_request_t *request){
|
||||
|
||||
|
||||
|
||||
#ifdef TESTCONFIG_ENABLE
|
||||
#ifdef TESTCONFIG_ENABLE
|
||||
// added for OpenBK7231T
|
||||
typedef struct item_new_test_config
|
||||
{
|
||||
@ -922,7 +922,7 @@ typedef struct item_new_test_config
|
||||
}ITEM_NEW_TEST_CONFIG,*ITEM_NEW_TEST_CONFIG_PTR;
|
||||
|
||||
ITEM_NEW_TEST_CONFIG testconfig;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static int http_rest_get_testconfig(http_request_t *request){
|
||||
return http_rest_error(request, 400, "unsupported");
|
||||
@ -937,7 +937,7 @@ static int http_rest_get_flash_vars_test(http_request_t *request){
|
||||
//#else
|
||||
//#ifndef DISABLE_FLASH_VARS_VARS
|
||||
// char *params = request->url + 17;
|
||||
// int increment = 0;
|
||||
// int increment = 0;
|
||||
// int len = 0;
|
||||
// int sres;
|
||||
// int i;
|
||||
@ -962,14 +962,14 @@ static int http_rest_get_flash_vars_test(http_request_t *request){
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// sprintf(tmp, "offset %d, boot count %d, boot success %d, bootfailures %d",
|
||||
// flash_vars_offset,
|
||||
// p->boot_count,
|
||||
// sprintf(tmp, "offset %d, boot count %d, boot success %d, bootfailures %d",
|
||||
// flash_vars_offset,
|
||||
// p->boot_count,
|
||||
// p->boot_success_count,
|
||||
// p->boot_count - p->boot_success_count );
|
||||
//
|
||||
// return http_rest_error(request, 200, tmp);
|
||||
//#else
|
||||
//#else
|
||||
return http_rest_error(request, 400, "flash test unsupported");
|
||||
}
|
||||
|
||||
|
||||
@ -353,7 +353,7 @@ void DRV_I2C_LCD_PCF8574_RunDevice(i2cDevice_t *dev)
|
||||
PCF8574_LCD_Clear(lcd);
|
||||
delay_ms(115);
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_I2C,"Testing lcd\n" );
|
||||
|
||||
|
||||
PCF8574_LCD_Write_String(lcd,"OpenBeken BK7231T LCD");
|
||||
delay_ms(115);
|
||||
PCF8574_LCD_Goto(lcd,2,2);
|
||||
|
||||
@ -17,13 +17,13 @@ DD_HANDLE i2c_hdl;
|
||||
void DRV_I2C_Write(byte addr, byte data)
|
||||
{
|
||||
char buff = (char)data;
|
||||
|
||||
|
||||
i2c_operater.op_addr = addr;
|
||||
ddev_write(i2c_hdl, &buff, 1, (UINT32)&i2c_operater);
|
||||
}
|
||||
void DRV_I2C_WriteBytes(byte addr, byte *data, int len) {
|
||||
|
||||
|
||||
|
||||
i2c_operater.op_addr = addr;
|
||||
ddev_write(i2c_hdl, (char*)data, len, (UINT32)&i2c_operater);
|
||||
}
|
||||
@ -31,14 +31,14 @@ void DRV_I2C_WriteBytes(byte addr, byte *data, int len) {
|
||||
//{
|
||||
// char data;
|
||||
// char buff = (char)data;
|
||||
//
|
||||
//
|
||||
// i2c_operater.op_addr = addr;
|
||||
// ddev_write(i2c_hdl, &buff, 0, (UINT32)&i2c_operater);
|
||||
//}
|
||||
|
||||
|
||||
void DRV_I2C_Read(byte addr, byte *data)
|
||||
{
|
||||
{
|
||||
i2c_operater.op_addr = addr;
|
||||
ddev_read(i2c_hdl, (char*)data, 1, (UINT32)&i2c_operater);
|
||||
}
|
||||
@ -80,7 +80,7 @@ void DRV_I2C_WriteBytes(byte addr, byte *data, int len) {
|
||||
}
|
||||
|
||||
void DRV_I2C_Read(byte addr, byte *data)
|
||||
{
|
||||
{
|
||||
}
|
||||
int DRV_I2C_Begin(int dev_adr, int busID) {
|
||||
|
||||
@ -216,7 +216,7 @@ int DRV_I2C_AddDevice_MCP23017(const void *context, const char *cmd, const char
|
||||
return 1;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
int DRV_I2C_AddDevice_PCF8574(const void *context, const char *cmd, const char *args, int cmdFlags) {
|
||||
const char *i2cModuleStr;
|
||||
int address;
|
||||
@ -271,10 +271,10 @@ int DRV_I2C_AddDevice_LCM1602(const void *context, const char *cmd, const char *
|
||||
//
|
||||
// TC74 A0 (address type 0)
|
||||
// setChannelType 5 temperature
|
||||
// addI2CDevice_TC74 I2C1 0x48 5
|
||||
// addI2CDevice_TC74 I2C1 0x48 5
|
||||
// TC74 A2 (address type 2)
|
||||
// setChannelType 6 temperature
|
||||
// addI2CDevice_TC74 I2C1 0x4A 6
|
||||
// addI2CDevice_TC74 I2C1 0x4A 6
|
||||
|
||||
//
|
||||
// MCP23017 - I2C 16 bit port expander - both inputs and outputs, right now we use it only as outputs
|
||||
@ -295,7 +295,7 @@ void DRV_I2C_Init()
|
||||
CMD_RegisterCommand("addI2CDevice_LCM1602","",DRV_I2C_AddDevice_LCM1602, "Adds a new I2C device", NULL);
|
||||
CMD_RegisterCommand("addI2CDevice_LCD_PCF8574","",DRV_I2C_AddDevice_PCF8574, "Adds a new I2C device", NULL);
|
||||
CMD_RegisterCommand("MCP23017_MapPinToChannel","",DRV_I2C_MCP23017_MapPinToChannel, "Adds a new I2C device", NULL);
|
||||
|
||||
|
||||
}
|
||||
void DRC_I2C_RunDevice(i2cDevice_t *dev)
|
||||
{
|
||||
|
||||
@ -29,9 +29,9 @@ static void MCP23017_setBits( i2cDevice_MCP23017_t *mcp, byte tgRegAddr, byte bi
|
||||
byte temp;
|
||||
|
||||
temp = MCP23017_readByte( mcp, tgRegAddr );
|
||||
|
||||
|
||||
temp |= bitMask;
|
||||
|
||||
|
||||
MCP23017_writeByte( mcp, tgRegAddr, temp );
|
||||
}
|
||||
static void MCP23017_clearBits( i2cDevice_MCP23017_t *mcp, byte tgRegAddr, byte bitMask )
|
||||
@ -39,9 +39,9 @@ static void MCP23017_clearBits( i2cDevice_MCP23017_t *mcp, byte tgRegAddr, byte
|
||||
byte temp;
|
||||
|
||||
temp = MCP23017_readByte( mcp, tgRegAddr );
|
||||
|
||||
|
||||
temp &= ~bitMask;
|
||||
|
||||
|
||||
MCP23017_writeByte( mcp, tgRegAddr, temp );
|
||||
}
|
||||
static void MCP23017_toggleBits( i2cDevice_MCP23017_t *mcp, byte tgRegAddr, byte bitMask )
|
||||
@ -49,9 +49,9 @@ static void MCP23017_toggleBits( i2cDevice_MCP23017_t *mcp, byte tgRegAddr, byte
|
||||
byte temp;
|
||||
|
||||
temp = MCP23017_readByte( mcp, tgRegAddr );
|
||||
|
||||
|
||||
temp ^= bitMask;
|
||||
|
||||
|
||||
MCP23017_writeByte( mcp, tgRegAddr, temp );
|
||||
}
|
||||
static void MCP23017_setDirectionPortA( i2cDevice_MCP23017_t *mcp, byte toWrite )
|
||||
@ -156,4 +156,4 @@ void DRV_I2C_MCP23017_RunDevice(i2cDevice_t *dev)
|
||||
#endif
|
||||
|
||||
// Nothing to do here right now, as we are using on change pin callback
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,10 +196,10 @@ static int jsmn_parse_string(jsmn_parser *parser, const char *js,
|
||||
jsmntok_t *token;
|
||||
|
||||
int start = parser->pos;
|
||||
|
||||
|
||||
/* Skip starting quote */
|
||||
parser->pos++;
|
||||
|
||||
|
||||
for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
|
||||
char c = js[parser->pos];
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ extern UINT32 flash_read(char *user_buf, UINT32 count, UINT32 address);
|
||||
extern UINT32 flash_write(char *user_buf, UINT32 count, UINT32 address);
|
||||
extern UINT32 flash_ctrl(UINT32 cmd, void *parm);
|
||||
|
||||
#ifdef LFS_BOOTCOUNT
|
||||
#ifdef LFS_BOOTCOUNT
|
||||
int boot_count = -1;
|
||||
#endif
|
||||
|
||||
@ -108,7 +108,7 @@ void init_lfs(int create){
|
||||
ADDLOGF_INFO("Mounted existing LFS");
|
||||
lfs_initialised = 1;
|
||||
}
|
||||
#ifdef LFS_BOOTCOUNT
|
||||
#ifdef LFS_BOOTCOUNT
|
||||
// read current count
|
||||
lfs_file_open(&lfs, &file, "boot_count", LFS_O_RDWR | LFS_O_CREAT);
|
||||
lfs_file_read(&lfs, &file, &boot_count, sizeof(boot_count));
|
||||
@ -121,7 +121,7 @@ void init_lfs(int create){
|
||||
// remember the storage is not updated until the file is closed successfully
|
||||
lfs_file_close(&lfs, &file);
|
||||
ADDLOGF_INFO("boot count %d", boot_count);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ static int lfs_write(const struct lfs_config *c, lfs_block_t block,
|
||||
|
||||
startAddr += block*LFS_BLOCK_SIZE;
|
||||
startAddr += off;
|
||||
|
||||
|
||||
GLOBAL_INT_DISABLE();
|
||||
flash_ctrl(CMD_FLASH_SET_PROTECT, &protect);
|
||||
flash_ctrl(CMD_FLASH_WRITE_ENABLE, (void *)0);
|
||||
@ -166,7 +166,7 @@ static int lfs_write(const struct lfs_config *c, lfs_block_t block,
|
||||
protect = FLASH_PROTECT_ALL;
|
||||
flash_ctrl(CMD_FLASH_SET_PROTECT, &protect);
|
||||
GLOBAL_INT_RESTORE();
|
||||
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -198,4 +198,4 @@ static int lfs_sync(const struct lfs_config *c){
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -26,15 +26,15 @@ unsigned int logfeatures = (
|
||||
(1 << 12) |
|
||||
(1 << 13) |
|
||||
(1 << 14) |
|
||||
(1 << 15) |
|
||||
(1 << 16) |
|
||||
(1 << 17) |
|
||||
(1 << 18) |
|
||||
(1 << 19) |
|
||||
(1 << 20) |
|
||||
(1 << 21) |
|
||||
(1 << 22) |
|
||||
(1 << 23) |
|
||||
(1 << 15) |
|
||||
(1 << 16) |
|
||||
(1 << 17) |
|
||||
(1 << 18) |
|
||||
(1 << 19) |
|
||||
(1 << 20) |
|
||||
(1 << 21) |
|
||||
(1 << 22) |
|
||||
(1 << 23) |
|
||||
(1 << 24)
|
||||
);
|
||||
static int log_delay = 0;
|
||||
@ -171,11 +171,11 @@ static struct tag_logMemory {
|
||||
} logMemory;
|
||||
|
||||
|
||||
static int initialised = 0;
|
||||
static int initialised = 0;
|
||||
|
||||
static void initLog( void ) {
|
||||
bk_printf("Entering init log...\r\n");
|
||||
logMemory.head = logMemory.tailserial = logMemory.tailtcp = logMemory.tailhttp = 0;
|
||||
logMemory.head = logMemory.tailserial = logMemory.tailtcp = logMemory.tailhttp = 0;
|
||||
logMemory.mutex = xSemaphoreCreateMutex( );
|
||||
initialised = 1;
|
||||
startSerialLog();
|
||||
@ -188,7 +188,7 @@ static void initLog( void ) {
|
||||
CMD_RegisterCommand("logfeature", "", log_command, "set log feature filter, <0..10> <0|1>", NULL);
|
||||
CMD_RegisterCommand("logtype", "", log_command, "logtype direct|all - direct logs only to serial immediately", NULL);
|
||||
CMD_RegisterCommand("logdelay", "", log_command, "logdelay 0..n - impose ms delay after every log", NULL);
|
||||
|
||||
|
||||
bk_printf("Commands registered!\r\n");
|
||||
}
|
||||
|
||||
@ -314,8 +314,8 @@ static int getHttp(char *buff, int buffsize){
|
||||
void startLogServer(){
|
||||
OSStatus err = kNoErr;
|
||||
|
||||
err = rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY,
|
||||
"TCP_server",
|
||||
err = rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY,
|
||||
"TCP_server",
|
||||
(beken_thread_function_t)log_server_thread,
|
||||
0x800,
|
||||
(beken_thread_arg_t)0 );
|
||||
@ -327,8 +327,8 @@ void startLogServer(){
|
||||
|
||||
void startSerialLog(){
|
||||
OSStatus err = kNoErr;
|
||||
err = rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY,
|
||||
"log_serial",
|
||||
err = rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY,
|
||||
"log_serial",
|
||||
(beken_thread_function_t)log_serial_thread,
|
||||
0x800,
|
||||
(beken_thread_arg_t)0 );
|
||||
@ -357,9 +357,9 @@ void log_server_thread( beken_thread_arg_t arg )
|
||||
server_addr.sin_addr.s_addr = INADDR_ANY;/* Accept conenction request on all network interface */
|
||||
server_addr.sin_port = htons( logTcpPort );/* Server listen on port: 20000 */
|
||||
err = bind( tcp_listen_fd, (struct sockaddr *) &server_addr, sizeof(server_addr) );
|
||||
|
||||
|
||||
err = listen( tcp_listen_fd, 0 );
|
||||
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
FD_ZERO( &readfds );
|
||||
@ -375,11 +375,11 @@ void log_server_thread( beken_thread_arg_t arg )
|
||||
os_strcpy( client_ip_str, inet_ntoa( client_addr.sin_addr ) );
|
||||
//addLog( "TCP Log Client %s:%d connected, fd: %d", client_ip_str, client_addr.sin_port, client_fd );
|
||||
if ( kNoErr
|
||||
!= rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY,
|
||||
!= rtos_create_thread( NULL, BEKEN_APPLICATION_PRIORITY,
|
||||
"Logging TCP Client",
|
||||
(beken_thread_function_t)log_client_thread,
|
||||
0x800,
|
||||
(beken_thread_arg_t)client_fd ) )
|
||||
0x800,
|
||||
(beken_thread_arg_t)client_fd ) )
|
||||
{
|
||||
close( client_fd );
|
||||
client_fd = -1;
|
||||
@ -387,11 +387,11 @@ void log_server_thread( beken_thread_arg_t arg )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( err != kNoErr ) {
|
||||
//addLog( "Server listener thread exit with err: %d", err );
|
||||
}
|
||||
|
||||
|
||||
close( tcp_listen_fd );
|
||||
rtos_delete_thread( NULL );
|
||||
}
|
||||
@ -412,9 +412,9 @@ static void log_client_thread( beken_thread_arg_t arg )
|
||||
}
|
||||
rtos_delay_milliseconds(10);
|
||||
}
|
||||
|
||||
|
||||
//addLog( "TCP client thread exit with err: %d", len );
|
||||
|
||||
|
||||
close( fd );
|
||||
rtos_delete_thread( NULL );
|
||||
}
|
||||
|
||||
@ -76,4 +76,4 @@ typedef enum {
|
||||
LOG_FEATURE_MAX = 17,
|
||||
} log_features;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -155,7 +155,7 @@ int MQTT_RegisterCallback( const char *basetopic, const char *subscriptiontopic,
|
||||
// find out if this subscription is new.
|
||||
for (i = 0; i < numCallbacks; i++){
|
||||
if (callbacks[i]){
|
||||
if (callbacks[i]->subscriptionTopic &&
|
||||
if (callbacks[i]->subscriptionTopic &&
|
||||
!strcmp(callbacks[i]->subscriptionTopic, subscriptiontopic)){
|
||||
break;
|
||||
}
|
||||
@ -215,7 +215,7 @@ int channelSet(mqtt_request_t* request){
|
||||
|
||||
addLogAdv(LOG_INFO,LOG_FEATURE_MQTT,"channelSet topic %i", request->topic);
|
||||
|
||||
// TODO: better
|
||||
// TODO: better
|
||||
while(*p != '/') {
|
||||
if(*p == 0)
|
||||
return 0;
|
||||
@ -285,7 +285,7 @@ int tasCmnd(mqtt_request_t* request){
|
||||
// strncpy does not terminate??!!!!
|
||||
copy[len] = '\0';
|
||||
|
||||
// TODO: better
|
||||
// TODO: better
|
||||
// skip to after second forward slash
|
||||
while(*p != '/') { if(*p == 0) return 0; p++; }
|
||||
p++;
|
||||
@ -329,7 +329,7 @@ void MQTT_PublishMain(mqtt_client_t *client, const char *sChannel, const char *s
|
||||
u8_t qos = 2; /* 0 1 or 2, see MQTT specification */
|
||||
u8_t retain = 0; /* No don't retain such crappy payload... */
|
||||
const char *baseName;
|
||||
|
||||
|
||||
if(client==0)
|
||||
return;
|
||||
if(mqtt_client_is_connected(client)==0) {
|
||||
@ -346,7 +346,7 @@ void MQTT_PublishMain(mqtt_client_t *client, const char *sChannel, const char *s
|
||||
if(err != ERR_OK) {
|
||||
addLogAdv(LOG_INFO,LOG_FEATURE_MQTT,"Publish err: %d\n", err);
|
||||
if(err == ERR_CONN) {
|
||||
|
||||
|
||||
// g_my_reconnect_mqtt_after_time = 5;
|
||||
|
||||
|
||||
@ -367,7 +367,7 @@ static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t f
|
||||
g_mqtt_request.received = data;
|
||||
g_mqtt_request.receivedLen = len;
|
||||
|
||||
addLogAdv(LOG_INFO,LOG_FEATURE_MQTT,"MQTT in topic %s", g_mqtt_request.topic);
|
||||
addLogAdv(LOG_INFO,LOG_FEATURE_MQTT,"MQTT in topic %s", g_mqtt_request.topic);
|
||||
|
||||
for (i = 0; i < numCallbacks; i++){
|
||||
char *cbtopic = callbacks[i]->topic;
|
||||
@ -513,7 +513,7 @@ static void MQTT_do_connect(mqtt_client_t *client)
|
||||
mqtt_client_info.client_id = mqtt_clientID;
|
||||
mqtt_client_info.client_pass = mqtt_pass;
|
||||
mqtt_client_info.client_user = mqtt_userName;
|
||||
|
||||
|
||||
sprintf(will_topic,"%s/connected",CFG_GetShortDeviceName());
|
||||
mqtt_client_info.will_topic = will_topic;
|
||||
mqtt_client_info.will_msg = "offline";
|
||||
@ -618,7 +618,7 @@ int MQTT_RunEverySecondUpdate() {
|
||||
//addLogAdv(LOG_INFO,LOG_FEATURE_MAIN, "Timer discovers disconnected mqtt %i\n",loopsWithDisconnected);
|
||||
loopsWithDisconnected++;
|
||||
if(loopsWithDisconnected > 10)
|
||||
{
|
||||
{
|
||||
if(mqtt_client == 0)
|
||||
{
|
||||
mqtt_client = mqtt_client_new();
|
||||
|
||||
@ -163,12 +163,12 @@ void Setup_Device_IntelligentLife_NF101A() {
|
||||
|
||||
|
||||
CFG_Save_SetupTimer();
|
||||
}
|
||||
}
|
||||
// https://www.elektroda.pl/rtvforum/topic3798114.html
|
||||
void Setup_Device_TuyaLEDDimmerSingleChannel() {
|
||||
CFG_ClearPins();
|
||||
|
||||
// pin 8 has PWM
|
||||
// pin 8 has PWM
|
||||
PIN_SetPinRoleForPinIndex(8, IOR_PWM);
|
||||
PIN_SetPinChannelForPinIndex(8, 1);
|
||||
|
||||
@ -281,7 +281,7 @@ void Setup_Device_NedisWIFIPO120FWT_16A() {
|
||||
// Button - RX1 - P10
|
||||
// BL0937-SEL - PWM4 - P24
|
||||
// Relay - PWM5 - P26
|
||||
|
||||
|
||||
|
||||
CFG_ClearPins();
|
||||
// LEd
|
||||
@ -303,10 +303,10 @@ void Setup_Device_NedisWIFIP130FWT_10A() {
|
||||
|
||||
// WB2S
|
||||
// Pins are:
|
||||
// Led - PWM0 - P6
|
||||
// Led - PWM0 - P6
|
||||
// Button - RX1 - P10
|
||||
// Relay - PWM5 - P26
|
||||
|
||||
|
||||
|
||||
CFG_ClearPins();
|
||||
// Led
|
||||
@ -323,24 +323,24 @@ void Setup_Device_NedisWIFIP130FWT_10A() {
|
||||
}
|
||||
|
||||
// https://www.elektroda.com/rtvforum/topic3819498.html
|
||||
//
|
||||
//
|
||||
void Setup_Device_TH06_LCD_RTCC_WB3S() {
|
||||
|
||||
}
|
||||
|
||||
// https://www.elektroda.pl/rtvforum/topic3804553.html
|
||||
// SmartSwitch Emax Home EDU8774 16A
|
||||
// SmartSwitch Emax Home EDU8774 16A
|
||||
void Setup_Device_EmaxHome_EDU8774() {
|
||||
|
||||
// WB2S
|
||||
// Pins are:
|
||||
// BL0937-CF - PWM0 - P6
|
||||
// BL0937-CF - PWM0 - P6
|
||||
// BL0937-CF1 - PWM1 - P7
|
||||
// BL0937-SEL - PWM2 - P8
|
||||
// Button - RX1 - P10
|
||||
// Relay - PWM4 - P24
|
||||
// Led - PWM5 - P26
|
||||
|
||||
|
||||
|
||||
CFG_ClearPins();
|
||||
// Button
|
||||
|
||||
@ -154,7 +154,7 @@ int CFG_GetPingIntervalSeconds() {
|
||||
return g_cfg.ping_interval;
|
||||
}
|
||||
void CFG_SetPingHost(const char *s) {
|
||||
// this will return non-zero if there were any changes
|
||||
// this will return non-zero if there were any changes
|
||||
if(strcpy_safe_checkForChanges(g_cfg.ping_host, s,sizeof(g_cfg.ping_host))) {
|
||||
// mark as dirty (value has changed)
|
||||
g_cfg_pendingChanges++;
|
||||
@ -179,14 +179,14 @@ void CFG_SetShortStartupCommand_AndExecuteNow(const char *s) {
|
||||
CMD_ExecuteCommand(s,COMMAND_FLAG_SOURCE_SCRIPT);
|
||||
}
|
||||
void CFG_SetShortStartupCommand(const char *s) {
|
||||
// this will return non-zero if there were any changes
|
||||
// this will return non-zero if there were any changes
|
||||
if(strcpy_safe_checkForChanges(g_cfg.initCommandLine, s,sizeof(g_cfg.initCommandLine))) {
|
||||
// mark as dirty (value has changed)
|
||||
g_cfg_pendingChanges++;
|
||||
}
|
||||
}
|
||||
int CFG_SetWebappRoot(const char *s) {
|
||||
// this will return non-zero if there were any changes
|
||||
// this will return non-zero if there were any changes
|
||||
if(strcpy_safe_checkForChanges(g_cfg.webappRoot, s,sizeof(g_cfg.webappRoot))) {
|
||||
// mark as dirty (value has changed)
|
||||
g_cfg_pendingChanges++;
|
||||
@ -209,14 +209,14 @@ int CFG_GetMQTTPort() {
|
||||
return g_cfg.mqtt_port;
|
||||
}
|
||||
void CFG_SetShortDeviceName(const char *s) {
|
||||
// this will return non-zero if there were any changes
|
||||
// this will return non-zero if there were any changes
|
||||
if(strcpy_safe_checkForChanges(g_cfg.shortDeviceName, s,sizeof(g_cfg.shortDeviceName))) {
|
||||
// mark as dirty (value has changed)
|
||||
g_cfg_pendingChanges++;
|
||||
}
|
||||
}
|
||||
void CFG_SetDeviceName(const char *s) {
|
||||
// this will return non-zero if there were any changes
|
||||
// this will return non-zero if there were any changes
|
||||
if(strcpy_safe_checkForChanges(g_cfg.longDeviceName, s,sizeof(g_cfg.longDeviceName))) {
|
||||
// mark as dirty (value has changed)
|
||||
g_cfg_pendingChanges++;
|
||||
@ -247,14 +247,14 @@ const char *CFG_GetWiFiPass(){
|
||||
return g_cfg.wifi_pass;
|
||||
}
|
||||
void CFG_SetWiFiSSID(const char *s) {
|
||||
// this will return non-zero if there were any changes
|
||||
// this will return non-zero if there were any changes
|
||||
if(strcpy_safe_checkForChanges(g_cfg.wifi_ssid, s,sizeof(g_cfg.wifi_ssid))) {
|
||||
// mark as dirty (value has changed)
|
||||
g_cfg_pendingChanges++;
|
||||
}
|
||||
}
|
||||
void CFG_SetWiFiPass(const char *s) {
|
||||
// this will return non-zero if there were any changes
|
||||
// this will return non-zero if there were any changes
|
||||
if(strcpy_safe_checkForChanges(g_cfg.wifi_pass, s,sizeof(g_cfg.wifi_pass))) {
|
||||
// mark as dirty (value has changed)
|
||||
g_cfg_pendingChanges++;
|
||||
@ -273,28 +273,28 @@ const char *CFG_GetMQTTPass() {
|
||||
return g_cfg.mqtt_pass;
|
||||
}
|
||||
void CFG_SetMQTTHost(const char *s) {
|
||||
// this will return non-zero if there were any changes
|
||||
// this will return non-zero if there were any changes
|
||||
if(strcpy_safe_checkForChanges(g_cfg.mqtt_host, s,sizeof(g_cfg.mqtt_host))) {
|
||||
// mark as dirty (value has changed)
|
||||
g_cfg_pendingChanges++;
|
||||
}
|
||||
}
|
||||
void CFG_SetMQTTBrokerName(const char *s) {
|
||||
// this will return non-zero if there were any changes
|
||||
// this will return non-zero if there were any changes
|
||||
if(strcpy_safe_checkForChanges(g_cfg.mqtt_brokerName, s,sizeof(g_cfg.mqtt_brokerName))) {
|
||||
// mark as dirty (value has changed)
|
||||
g_cfg_pendingChanges++;
|
||||
}
|
||||
}
|
||||
void CFG_SetMQTTUserName(const char *s) {
|
||||
// this will return non-zero if there were any changes
|
||||
// this will return non-zero if there were any changes
|
||||
if(strcpy_safe_checkForChanges(g_cfg.mqtt_userName, s,sizeof(g_cfg.mqtt_userName))) {
|
||||
// mark as dirty (value has changed)
|
||||
g_cfg_pendingChanges++;
|
||||
}
|
||||
}
|
||||
void CFG_SetMQTTPass(const char *s) {
|
||||
// this will return non-zero if there were any changes
|
||||
// this will return non-zero if there were any changes
|
||||
if(strcpy_safe_checkForChanges(g_cfg.mqtt_pass, s,sizeof(g_cfg.mqtt_pass))) {
|
||||
// mark as dirty (value has changed)
|
||||
g_cfg_pendingChanges++;
|
||||
@ -347,7 +347,7 @@ void CFG_InitAndLoad() {
|
||||
|
||||
HAL_Configuration_ReadConfigMemory(&g_cfg,sizeof(g_cfg));
|
||||
chkSum = CFG_CalcChecksum(&g_cfg);
|
||||
if(g_cfg.ident0 != CFG_IDENT_0 || g_cfg.ident1 != CFG_IDENT_1 || g_cfg.ident2 != CFG_IDENT_2
|
||||
if(g_cfg.ident0 != CFG_IDENT_0 || g_cfg.ident1 != CFG_IDENT_1 || g_cfg.ident2 != CFG_IDENT_2
|
||||
|| chkSum != g_cfg.crc) {
|
||||
addLogAdv(LOG_WARN, LOG_FEATURE_CFG, "CFG_InitAndLoad: Config crc or ident mismatch. Default config will be loaded.");
|
||||
CFG_SetDefaultConfig();
|
||||
|
||||
@ -46,7 +46,7 @@ typedef unsigned char uint8_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned short uint16_t;
|
||||
|
||||
|
||||
|
||||
|
||||
#elif PLATFORM_BL602
|
||||
|
||||
@ -80,8 +80,8 @@ typedef int OSStatus;
|
||||
|
||||
// wrappers for XR809 threads to work like bekken
|
||||
OSStatus rtos_delete_thread( beken_thread_t* thread );
|
||||
OSStatus rtos_create_thread( beken_thread_t* thread,
|
||||
uint8_t priority, const char* name,
|
||||
OSStatus rtos_create_thread( beken_thread_t* thread,
|
||||
uint8_t priority, const char* name,
|
||||
beken_thread_function_t function,
|
||||
uint32_t stack_size, beken_thread_arg_t arg );
|
||||
|
||||
@ -121,8 +121,8 @@ typedef int OSStatus;
|
||||
|
||||
// wrappers for XR809 threads to work like bekken
|
||||
OSStatus rtos_delete_thread( beken_thread_t* thread );
|
||||
OSStatus rtos_create_thread( beken_thread_t* thread,
|
||||
uint8_t priority, const char* name,
|
||||
OSStatus rtos_create_thread( beken_thread_t* thread,
|
||||
uint8_t priority, const char* name,
|
||||
beken_thread_function_t function,
|
||||
uint32_t stack_size, beken_thread_arg_t arg );
|
||||
|
||||
|
||||
@ -144,7 +144,7 @@ static u8_t ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p, const ip_a
|
||||
// LWIP_DEBUGF( PING_DEBUG, (" %"U32_F" ms\n", ms));
|
||||
ping_received++;
|
||||
bReceivedLastOneSend = 1;
|
||||
|
||||
|
||||
//addLogAdv(LOG_INFO,LOG_FEATURE_MAIN,"Ping recv: %ims (total lost %i, recv %i)\r\n", ms,ping_lost,ping_received);
|
||||
|
||||
// addLogAdv(LOG_INFO,LOG_FEATURE_MAIN,"Ping recv: %ims\r\n", ms);
|
||||
@ -182,4 +182,4 @@ void Main_SetupPingWatchDog(const char *target/*, int delayBetweenPings_Seconds*
|
||||
raw_bind(ping_pcb, IP_ADDR_ANY);
|
||||
// void sys_timeout (u32_t msecs, sys_timeout_handler handler, void *arg)
|
||||
sys_timeout(PING_DELAY, ping_timeout, ping_pcb);
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,10 +39,10 @@ typedef struct pinButton_ {
|
||||
uint8_t repeat : 4;
|
||||
uint8_t event : 4;
|
||||
uint8_t state : 3;
|
||||
uint8_t debounce_cnt : 3;
|
||||
uint8_t debounce_cnt : 3;
|
||||
uint8_t active_level : 1;
|
||||
uint8_t button_level : 1;
|
||||
|
||||
|
||||
uint8_t (*hal_button_Level)(void *self);
|
||||
new_btn_callback cb[BTN_number_of_event];
|
||||
}pinButton_s;
|
||||
@ -142,7 +142,7 @@ bool BTN_ShouldInvert(int index) {
|
||||
addLogAdv(LOG_ERROR, LOG_FEATURE_CFG, "BTN_ShouldInvert: Pin index %i out of range <0,%i).",index,PLATFORM_GPIO_MAX);
|
||||
return false;
|
||||
}
|
||||
if(g_cfg.pins.roles[index] == IOR_Button_n || g_cfg.pins.roles[index] == IOR_Button_ToggleAll_n||
|
||||
if(g_cfg.pins.roles[index] == IOR_Button_n || g_cfg.pins.roles[index] == IOR_Button_ToggleAll_n||
|
||||
g_cfg.pins.roles[index] == IOR_DigitalInput_n || g_cfg.pins.roles[index] == IOR_DigitalInput_NoPup_n) {
|
||||
return true;
|
||||
}
|
||||
@ -172,7 +172,7 @@ static uint8_t button_generic_get_gpio_value(void *param)
|
||||
void NEW_button_init(pinButton_s* handle, uint8_t(*pin_level)(void *self), uint8_t active_level)
|
||||
{
|
||||
memset(handle, sizeof(pinButton_s), 0);
|
||||
|
||||
|
||||
handle->event = (uint8_t)BTN_NONE_PRESS;
|
||||
handle->hal_button_Level = pin_level;
|
||||
handle->button_level = handle->hal_button_Level(handle);
|
||||
@ -209,7 +209,7 @@ void CHANNEL_SetAll(int iVal, bool bForce) {
|
||||
int i;
|
||||
|
||||
|
||||
for(i = 0; i < PLATFORM_GPIO_MAX; i++) {
|
||||
for(i = 0; i < PLATFORM_GPIO_MAX; i++) {
|
||||
switch(g_cfg.pins.roles[i])
|
||||
{
|
||||
case IOR_Button:
|
||||
@ -260,12 +260,12 @@ void CHANNEL_DoSpecialToggleAll() {
|
||||
|
||||
anyEnabled = 0;
|
||||
|
||||
for(i = 0; i < CHANNEL_MAX; i++) {
|
||||
for(i = 0; i < CHANNEL_MAX; i++) {
|
||||
if(CHANNEL_IsInUse(i)==false)
|
||||
continue;
|
||||
if(g_channelValues[i] > 0) {
|
||||
anyEnabled++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(anyEnabled)
|
||||
CHANNEL_SetAll(0, true);
|
||||
@ -600,7 +600,7 @@ void PIN_Input_Handler(int pinIndex)
|
||||
{
|
||||
pinButton_s *handle;
|
||||
uint8_t read_gpio_level;
|
||||
|
||||
|
||||
handle = &g_buttons[pinIndex];
|
||||
read_gpio_level = button_generic_get_gpio_value(handle);
|
||||
|
||||
@ -655,7 +655,7 @@ void PIN_Input_Handler(int pinIndex)
|
||||
if(handle->repeat == 2) {
|
||||
EVENT_CB(BTN_DOUBLE_CLICK); // repeat hit
|
||||
Button_OnDoubleClick(pinIndex);
|
||||
}
|
||||
}
|
||||
EVENT_CB(BTN_PRESS_REPEAT); // repeat hit
|
||||
handle->ticks = 0;
|
||||
handle->state = 3;
|
||||
@ -752,13 +752,13 @@ void PIN_ticks(void *param)
|
||||
#if 1
|
||||
if(g_cfg.pins.roles[i] == IOR_PWM) {
|
||||
HAL_PIN_PWM_Update(i,g_channelValues[g_cfg.pins.channels[i]]);
|
||||
} else
|
||||
} else
|
||||
#endif
|
||||
if(g_cfg.pins.roles[i] == IOR_Button || g_cfg.pins.roles[i] == IOR_Button_n
|
||||
|| g_cfg.pins.roles[i] == IOR_Button_ToggleAll || g_cfg.pins.roles[i] == IOR_Button_ToggleAll_n) {
|
||||
//addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL,"Test hold %i\r\n",i);
|
||||
PIN_Input_Handler(i);
|
||||
}
|
||||
}
|
||||
else if(g_cfg.pins.roles[i] == IOR_DigitalInput || g_cfg.pins.roles[i] == IOR_DigitalInput_n
|
||||
||
|
||||
g_cfg.pins.roles[i] == IOR_DigitalInput_NoPup || g_cfg.pins.roles[i] == IOR_DigitalInput_NoPup_n) {
|
||||
@ -855,7 +855,7 @@ static int CMD_ShowChannelValues(const void *context, const char *cmd, const cha
|
||||
if(g_channelValues[i] > 0) {
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_GENERAL,"Channel %i value is %i", i, g_channelValues[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -928,13 +928,13 @@ void PIN_Init(void)
|
||||
OS_TimerStart(&timer); /* start OS timer to feed watchdog */
|
||||
#else
|
||||
OSStatus result;
|
||||
|
||||
|
||||
result = rtos_init_timer(&g_pin_timer,
|
||||
PIN_TMR_DURATION,
|
||||
PIN_ticks,
|
||||
(void *)0);
|
||||
ASSERT(kNoErr == result);
|
||||
|
||||
|
||||
result = rtos_start_timer(&g_pin_timer);
|
||||
ASSERT(kNoErr == result);
|
||||
#endif
|
||||
|
||||
@ -66,11 +66,11 @@ typedef struct pinsState_s {
|
||||
// (so we assume we have maximum of 32 pins)
|
||||
byte roles[32];
|
||||
byte channels[32];
|
||||
// extra channels array - this is needed for
|
||||
// extra channels array - this is needed for
|
||||
// buttons, so button can toggle one relay on single click
|
||||
// and other relay on double click
|
||||
byte channels2[32];
|
||||
// This single field above, is indexed by CHANNEL INDEX
|
||||
// This single field above, is indexed by CHANNEL INDEX
|
||||
// (not by pin index)
|
||||
byte channelTypes[CHANNEL_MAX];
|
||||
} pinsState_t;
|
||||
@ -78,7 +78,7 @@ typedef struct pinsState_s {
|
||||
//
|
||||
// Main config structure (less than 2KB)
|
||||
//
|
||||
// This config structure is supposed to be saved only when user
|
||||
// This config structure is supposed to be saved only when user
|
||||
// changes the device configuration, so really not often.
|
||||
// We should not worry about flash memory wear in this case.
|
||||
// The saved-every-reboot values are stored elsewhere
|
||||
|
||||
@ -37,7 +37,7 @@ int init_ota(unsigned int startaddr){
|
||||
addr = startaddr;
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_OTA,"init OTA, startaddr 0x%x\n", startaddr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_OTA,"aborting OTA, startaddr 0x%x < 0xff000\n", startaddr);
|
||||
return 0;
|
||||
}
|
||||
@ -132,7 +132,7 @@ int myhttpclientcallback(httprequest_t* request){
|
||||
CFG_Save_IfThereArePendingChanges();
|
||||
|
||||
rtos_delay_milliseconds(1000);
|
||||
bk_reboot();
|
||||
bk_reboot();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -149,7 +149,7 @@ int myhttpclientcallback(httprequest_t* request){
|
||||
}
|
||||
|
||||
// NOTE: these MUST persist
|
||||
// note: url must have a '/' after host, else it can;t parse it..
|
||||
// note: url must have a '/' after host, else it can;t parse it..
|
||||
static char url[256] = "http://raspberrypi:1880/firmware";
|
||||
static const char *header = "";
|
||||
static char *content_type = "text/csv";
|
||||
@ -173,7 +173,7 @@ void otarequest(const char *urlin){
|
||||
httpclient_data_t *client_data = &request->client_data;
|
||||
|
||||
if (http_buf == (void *)0){
|
||||
http_buf = os_malloc(BUF_SIZE+1);
|
||||
http_buf = os_malloc(BUF_SIZE+1);
|
||||
if (http_buf == (void *)0) {
|
||||
addLogAdv(LOG_INFO, LOG_FEATURE_OTA,"startrequest Malloc failed.\r\n");
|
||||
return;
|
||||
@ -186,10 +186,10 @@ void otarequest(const char *urlin){
|
||||
client_data->post_buf = post_data; //Sets the user data to be posted.
|
||||
client_data->post_buf_len = strlen(post_data); //Sets the post data length.
|
||||
client_data->post_content_type = content_type; //Sets the content type.
|
||||
request->data_callback = &myhttpclientcallback;
|
||||
request->data_callback = &myhttpclientcallback;
|
||||
request->port = 80;//HTTP_PORT;
|
||||
request->url = url;
|
||||
request->method = HTTPCLIENT_GET;
|
||||
request->method = HTTPCLIENT_GET;
|
||||
request->timeout = 10000;
|
||||
HTTPClient_Async_SendGeneric(request);
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
#define START_ADR_OF_BK_PARTITION_OTA 0x132000
|
||||
#endif
|
||||
|
||||
// initialise OTA flash starting at startaddr
|
||||
// initialise OTA flash starting at startaddr
|
||||
int init_ota(unsigned int startaddr);
|
||||
|
||||
// add any length of data to OTA
|
||||
@ -21,4 +21,4 @@ void add_otadata(unsigned char *data, int len);
|
||||
// finalise OTA flash (write last sector if incomplete)
|
||||
void close_ota();
|
||||
|
||||
void otarequest(const char *urlin);
|
||||
void otarequest(const char *urlin);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
char Tiny_CRC8(const char *data,int length)
|
||||
char Tiny_CRC8(const char *data,int length)
|
||||
{
|
||||
char crc = 0x00;
|
||||
char extract;
|
||||
@ -11,7 +11,7 @@ char Tiny_CRC8(const char *data,int length)
|
||||
for(i=0;i<length;i++)
|
||||
{
|
||||
extract = *data;
|
||||
for (tempI = 8; tempI; tempI--)
|
||||
for (tempI = 8; tempI; tempI--)
|
||||
{
|
||||
sum = (crc ^ extract) & 0x01;
|
||||
crc >>= 1;
|
||||
|
||||
@ -67,8 +67,8 @@ size_t xPortGetFreeHeapSize() {
|
||||
|
||||
|
||||
|
||||
OSStatus rtos_create_thread( beken_thread_t* thread,
|
||||
uint8_t priority, const char* name,
|
||||
OSStatus rtos_create_thread( beken_thread_t* thread,
|
||||
uint8_t priority, const char* name,
|
||||
beken_thread_function_t function,
|
||||
uint32_t stack_size, beken_thread_arg_t arg ) {
|
||||
OSStatus err = kNoErr;
|
||||
@ -85,7 +85,7 @@ OSStatus rtos_create_thread( beken_thread_t* thread,
|
||||
TaskHandle_t *pvCreatedTask
|
||||
);
|
||||
*/
|
||||
if(err == pdPASS){
|
||||
if(err == pdPASS){
|
||||
printf("Thread create %s - pdPASS\n",name);
|
||||
return 0;
|
||||
} else if(err == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY ) {
|
||||
@ -132,16 +132,16 @@ void Main_OnWiFiStatusChange(int code){
|
||||
g_bHasWiFiConnected = 0;
|
||||
ADDLOGF_INFO("Main_OnWiFiStatusChange - WIFI_STA_AUTH_FAILED\r\n");
|
||||
break;
|
||||
case WIFI_STA_CONNECTED:
|
||||
case WIFI_STA_CONNECTED:
|
||||
g_bHasWiFiConnected = 1;
|
||||
ADDLOGF_INFO("Main_OnWiFiStatusChange - WIFI_STA_CONNECTED\r\n");
|
||||
break;
|
||||
/* for softap mode */
|
||||
case WIFI_AP_CONNECTED:
|
||||
case WIFI_AP_CONNECTED:
|
||||
g_bHasWiFiConnected = 1;
|
||||
ADDLOGF_INFO("Main_OnWiFiStatusChange - WIFI_AP_CONNECTED\r\n");
|
||||
break;
|
||||
case WIFI_AP_FAILED:
|
||||
case WIFI_AP_FAILED:
|
||||
g_bHasWiFiConnected = 0;
|
||||
ADDLOGF_INFO("Main_OnWiFiStatusChange - WIFI_AP_FAILED\r\n");
|
||||
break;
|
||||
@ -170,7 +170,7 @@ void Main_OnEverySecond()
|
||||
DRV_OnEverySecond();
|
||||
#endif
|
||||
|
||||
// some users say that despite our simple reconnect mechanism
|
||||
// some users say that despite our simple reconnect mechanism
|
||||
// there are some rare cases when devices stuck outside network
|
||||
// That is why we can also reconnect them by basing on ping
|
||||
if(g_timeSinceLastPingReply != -1 && g_secondsElapsed > 60) {
|
||||
@ -184,13 +184,13 @@ void Main_OnEverySecond()
|
||||
|
||||
|
||||
g_secondsElapsed ++;
|
||||
if(bSafeMode) {
|
||||
if(bSafeMode) {
|
||||
safe = "[SAFE] ";
|
||||
} else {
|
||||
safe = "";
|
||||
}
|
||||
#ifndef PLATFORM_BL602
|
||||
ADDLOGF_INFO("%sTime %i, free %d, MQTT %i, bWifi %i, secondsWithNoPing %i, socks %i/%i\n",
|
||||
ADDLOGF_INFO("%sTime %i, free %d, MQTT %i, bWifi %i, secondsWithNoPing %i, socks %i/%i\n",
|
||||
safe, g_secondsElapsed, xPortGetFreeHeapSize(),bMQTTconnected, g_bHasWiFiConnected,g_timeSinceLastPingReply,
|
||||
LWIP_GetActiveSockets(),LWIP_GetMaxSockets());
|
||||
#endif
|
||||
@ -236,7 +236,7 @@ void Main_OnEverySecond()
|
||||
} else {
|
||||
// mark as disabled
|
||||
g_timeSinceLastPingReply = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(g_connectToWiFi){
|
||||
@ -263,16 +263,16 @@ void Main_OnEverySecond()
|
||||
if (g_saveCfgAfter){
|
||||
g_saveCfgAfter--;
|
||||
if (!g_saveCfgAfter){
|
||||
CFG_Save_IfThereArePendingChanges();
|
||||
CFG_Save_IfThereArePendingChanges();
|
||||
}
|
||||
}
|
||||
if (g_reset){
|
||||
g_reset--;
|
||||
if (!g_reset){
|
||||
// ensure any config changes are saved before reboot.
|
||||
CFG_Save_IfThereArePendingChanges();
|
||||
CFG_Save_IfThereArePendingChanges();
|
||||
ADDLOGF_INFO("Going to call HAL_RebootModule\r\n");
|
||||
HAL_RebootModule();
|
||||
HAL_RebootModule();
|
||||
} else {
|
||||
|
||||
ADDLOGF_INFO("Module reboot in %i...\r\n",g_reset);
|
||||
@ -403,4 +403,4 @@ void Main_Init()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ void strcat_safe_test(){
|
||||
urldecode2_safe(buff,"qqqqqq%40qqqq",sizeof(buff));
|
||||
urldecode2_safe(buff,"qqqqqq%40qqqq",sizeof(buff));
|
||||
|
||||
|
||||
|
||||
misc_formatUpTimeString(15, timeStrA);
|
||||
misc_formatUpTimeString(65, timeStrB);
|
||||
misc_formatUpTimeString(125, timeStrC);
|
||||
@ -98,7 +98,7 @@ DWORD WINAPI Thread_SimulateTUYAMCUSendingData(void* arg)
|
||||
{
|
||||
int r;
|
||||
const char *p;
|
||||
const char *packets[] = {
|
||||
const char *packets[] = {
|
||||
"55AA00000000FF",
|
||||
"55AA00000000FF",
|
||||
"55AA0001000000",
|
||||
@ -118,7 +118,7 @@ DWORD WINAPI Thread_SimulateTUYAMCUSendingData(void* arg)
|
||||
p += 2;
|
||||
Sleep(10);
|
||||
}
|
||||
|
||||
|
||||
Sleep(1000);
|
||||
}
|
||||
return 0;
|
||||
@ -137,7 +137,7 @@ int Main_IsConnectedToWiFi() {
|
||||
//
|
||||
// printf(t);
|
||||
//}
|
||||
int __cdecl main(void)
|
||||
int __cdecl main(void)
|
||||
{
|
||||
WSADATA wsaData;
|
||||
int iResult;
|
||||
@ -153,7 +153,7 @@ int __cdecl main(void)
|
||||
char recvbuf[DEFAULT_BUFLEN];
|
||||
char outbuf[DEFAULT_BUFLEN];
|
||||
int recvbuflen = DEFAULT_BUFLEN;
|
||||
|
||||
|
||||
strcat_safe_test();
|
||||
|
||||
Tokenizer_TokenizeString("dsfafd dasfdsaf dsaf dsaf dsa fdsaf dsafdsa");
|
||||
@ -234,7 +234,7 @@ int __cdecl main(void)
|
||||
WSACleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Receive until the peer shuts down the connection
|
||||
do {
|
||||
|
||||
Reference in New Issue
Block a user