Skip to content

Commit 1cc0603

Browse files
authored
Cmd Flags 64bit repair + webui (#1548)
* flags 64bit cmd repair + webui * uint32 * flags 0 webui strange char repair
1 parent fb33459 commit 1cc0603

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

src/cmnds/cmd_main.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ static commandResult_t CMD_Flags(const void* context, const char* cmd, const cha
307307
union {
308308
long long newValue;
309309
struct {
310-
int ints[2];
311-
int dummy[2]; // just to be safe
310+
uint32_t ints[2];
311+
uint32_t dummy[2]; // just to be safe
312312
};
313313
} u;
314314
// TODO: check on other platforms, on Beken it's 8, 64 bit
@@ -319,11 +319,12 @@ static commandResult_t CMD_Flags(const void* context, const char* cmd, const cha
319319
//ADDLOG_INFO(LOG_FEATURE_CMD, "Argument/sscanf error!");
320320
return CMD_RES_BAD_ARGUMENT;
321321
}
322-
}
323-
else {
322+
//ADDLOG_INFO(LOG_FEATURE_CMD, "CMD_Flags: 0-31: %X 32-63: %2 = %X", u.ints[0], u.ints[1]);
323+
u.newValue = (uint64_t)strtoull(args, NULL, 10);
324+
//ADDLOG_INFO(LOG_FEATURE_CMD, "CMD_Flags (new): 0-31: %X 32-63: %2 = %X", u.ints[0], u.ints[1]);
325+
} else {
324326
return CMD_RES_NOT_ENOUGH_ARGUMENTS;
325327
}
326-
327328
CFG_SetFlags(u.ints[0], u.ints[1]);
328329
ADDLOG_INFO(LOG_FEATURE_CMD, "New flags set!");
329330

src/httpserver/http_fns.c

+25-2
Original file line numberDiff line numberDiff line change
@@ -2818,6 +2818,26 @@ const char* g_obk_flagNames[] = {
28182818
"error",
28192819
"error",
28202820
};
2821+
2822+
void uint64_to_str(uint64_t num, char* str) {
2823+
char temp[21]; // uint64_t 20 numbers + \0
2824+
int i = 0;
2825+
if (num == 0) {
2826+
temp[i++] = '0';
2827+
} else {
2828+
while (num > 0) {
2829+
temp[i++] = '0' + (num % 10);
2830+
num /= 10;
2831+
}
2832+
}
2833+
temp[i] = '\0';
2834+
int j;
2835+
for (j = 0; j < i; j++) {
2836+
str[j] = temp[i - j - 1];
2837+
}
2838+
str[j] = '\0';
2839+
}
2840+
28212841
int http_fn_cfg_generic(http_request_t* request) {
28222842
int i;
28232843
char tmpA[64];
@@ -2855,9 +2875,12 @@ int http_fn_cfg_generic(http_request_t* request) {
28552875
CFG_Save_IfThereArePendingChanges();
28562876

28572877
// 32 bit type
2858-
hprintf255(request, "<h4>Flags (Current value=%i)</h4>", CFG_GetFlags());
2878+
//hprintf255(request, "<h4>Flags (Current value=%i)</h4>", CFG_GetFlags());
28592879
// 64 bit - TODO fixme
2860-
//hprintf255(request, "<h4>Flags (Current value=%lu)</h4>", CFG_GetFlags64());
2880+
//hprintf255(request, "<h4>Flags (Current value=%llu)</h4>", CFG_GetFlags64());
2881+
char buf[21];
2882+
uint64_to_str(CFG_GetFlags64(), buf);
2883+
hprintf255(request, "<h4>Flags (Current value=%s)</h4>", buf);
28612884
poststr(request, "<form action=\"/cfg_generic\">");
28622885

28632886
for (i = 0; i < OBK_TOTAL_FLAGS; i++) {

src/new_cfg.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ int CFG_DeviceGroups_GetSendFlags() {
510510
int CFG_DeviceGroups_GetRecvFlags() {
511511
return g_cfg.dgr_recvFlags;
512512
}
513-
void CFG_SetFlags(int first4bytes, int second4bytes) {
513+
void CFG_SetFlags(uint32_t first4bytes, uint32_t second4bytes) {
514514
if (g_cfg.genericFlags != first4bytes || g_cfg.genericFlags2 != second4bytes) {
515515
g_cfg.genericFlags = first4bytes;
516516
g_cfg.genericFlags2 = second4bytes;
@@ -571,9 +571,10 @@ bool CFG_HasLoggerFlag(int flag) {
571571
int CFG_GetFlags() {
572572
return g_cfg.genericFlags;
573573
}
574-
unsigned long CFG_GetFlags64() {
575-
unsigned long* pAllGenericFlags = (unsigned long*)&g_cfg.genericFlags;
576-
return *pAllGenericFlags;
574+
uint64_t CFG_GetFlags64() {
575+
//unsigned long long* pAllGenericFlags = (unsigned long*)&g_cfg.genericFlags;
576+
//*pAllGenericFlags;
577+
return (uint64_t)g_cfg.genericFlags | (uint64_t)g_cfg.genericFlags2 << 32;
577578
}
578579
bool CFG_HasFlag(int flag) {
579580
if (flag >= 32) {

src/new_cfg.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ void CFG_DeviceGroups_SetRecvFlags(int newSendFlags);
6969
const char *CFG_DeviceGroups_GetName();
7070
int CFG_DeviceGroups_GetSendFlags();
7171
int CFG_DeviceGroups_GetRecvFlags();
72-
void CFG_SetFlags(int first4bytes, int second4bytes);
72+
void CFG_SetFlags(uint32_t first4bytes, uint32_t second4bytes);
7373
void CFG_SetFlag(int flag, bool bValue);
7474
bool CFG_HasFlag(int flag);
7575
void CFG_SetLoggerFlag(int flag, bool bValue);
7676
bool CFG_HasLoggerFlag(int flag);
7777
void CFG_SetMac(char *mac);
7878
int CFG_GetFlags();
79-
unsigned long CFG_GetFlags64();
79+
uint64_t CFG_GetFlags64();
8080
const char* CFG_GetNTPServer();
8181
void CFG_SetNTPServer(const char *s);
8282
// BL0937, BL0942, etc constants

src/new_pins.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1274,9 +1274,9 @@ typedef struct mainConfig_s {
12741274
// 0x4
12751275
int version;
12761276
// 0x08
1277-
int genericFlags;
1277+
uint32_t genericFlags;
12781278
// 0x0C
1279-
int genericFlags2;
1279+
uint32_t genericFlags2;
12801280
// 0x10
12811281
unsigned short changeCounter;
12821282
unsigned short otaCounter;

0 commit comments

Comments
 (0)