testing calc enable
This commit is contained in:
@@ -12,4 +12,5 @@ void EvseRead();
|
||||
bool CheckStartCondition();
|
||||
bool CheckVoltage();
|
||||
void ResetValuesInOffMode();
|
||||
void CalcEnable();
|
||||
#endif
|
||||
|
||||
Binary file not shown.
@@ -1,4 +1,5 @@
|
||||
#include "my_math.h"
|
||||
#include "errormessage.h"
|
||||
#include "charger.h"
|
||||
#ifdef TEST_COMMON_H
|
||||
#include "../test/test_common.h"
|
||||
@@ -177,3 +178,33 @@ void ResetValuesInOffMode()
|
||||
}
|
||||
}
|
||||
|
||||
void CalcEnable()
|
||||
{
|
||||
static int recheckCan = 10;
|
||||
bool enablePol = Param::GetBool(Param::enablepol);
|
||||
bool enable = DigIo::enable_in.Get() ^ enablePol;
|
||||
|
||||
enable &= !Param::GetBool(Param::cancontrol) || Param::GetBool(Param::canenable);
|
||||
|
||||
if (Param::GetBool(Param::cancontrol))
|
||||
{
|
||||
if (recheckCan == 0)
|
||||
{
|
||||
if (Param::GetInt(Param::canenable) == 3)
|
||||
{
|
||||
Param::SetInt(Param::canenable, 0);
|
||||
ErrorMessage::Post(ERR_EXTCAN);
|
||||
}
|
||||
else
|
||||
{
|
||||
Param::SetInt(Param::canenable, 3); //Must be overwritten by CAN message within the next second
|
||||
}
|
||||
recheckCan = 10;
|
||||
}
|
||||
|
||||
recheckCan--;
|
||||
}
|
||||
|
||||
Param::SetInt(Param::enable, enable);
|
||||
}
|
||||
|
||||
|
||||
@@ -211,36 +211,6 @@ static void ChargerStateMachine()
|
||||
Param::SetInt(Param::state, state);
|
||||
}
|
||||
|
||||
static void CalcEnable()
|
||||
{
|
||||
static int recheckCan = 10;
|
||||
bool enablePol = Param::GetBool(Param::enablepol);
|
||||
bool enable = DigIo::enable_in.Get() ^ enablePol;
|
||||
|
||||
enable &= !Param::GetBool(Param::cancontrol) || Param::GetBool(Param::canenable);
|
||||
|
||||
if (Param::GetBool(Param::cancontrol))
|
||||
{
|
||||
if (recheckCan == 0)
|
||||
{
|
||||
if (Param::GetInt(Param::canenable) == 3)
|
||||
{
|
||||
Param::SetInt(Param::canenable, 0);
|
||||
ErrorMessage::Post(ERR_EXTCAN);
|
||||
}
|
||||
else
|
||||
{
|
||||
Param::SetInt(Param::canenable, 3); //Must be overwritten by CAN message within the next second
|
||||
}
|
||||
recheckCan = 10;
|
||||
}
|
||||
|
||||
recheckCan--;
|
||||
}
|
||||
|
||||
Param::SetInt(Param::enable, enable);
|
||||
}
|
||||
|
||||
//sample 100ms task
|
||||
static void Ms100Task(void)
|
||||
{
|
||||
|
||||
@@ -26,6 +26,7 @@ int main() {
|
||||
(TestCase){"test_check_start_condition", test_check_start_condition},
|
||||
(TestCase){"test_check_voltage", test_check_voltage},
|
||||
(TestCase){"test_reset_values_in_off_mode", test_reset_values_in_off_mode},
|
||||
(TestCase){"test_calc_enable", test_calc_enable},
|
||||
// Example:
|
||||
//(TestCase){"Your tests name", function_name_without_brackets}
|
||||
//...
|
||||
|
||||
Binary file not shown.
@@ -181,3 +181,60 @@ void test_reset_values_in_off_mode(){
|
||||
assert(0 == Param::GetInt(Param::c3stt));
|
||||
assert(0 == Param::GetInt(Param::c3uac));
|
||||
}
|
||||
|
||||
void test_calc_enable(){
|
||||
|
||||
int enable;
|
||||
|
||||
//default off
|
||||
Param::SetInt(Param::enable, 0);
|
||||
Param::SetInt(Param::enablepol, 0); // polarity switch for DigIo
|
||||
Param::SetInt(Param::cancontrol, 0);
|
||||
Param::SetInt(Param::canenable, 0);
|
||||
DigIo::enable_in.Clear();
|
||||
CalcEnable();
|
||||
enable = Param::GetInt(Param::enable);
|
||||
assert(!enable);
|
||||
|
||||
//only DigIo high -> on
|
||||
Param::SetInt(Param::enable, 0);
|
||||
Param::SetInt(Param::enablepol, 0);
|
||||
Param::SetInt(Param::cancontrol, 0);
|
||||
Param::SetInt(Param::canenable, 0);
|
||||
DigIo::enable_in.Set();
|
||||
CalcEnable();
|
||||
enable = Param::GetInt(Param::enable);
|
||||
assert(enable);
|
||||
|
||||
//DigIo and enablepol high -> off
|
||||
Param::SetInt(Param::enable, 0);
|
||||
Param::SetInt(Param::enablepol, 1);
|
||||
Param::SetInt(Param::cancontrol, 0);
|
||||
Param::SetInt(Param::canenable, 0);
|
||||
DigIo::enable_in.Set();
|
||||
CalcEnable();
|
||||
enable = Param::GetInt(Param::enable);
|
||||
assert(!enable);
|
||||
|
||||
|
||||
// DigIo & canenable -> on
|
||||
Param::SetInt(Param::enable, 0);
|
||||
Param::SetInt(Param::enablepol, 0);
|
||||
Param::SetInt(Param::cancontrol, 0);
|
||||
Param::SetInt(Param::canenable, 2);
|
||||
DigIo::enable_in.Set();
|
||||
CalcEnable();
|
||||
enable = Param::GetInt(Param::enable);
|
||||
assert(enable);
|
||||
|
||||
//recheck can after 10+ calls
|
||||
// TODO unfinished test
|
||||
//int canenable = Param::GetInt(Param::canenable);
|
||||
//Param::SetInt(Param::cancontrol, 1);
|
||||
//for(int i =0; i < 15;i++){
|
||||
// CalcEnable();
|
||||
// enable = Param::GetInt(Param::enable);
|
||||
// assert(enable);
|
||||
//}
|
||||
//assert(3 == canenable);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user