Homepage GitHub

How to caluclate XXXXXXX_MASSAGE_SIZE


(Skyyuzhang) #1

when i was learning basic tutorials I found that debug.value have a size in this code the buffer size was define to 62 i want to know why .

publishCanard(void)
{  
    static uint32_t publish_time = 0;
    static int step = 0;
    if(HAL_GetTick() < publish_time + PUBLISHER_PERIOD_mS) {return;} // rate limiting
    publish_time = HAL_GetTick();
    uint8_t buffer[UAVCAN_PROTOCOL_DEBUG_KEYVALUE_MESSAGE_SIZE];
    memset(buffer,0x00,UAVCAN_PROTOCOL_DEBUG_KEYVALUE_MESSAGE_SIZE);
    step++;
    if(step == 256) 
    {
        step = 0;
    }
    float val = sine_wave[step];
    static uint8_t transfer_id = 0;
    canardEncodeScalar(buffer, 0, 32, &val);
    memcpy(&buffer[4], "sin", 3);    
    canardBroadcast(&g_canard, 
                    UAVCAN_PROTOCOL_DEBUG_KEYVALUE_SIGNATURE,
                    UAVCAN_PROTOCOL_DEBUG_KEYVALUE_ID,
                    &transfer_id,
                    CANARD_TRANSFER_PRIORITY_LOW,
                    &buffer[0], 
                    7);
}

(Pavel Kirienko) #2

Because that’s the maximum serialized size of this message. You can see that here: https://github.com/UAVCAN/dsdl/blob/c1b8dcd4234b6551018684f868a9a4ab79119ee9/uavcan/protocol/debug/16370.KeyValue.uavcan