#include "main.h"

#define MODULE MAIN
LOG_MODULE_REGISTER(MODULE);

int main(void)
{
        bool ok;

        uint8_t cbor_payload[200] = {0};
        //memset(cbor_payload, 0x00,  sizeof(cbor_payload));

        // Create zcbor state variable for encoding.
        ZCBOR_STATE_E(encoding_state, 3, cbor_payload, sizeof(cbor_payload), 0);

        uint32_t ints[1] = {1};

        char var[] = "test";
        ok = zcbor_map_start_encode(encoding_state, 10);
        ok &= cbor_add_uint64(encoding_state, "var3", 123);
        ok &= zcbor_uint32_encode(encoding_state, ints) &&
        zcbor_tstr_put_term(encoding_state, var, strlen(var));
        ok &= zcbor_map_end_encode(encoding_state, 10);

        if (!ok) {
                LOG_ERR("Encoding failed: %d", zcbor_peek_error(encoding_state));
                return 0;
        }

        com_uart1_send_data(cbor_payload, strlen(cbor_payload));


        ZCBOR_STATE_D(decoding_state, 3, cbor_payload, sizeof(cbor_payload), 10, 0);
        struct zcbor_string name = { 0 };
        uint64_t var3 = 0;
        size_t decoded;
        struct zcbor_map_decode_key_val fs_download_decode[] = {
                ZCBOR_MAP_DECODE_KEY_DECODER("1", zcbor_tstr_decode, &name),
                ZCBOR_MAP_DECODE_KEY_DECODER("var3", zcbor_uint64_decode, &var3),
        };

        ok = zcbor_map_decode_bulk(decoding_state, fs_download_decode, ARRAY_SIZE(fs_download_decode),
                                        &decoded) == 0;

        if (!ok) {
                LOG_ERR("Decoding failed: %d", zcbor_peek_error(decoding_state));
        }

        if(decoded)
        {
                LOG_INF("var3 : %lld var8 : %s", var3, name.value);
                //LOG_INF("var3 : %lld", var3);
        }
        else
        {
                LOG_WRN("No decoded");
        }

        while(1)
        {
                k_msleep(1000);	

        }

        return 0;
}
