Ejemplo n.º 1
0
static void cmdDirDumpRequest(MacPacket packet) {

    Payload pld;
    MacPacket response;
    unsigned int *frame, req_addr, req_pan, i, size;

    pld = macGetPayload(packet);
    frame = (unsigned int*) payGetData(pld);

    req_addr = frame[0];
    req_pan = frame[1];

    // Send all if both addresses 0
    if(req_addr == 0 && req_pan == 0) {

        size = dirGetSize();
        DirEntry entries[size];
        dirGetEntries(entries); // Assume we get size # of entries

        i = 0;
        while(i < size) {
            
            response = radioRequestPacket(sizeof(DirEntryStruct));
            if(response == NULL) { continue; }
            macSetDestAddr(response, macGetSrcAddr(packet));
            pld = macGetPayload(response);
            paySetType(pld, CMD_DIR_DUMP_RESPONSE);
            paySetData(pld, sizeof(DirEntryStruct), (unsigned char*) entries[i]);
            while(!radioEnqueueTxPacket(response));
            i++;
        }
                
    } else {

        DirEntry entry;

        entry = dirQueryAddress(req_addr, req_pan);
        if(entry == NULL) { return; }
        
        while(1) {
            
            response = radioRequestPacket(sizeof(DirEntryStruct));
            if(response == NULL) { continue; }
            macSetDestAddr(response, macGetSrcAddr(packet));
            pld = macGetPayload(response);
            paySetType(pld, CMD_DIR_DUMP_RESPONSE);
            //paySetData(pld, sizeof(DirEntryStruct), (unsigned char*) &entry);
            memcpy(payGetData(pld), entry, sizeof(DirEntryStruct));
            while(!radioEnqueueTxPacket(response));
            break;
        }
    }
    
}
Ejemplo n.º 2
0
void clksyncHandleRequest(MacPacket packet) {

    Payload pld;
    MacPacket response;
    unsigned long* frame;
    unsigned long s0, m1, m2;
    
    pld = macGetPayload(packet);
    frame = (unsigned long*) payGetData(pld);
    
    s0 = frame[0]; // Read requester time of flight
    m1 = packet->timestamp + sclockGetOffsetTicks(); // Read local time of reception

    response = radioRequestPacket(12); // Sending 3 longs
    if(response == NULL) { return; }

    macSetDestAddr(response, macGetSrcAddr(packet));
    macSetDestPan(response, macGetSrcPan(packet));
    pld = macGetPayload(response); // Create response packet
    paySetType(pld, CMD_CLOCK_UPDATE_RESPONSE);
    paySetData(pld, 4, (unsigned char*) &s0);
    payAppendData(pld, 4, 4, (unsigned char*) & m1);
    
    // Empty TX queue to minimize time of flight error
    while(!radioTxQueueEmpty()) { radioProcess(); }
    
    m2 = sclockGetGlobalTicks(); // Get approximate time of flight
    payAppendData(pld, 8, 4, (unsigned char*) & m2);
    
    while(!radioEnqueueTxPacket(response)) { radioProcess(); }
    radioProcess();    

}
Ejemplo n.º 3
0
static void cmdCamParamResponse(MacPacket packet) {

    Payload pld;
    unsigned char *frame;
    CamParamStruct *params;
    LStrobeParamStruct lstrobe_params;
    DirEntry entry;
    unsigned int addr, pan;
    
    pld = macGetPayload(packet);
    frame = payGetData(pld);
    params = (CamParamStruct*) frame;
        
    addr = macGetSrcAddr(packet);
    pan = macGetSrcPan(packet);
    entry = dirQueryAddress(addr, pan);
    
    if(entry == NULL) { return; }
    entry->frame_period = params->frame_period;
    entry->frame_start = params->frame_start;

    lstrobe_params.period = 5*(params->frame_period/4);
    lstrobe_params.period_offset = (params->frame_start/4) % (params->frame_period/4);
    lstrobe_params.on_time = 625/4; // 1 ms
    lstrobe_params.off_time = lstrobe_params.period - lstrobe_params.on_time;
    lstrobeSetParam(&lstrobe_params);
    lstrobeStart();
    
}
Ejemplo n.º 4
0
static void cmdGetMemContents(MacPacket packet) {

    Payload pld;
    MacPacket data_packet;
    unsigned char *frame;
    DfmemGeometryStruct geo;

    pld = macGetPayload(packet);
    frame = payGetData(pld);
    dfmemGetGeometryParams(&geo);

    unsigned int start_page = frame[0] + (frame[1] << 8);
    unsigned int end_page = frame[2] + (frame[3] << 8);
    unsigned int tx_data_size = frame[4] + (frame[5] << 8);
    unsigned int page, j;
    unsigned char count = 0;
    
    // Send back memory contents
    for (page = start_page; page < end_page; ++page) {
        j = 0;
        while (j + tx_data_size <= geo.bytes_per_page) {
            data_packet = NULL;
            while(data_packet == NULL) {
                data_packet = radioRequestPacket(tx_data_size);
            }

            macSetDestAddr(data_packet, macGetSrcAddr(packet));
            macSetDestPan(data_packet, macGetSrcPan(packet));
            pld = macGetPayload(data_packet);

            dfmemRead(page, j, tx_data_size, payGetData(pld));

            paySetStatus(pld, count++);
            paySetType(pld, CMD_RESPONSE_TELEMETRY);
            while(!radioEnqueueTxPacket(data_packet));
            j += tx_data_size;
            delay_ms(20);
        }

    }

    // Signal end of transfer    
    LED_GREEN = 0; LED_RED = 0; LED_ORANGE = 0;
    
}
Ejemplo n.º 5
0
static void cmdGetGyroCalibParam(MacPacket packet) {
        
    //Payload pld = macGetPayload(packet);
    //unsigned char status = payGetStatus(pld);
    //unsigned char* frame = payGetData(pld);
    unsigned int srcAddr = macGetSrcAddr(packet);
    
    Payload pld;
    MacPacket response;
    
    response = radioRequestPacket(12);
    if(response == NULL) { return; }
    macSetDestAddr(response, srcAddr);
    pld = response->payload;
    paySetData(pld, 12, gyroGetCalibParam());
    paySetStatus(pld, 0);
    paySetType(pld, CMD_GET_GYRO_CALIB_PARAM);
    while(!radioEnqueueTxPacket(response));
}
Ejemplo n.º 6
0
/*-----------------------------------------------------------------------------
 *          AUX functions
-----------------------------------------------------------------------------*/
static void cmdEcho(MacPacket packet) {
        
    Payload pld = macGetPayload(packet);
    unsigned char status = payGetStatus(pld);
    unsigned char* frame = payGetData(pld);
    unsigned int length = payGetDataLength(pld);
    unsigned int srcAddr = macGetSrcAddr(packet);
    
    MacPacket response;
    
    response = radioRequestPacket(length);
    if(response == NULL) { return; }
    macSetDestAddr(response, srcAddr);
    
    pld = response->payload;
    paySetData(pld, length, frame);
    paySetStatus(pld, status);
    paySetType(pld, CMD_ECHO);
    
    while(!radioEnqueueTxPacket(response));
}
Ejemplo n.º 7
0
static void cmdCamParamRequest(MacPacket packet) {

    Payload pld;
    CamParamStruct params;
    MacPacket response;
    
    pld = macGetPayload(packet);
    camGetParams(&params);
    
    response = radioRequestPacket(sizeof(CamParamStruct));
    if(response == NULL) { return; }
    
    macSetDestAddr(response, macGetSrcAddr(packet));
    pld = macGetPayload(response);
    paySetType(pld, CMD_CAM_PARAM_RESPONSE);
    paySetStatus(pld, 0);
    paySetData(pld, sizeof(CamParamStruct), (unsigned char*)&params);

    while(!radioEnqueueTxPacket(response));


}
Ejemplo n.º 8
0
static void cmdRequestAttitude(MacPacket packet) {

    telemSendAttitude(macGetSrcAddr(packet));

}
Ejemplo n.º 9
0
// ====== Camera and Vision ===================================================
// TODO: Use a struct to simplify the packetization
static void cmdRequestRawFrame(MacPacket packet) {
    
    unsigned int srcAddr, srcPan, height, width, i, temp;
    unsigned int sent, to_send, block_size = 75;
    MacPacket response;
    Payload pld;
    CamFrame frame;
    CamRow *row;
    CvResultStruct info;

    srcAddr = macGetSrcAddr(packet);
    srcPan = macGetSrcPan(packet);    

    frame = NULL;
    while(frame == NULL) {
        frame = camGetFrame();
    }           

    cvProcessFrame(frame, &info);    

    height = DS_IMAGE_ROWS;
    width = DS_IMAGE_COLS;

    for(i = 0; i < height; i++) {        
        row = &(frame->pixels[i]);
        to_send = width;
        while(to_send > 0) {            
            response = radioRequestPacket(block_size + 6);
            if(response == NULL) { continue; }
            pld = macGetPayload(response);
            paySetType(pld, CMD_RAW_FRAME_RESPONSE);
            paySetStatus(pld, 0);
            macSetDestAddr(response, srcAddr);
            macSetDestPan(response, srcPan);
            temp = frame->frame_num;
            paySetData(pld, 2, (unsigned char *)&temp);
            temp = i;
            payAppendData(pld, 2, 2, (unsigned char*)&temp);
            temp = width - to_send;
            payAppendData(pld, 4, 2, (unsigned char*)&temp);
            temp = (block_size < to_send) ? block_size : to_send;
            payAppendData(pld, 6, temp, *row + (width - to_send));

            while(!radioEnqueueTxPacket(response));

            to_send = to_send - temp;

        }

    }
    sent = 0;
    while(!sent) {
        response = radioRequestPacket(10);
        if(response == NULL) { continue; }
        pld = macGetPayload(response);
        paySetType(pld, CMD_CENTROID_REPORT);
        paySetStatus(pld, 1);
        macSetDestAddr(response, srcAddr);
        macSetDestPan(response, srcPan);
        temp = info.centroid[0];
        paySetData(pld, 2, (unsigned char*)&temp);
        temp = info.centroid[1];
        payAppendData(pld, 2, 2, (unsigned char*)&temp);
        temp = info.max[0];
        payAppendData(pld, 4, 2, (unsigned char*)&temp);
        temp = info.max[1];
        payAppendData(pld, 6, 2, (unsigned char*)&temp);
        temp = info.max_lum;
        payAppendData(pld, 8, 1, (unsigned char*)&temp);
        temp = info.avg_lum;
        payAppendData(pld, 9, 1, (unsigned char*)&temp);
        while(!radioEnqueueTxPacket(response));
        sent = 1;
    }
    camReturnFrame(frame);

}
Ejemplo n.º 10
0
static void cmdToggleStreaming(MacPacket packet) {
    
    telemToggleStreaming(macGetSrcAddr(packet));
    
}
Ejemplo n.º 11
0
static void cmdRequestTelemetry(MacPacket packet) {

    telemSendB(macGetSrcAddr(packet));

}