2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
21 int8_t ms5611_crc(uint16_t *prom);
22 void ms5611_calculate(int32_t *pressure, int32_t *temperature);
24 extern uint16_t ms5611_c[8];
25 extern uint32_t ms5611_up;
26 extern uint32_t ms5611_ut;
31 #include "unittest_macros.h"
32 #include "gtest/gtest.h"
35 TEST(baroMS5611Test, TestValidMs5611Crc)
39 uint16_t ms5611_prom[] = {0x3132,0x3334,0x3536,0x3738,0x3940,0x4142,0x4344,0x450B};
42 int8_t result = ms5611_crc(ms5611_prom);
49 TEST(baroMS5611Test, TestInvalidMs5611Crc)
53 uint16_t ms5611_prom[] = {0x3132,0x3334,0x3536,0x3738,0x3940,0x4142,0x4344,0x4500};
56 int8_t result = ms5611_crc(ms5611_prom);
59 EXPECT_EQ(-1, result);
63 TEST(baroMS5611Test, TestMs5611AllZeroProm)
67 uint16_t ms5611_prom[] = {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
70 int8_t result = ms5611_crc(ms5611_prom);
73 EXPECT_EQ(-1, result);
77 TEST(baroMS5611Test, TestMs5611AllOnesProm)
81 uint16_t ms5611_prom[] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
84 int8_t result = ms5611_crc(ms5611_prom);
87 EXPECT_EQ(-1, result);
91 TEST(baroMS5611Test, TestMs5611CalculatePressureGT20Deg)
95 int32_t pressure, temperature;
96 uint16_t ms5611_c_test[] = {0x0000, 40127, 36924, 23317, 23282, 33464, 28312, 0x0000}; // calibration data from MS5611 datasheet
97 memcpy(&ms5611_c, &ms5611_c_test, sizeof(ms5611_c_test));
99 ms5611_up = 9085466; // Digital pressure value from MS5611 datasheet
100 ms5611_ut = 8569150; // Digital temperature value from MS5611 datasheet
103 ms5611_calculate(&pressure, &temperature);
106 EXPECT_EQ(2007, temperature); // 20.07 deg C
107 EXPECT_EQ(100009, pressure); // 1000.09 mbar
111 TEST(baroMS5611Test, TestMs5611CalculatePressureLT20Deg)
115 int32_t pressure, temperature;
116 uint16_t ms5611_c_test[] = {0x0000, 40127, 36924, 23317, 23282, 33464, 28312, 0x0000}; // calibration data from MS5611 datasheet
117 memcpy(&ms5611_c, &ms5611_c_test, sizeof(ms5611_c_test));
119 ms5611_up = 9085466; // Digital pressure value from MS5611 datasheet
120 ms5611_ut = 8069150; // Digital temperature value
123 ms5611_calculate(&pressure, &temperature);
126 EXPECT_EQ(205, temperature); // 2.05 deg C
127 EXPECT_EQ(96512, pressure); // 965.12 mbar
131 TEST(baroMS5611Test, TestMs5611CalculatePressureLTMinus15Deg)
135 int32_t pressure, temperature;
136 uint16_t ms5611_c_test[] = {0x0000, 40127, 36924, 23317, 23282, 33464, 28312, 0x0000}; // calibration data from MS5611 datasheet
137 memcpy(&ms5611_c, &ms5611_c_test, sizeof(ms5611_c_test));
139 ms5611_up = 9085466; // Digital pressure value from MS5611 datasheet
140 ms5611_ut = 7369150; // Digital temperature value
143 ms5611_calculate(&pressure, &temperature);
146 EXPECT_EQ(-2710, temperature); // -27.10 deg C
147 EXPECT_EQ(90613, pressure); // 906.13 mbar
155 void delay(uint32_t) {}
156 void delayMicroseconds(uint32_t) {}
157 bool i2cWrite(uint8_t, uint8_t, uint8_t) {
160 bool i2cRead(uint8_t, uint8_t, uint8_t, uint8_t) {