Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
titlecanard_publish
#define PUBLISHER_PERIOD_mS                            25
#define UAVCAN_PROTOCOL_DEBUG_KEYVALUE_ID              16370   
#define UAVCAN_PROTOCOL_DEBUG_KEYVALUE_SIGNATURE       0xe02f25d6e0c98ae0 
#define UAVCAN_PROTOCOL_DEBUG_KEYVALUE_MESSAGE_SIZE    62   

void canardPublishpublishCanard(void)
{  
    static uint32_t publish_time = 0;
    static int step = 0;
    if(getUptime() < publish_time + PUBLISHER_PERIOD_mS) {return;} // to enter this function only once a period
    publish_time = getUptime();
  
    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);
    memset(buffer,0x00,UAVCAN_PROTOCOL_DEBUG_KEYVALUE_MESSAGE_SIZE);
  
    val = step;
    canardEncodeScalar(buffer, 0, 32, &val);
    memcpy(&buffer[4], "stp", 3);  
    canardBroadcast(&g_canard, 
                    UAVCAN_PROTOCOL_DEBUG_KEYVALUE_SIGNATURE,
                    UAVCAN_PROTOCOL_DEBUG_KEYVALUE_ID,
                    &transfer_id,
                    CANARD_TRANSFER_PRIORITY_LOW,
                    &buffer[0], 
                    7);
}

...

Code Block
titlemain
int main(void)
{    /*!< At this stage the microcontrollers clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f37x.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f37x.c file */
    RCC_GetClocksFreq(&RCC_Clocks); //To make sure RCC is initialised properly
    hwInit();
    swInit();
    SysTick_Config(SystemCoreClock / 1000);
    while(1)
    {
        canardSendsendCanard();
        canardReceivereceiveCanard();
        canardSpinspinCanard();
        canardPublishpublishCanard();
    }
}

Now its time to flash the firmware to Babel and check if everything is working as expected. You should find a bunch of new messages in Bus monitor panel:

...