예제 #1
0
void telemReadbackSamples(unsigned long numSamples, unsigned int src_addr) {
    int delaytime_ms = READBACK_DELAY_TIME_MS;
    unsigned long i = 0; //will actually be the same as the sampleIndex

    telemStruct_t sampleData;

    //This is a terrible hack to avoid bus conflicts.
    //TODO: find source of bus problems and fix
    DisableIntT1;
    DisableIntT5;

    for (i = 0; i < numSamples; i++) {
        //Retireve data from flash
        telemGetSample(i, sizeof (sampleData), (unsigned char*) (&sampleData));
        //Reliable send, with linear backoff
        do {
            //debugpins1_set();
            telemSendDataDelay(&sampleData, delaytime_ms, src_addr);
            //Linear backoff
            delaytime_ms += 0;
            //debugpins1_clr();
        } while (trxGetLastACKd() == 0);
        
        delaytime_ms = READBACK_DELAY_TIME_MS;
    }

    //This is a terrible hack to avoid bus conflicts.
    //TODO: find source of bus problems and fix
    EnableIntT1;
    EnableIntT5;
}
예제 #2
0
void xbeeHandleAt(Payload rx_pld)
{
    unsigned char frame;
    unsigned char length;
//    unsigned char test;

    //This should really be some sort of dynamic queue to be generalized
    unsigned char bytes[10];


    //unsigned short int command;
    WordVal command;
    WordVal data;

    length = payGetPayloadLength(rx_pld);
    frame = rx_pld->pld_data[0];

    //test = rx_pld->pld_data[1];
    //test = rx_pld->pld_data[2];

/*
    command = rx_pld->pld_data[1];
    command = command << 8;

    command = command + rx_pld->pld_data[2];
*/
    command.byte.HB = rx_pld->pld_data[1];
    command.byte.LB = rx_pld->pld_data[2];

    switch (command.val)
    {
        case AT_CHANNEL:
            if (length != 3)
            {
                radioSetChannel(rx_pld->pld_data[3]);
            }
            if (frame != 0)
            {
                bytes[0] = radioGetChannel();
                xbeeHandleATR(frame, command, bytes, 1);
            }
            break;
        case AT_PAN_ID:
            if (length != 3)
            {
                data.byte.HB = rx_pld->pld_data[3];
                data.byte.LB = rx_pld->pld_data[4];
                radioSetSrcPanID(data.val);
            }
            if (frame != 0)
            {
                data.val = (unsigned int)radioGetSrcPanID();
                bytes[0] = data.byte.HB;
                bytes[1] = data.byte.LB;

                xbeeHandleATR(frame, command, bytes, 2);
            }
            break;
        case AT_SRC_ADR:
            if (length != 3)
            {
                data.byte.HB = rx_pld->pld_data[3];
                data.byte.LB = rx_pld->pld_data[4];
                radioSetSrcAddr(data.val);
            }
            if (frame != 0)
            {
                data.val = radioGetSrcAddr();
                bytes[0] = data.byte.HB;
                bytes[1] = data.byte.LB;

                xbeeHandleATR(frame, command, bytes, 2);
            }
            break;
        case AT_ACK_LAST:
            if (frame != 0)
            {
                bytes[0] = 0;
                bytes[1] = trxGetLastACKd();

                xbeeHandleATR(frame, command, bytes, 2);
            }
            break;
        case AT_SNIFFER:
            if (length != 3)
                trxSetPromMode(rx_pld->pld_data[3]);  //Put radio in sniffer mode
            break;
    }
}