feat: implement cel_crsf_param_write

Fire-and-forget parameter write. Builds CRSF PARAM_WRITE frame
and sends it over the serial port.
This commit is contained in:
2026-06-14 21:55:15 +02:00
parent 5d18258330
commit 8c4045e2a4
3 changed files with 55 additions and 11 deletions
+44 -2
View File
@@ -1,9 +1,16 @@
#include "unity.h"
#include "celrs/crsf_param.h"
#include "Mockserial_internal.h"
#include <string.h>
void setUp(void) {}
void tearDown(void) {}
void setUp(void) {
Mockserial_internal_Init();
}
void tearDown(void) {
Mockserial_internal_Verify();
Mockserial_internal_Destroy();
}
/* cel_crsf_param_parse tests */
@@ -161,6 +168,38 @@ void test_param_parse_options_truncation(void) {
TEST_ASSERT_EQUAL_UINT8(255, strlen(param.options)); /* truncated to 255 */
}
/* cel_crsf_param_write tests */
void test_param_write_null_port(void) {
TEST_ASSERT_EQUAL_INT(-1, cel_crsf_param_write(NULL, 0, 0));
}
void test_param_write_success(void) {
cel_serial_platform_open_ExpectAndReturn("COM3", 400000,
(cel_serial_platform_handle)42);
cel_serial_port* port = cel_serial_open("COM3", 400000);
TEST_ASSERT_NOT_NULL(port);
cel_serial_platform_write_ExpectAnyArgsAndReturn(8);
TEST_ASSERT_EQUAL_INT(0, cel_crsf_param_write(port, 5, 3));
cel_serial_platform_close_Expect((cel_serial_platform_handle)42);
cel_serial_close(port);
}
void test_param_write_partial_write(void) {
cel_serial_platform_open_ExpectAndReturn("COM3", 400000,
(cel_serial_platform_handle)42);
cel_serial_port* port = cel_serial_open("COM3", 400000);
TEST_ASSERT_NOT_NULL(port);
cel_serial_platform_write_ExpectAnyArgsAndReturn(4);
TEST_ASSERT_EQUAL_INT(-1, cel_crsf_param_write(port, 5, 3));
cel_serial_platform_close_Expect((cel_serial_platform_handle)42);
cel_serial_close(port);
}
int main(void) {
UNITY_BEGIN();
RUN_TEST(test_param_parse_null_args);
@@ -172,5 +211,8 @@ int main(void) {
RUN_TEST(test_param_parse_folder);
RUN_TEST(test_param_parse_name_truncation);
RUN_TEST(test_param_parse_options_truncation);
RUN_TEST(test_param_write_null_port);
RUN_TEST(test_param_write_success);
RUN_TEST(test_param_write_partial_write);
return UNITY_END();
}