feat: 添加CM3/4/7的硬件与软件浮点单元构建矩阵,变更api接口为dr_*
This commit is contained in:
+98
-98
@@ -16,14 +16,14 @@ static const char *_cur_name;
|
||||
|
||||
#define FIXTURE_MAX 16
|
||||
typedef struct {
|
||||
datarouter_port_t ports[FIXTURE_MAX];
|
||||
dr_port_t ports[FIXTURE_MAX];
|
||||
int count;
|
||||
} fixture_t;
|
||||
|
||||
#define FIXTURE_INIT(f) memset((f), 0, sizeof(*(f)))
|
||||
#define FIXTURE_PUSH(f, p) do { if ((f)->count < FIXTURE_MAX) (f)->ports[(f)->count++] = (p); } while (0)
|
||||
#define FIXTURE_CLEAN(f) do { for (int _i = 0; _i < (f)->count; _i++) datarouter_port_delete((f)->ports[_i]); } while (0)
|
||||
#define FIXTURE_CREATE(f) ({ datarouter_port_t _p = datarouter_port_create(); FIXTURE_PUSH(f, _p); _p; })
|
||||
#define FIXTURE_CLEAN(f) do { for (int _i = 0; _i < (f)->count; _i++) dr_port_delete((f)->ports[_i]); } while (0)
|
||||
#define FIXTURE_CREATE(f) ({ dr_port_t _p = dr_port_create(); FIXTURE_PUSH(f, _p); _p; })
|
||||
|
||||
#define TEST_START(name) \
|
||||
static void test_##name(void) \
|
||||
@@ -68,7 +68,7 @@ static void reset_h(void) { _h_cnt = 0; _h_pos = 0; }
|
||||
* ================================================================ */
|
||||
|
||||
TEST_START(error_uninit)
|
||||
CHECK(datarouter_send_sensor("d", 1) == -1, "expected -1");
|
||||
CHECK(dr_send_sensor("d", 1) == -1, "expected -1");
|
||||
TEST_END()
|
||||
|
||||
/* ================================================================
|
||||
@@ -82,22 +82,22 @@ TEST_END()
|
||||
TEST_START(port_create_max)
|
||||
int c = 0;
|
||||
for (int i = 0; i < 64; i++) {
|
||||
datarouter_port_t p = datarouter_port_create();
|
||||
if (p == DATAROUTER_INVALID_PORT) break;
|
||||
dr_port_t p = dr_port_create();
|
||||
if (p == DR_INVALID_PORT) break;
|
||||
FIXTURE_PUSH(&_fix, p); c++;
|
||||
}
|
||||
CHECK(c >= 64, "got %d", c);
|
||||
CHECK(datarouter_port_create() == DATAROUTER_INVALID_PORT, NULL);
|
||||
CHECK(dr_port_create() == DR_INVALID_PORT, NULL);
|
||||
TEST_END()
|
||||
|
||||
TEST_START(port_delete_invalid)
|
||||
datarouter_port_delete(-1); datarouter_port_delete(999);
|
||||
dr_port_delete(-1); dr_port_delete(999);
|
||||
TEST_END()
|
||||
|
||||
TEST_START(port_default_state)
|
||||
datarouter_port_t p = FIXTURE_CREATE(&_fix);
|
||||
CHECK(datarouter_port_get_send_type(p) == -1, NULL);
|
||||
CHECK(datarouter_port_handler_count(p) == 0, NULL);
|
||||
dr_port_t p = FIXTURE_CREATE(&_fix);
|
||||
CHECK(dr_port_get_send_type(p) == -1, NULL);
|
||||
CHECK(dr_port_handler_count(p) == 0, NULL);
|
||||
TEST_END()
|
||||
|
||||
/* ================================================================
|
||||
@@ -105,26 +105,26 @@ TEST_END()
|
||||
* ================================================================ */
|
||||
|
||||
TEST_START(send_type_set_get)
|
||||
datarouter_port_t p = FIXTURE_CREATE(&_fix);
|
||||
datarouter_port_set_send_type(p, DATAROUTER_SEND_sensor);
|
||||
CHECK(datarouter_port_get_send_type(p) == DATAROUTER_SEND_sensor, NULL);
|
||||
datarouter_port_set_send_type(p, -1);
|
||||
CHECK(datarouter_port_get_send_type(p) == -1, NULL);
|
||||
dr_port_t p = FIXTURE_CREATE(&_fix);
|
||||
dr_port_set_send_type(p, DR_SEND_sensor);
|
||||
CHECK(dr_port_get_send_type(p) == DR_SEND_sensor, NULL);
|
||||
dr_port_set_send_type(p, -1);
|
||||
CHECK(dr_port_get_send_type(p) == -1, NULL);
|
||||
TEST_END()
|
||||
|
||||
TEST_START(handler_add_remove)
|
||||
datarouter_port_t p = FIXTURE_CREATE(&_fix);
|
||||
CHECK(datarouter_port_add_handler(p, _h) == 0, NULL);
|
||||
CHECK(datarouter_port_handler_count(p) == 1, NULL);
|
||||
CHECK(datarouter_port_remove_handler(p, _h) == 0, NULL);
|
||||
CHECK(datarouter_port_handler_count(p) == 0, NULL);
|
||||
dr_port_t p = FIXTURE_CREATE(&_fix);
|
||||
CHECK(dr_port_add_handler(p, _h) == 0, NULL);
|
||||
CHECK(dr_port_handler_count(p) == 1, NULL);
|
||||
CHECK(dr_port_remove_handler(p, _h) == 0, NULL);
|
||||
CHECK(dr_port_handler_count(p) == 0, NULL);
|
||||
TEST_END()
|
||||
|
||||
TEST_START(handler_clear)
|
||||
datarouter_port_t p = FIXTURE_CREATE(&_fix);
|
||||
datarouter_port_add_handler(p, _h);
|
||||
datarouter_port_clear_handlers(p);
|
||||
CHECK(datarouter_port_handler_count(p) == 0, NULL);
|
||||
dr_port_t p = FIXTURE_CREATE(&_fix);
|
||||
dr_port_add_handler(p, _h);
|
||||
dr_port_clear_handlers(p);
|
||||
CHECK(dr_port_handler_count(p) == 0, NULL);
|
||||
TEST_END()
|
||||
|
||||
/* ================================================================
|
||||
@@ -133,39 +133,39 @@ TEST_END()
|
||||
|
||||
TEST_START(send_no_match_port)
|
||||
/* 没有端口配置该 send_type */
|
||||
CHECK(datarouter_send_sensor("d", 1) == -2, "expected -2");
|
||||
CHECK(dr_send_sensor("d", 1) == -2, "expected -2");
|
||||
TEST_END()
|
||||
|
||||
TEST_START(send_one_port_one_handler)
|
||||
datarouter_port_t p = FIXTURE_CREATE(&_fix);
|
||||
datarouter_port_set_send_type(p, DATAROUTER_SEND_sensor);
|
||||
datarouter_port_add_handler(p, _h);
|
||||
dr_port_t p = FIXTURE_CREATE(&_fix);
|
||||
dr_port_set_send_type(p, DR_SEND_sensor);
|
||||
dr_port_add_handler(p, _h);
|
||||
reset_h();
|
||||
CHECK(datarouter_send_sensor("d", 1) == 0, NULL);
|
||||
CHECK(dr_send_sensor("d", 1) == 0, NULL);
|
||||
CHECK(_h_cnt == 1, "cnt=%d", _h_cnt);
|
||||
CHECK(_h_port[0] == (int)p, "port=%d", _h_port[0]);
|
||||
TEST_END()
|
||||
|
||||
TEST_START(send_one_port_multi_handler)
|
||||
datarouter_port_t p = FIXTURE_CREATE(&_fix);
|
||||
datarouter_port_set_send_type(p, DATAROUTER_SEND_sensor);
|
||||
datarouter_port_add_handler(p, _h);
|
||||
datarouter_port_add_handler(p, _h2);
|
||||
dr_port_t p = FIXTURE_CREATE(&_fix);
|
||||
dr_port_set_send_type(p, DR_SEND_sensor);
|
||||
dr_port_add_handler(p, _h);
|
||||
dr_port_add_handler(p, _h2);
|
||||
reset_h();
|
||||
CHECK(datarouter_send_sensor("d", 1) == 0, NULL);
|
||||
CHECK(dr_send_sensor("d", 1) == 0, NULL);
|
||||
CHECK(_h_cnt == 2, "cnt=%d", _h_cnt);
|
||||
TEST_END()
|
||||
|
||||
TEST_START(send_multi_ports_same_type)
|
||||
/* 两个端口同类型,各一个 handler */
|
||||
datarouter_port_t p1 = FIXTURE_CREATE(&_fix);
|
||||
datarouter_port_t p2 = FIXTURE_CREATE(&_fix);
|
||||
datarouter_port_set_send_type(p1, DATAROUTER_SEND_sensor);
|
||||
datarouter_port_set_send_type(p2, DATAROUTER_SEND_sensor);
|
||||
datarouter_port_add_handler(p1, _h);
|
||||
datarouter_port_add_handler(p2, _h);
|
||||
dr_port_t p1 = FIXTURE_CREATE(&_fix);
|
||||
dr_port_t p2 = FIXTURE_CREATE(&_fix);
|
||||
dr_port_set_send_type(p1, DR_SEND_sensor);
|
||||
dr_port_set_send_type(p2, DR_SEND_sensor);
|
||||
dr_port_add_handler(p1, _h);
|
||||
dr_port_add_handler(p2, _h);
|
||||
reset_h();
|
||||
CHECK(datarouter_send_sensor("d", 1) == 0, NULL);
|
||||
CHECK(dr_send_sensor("d", 1) == 0, NULL);
|
||||
CHECK(_h_cnt == 2, "cnt=%d", _h_cnt);
|
||||
/* p1 和 p2 各触发一次 */
|
||||
CHECK((_h_port[0]==p1 && _h_port[1]==p2) ||
|
||||
@@ -173,80 +173,80 @@ TEST_START(send_multi_ports_same_type)
|
||||
TEST_END()
|
||||
|
||||
TEST_START(send_multi_port_multi_handler)
|
||||
datarouter_port_t p1 = FIXTURE_CREATE(&_fix);
|
||||
datarouter_port_t p2 = FIXTURE_CREATE(&_fix);
|
||||
datarouter_port_set_send_type(p1, DATAROUTER_SEND_sensor);
|
||||
datarouter_port_set_send_type(p2, DATAROUTER_SEND_sensor);
|
||||
datarouter_port_add_handler(p1, _h);
|
||||
datarouter_port_add_handler(p1, _h2); /* p1 两个 */
|
||||
datarouter_port_add_handler(p2, _h3); /* p2 一个 */
|
||||
dr_port_t p1 = FIXTURE_CREATE(&_fix);
|
||||
dr_port_t p2 = FIXTURE_CREATE(&_fix);
|
||||
dr_port_set_send_type(p1, DR_SEND_sensor);
|
||||
dr_port_set_send_type(p2, DR_SEND_sensor);
|
||||
dr_port_add_handler(p1, _h);
|
||||
dr_port_add_handler(p1, _h2); /* p1 两个 */
|
||||
dr_port_add_handler(p2, _h3); /* p2 一个 */
|
||||
reset_h();
|
||||
CHECK(datarouter_send_sensor("d", 1) == 0, NULL);
|
||||
CHECK(dr_send_sensor("d", 1) == 0, NULL);
|
||||
CHECK(_h_cnt == 3, "cnt=%d", _h_cnt);
|
||||
TEST_END()
|
||||
|
||||
TEST_START(send_type_filter)
|
||||
/* 两个端口不同类型,只触发匹配的 */
|
||||
datarouter_port_t p1 = FIXTURE_CREATE(&_fix);
|
||||
datarouter_port_t p2 = FIXTURE_CREATE(&_fix);
|
||||
datarouter_port_set_send_type(p1, DATAROUTER_SEND_sensor);
|
||||
datarouter_port_set_send_type(p2, DATAROUTER_SEND_status);
|
||||
datarouter_port_add_handler(p1, _h);
|
||||
datarouter_port_add_handler(p2, _h);
|
||||
dr_port_t p1 = FIXTURE_CREATE(&_fix);
|
||||
dr_port_t p2 = FIXTURE_CREATE(&_fix);
|
||||
dr_port_set_send_type(p1, DR_SEND_sensor);
|
||||
dr_port_set_send_type(p2, DR_SEND_status);
|
||||
dr_port_add_handler(p1, _h);
|
||||
dr_port_add_handler(p2, _h);
|
||||
reset_h();
|
||||
CHECK(datarouter_send_sensor("d", 1) == 0, NULL);
|
||||
CHECK(dr_send_sensor("d", 1) == 0, NULL);
|
||||
CHECK(_h_cnt == 1, "cnt=%d", _h_cnt);
|
||||
CHECK(_h_port[0] == (int)p1, "only p1 should fire");
|
||||
TEST_END()
|
||||
|
||||
TEST_START(send_after_remove_handler)
|
||||
datarouter_port_t p = FIXTURE_CREATE(&_fix);
|
||||
datarouter_port_set_send_type(p, DATAROUTER_SEND_sensor);
|
||||
datarouter_port_add_handler(p, _h);
|
||||
reset_h(); datarouter_send_sensor("d", 1); CHECK(_h_cnt == 1, NULL);
|
||||
datarouter_port_remove_handler(p, _h);
|
||||
CHECK(datarouter_send_sensor("d", 1) == -2, "expected -2 after remove");
|
||||
dr_port_t p = FIXTURE_CREATE(&_fix);
|
||||
dr_port_set_send_type(p, DR_SEND_sensor);
|
||||
dr_port_add_handler(p, _h);
|
||||
reset_h(); dr_send_sensor("d", 1); CHECK(_h_cnt == 1, NULL);
|
||||
dr_port_remove_handler(p, _h);
|
||||
CHECK(dr_send_sensor("d", 1) == -2, "expected -2 after remove");
|
||||
TEST_END()
|
||||
|
||||
TEST_START(send_after_delete_port)
|
||||
datarouter_port_t p = FIXTURE_CREATE(&_fix);
|
||||
datarouter_port_set_send_type(p, DATAROUTER_SEND_sensor);
|
||||
datarouter_port_add_handler(p, _h);
|
||||
datarouter_port_delete(p);
|
||||
CHECK(datarouter_send_sensor("d", 1) == -2, "expected -2");
|
||||
dr_port_t p = FIXTURE_CREATE(&_fix);
|
||||
dr_port_set_send_type(p, DR_SEND_sensor);
|
||||
dr_port_add_handler(p, _h);
|
||||
dr_port_delete(p);
|
||||
CHECK(dr_send_sensor("d", 1) == -2, "expected -2");
|
||||
_fix.count--;
|
||||
TEST_END()
|
||||
|
||||
TEST_START(send_zero_length)
|
||||
datarouter_port_t p = FIXTURE_CREATE(&_fix);
|
||||
datarouter_port_set_send_type(p, DATAROUTER_SEND_sensor);
|
||||
datarouter_port_add_handler(p, _h);
|
||||
dr_port_t p = FIXTURE_CREATE(&_fix);
|
||||
dr_port_set_send_type(p, DR_SEND_sensor);
|
||||
dr_port_add_handler(p, _h);
|
||||
reset_h();
|
||||
CHECK(datarouter_send_sensor("x", 0) == 0, NULL);
|
||||
CHECK(dr_send_sensor("x", 0) == 0, NULL);
|
||||
CHECK(_h_cnt == 1, NULL);
|
||||
TEST_END()
|
||||
|
||||
TEST_START(send_null_data)
|
||||
datarouter_port_t p = FIXTURE_CREATE(&_fix);
|
||||
datarouter_port_set_send_type(p, DATAROUTER_SEND_sensor);
|
||||
datarouter_port_add_handler(p, _h);
|
||||
dr_port_t p = FIXTURE_CREATE(&_fix);
|
||||
dr_port_set_send_type(p, DR_SEND_sensor);
|
||||
dr_port_add_handler(p, _h);
|
||||
reset_h();
|
||||
CHECK(datarouter_send_sensor(NULL, 0) == 0, NULL);
|
||||
CHECK(dr_send_sensor(NULL, 0) == 0, NULL);
|
||||
CHECK(_h_cnt == 1, NULL);
|
||||
TEST_END()
|
||||
|
||||
TEST_START(send_multi_cap)
|
||||
/* 发送 status 不影响 sensor 端口 */
|
||||
datarouter_port_t p1 = FIXTURE_CREATE(&_fix);
|
||||
datarouter_port_t p2 = FIXTURE_CREATE(&_fix);
|
||||
datarouter_port_set_send_type(p1, DATAROUTER_SEND_sensor);
|
||||
datarouter_port_set_send_type(p2, DATAROUTER_SEND_status);
|
||||
datarouter_port_add_handler(p1, _h);
|
||||
datarouter_port_add_handler(p2, _h);
|
||||
dr_port_t p1 = FIXTURE_CREATE(&_fix);
|
||||
dr_port_t p2 = FIXTURE_CREATE(&_fix);
|
||||
dr_port_set_send_type(p1, DR_SEND_sensor);
|
||||
dr_port_set_send_type(p2, DR_SEND_status);
|
||||
dr_port_add_handler(p1, _h);
|
||||
dr_port_add_handler(p2, _h);
|
||||
reset_h();
|
||||
CHECK(datarouter_send_sensor("d", 1) == 0, NULL);
|
||||
CHECK(dr_send_sensor("d", 1) == 0, NULL);
|
||||
CHECK(_h_cnt == 1, "sensor: cnt=%d", _h_cnt);
|
||||
CHECK(datarouter_send_status("d", 1) == 0, NULL);
|
||||
CHECK(dr_send_status("d", 1) == 0, NULL);
|
||||
CHECK(_h_cnt == 2, "status: cnt=%d", _h_cnt);
|
||||
TEST_END()
|
||||
|
||||
@@ -255,12 +255,12 @@ TEST_END()
|
||||
* ================================================================ */
|
||||
|
||||
static int _rx_r;
|
||||
void datarouter_on_recv_rtcm(uint32_t p, const void *d, size_t l)
|
||||
void dr_on_recv_rtcm(uint32_t p, const void *d, size_t l)
|
||||
{ (void)p; (void)d; (void)l; _rx_r++; }
|
||||
|
||||
TEST_START(recv_callback)
|
||||
_rx_r = 0;
|
||||
datarouter_on_recv_rtcm(0, "d", 1);
|
||||
dr_on_recv_rtcm(0, "d", 1);
|
||||
CHECK(_rx_r == 1, "cnt=%d", _rx_r);
|
||||
TEST_END()
|
||||
|
||||
@@ -269,19 +269,19 @@ TEST_END()
|
||||
* ================================================================ */
|
||||
|
||||
TEST_START(send_cap_meta)
|
||||
CHECK(datarouter_send_cap_count() == 2, NULL);
|
||||
CHECK(strcmp(datarouter_send_cap_name(0), "sensor") == 0, NULL);
|
||||
CHECK(strcmp(datarouter_send_cap_desc(0), "Sensor data report") == 0, NULL);
|
||||
CHECK(datarouter_send_cap_name(-1) == NULL, NULL);
|
||||
CHECK(datarouter_send_cap_name(99) == NULL, NULL);
|
||||
CHECK(dr_send_cap_count() == 2, NULL);
|
||||
CHECK(strcmp(dr_send_cap_name(0), "sensor") == 0, NULL);
|
||||
CHECK(strcmp(dr_send_cap_desc(0), "Sensor data report") == 0, NULL);
|
||||
CHECK(dr_send_cap_name(-1) == NULL, NULL);
|
||||
CHECK(dr_send_cap_name(99) == NULL, NULL);
|
||||
TEST_END()
|
||||
|
||||
TEST_START(recv_cap_meta)
|
||||
CHECK(datarouter_recv_cap_count() == 2, NULL);
|
||||
CHECK(strcmp(datarouter_recv_cap_name(0), "rtcm") == 0, NULL);
|
||||
CHECK(strcmp(datarouter_recv_cap_desc(0), "RTCM correction data") == 0, NULL);
|
||||
CHECK(datarouter_recv_cap_name(-1) == NULL, NULL);
|
||||
CHECK(datarouter_recv_cap_desc(99) == NULL, NULL);
|
||||
CHECK(dr_recv_cap_count() == 2, NULL);
|
||||
CHECK(strcmp(dr_recv_cap_name(0), "rtcm") == 0, NULL);
|
||||
CHECK(strcmp(dr_recv_cap_desc(0), "RTCM correction data") == 0, NULL);
|
||||
CHECK(dr_recv_cap_name(-1) == NULL, NULL);
|
||||
CHECK(dr_recv_cap_desc(99) == NULL, NULL);
|
||||
TEST_END()
|
||||
|
||||
/* ================================================================
|
||||
@@ -297,7 +297,7 @@ int main(void)
|
||||
printf("[uninitialized]\n");
|
||||
RUN(error_uninit);
|
||||
|
||||
datarouter_init();
|
||||
dr_init();
|
||||
|
||||
printf("\n[port management]\n");
|
||||
RUN(port_create_basic);
|
||||
@@ -306,7 +306,7 @@ int main(void)
|
||||
RUN(port_default_state);
|
||||
printf("\n");
|
||||
|
||||
datarouter_reset(); datarouter_init();
|
||||
dr_reset(); dr_init();
|
||||
printf("[send_type & handler]\n");
|
||||
RUN(send_type_set_get);
|
||||
RUN(handler_add_remove);
|
||||
|
||||
Reference in New Issue
Block a user