Exemplo n.º 1
0
////////////////////////////////////////////////////////////////////
// Discovers a route to the destination (if necessary), sends and 
// waits for delivery to the next hop (but not for delivery to the final destination)
uint8_t RHMesh::sendtoWait(uint8_t* buf, uint8_t len, uint8_t address)
{
    if (len > RH_MESH_MAX_MESSAGE_LEN)
	return RH_ROUTER_ERROR_INVALID_LENGTH;

    RoutingTableEntry* route = getRouteTo(address);
    if (!route && !doArp(address))
	return RH_ROUTER_ERROR_NO_ROUTE;

    // Now have a route. Contruct an applicaiotn layer message and dend it via that route
    MeshApplicationMessage* a = (MeshApplicationMessage*)&_tmpMessage;
    a->header.msgType = RH_MESH_MESSAGE_TYPE_APPLICATION;
    memcpy(a->data, buf, len);
    return RHRouter::sendtoWait(_tmpMessage, sizeof(RHMesh::MeshMessageHeader) + len, address);
}
Exemplo n.º 2
0
////////////////////////////////////////////////////////////////////
// Discovers a route to the destination (if necessary), sends and 
// waits for delivery to the next hop (but not for delivery to the final destination)
uint8_t RF22Mesh::sendtoWait(uint8_t* buf, uint8_t len, uint8_t address)
{
    freeMem( F( "RF22Mesh::sendtoWait" ) );
    uint8_t frags = 0, ret;
    uint16_t frag_len = 0, len_remain = (uint16_t) len;



    if (len > GLOBAL_BUFFER_SIZE)
	return RF22_ROUTER_ERROR_INVALID_LENGTH;

    if( address != RF22_BROADCAST_ADDRESS ) {
        RoutingTableEntry* route = getRouteTo(address);
        if( !route && !doArp( address ) ) {

            return RF22_ROUTER_ERROR_NO_ROUTE;
        }
    }

    frags = ( len / RF22_MESH_MAX_MESSAGE_LEN ) + 1;
    #ifdef CLIENT
    Serial.print( F( "frags: " ) );
    Serial.println( frags );
    #endif

    for( uint8_t i = 0; i < frags; i++ ) {

        // Now have a route. Contruct an applicaiotn layer message and dend it via that route
        MeshApplicationMessage* a = (MeshApplicationMessage*)&_tmpMessage;
        a->header.msgType = RF22_MESH_MESSAGE_TYPE_APPLICATION;

        if( i < frags - 1 ) {
            a->header.frag = 1;
            frag_len = RF22_MESH_MAX_MESSAGE_LEN;
            len_remain -= frag_len;
        } else {
            a->header.frag = 0;
            frag_len = len_remain;
            len_remain -= frag_len;
            //frag_len = len < ( frags * RF22_MESH_MAX_MESSAGE_LEN ) ? len : len - ( frags * RF22_MESH_MAX_MESSAGE_LEN );
        }
        #ifdef CLIENT
        Serial.print( F( "frag_len: " ) );
        Serial.println( frag_len );
        #endif
        a->header.seqno = i;

        memcpy( a->data, buf + ( i * RF22_MESH_MAX_MESSAGE_LEN ), frag_len );
        #ifdef CLIENT
        for( int i = 0; i < frag_len; i++ ) {
            Serial.print( a->data[i], HEX );
            Serial.print( F( ", " ) );
        }
        Serial.println( F( "" ) );
        #endif

        ret = RF22Router::sendtoWait(_tmpMessage, sizeof(RF22Mesh::MeshMessageHeader) + frag_len, address);
        if( ret != RF22_ROUTER_ERROR_NONE ) {

            return ret;
        }

    }
    return 0;
}