fix flags error?

This commit is contained in:
Tester23
2025-01-05 15:01:41 +01:00
parent 3a1c3e9bbf
commit 9cf91af8aa
5 changed files with 16 additions and 16 deletions

View File

@@ -248,27 +248,22 @@ static commandResult_t CMD_SetFlag(const void* context, const char* cmd, const c
return CMD_RES_OK;
}
static commandResult_t CMD_Flags(const void* context, const char* cmd, const char* args, int cmdFlags) {
union {
long long newValue;
struct {
int ints[2];
int dummy[2]; // just to be safe
};
} u;
long long newValue;
// TODO: check on other platforms, on Beken it's 8, 64 bit
// On Windows simulator it's 8 as well
//ADDLOG_INFO(LOG_FEATURE_CMD, "CMD_Flags: sizeof(newValue) = %i", sizeof(u.newValue));
if (args && *args) {
if (1 != sscanf(args, "%lld", &u.newValue)) {
if (1 != sscanf(args, "%llu", &newValue)) {
//ADDLOG_INFO(LOG_FEATURE_CMD, "Argument/sscanf error!");
return CMD_RES_BAD_ARGUMENT;
}
}
else {
ADDLOG_INFO(LOG_FEATURE_CMD, "Flags are %llu",&g_cfg.genericFlags);
return CMD_RES_NOT_ENOUGH_ARGUMENTS;
}
CFG_SetFlags(u.ints[0], u.ints[1]);
int *ints = (int)&newValue;
CFG_SetFlags(ints[0], ints[1]);
ADDLOG_INFO(LOG_FEATURE_CMD, "New flags set!");
return CMD_RES_OK;

View File

@@ -563,8 +563,8 @@ bool CFG_HasLoggerFlag(int flag) {
int CFG_GetFlags() {
return g_cfg.genericFlags;
}
unsigned long CFG_GetFlags64() {
unsigned long* pAllGenericFlags = (unsigned long*)&g_cfg.genericFlags;
unsigned long long CFG_GetFlags64() {
unsigned long long* pAllGenericFlags = (unsigned long long*)&g_cfg.genericFlags;
return *pAllGenericFlags;
}
bool CFG_HasFlag(int flag) {

View File

@@ -76,7 +76,7 @@ void CFG_SetLoggerFlag(int flag, bool bValue);
bool CFG_HasLoggerFlag(int flag);
void CFG_SetMac(char *mac);
int CFG_GetFlags();
unsigned long CFG_GetFlags64();
unsigned long long CFG_GetFlags64();
const char* CFG_GetNTPServer();
void CFG_SetNTPServer(const char *s);
// BL0937, BL0942, etc constants

View File

@@ -191,8 +191,13 @@ void Test_Commands_Generic() {
CMD_ExecuteCommand("Flags 444", 0);
SELFTEST_ASSERT(CFG_GetFlags() == 444);
SELFTEST_ASSERT(CFG_GetFlags64() == 444);
//CMD_ExecuteCommand("Flags 8589934592", 0);
//SELFTEST_ASSERT(CFG_GetFlags64() == 8589934592);
CMD_ExecuteCommand("Flags 8589934592", 0);
SELFTEST_ASSERT(CFG_GetFlags64() == 8589934592);
CMD_ExecuteCommand("Flags 8589934594", 0);
SELFTEST_ASSERT(CFG_GetFlags64() == 8589934594);
CMD_ExecuteCommand("Flags 8589934593", 0);
SELFTEST_ASSERT(CFG_GetFlags64() == 8589934593);
}

View File

@@ -129,6 +129,7 @@ void SIM_ClearOBK(const char *flashPath) {
Main_Init();
}
void Win_DoUnitTests() {
Test_Commands_Generic();
Test_TuyaMCU_Boolean();
Test_TuyaMCU_DP22();
@@ -166,7 +167,6 @@ void Win_DoUnitTests() {
Test_Demo_ButtonScrollingChannelValues();
Test_CFG_Via_HTTP();
Test_Commands_Calendar();
Test_Commands_Generic();
Test_Demo_SimpleShuttersScript();
Test_Role_ToggleAll();
Test_Demo_FanCyclingRelays();