11
11
12
12
#include "message_channel.h"
13
13
14
- #include "zcbor_decode.h"
15
- #include "button_object_decode.h"
16
14
#include <dk_buttons_and_leds.h>
17
15
#include <date_time.h>
18
16
19
17
DEFINE_FFF_GLOBALS ;
20
18
21
19
LOG_MODULE_REGISTER (button_module_test , 4 );
22
20
23
- ZBUS_MSG_SUBSCRIBER_DEFINE (transport );
24
- ZBUS_CHAN_ADD_OBS (PAYLOAD_CHAN , transport , 0 );
21
+ ZBUS_MSG_SUBSCRIBER_DEFINE (button_subscriber );
22
+ ZBUS_CHAN_ADD_OBS (BUTTON_CHAN , button_subscriber , 0 );
25
23
26
24
#define FAKE_TIME_MS 1716552398505
27
25
@@ -42,10 +40,10 @@ int dk_buttons_init(button_handler_t _button_handler)
42
40
void tearDown (void )
43
41
{
44
42
const struct zbus_channel * chan ;
45
- static struct payload received_payload ;
43
+ uint8_t button_number ;
46
44
int err ;
47
45
48
- err = zbus_sub_wait_msg (& transport , & chan , & received_payload , K_MSEC (1000 ));
46
+ err = zbus_sub_wait_msg (& button_subscriber , & chan , & button_number , K_MSEC (1000 ));
49
47
if (err == 0 ) {
50
48
LOG_ERR ("Unhandled message in payload channel" );
51
49
TEST_FAIL ();
@@ -55,16 +53,15 @@ void tearDown(void)
55
53
void test_button_trigger (void )
56
54
{
57
55
const struct zbus_channel * chan ;
58
- static struct payload received_payload ;
59
- struct button_object button_obj = { 0 };
56
+ uint8_t button_number ;
60
57
int err ;
61
58
62
59
TEST_ASSERT_NOT_NULL (button_handler );
63
60
button_handler (DK_BTN1_MSK , DK_BTN1_MSK );
64
61
65
- err = zbus_sub_wait_msg (& transport , & chan , & received_payload , K_MSEC (1000 ));
62
+ err = zbus_sub_wait_msg (& button_subscriber , & chan , & button_number , K_MSEC (1000 ));
66
63
if (err == - ENOMSG ) {
67
- LOG_ERR ("No payload message received" );
64
+ LOG_ERR ("No BUTTON_CHAN message received" );
68
65
TEST_FAIL ();
69
66
} else if (err ) {
70
67
LOG_ERR ("zbus_sub_wait, error: %d" , err );
@@ -73,21 +70,11 @@ void test_button_trigger(void)
73
70
return ;
74
71
}
75
72
76
- /* check if chan is payload channel */
77
- if (chan != & PAYLOAD_CHAN ) {
73
+ /* check if chan is button channel */
74
+ if (chan != & BUTTON_CHAN ) {
78
75
LOG_ERR ("Received message from wrong channel" );
79
76
TEST_FAIL ();
80
77
}
81
-
82
- /* decode payload */
83
- err = cbor_decode_button_object (received_payload .buffer ,
84
- received_payload .buffer_len ,
85
- & button_obj ,
86
- NULL );
87
- if (err != ZCBOR_SUCCESS ) {
88
- LOG_ERR ("Failed to decode payload" );
89
- TEST_FAIL ();
90
- }
91
78
}
92
79
93
80
/* This is required to be added to each test. That is because unity's
0 commit comments