2323#include <ocre/ocre.h>
2424
2525#include "ipc.h"
26+ #include "zcbor_helpers.h"
2627
2728#define SOCK_PATH "ocre.sock"
2829#define RX_BUFFER_SIZE 2048
3435/* Global ocre context for the server */
3536static struct ocre_context * ctx = NULL ;
3637
37- static void print_hex (const char * label , const uint8_t * data , size_t len )
38- {
39- printf ("HEX %s: " , label );
40- for (size_t i = 0 ; i < len ; i ++ ) {
41- printf ("%02x " , data [i ]);
42- }
43- printf ("\n" );
44- }
45-
46- /* Helper to decode a string or nil, returns true if string was decoded, false if nil */
47- static bool decode_string_or_nil (zcbor_state_t * state , char * buffer , size_t buffer_size , bool * is_nil )
48- {
49- * is_nil = false;
50-
51- /* Try to decode nil first */
52- if (zcbor_nil_expect (state , NULL )) {
53- * is_nil = true;
54- buffer [0 ] = '\0' ;
55- return true;
56- }
57-
58- zcbor_pop_error (state );
59-
60- /* Decode as string */
61- struct zcbor_string str ;
62- if (!zcbor_tstr_decode (state , & str )) {
63- return false;
64- }
65-
66- size_t copy_len = str .len < buffer_size - 1 ? str .len : buffer_size - 1 ;
67- memcpy (buffer , str .value , copy_len );
68- buffer [copy_len ] = '\0' ;
69-
70- return true;
71- }
72-
73- /* Helper to decode a string array (CBOR list of strings) */
74- static bool decode_string_array (zcbor_state_t * state , char * * arr , size_t max_count , size_t * out_count , bool * is_nil )
75- {
76- * is_nil = false;
77- * out_count = 0 ;
78-
79- /* Try to decode nil first */
80- if (zcbor_nil_expect (state , NULL )) {
81- * is_nil = true;
82- return true;
83- }
84-
85- zcbor_pop_error (state );
86-
87- /* Decode as list */
88- if (!zcbor_list_start_decode (state )) {
89- return false;
90- }
91-
92- size_t count = 0 ;
93- while (!zcbor_list_end_decode (state ) && count < max_count ) {
94- struct zcbor_string str ;
95- if (!zcbor_tstr_decode (state , & str )) {
96- break ;
97- }
98-
99- /* Allocate and copy string */
100- arr [count ] = malloc (str .len + 1 );
101- if (arr [count ] == NULL ) {
102- return false;
103- }
104- memcpy (arr [count ], str .value , str .len );
105- arr [count ][str .len ] = '\0' ;
106- count ++ ;
107- }
108-
109- arr [count ] = NULL ; /* NULL-terminate the array */
110- * out_count = count ;
111-
112- return true;
113- }
114-
115- /* Helper to free a string array */
116- static void free_string_array (char * * arr , size_t count )
117- {
118- for (size_t i = 0 ; i < count ; i ++ ) {
119- free (arr [i ]);
120- }
121- }
122-
123- /* Helper to encode a string or nil */
124- static bool encode_string_or_nil (zcbor_state_t * state , const char * str )
125- {
126- if (str == NULL ) {
127- return zcbor_nil_put (state , NULL );
128- }
129- return zcbor_tstr_put_term (state , str , STRING_BUFFER_SIZE );
130- }
38+ // static void print_hex(const char *label, const uint8_t *data, size_t len)
39+ // {
40+ // printf("HEX %s: ", label);
41+ // for (size_t i = 0; i < len; i++) {
42+ // printf("%02x ", data[i]);
43+ // }
44+ // printf("\n");
45+ // }
13146
13247static int handle_context_create_container (zcbor_state_t * dec_state , uint8_t * tx_buf , size_t tx_buf_size )
13348{
@@ -881,8 +796,8 @@ int main(void)
881796 break ;
882797 }
883798
884- printf ("Received %d bytes\n" , n );
885- print_hex ("received" , rx_buf , n );
799+ // printf("Received %d bytes\n", n);
800+ // print_hex("received", rx_buf, n);
886801
887802 /* Process the request and generate response */
888803 int response_len = process_request (rx_buf , n , tx_buf , sizeof (tx_buf ));
@@ -892,7 +807,7 @@ int main(void)
892807 break ;
893808 }
894809
895- print_hex ("sending" , tx_buf , response_len );
810+ // print_hex("sending", tx_buf, response_len);
896811
897812 if (send (s2 , tx_buf , response_len , 0 ) < 0 ) {
898813 perror ("send" );
0 commit comments