2019-01-03 21:30:15 -08:00
|
|
|
/*
|
|
|
|
* @file test_hip9011.cpp
|
|
|
|
*
|
|
|
|
* Created on: Mar 22, 2018
|
|
|
|
*/
|
|
|
|
|
2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
2019-04-12 13:08:52 -07:00
|
|
|
#include "hip9011_logic.h"
|
2021-08-03 19:05:01 -07:00
|
|
|
|
2019-01-07 22:20:18 -08:00
|
|
|
using ::testing::_;
|
2019-01-03 21:30:15 -08:00
|
|
|
|
|
|
|
TEST(hip9011, lookup) {
|
2021-03-30 07:56:25 -07:00
|
|
|
HIP9011 instance(NULL);
|
|
|
|
|
|
|
|
assertEqualsM2("", 3183.1013, instance.getRpmByAngleWindowAndTimeUs(600, 360), 0.1);
|
|
|
|
assertEqualsM2("40us", 47746.5195, instance.getRpmByAngleWindowAndTimeUs(40, 360), 0.1);
|
2019-01-03 21:30:15 -08:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
assertEqualsM2("600us 50 degree", 442.0974, instance.getRpmByAngleWindowAndTimeUs(600, 50), 0.1);
|
|
|
|
assertEqualsM2("240us 50 degree", 1105.2435, instance.getRpmByAngleWindowAndTimeUs(240, 50), 0.1);
|
|
|
|
assertEqualsM2("240us 50 degree", 6631.4619, instance.getRpmByAngleWindowAndTimeUs(40, 50), 0.1);
|
2019-01-03 21:30:15 -08:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
EXPECT_EQ(0, instance.getGainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/3, 0, NAN, NAN));
|
|
|
|
EXPECT_EQ(0, instance.getGainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/2, 0, NAN, NAN));
|
|
|
|
EXPECT_EQ(47, instance.getGainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/0.234, 0, NAN, NAN));
|
|
|
|
EXPECT_EQ(63, instance.getGainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/0.000001, 0, NAN, NAN));
|
|
|
|
EXPECT_EQ(63, instance.getGainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/-1.0, 0, NAN, NAN));
|
2019-01-03 21:30:15 -08:00
|
|
|
|
2019-01-07 20:23:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(hip9011, rpmLookup) {
|
2019-01-16 20:36:38 -08:00
|
|
|
HIP9011 instance(NULL);
|
2019-01-07 20:23:50 -08:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
instance.angleWindowWidth = 50.0;
|
|
|
|
instance.prepareRpmLookup();
|
2019-01-03 21:30:15 -08:00
|
|
|
|
2019-01-16 20:36:38 -08:00
|
|
|
EXPECT_EQ(31, instance.getIntegrationIndexByRpm(1));
|
|
|
|
EXPECT_EQ(21, instance.getIntegrationIndexByRpm(1100));
|
|
|
|
EXPECT_EQ(1, instance.getIntegrationIndexByRpm(6600));
|
|
|
|
EXPECT_EQ(0, instance.getIntegrationIndexByRpm(16600));
|
2019-01-03 21:30:15 -08:00
|
|
|
}
|
2019-01-03 21:51:32 -08:00
|
|
|
|
|
|
|
TEST(hip9011, band) {
|
2021-03-30 07:56:25 -07:00
|
|
|
HIP9011 instance(NULL);
|
2019-01-03 21:51:32 -08:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
EXPECT_FLOAT_EQ(3, instance.getBand(/* knockBandCustom*/3, /*cylinderBore*/76, /*hip9011Gain*/NAN, 0, NAN, NAN));
|
2022-01-14 18:51:03 -08:00
|
|
|
EXPECT_NEAR_M4(7.5389242, instance.getBand(/* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/NAN, 0, NAN, NAN));
|
2019-01-03 21:51:32 -08:00
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
EXPECT_EQ(42, instance.getBandIndex(/* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/NAN, 0, NAN, NAN));
|
2019-01-04 06:24:23 -08:00
|
|
|
|
2019-01-03 21:51:32 -08:00
|
|
|
}
|
2019-01-07 21:28:53 -08:00
|
|
|
|
|
|
|
class MockHip9011Hardware : public Hip9011HardwareInterface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MockHip9011Hardware() { }
|
|
|
|
|
2021-03-30 07:56:25 -07:00
|
|
|
MOCK_METHOD2(sendSyncCommand, int(unsigned char, unsigned char *));
|
2019-01-07 21:28:53 -08:00
|
|
|
};
|
|
|
|
|
2019-01-07 22:20:18 -08:00
|
|
|
TEST(hip9011, configurationCommands) {
|
2019-01-07 21:28:53 -08:00
|
|
|
|
2019-01-07 22:20:18 -08:00
|
|
|
MockHip9011Hardware mock;
|
|
|
|
|
|
|
|
HIP9011 instance(&mock);
|
|
|
|
|
|
|
|
// want to invoke method with same parameters a few times
|
2021-02-28 12:42:57 -08:00
|
|
|
#define PARAMETERS 600, /* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/1, HIP_8MHZ_PRESCALER, 0.0, 50.0
|
2019-01-07 22:20:18 -08:00
|
|
|
|
|
|
|
// Not making assumptions on the message send ...
|
2021-03-30 07:56:25 -07:00
|
|
|
EXPECT_CALL(mock, sendSyncCommand(SET_GAIN_CMD(0xE), 0)).Times(1);
|
|
|
|
EXPECT_CALL(mock, sendSyncCommand(SET_INTEGRATOR_CMD(0x1C), 0)).Times(1);
|
|
|
|
EXPECT_CALL(mock, sendSyncCommand(SET_BAND_PASS_CMD(0x2A), 0)).Times(1);
|
|
|
|
EXPECT_CALL(mock, sendSyncCommand(SET_PRESCALER_CMD(6), 0)).Times(1);
|
|
|
|
instance.handleSettings(PARAMETERS);
|
2019-01-07 22:20:18 -08:00
|
|
|
|
|
|
|
// initialization is over, no commands should be sent
|
2021-03-30 07:56:25 -07:00
|
|
|
EXPECT_CALL(mock, sendSyncCommand(_, _)).Times(0);
|
|
|
|
instance.handleSettings(PARAMETERS);
|
2019-01-07 21:28:53 -08:00
|
|
|
}
|