source/main.cpp
// This is called from RX_DONE, so whenever a message came in
This is called from RX_DONE, so whenever a message came in
This is called from RX_DONE so whenever a message came in
static void receive_message()
{
    uint8_t rx_buffer[255] = { 0 };
    uint8_t port;
    int flags;
    int16_t retcode = lorawan.receive(rx_buffer, sizeof(rx_buffer), port, flags);
    if (retcode < 0) {
        printf("receive() - Error code %d\n", retcode);
        return;
    }
    printf("Received %d bytes on port %u\n", retcode, port);
    LW_UC_STATUS status = LW_UC_OK;
    if (port == 200) {
        status = uc.handleMulticastControlCommand(rx_buffer, retcode);
    }
    else if (port == 201) {
        loramac_protocol_params params;
        lorawan.get_session(&params);
        status = uc.handleFragmentationCommand(params.dev_addr, rx_buffer, retcode);
        if (in_class_c_mode) {
            turn_led_on();
            evqueue.call_in(200, &turn_led_off);
        }
    }
    else if (port == 202) {
        status = uc.handleClockSyncCommand(rx_buffer, retcode);
        if (status == LW_UC_OK) {
            clock_is_synced = true;
        }
    }
    else {
        printf("Data received on port %d (length %d): ", port, retcode);
        for (uint8_t i = 0; i < retcode; i++) {
            printf("%02x ", rx_buffer[i]);
        }
        printf("\n");
    }
    if (status != LW_UC_OK) {
        printf("Failed to handle UC command on port %d, status %d\n", port, status);
    }
}
static void receive_message ( ) { uint8_t rx_buffer [ 255 ] = { 0 } ; uint8_t port ; int flags ; int16_t retcode = lorawan . receive ( rx_buffer , sizeof ( rx_buffer ) , port , flags ) ; if ( retcode < 0 ) { printf ( " \n " , retcode ) ; return ; } printf ( " \n " , retcode , port ) ; LW_UC_STATUS status = LW_UC_OK ; if ( port == 200 ) { status = uc . handleMulticastControlCommand ( rx_buffer , retcode ) ; } else if ( port == 201 ) { loramac_protocol_params params ; lorawan . get_session ( & params ) ; status = uc . handleFragmentationCommand ( params . dev_addr , rx_buffer , retcode ) ; if ( in_class_c_mode ) { turn_led_on ( ) ; evqueue . call_in ( 200 , & turn_led_off ) ; } } else if ( port == 202 ) { status = uc . handleClockSyncCommand ( rx_buffer , retcode ) ; if ( status == LW_UC_OK ) { clock_is_synced = true ; } } else { printf ( " " , port , retcode ) ; for ( uint8_t i = 0 ; i < retcode ; i ++ ) { printf ( " " , rx_buffer [ i ] ) ; } printf ( " \n " ) ; } if ( status != LW_UC_OK ) { printf ( " \n " , port , status ) ; } }
This is called from RX_DONE, so whenever a message came in
This is called from RX_DONE so whenever a message came in
// retrieve current session and set dev addr // blink LED when receiving a packet in Class C mode