Beispiel #1
0
/*!
 * \brief   Prepares the payload of the frame
 *
 * \retval  [0: frame could be sent, 1: error]
 */
static bool SendFrame( void )
{
      pc.printf("SendFrame\r\n");
    McpsReq_t mcpsReq;
    LoRaMacTxInfo_t txInfo;
    
    if( LoRaMacQueryTxPossible( AppDataSize, &txInfo ) != LORAMAC_STATUS_OK )  // Unable to send frame 
    {
          pc.printf("SendFrame - Unable to Send\r\n");
        // Send empty frame in order to flush MAC commands
        mcpsReq.Type = MCPS_UNCONFIRMED;
        mcpsReq.Req.Unconfirmed.fBuffer = NULL;
        mcpsReq.Req.Unconfirmed.fBufferSize = 0;
        mcpsReq.Req.Unconfirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
    }
    else  // Frame is ok to send
    {
        if( IsTxConfirmed == false )  // Configured at start of main.cpp
        {
              pc.printf("SendFrame - Unconfirmed\r\n");
            mcpsReq.Type = MCPS_UNCONFIRMED;
            mcpsReq.Req.Unconfirmed.fPort = AppPort;
            mcpsReq.Req.Unconfirmed.fBuffer = AppData;
            mcpsReq.Req.Unconfirmed.fBufferSize = AppDataSize;
            mcpsReq.Req.Unconfirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
        }
        else
        {
              pc.printf("SendFrame - Confirmed\r\n");
            mcpsReq.Type = MCPS_CONFIRMED;
            mcpsReq.Req.Confirmed.fPort = AppPort;
            mcpsReq.Req.Confirmed.fBuffer = AppData;
            mcpsReq.Req.Confirmed.fBufferSize = AppDataSize;
            mcpsReq.Req.Confirmed.NbTrials = 8; // number of retries in case of failure to confirm
            mcpsReq.Req.Confirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
        }
    }

    /*  Possible return values of LoRaMacMcpsRequest are:
     *          \ref LORAMAC_STATUS_OK,
     *          \ref LORAMAC_STATUS_BUSY,
     *          \ref LORAMAC_STATUS_SERVICE_UNKNOWN,
     *          \ref LORAMAC_STATUS_PARAMETER_INVALID,
     *          \ref LORAMAC_STATUS_NO_NETWORK_JOINED,
     *          \ref LORAMAC_STATUS_LENGTH_ERROR,
     *          \ref LORAMAC_STATUS_DEVICE_OFF.
     */
      pc.printf("SendFrame  LoRaMacMcpsRequest Status = %d\r\n", LoRaMacMcpsRequest( &mcpsReq ) );
    if( LoRaMacMcpsRequest( &mcpsReq ) == LORAMAC_STATUS_OK ) 
    {
        return false; // NextTx is set to this, meaning don't resend
    }
    return true;  // NextTx is set to this, so will resend
}
Beispiel #2
0
uint8_t LoRaMacSendConfirmedFrame( uint8_t fPort, void *fBuffer, uint16_t fBufferSize, uint8_t nbRetries )
{
    MibRequestConfirm_t mibGet;
    McpsReq_t mcpsRequest;
    uint8_t retStatus;

    memset1( ( uint8_t* )&LoRaMacEventInfo, 0, sizeof( LoRaMacEventInfo ) );

    mibGet.Type = MIB_CHANNELS_DATARATE;
    LoRaMacMibGetRequestConfirm( &mibGet );

    mcpsRequest.Type = MCPS_CONFIRMED;
    mcpsRequest.Req.Confirmed.fBuffer = fBuffer;
    mcpsRequest.Req.Confirmed.fBufferSize = fBufferSize;
    mcpsRequest.Req.Confirmed.fPort = fPort;
    mcpsRequest.Req.Confirmed.nbRetries = nbRetries;
    mcpsRequest.Req.Confirmed.Datarate = mibGet.Param.ChannelsDatarate;

    switch( LoRaMacMcpsRequest( &mcpsRequest ) )
    {
        case LORAMAC_STATUS_OK:
            retStatus = 0U;
            break;
        case LORAMAC_STATUS_BUSY:
            retStatus = 1U;
            break;
        case LORAMAC_STATUS_NO_NETWORK_JOINED:
            retStatus = 2U;
            break;
        case LORAMAC_STATUS_LENGTH_ERROR:
        case LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR:
            retStatus = 3U;
            break;
        case LORAMAC_STATUS_SERVICE_UNKNOWN:
            retStatus = 4U;
            break;
        case LORAMAC_STATUS_DEVICE_OFF:
            retStatus = 6U;
            break;
        default:
            retStatus = 1U;
            break;
    }

    return retStatus;
}
Beispiel #3
0
/*!
 * \brief   Prepares the payload of the frame
 *
 * \retval  [0: frame could be send, 1: error]
 */
static bool SendFrame( void )
{
    McpsReq_t mcpsReq;
    LoRaMacTxInfo_t txInfo;

    if( LoRaMacQueryTxPossible( AppDataSize, &txInfo ) != LORAMAC_STATUS_OK )
    {
        // Send empty frame in order to flush MAC commands
        mcpsReq.Type = MCPS_UNCONFIRMED;
        mcpsReq.Req.Unconfirmed.fBuffer = NULL;
        mcpsReq.Req.Unconfirmed.fBufferSize = 0;
        mcpsReq.Req.Unconfirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
    }
    else
    {
        if( IsTxConfirmed == false )
        {
            mcpsReq.Type = MCPS_UNCONFIRMED;
            mcpsReq.Req.Unconfirmed.fPort = AppPort;
            mcpsReq.Req.Unconfirmed.fBuffer = AppData;
            mcpsReq.Req.Unconfirmed.fBufferSize = AppDataSize;
            mcpsReq.Req.Unconfirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
        }
        else
        {
            mcpsReq.Type = MCPS_CONFIRMED;
            mcpsReq.Req.Confirmed.fPort = AppPort;
            mcpsReq.Req.Confirmed.fBuffer = AppData;
            mcpsReq.Req.Confirmed.fBufferSize = AppDataSize;
            mcpsReq.Req.Confirmed.NbTrials = 8;
            mcpsReq.Req.Confirmed.Datarate = LORAWAN_DEFAULT_DATARATE;
        }
    }

    if( LoRaMacMcpsRequest( &mcpsReq ) == LORAMAC_STATUS_OK )
    {
        return false;
    }
    return true;
}
Beispiel #4
0
/* Prepares the payload of the frame */
static uint8_t _semtech_loramac_send(semtech_loramac_t *mac,
                                     uint8_t *payload, uint8_t len)
{
    DEBUG("[semtech-loramac] send frame %s\n", (char *)payload);
    McpsReq_t mcpsReq;
    LoRaMacTxInfo_t txInfo;
    uint8_t dr = semtech_loramac_get_dr(mac);

    if (LoRaMacQueryTxPossible(len, &txInfo) != LORAMAC_STATUS_OK) {
        DEBUG("[semtech-loramac] empty frame in order to flush MAC commands\n");
        /* Send empty frame in order to flush MAC commands */
        mcpsReq.Type = MCPS_UNCONFIRMED;
        mcpsReq.Req.Unconfirmed.fBuffer = NULL;
        mcpsReq.Req.Unconfirmed.fBufferSize = 0;
        mcpsReq.Req.Unconfirmed.Datarate = (int8_t)dr;
    }
    else {
        if (mac->cnf == LORAMAC_TX_UNCNF) {
            DEBUG("[semtech-loramac] MCPS request: unconfirmed TX\n");
            mcpsReq.Type = MCPS_UNCONFIRMED;
            mcpsReq.Req.Unconfirmed.fPort = mac->port;
            mcpsReq.Req.Unconfirmed.fBuffer = payload;
            mcpsReq.Req.Unconfirmed.fBufferSize = len;
            mcpsReq.Req.Unconfirmed.Datarate = (int8_t)dr;
        }
        else {
            DEBUG("[semtech-loramac] MCPS request: confirmed TX\n");
            mcpsReq.Type = MCPS_CONFIRMED;
            mcpsReq.Req.Confirmed.fPort = mac->port;
            mcpsReq.Req.Confirmed.fBuffer = payload;
            mcpsReq.Req.Confirmed.fBufferSize = len;
            mcpsReq.Req.Confirmed.NbTrials = 3;
            mcpsReq.Req.Confirmed.Datarate = (int8_t)dr;
        }
    }

    uint8_t req_status = LoRaMacMcpsRequest(&mcpsReq);
    uint8_t ret = SEMTECH_LORAMAC_TX_ERROR;
    switch (req_status) {
        case LORAMAC_STATUS_OK:
            DEBUG("[semtech-loramac] MCPS request: OK\n");
            ret = SEMTECH_LORAMAC_TX_OK;
            break;
        case LORAMAC_STATUS_PARAMETER_INVALID:
            DEBUG("[semtech-loramac] MCPS request: invalid parameter\n");
            break;
        case LORAMAC_STATUS_BUSY:
            DEBUG("[semtech-loramac] MCPS request: busy\n");
            ret = SEMTECH_LORAMAC_BUSY;
            break;
        case LORAMAC_STATUS_DUTYCYCLE_RESTRICTED:
            DEBUG("[semtech-loramac] MCPS request: dutycycle restricted\n");
            ret = SEMTECH_LORAMAC_DUTYCYCLE_RESTRICTED;
            break;
        default:
            DEBUG("[semtech-loramac] MCPS request: unknown status %d\n",
                  req_status);
            break;
    }

    return ret;
}