drivers: IMU WT61PC noi thang UART (mcu.protocol: wt61pc), bo ESP32 -- doc quyen cong, tach khung co resync, canh bao khi im
This commit is contained in:
@@ -62,6 +62,8 @@ if(VSLAM_BUILD_DRIVERS)
|
||||
vslam_add_test(test_scan_sanitizer LIBS vslam_drivers vslam_common)
|
||||
vslam_add_test(test_clock_sync LIBS vslam_drivers vslam_common)
|
||||
vslam_add_test(test_mcu_protocol LIBS vslam_drivers vslam_common)
|
||||
vslam_add_test(test_wt61pc_protocol LIBS vslam_drivers vslam_common)
|
||||
vslam_add_test(test_wt61pc_bridge LIBS vslam_drivers vslam_common)
|
||||
vslam_add_test(test_record_io LIBS vslam_drivers vslam_common)
|
||||
# Tay cam: khoa CAM GIAC LAI port tu base_kit (he so turbo/slow, deadzone,
|
||||
# cu kich thang ma sat tinh, luat nhuong quyen 1.5 s). Khong can tay cam.
|
||||
|
||||
283
test/test_wt61pc_bridge.cc
Normal file
283
test/test_wt61pc_bridge.cc
Normal file
@@ -0,0 +1,283 @@
|
||||
// Cau noi WT61PC qua mot cap pty: phia slave la "cong serial" ma driver mo, phia
|
||||
// master la "cam bien" ghi khung vao. Chay duoc ma khong can phan cung, va di
|
||||
// qua dung termios/read cua driver that.
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <cmath>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "vslam/clock.h"
|
||||
#include "vslam/driver_config.h"
|
||||
#include "vslam/driver_interfaces.h"
|
||||
|
||||
using namespace vslam;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr double kG = 9.80665;
|
||||
constexpr double kDeg = M_PI / 180.0;
|
||||
|
||||
std::vector<uint8_t> MakeFrame(uint8_t type, int16_t x, int16_t y, int16_t z) {
|
||||
auto lo = [](int16_t v) {
|
||||
return static_cast<uint8_t>(static_cast<uint16_t>(v) & 0xFF);
|
||||
};
|
||||
auto hi = [](int16_t v) {
|
||||
return static_cast<uint8_t>((static_cast<uint16_t>(v) >> 8) & 0xFF);
|
||||
};
|
||||
std::vector<uint8_t> f = {0x55, type, lo(x), hi(x), lo(y), hi(y),
|
||||
lo(z), hi(z), 0x00, 0x00, 0x00};
|
||||
uint8_t sum = 0;
|
||||
for (size_t i = 0; i < 10; ++i) sum = static_cast<uint8_t>(sum + f[i]);
|
||||
f[10] = sum;
|
||||
return f;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Cat(std::initializer_list<std::vector<uint8_t>> parts) {
|
||||
std::vector<uint8_t> out;
|
||||
for (const auto& p : parts) out.insert(out.end(), p.begin(), p.end());
|
||||
return out;
|
||||
}
|
||||
|
||||
class FakePort {
|
||||
public:
|
||||
FakePort() {
|
||||
master_ = ::posix_openpt(O_RDWR | O_NOCTTY);
|
||||
if (master_ < 0) return;
|
||||
char name[128] = {};
|
||||
if (::grantpt(master_) != 0 || ::unlockpt(master_) != 0 ||
|
||||
::ptsname_r(master_, name, sizeof(name)) != 0) {
|
||||
::close(master_);
|
||||
master_ = -1;
|
||||
return;
|
||||
}
|
||||
slave_ = name;
|
||||
}
|
||||
~FakePort() {
|
||||
if (master_ >= 0) ::close(master_);
|
||||
}
|
||||
|
||||
bool ok() const { return master_ >= 0; }
|
||||
const std::string& slave() const { return slave_; }
|
||||
|
||||
void Write(const std::vector<uint8_t>& bytes) {
|
||||
size_t off = 0;
|
||||
while (off < bytes.size()) {
|
||||
const ssize_t n = ::write(master_, bytes.data() + off, bytes.size() - off);
|
||||
if (n <= 0) break;
|
||||
off += static_cast<size_t>(n);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int master_ = -1;
|
||||
std::string slave_;
|
||||
};
|
||||
|
||||
class ImuCollector {
|
||||
public:
|
||||
void Add(const Imu& imu) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(mu_);
|
||||
list_.push_back(imu);
|
||||
}
|
||||
cv_.notify_all();
|
||||
}
|
||||
bool WaitFor(size_t n, std::chrono::milliseconds timeout) {
|
||||
std::unique_lock<std::mutex> lk(mu_);
|
||||
return cv_.wait_for(lk, timeout, [&] { return list_.size() >= n; });
|
||||
}
|
||||
std::vector<Imu> Get() const {
|
||||
std::lock_guard<std::mutex> lk(mu_);
|
||||
return list_;
|
||||
}
|
||||
|
||||
private:
|
||||
mutable std::mutex mu_;
|
||||
std::condition_variable cv_;
|
||||
std::vector<Imu> list_;
|
||||
};
|
||||
|
||||
McuConfig MakeConfig(const std::string& port) {
|
||||
McuConfig c;
|
||||
c.protocol = McuProtocol::kWt61pc;
|
||||
c.port = port;
|
||||
c.baud = 9600;
|
||||
c.imu_lag_sec = 0.0;
|
||||
return c;
|
||||
}
|
||||
|
||||
// Kernel/pty khong chac ap TIOCEXCL (root thi khong bao gio bi chan). Tu kiem
|
||||
// truoc de test khong bao dong gia.
|
||||
bool PtyHonoursExcl(const std::string& slave) {
|
||||
const int a = ::open(slave.c_str(), O_RDWR | O_NOCTTY);
|
||||
if (a < 0) return false;
|
||||
bool honoured = false;
|
||||
if (::ioctl(a, TIOCEXCL) == 0) {
|
||||
errno = 0;
|
||||
const int b = ::open(slave.c_str(), O_RDWR | O_NOCTTY);
|
||||
honoured = (b < 0 && errno == EBUSY);
|
||||
if (b >= 0) ::close(b);
|
||||
::ioctl(a, TIOCNXCL);
|
||||
}
|
||||
::close(a);
|
||||
return honoured;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(Wt61pcBridge, PhatNgayKhiCoKhungGyroKhongDoiAngle) {
|
||||
FakePort port;
|
||||
if (!port.ok()) GTEST_SKIP() << "khong tao duoc pty (container khong co /dev/ptmx?)";
|
||||
auto bridge = CreateMcuBridge(MakeConfig(port.slave()), MakeSystemClock());
|
||||
ImuCollector got;
|
||||
bridge->SetImuCallback([&](ImuPtr imu) { got.Add(*imu); });
|
||||
ASSERT_TRUE(bridge->Open().ok());
|
||||
|
||||
// Chi Acc + Gyro, khong gui Angle: phai ra dung mot mau.
|
||||
port.Write(Cat({MakeFrame(0x51, 0, 0, 2048), MakeFrame(0x52, 0, 0, 16384)}));
|
||||
ASSERT_TRUE(got.WaitFor(1, 2000ms));
|
||||
|
||||
const auto v = got.Get();
|
||||
ASSERT_EQ(v.size(), 1u);
|
||||
EXPECT_NEAR(v[0].linear_acceleration.z, kG, 1e-9);
|
||||
EXPECT_NEAR(v[0].angular_velocity.z, 1000.0 * kDeg, 1e-9);
|
||||
// Khong mang orientation.
|
||||
EXPECT_LT(v[0].orientation_covariance[0], 0.0);
|
||||
EXPECT_TRUE(bridge->Stats().connected);
|
||||
bridge->Close();
|
||||
}
|
||||
|
||||
TEST(Wt61pcBridge, GyroKhongCoGiaTocDiTruocThiBoMau) {
|
||||
FakePort port;
|
||||
if (!port.ok()) GTEST_SKIP() << "khong tao duoc pty (container khong co /dev/ptmx?)";
|
||||
auto bridge = CreateMcuBridge(MakeConfig(port.slave()), MakeSystemClock());
|
||||
ImuCollector got;
|
||||
bridge->SetImuCallback([&](ImuPtr imu) { got.Add(*imu); });
|
||||
ASSERT_TRUE(bridge->Open().ok());
|
||||
|
||||
// Gyro lac loai, hoac Angle don doc: khong duoc ghep voi gia toc cu.
|
||||
port.Write(Cat({MakeFrame(0x52, 0, 0, 16384), MakeFrame(0x53, 1, 2, 3)}));
|
||||
EXPECT_FALSE(got.WaitFor(1, 400ms));
|
||||
|
||||
// Chu ky day du sau do thi ra mau.
|
||||
port.Write(Cat({MakeFrame(0x51, 0, 0, 2048), MakeFrame(0x52, 0, 0, 16384)}));
|
||||
EXPECT_TRUE(got.WaitFor(1, 2000ms));
|
||||
bridge->Close();
|
||||
}
|
||||
|
||||
TEST(Wt61pcBridge, DauThoiGianKhongLuiVaTruImuLag) {
|
||||
FakePort port;
|
||||
if (!port.ok()) GTEST_SKIP() << "khong tao duoc pty (container khong co /dev/ptmx?)";
|
||||
McuConfig cfg = MakeConfig(port.slave());
|
||||
cfg.imu_lag_sec = 0.2;
|
||||
auto clock = MakeSystemClock();
|
||||
auto bridge = CreateMcuBridge(cfg, clock);
|
||||
|
||||
std::mutex mu;
|
||||
std::vector<double> stamps;
|
||||
std::vector<double> seen_at;
|
||||
ImuCollector got;
|
||||
bridge->SetImuCallback([&](ImuPtr imu) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(mu);
|
||||
stamps.push_back(imu->header.stamp.toSec());
|
||||
seen_at.push_back(clock->Now().toSec());
|
||||
}
|
||||
got.Add(*imu);
|
||||
});
|
||||
ASSERT_TRUE(bridge->Open().ok());
|
||||
|
||||
// Nam chu ky lien nhau trong mot lan ghi: co the vao cung mot lan read().
|
||||
std::vector<uint8_t> burst;
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
const auto c = Cat({MakeFrame(0x51, 0, 0, 2048), MakeFrame(0x52, 0, 0, 16384),
|
||||
MakeFrame(0x53, 0, 0, 0)});
|
||||
burst.insert(burst.end(), c.begin(), c.end());
|
||||
}
|
||||
port.Write(burst);
|
||||
ASSERT_TRUE(got.WaitFor(5, 3000ms));
|
||||
bridge->Close();
|
||||
|
||||
std::lock_guard<std::mutex> lk(mu);
|
||||
ASSERT_GE(stamps.size(), 5u);
|
||||
for (size_t i = 1; i < stamps.size(); ++i) {
|
||||
EXPECT_GE(stamps[i], stamps[i - 1]) << "stamp lui o mau " << i;
|
||||
}
|
||||
// Moi stamp phai cu hon luc nhan it nhat imu_lag_sec (0.2 s), va khong cu hon
|
||||
// qua mot khoang vo ly.
|
||||
for (size_t i = 0; i < stamps.size(); ++i) {
|
||||
EXPECT_LE(stamps[i], seen_at[i] - 0.2 + 1e-3) << "mau " << i;
|
||||
EXPECT_GE(stamps[i], seen_at[i] - 0.2 - 1.0) << "mau " << i;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Wt61pcBridge, ImLangThiBaoLoiVaHetLoiKhiCoDuLieu) {
|
||||
FakePort port;
|
||||
if (!port.ok()) GTEST_SKIP() << "khong tao duoc pty (container khong co /dev/ptmx?)";
|
||||
McuConfig cfg = MakeConfig(port.slave());
|
||||
cfg.no_data_warn_sec = 0.3;
|
||||
auto bridge = CreateMcuBridge(cfg, MakeSystemClock());
|
||||
ImuCollector got;
|
||||
bridge->SetImuCallback([&](ImuPtr imu) { got.Add(*imu); });
|
||||
ASSERT_TRUE(bridge->Open().ok());
|
||||
|
||||
std::this_thread::sleep_for(800ms);
|
||||
EXPECT_FALSE(bridge->Stats().connected);
|
||||
EXPECT_NE(bridge->Stats().last_error.find("khong co khung"), std::string::npos)
|
||||
<< bridge->Stats().last_error;
|
||||
|
||||
port.Write(Cat({MakeFrame(0x51, 0, 0, 2048), MakeFrame(0x52, 0, 0, 16384)}));
|
||||
ASSERT_TRUE(got.WaitFor(1, 2000ms));
|
||||
EXPECT_TRUE(bridge->Stats().connected);
|
||||
bridge->Close();
|
||||
}
|
||||
|
||||
TEST(Wt61pcBridge, CongKhongTonTaiLaLoiUnavailable) {
|
||||
McuConfig cfg = MakeConfig("/dev/khong_co_imu_nay");
|
||||
auto bridge = CreateMcuBridge(cfg, MakeSystemClock());
|
||||
const StatusResponse st = bridge->Open();
|
||||
ASSERT_FALSE(st.ok());
|
||||
EXPECT_EQ(st.code, StatusCode::kUnavailable);
|
||||
EXPECT_NE(st.message.find("/dev/khong_co_imu_nay"), std::string::npos) << st.message;
|
||||
}
|
||||
|
||||
TEST(Wt61pcBridge, BaudKhongHoTroBiTuChoi) {
|
||||
FakePort port;
|
||||
if (!port.ok()) GTEST_SKIP() << "khong tao duoc pty (container khong co /dev/ptmx?)";
|
||||
McuConfig cfg = MakeConfig(port.slave());
|
||||
cfg.baud = 12345;
|
||||
auto bridge = CreateMcuBridge(cfg, MakeSystemClock());
|
||||
const StatusResponse st = bridge->Open();
|
||||
ASSERT_FALSE(st.ok());
|
||||
EXPECT_EQ(st.code, StatusCode::kInvalidArgument);
|
||||
}
|
||||
|
||||
TEST(Wt61pcBridge, DocQuyenCongChuongTrinhThuHaiBiEbusy) {
|
||||
FakePort port;
|
||||
if (!port.ok()) GTEST_SKIP() << "khong tao duoc pty (container khong co /dev/ptmx?)";
|
||||
if (!PtyHonoursExcl(port.slave())) {
|
||||
GTEST_SKIP() << "pty/kernel/quyen root nay khong ap TIOCEXCL";
|
||||
}
|
||||
auto bridge = CreateMcuBridge(MakeConfig(port.slave()), MakeSystemClock());
|
||||
ASSERT_TRUE(bridge->Open().ok());
|
||||
|
||||
errno = 0;
|
||||
const int fd = ::open(port.slave().c_str(), O_RDWR | O_NOCTTY);
|
||||
EXPECT_LT(fd, 0);
|
||||
EXPECT_EQ(errno, EBUSY);
|
||||
if (fd >= 0) ::close(fd);
|
||||
bridge->Close();
|
||||
}
|
||||
170
test/test_wt61pc_protocol.cc
Normal file
170
test/test_wt61pc_protocol.cc
Normal file
@@ -0,0 +1,170 @@
|
||||
#include "vslam/wt61pc_protocol.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
|
||||
using namespace vslam;
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr double kG = 9.80665;
|
||||
constexpr double kDeg = M_PI / 180.0;
|
||||
|
||||
// Dung mot khung 11 byte dung checksum.
|
||||
std::vector<uint8_t> MakeFrame(uint8_t type, int16_t x, int16_t y, int16_t z) {
|
||||
auto lo = [](int16_t v) {
|
||||
return static_cast<uint8_t>(static_cast<uint16_t>(v) & 0xFF);
|
||||
};
|
||||
auto hi = [](int16_t v) {
|
||||
return static_cast<uint8_t>((static_cast<uint16_t>(v) >> 8) & 0xFF);
|
||||
};
|
||||
std::vector<uint8_t> f = {0x55, type, lo(x), hi(x), lo(y), hi(y),
|
||||
lo(z), hi(z), 0x00, 0x00, 0x00};
|
||||
uint8_t sum = 0;
|
||||
for (size_t i = 0; i < 10; ++i) sum = static_cast<uint8_t>(sum + f[i]);
|
||||
f[10] = sum;
|
||||
return f;
|
||||
}
|
||||
|
||||
// Nap het chuoi byte, tra ve cac khung hop le theo thu tu.
|
||||
std::vector<Wt61pcFrame> Feed(Wt61pcParser& p, const std::vector<uint8_t>& bytes) {
|
||||
std::vector<Wt61pcFrame> out;
|
||||
Wt61pcFrame f;
|
||||
for (uint8_t b : bytes) {
|
||||
if (p.Push(b, &f)) out.push_back(f);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// --- Doi don vi ------------------------------------------------------------
|
||||
|
||||
TEST(Wt61pc, GiaToc) {
|
||||
Wt61pcParser p;
|
||||
// 2048 = 32768 / 16: dung 1 g.
|
||||
const auto fr = Feed(p, MakeFrame(0x51, 0, 0, 2048));
|
||||
ASSERT_EQ(fr.size(), 1u);
|
||||
EXPECT_EQ(fr[0].type, Wt61pcType::kAccel);
|
||||
EXPECT_NEAR(fr[0].x, 0.0, 1e-12);
|
||||
EXPECT_NEAR(fr[0].z, kG, 1e-9);
|
||||
}
|
||||
|
||||
TEST(Wt61pc, VanTocGocGiuDau) {
|
||||
Wt61pcParser p;
|
||||
// 16384 = nua thang do = 1000 do/s. Gia tri am phai giu dau (int16).
|
||||
const auto fr = Feed(p, MakeFrame(0x52, 16384, -16384, 0));
|
||||
ASSERT_EQ(fr.size(), 1u);
|
||||
EXPECT_EQ(fr[0].type, Wt61pcType::kGyro);
|
||||
EXPECT_NEAR(fr[0].x, 1000.0 * kDeg, 1e-9);
|
||||
EXPECT_NEAR(fr[0].y, -1000.0 * kDeg, 1e-9);
|
||||
EXPECT_NEAR(fr[0].z, 0.0, 1e-12);
|
||||
}
|
||||
|
||||
TEST(Wt61pc, Goc) {
|
||||
Wt61pcParser p;
|
||||
// 16384 = nua thang = 90 do.
|
||||
const auto fr = Feed(p, MakeFrame(0x53, 16384, -8192, 0));
|
||||
ASSERT_EQ(fr.size(), 1u);
|
||||
EXPECT_EQ(fr[0].type, Wt61pcType::kAngle);
|
||||
EXPECT_NEAR(fr[0].x, M_PI / 2.0, 1e-9);
|
||||
EXPECT_NEAR(fr[0].y, -M_PI / 4.0, 1e-9);
|
||||
}
|
||||
|
||||
// --- Dong byte ---------------------------------------------------------------
|
||||
|
||||
TEST(Wt61pc, MotChuKyBaKhungDungThuTu) {
|
||||
Wt61pcParser p;
|
||||
std::vector<uint8_t> in;
|
||||
for (uint8_t t : {0x51, 0x52, 0x53}) {
|
||||
const auto f = MakeFrame(t, 1, 2, 3);
|
||||
in.insert(in.end(), f.begin(), f.end());
|
||||
}
|
||||
const auto fr = Feed(p, in);
|
||||
ASSERT_EQ(fr.size(), 3u);
|
||||
EXPECT_EQ(fr[0].type, Wt61pcType::kAccel);
|
||||
EXPECT_EQ(fr[1].type, Wt61pcType::kGyro);
|
||||
EXPECT_EQ(fr[2].type, Wt61pcType::kAngle);
|
||||
EXPECT_EQ(p.bad_checksum(), 0u);
|
||||
EXPECT_EQ(p.skipped_bytes(), 0u);
|
||||
}
|
||||
|
||||
TEST(Wt61pc, KhungBiCatLamDoiQuaHaiLanNap) {
|
||||
// read() co the dut khung o bat ky byte nao.
|
||||
Wt61pcParser p;
|
||||
const auto f = MakeFrame(0x52, 100, 200, 300);
|
||||
const std::vector<uint8_t> a(f.begin(), f.begin() + 5);
|
||||
const std::vector<uint8_t> b(f.begin() + 5, f.end());
|
||||
EXPECT_TRUE(Feed(p, a).empty());
|
||||
const auto fr = Feed(p, b);
|
||||
ASSERT_EQ(fr.size(), 1u);
|
||||
EXPECT_EQ(fr[0].type, Wt61pcType::kGyro);
|
||||
}
|
||||
|
||||
TEST(Wt61pc, RacTruocKhungKhongPhaKhung) {
|
||||
Wt61pcParser p;
|
||||
std::vector<uint8_t> in = {0x01, 0x02, 0xFF, 0x00};
|
||||
const auto f = MakeFrame(0x52, 100, 200, 300);
|
||||
in.insert(in.end(), f.begin(), f.end());
|
||||
const auto fr = Feed(p, in);
|
||||
ASSERT_EQ(fr.size(), 1u);
|
||||
EXPECT_EQ(p.skipped_bytes(), 4u);
|
||||
}
|
||||
|
||||
TEST(Wt61pc, ChecksumSaiBiBoVaDem) {
|
||||
auto f = MakeFrame(0x51, 1, 2, 3);
|
||||
f[10] ^= 0x01;
|
||||
Wt61pcParser p;
|
||||
EXPECT_TRUE(Feed(p, f).empty());
|
||||
EXPECT_EQ(p.bad_checksum(), 1u);
|
||||
}
|
||||
|
||||
TEST(Wt61pc, HaiByteDauKhungLienTiepThiByteSauLaDauKhung) {
|
||||
// 0x55 0x55 ...: byte dau la rac, byte thu hai moi la dau khung that.
|
||||
Wt61pcParser p;
|
||||
std::vector<uint8_t> in = {0x55};
|
||||
const auto f = MakeFrame(0x51, 0, 0, 2048);
|
||||
in.insert(in.end(), f.begin(), f.end());
|
||||
const auto fr = Feed(p, in);
|
||||
ASSERT_EQ(fr.size(), 1u);
|
||||
EXPECT_NEAR(fr[0].z, kG, 1e-9);
|
||||
EXPECT_EQ(p.skipped_bytes(), 1u);
|
||||
}
|
||||
|
||||
TEST(Wt61pc, MatDongBoTrongKhungGiaVanLayDuocKhungThat) {
|
||||
// Dau gia "0x55 0x51" + 2 byte rac gom du 11 byte cung 7 byte dau cua khung
|
||||
// that, nen checksum sai. Neu bo ca 11 byte thi mat luon khung that -- o
|
||||
// 10 Hz do la mat ca mot mau. Parser phai truot toi 0x55 that.
|
||||
Wt61pcParser p;
|
||||
std::vector<uint8_t> in = {0x55, 0x51, 0x00, 0x00};
|
||||
const auto real = MakeFrame(0x52, 1000, -2000, 3000);
|
||||
in.insert(in.end(), real.begin(), real.end());
|
||||
const auto fr = Feed(p, in);
|
||||
ASSERT_EQ(fr.size(), 1u);
|
||||
EXPECT_EQ(fr[0].type, Wt61pcType::kGyro);
|
||||
EXPECT_NEAR(fr[0].x, 1000.0 * 2000.0 / 32768.0 * kDeg, 1e-9);
|
||||
EXPECT_NEAR(fr[0].y, -2000.0 * 2000.0 / 32768.0 * kDeg, 1e-9);
|
||||
EXPECT_NEAR(fr[0].z, 3000.0 * 2000.0 / 32768.0 * kDeg, 1e-9);
|
||||
EXPECT_EQ(p.bad_checksum(), 1u);
|
||||
}
|
||||
|
||||
TEST(Wt61pc, KhungLoaiKhacDungChecksumKhongTraVe) {
|
||||
// 0x54 = tu ke. WT61PC khong co; dem de thay khi cam nham cam bien.
|
||||
Wt61pcParser p;
|
||||
EXPECT_TRUE(Feed(p, MakeFrame(0x54, 1, 2, 3)).empty());
|
||||
EXPECT_EQ(p.other_frames(), 1u);
|
||||
EXPECT_EQ(p.bad_checksum(), 0u);
|
||||
// Khung ke tiep van doc duoc.
|
||||
EXPECT_EQ(Feed(p, MakeFrame(0x51, 0, 0, 2048)).size(), 1u);
|
||||
}
|
||||
|
||||
TEST(Wt61pc, ResetBoKhungDangDo) {
|
||||
Wt61pcParser p;
|
||||
const auto f = MakeFrame(0x51, 0, 0, 2048);
|
||||
const std::vector<uint8_t> head(f.begin(), f.begin() + 5);
|
||||
EXPECT_TRUE(Feed(p, head).empty());
|
||||
p.Reset();
|
||||
EXPECT_EQ(Feed(p, f).size(), 1u);
|
||||
}
|
||||
Reference in New Issue
Block a user