Skip to content

Commit

Permalink
charging driver small self test
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Aug 8, 2023
1 parent 30aa47f commit a362dc0
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions openBeken_win32_mvsc2017.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@
</ClCompile>
<ClCompile Include="src\selftest\selftest_batteryDriver.c" />
<ClCompile Include="src\selftest\selftest_buttonEvents.c" />
<ClCompile Include="src\selftest\selftest_chargingDriver.c" />
<ClCompile Include="src\selftest\selftest_clockEvents.c" />
<ClCompile Include="src\selftest\selftest_cmd_startup.c" />
<ClCompile Include="src\selftest\selftest_flashSearch.c" />
Expand Down
3 changes: 3 additions & 0 deletions openBeken_win32_mvsc2017.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,9 @@
<ClCompile Include="src\driver\drv_chargingLimit.c">
<Filter>Drv</Filter>
</ClCompile>
<ClCompile Include="src\selftest\selftest_chargingDriver.c">
<Filter>SelfTest</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\new_cfg.h" />
Expand Down
49 changes: 49 additions & 0 deletions src/selftest/selftest_chargingDriver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifdef WINDOWS

#include "selftest_local.h"

void Test_ChargeLimitDriver() {
int i;
// reset whole device
SIM_ClearOBK(0);

int start10 = 1000;
CHANNEL_Set(10, start10, 0);
CHANNEL_Set(12, 0, 0);
CMD_ExecuteCommand("startDriver ChargingLimit", 0);
// chSetupLimit 5 5000 3600 "POWER OFF"
CMD_ExecuteCommand("alias MyEvent SetChannel 12 1", 0);
CMD_ExecuteCommand("chSetupLimit 10 5 3600 MyEvent", 0);

// simulate time passing
for (int i = 0; i < 10; i++) {
CMD_ExecuteCommand("addChannel 10 2", 0);
Main_OnEverySecond();
int val10 = CHANNEL_Get(10);
int nowDelta = val10 - start10;
if (nowDelta >= 5) {
SELFTEST_ASSERT_CHANNEL(12,1);
}
else {
SELFTEST_ASSERT_CHANNEL(12, 0);
}
}

// simulate time passing - time limit 5 seconds
CHANNEL_Set(12, 0, 0);
CMD_ExecuteCommand("chSetupLimit 10 5 5 MyEvent", 0);
for (int i = 0; i < 15; i++) {
Main_OnEverySecond();
// has 5 seconds passed?
if (i >= 4) {
SELFTEST_ASSERT_CHANNEL(12, 1);
}
else {
SELFTEST_ASSERT_CHANNEL(12, 0);
}
}

}


#endif
1 change: 1 addition & 0 deletions src/selftest/selftest_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ void Test_WaitFor();
void Test_IF_Inside_Backlog();
void Test_MQTT_Get_LED_EnableAll();
void Test_TuyaMCU_BatteryPowered();
void Test_ChargeLimitDriver();

void Test_GetJSONValue_Setup(const char *text);
void Test_FakeHTTPClientPacket_GET(const char *tg);
Expand Down
1 change: 1 addition & 0 deletions src/win_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ void SIM_ClearOBK(const char *flashPath) {
}
void Win_DoUnitTests() {

Test_ChargeLimitDriver();
// this is slowest
Test_TuyaMCU_Basic();
Test_Battery();
Expand Down

0 comments on commit a362dc0

Please sign in to comment.