Beispiel #1
0
void CC_t::Task(void) {
    if (IsShutdown) return;
    // Do with CC what needed
    GetState();
    switch (State) {
        case CC_STB_RX_OVF:
            klPrintf("RX ovf\r");
            FlushRxFIFO();
            break;
        case CC_STB_TX_UNDF:
            klPrintf("TX undf\r");
            FlushTxFIFO();
            break;

        case CC_STB_IDLE:
            if (SearchState == IsWaiting) {
                EnterRX();
            }
            else {
                //klPrintf("TX\r");
                // Prepare packet to send
                TX_Pkt.To = 207;
                WriteTX();
                EnterTX();
                //klPrintf("TX\r");
            }
            break;

        default: // Just get out in other cases
            //klPrintf("Other: %X\r", State);
            break;
    } //Switch
}
Beispiel #2
0
void CC_t::TransmitAndWaitIdle(void) {
    WaitUntilChannelIsBusy();   // If this is not done, time after time FIFO is destroyed
    EnterIdle();
    WriteTX((uint8_t*)(&PktTx), CC_PKT_LEN);
    EnterTX();
    while(IrqPin == 0); // Wait until sync word is sent
    while(IrqPin == 1); // Wait until transmission completed
}
Beispiel #3
0
void cc1101_t::Transmit(void *Ptr, uint8_t Length) {
    // WaitUntilChannelIsBusy();   // If this is not done, time after time FIFO is destroyed
    do {
        EnterIdle();
    } while(IState != CC_STB_IDLE);
    WriteTX((uint8_t*)Ptr, Length);
    EnterTX();
}
Beispiel #4
0
void cc1101_t::TransmitAsync(rPkt_t *pPkt) {
    // WaitUntilChannelIsBusy();   // If this is not done, time after time FIFO is destroyed
    PWaitingThread = NULL;
    State = ccTransmitting;
    while(IState != CC_STB_IDLE) EnterIdle();
    WriteTX((uint8_t*)pPkt, RPKT_LEN);
    EnterTX();
}
Beispiel #5
0
void CC_t::Transmit(void) {
    do {
        EnterIdle();
    } while(IState != CC_STB_IDLE);

    WriteTX((uint8_t*)(&PktTx), CC_PKT_LEN);
    Aim = caTx;
    EnterTX();
}
Beispiel #6
0
void cc1101_t::Transmit(void *Ptr) {
    // WaitUntilChannelIsBusy();   // If this is not done, time after time FIFO is destroyed
    while(IState != CC_STB_IDLE) EnterIdle();
    WriteTX((uint8_t*)Ptr, IPktSz);
    // Enter TX and wait IRQ
    chSysLock();
    EnterTX();
    chThdSuspendS(&ThdRef);    // Wait IRQ
    chSysUnlock();  // Will be here when IRQ fires
}
Beispiel #7
0
void cc1101_t::TransmitSync(void *Ptr) {
    // WaitUntilChannelIsBusy();   // If this is not done, time after time FIFO is destroyed
    while(IState != CC_STB_IDLE) EnterIdle();
    WriteTX((uint8_t*)Ptr, IPktSz);
    // Enter TX and wait IRQ
    chSysLock();
    PWaitingThread = chThdSelf();
    EnterTX();
    chSchGoSleepS(THD_STATE_SUSPENDED);
    chSysUnlock();  // Will be here when IRQ fires
}
Beispiel #8
0
void cc1101_t::TransmitSync(rPkt_t *pPkt) {
    // WaitUntilChannelIsBusy();   // If this is not done, time after time FIFO is destroyed
    while(IState != CC_STB_IDLE) EnterIdle();
    WriteTX((uint8_t*)pPkt, RPKT_LEN);
    EnterTX();
    // Waiting for the IRQ to happen
    chSysLock();
    PWaitingThread = chThdSelf();
    chSchGoSleepS(THD_STATE_SUSPENDED);
    chSysUnlock();  // Will be here when IRQ will fire
}
Beispiel #9
0
// ========================== Implementation ===================================
void CC_t::Task(void) {
    // Do with CC what needed
    GetState();
    switch (State){
        case CC_STB_RX_OVF:
            FlushRxFIFO();
            klPrintf("RX_OVF");
            break;
        case CC_STB_TX_UNDF:
            FlushTxFIFO();
            klPrintf("\rTX_OVF");
            break;

        case CC_STB_IDLE:
            //Uart.PrintString("\rIDLE");
            //EnterRX();
            if (Delay.Elapsed(&Timer, 100)) {
                klPrintf("TX\r");
                // Prepare packet to send
                TX_Pkt.PktID++;
                WriteTX();
                //CC.EnterTXAndWaitToComplete();
                EnterTX();
            }
            break;

        case CC_STB_RX:
            //Uart.PrintString("\rRX");
//            if (GDO0_IsHi()) GDO0_WasHi = true;
//            // Check if GDO0 has fallen
//            else if (GDO0_WasHi) {
//                //UART_PrintString("\rIRQ\r");
//                GDO0_WasHi = false;
//                FifoSize = ReadRegister(CC_RXBYTES); // Get number of bytes in FIFO
//                if (FifoSize != 0) {
//                    ReadRX(RX_PktArray, (CC_PKT_LEN+2));    // Read two extra bytes of RSSI & LQI
//                    EVENT_NewPacket();
//                } // if size>0
//            } // if falling edge
            break;

        case CC_STB_TX:
            //UART_PrintString("\rTX");
            break;

        default: // Just get out in other cases
            //Uart.PrintString("\rOther: ");
            //Uart.PrintUint(CC.State);
            break;
    }//Switch
}
Beispiel #10
0
void CC_t::Task(void) {
    // Proceed with state processing
    GetState();
    switch (State) {
        case CC_STB_RX_OVF:
            Uart.Printf("RX ovf\r");
            FlushRxFIFO();
            break;
        case CC_STB_TX_UNDF:
            Uart.Printf("TX undf\r");
            FlushTxFIFO();
            break;

        case CC_STB_IDLE:
            if (SearchState == IsCalling) { // Call alien
                WriteTX();
                //klPrintf("TX: %u\r", TX_Pkt.To);
                EnterTX();
            }
            else {  // Is waiting
                if (Delay.Elapsed(&Timer, RX_WAIT_TIME)) SearchState = IsCalling;
                else EnterRX();
            }
            break;

        case CC_STB_RX:
            if (Delay.Elapsed(&Timer, RX_WAIT_TIME)) {
                SearchState = IsCalling;
                EnterIdle();
                // Note that all was interrogated
                if((TX_Pkt.To == MAX_ADDRESS) and (PktCounter == TRY_COUNT-1)) Signal.AllThemCalled = true;
            }
            break;

        default: // Just get out in other cases
            //klPrintf("Other: %X\r", State);
            break;
    } //Switch
}
Beispiel #11
0
void* serialTX(void* params){
	while(1){
		int servo = -1, value = -1;
		char buf0[128], buf1[128];

		if(oscillating){
			int i = 0;
			oscTime += 0.016f;
			int angle = 10 + (int)(50 * (cos(oscTime) + 1) / 2.0f);

			for(i = 4; i--;){
				//if(overloaded[i]){
				//	txState.Angle[i] = 10;
				//	continue;
				//}
				txState.Angle[i] = angle;
			}

			WriteTX(&txState);
			usleep(35000);

			continue;
		}

		printf("Servo: "); scanf("%d", &servo);
		if(servo > 0 && servo <= SERVOS){
			printf("Value: "); scanf("%d", &value);
			if(value >= 0 && value <= 180){
				// send
				txState.Angle[servo - 1] = value;

				if(WriteTX(&txState) < 0)
					serialport_flush(USB);
			}
		}
		else if(servo == -1){
			ServoStates txState = {
				{90,90,90,90 ,90,90,90,90}
			};
			WriteTX(&txState);
		}
		else if(servo == -2){
			ServoStates txState = {
				{50,50,50,50 ,50,50,50,50}
			};
			WriteTX(&txState);

		}
		else if(servo == -3){
			char command[128];
			int value;
			printf("Value: "); scanf("%d", &value);
			
			{
				ServoStates txState = {
					{value,value,value,value ,value,value,value,value}
				};
				WriteTX(&txState);
			}
		}
		else if(servo == -4) oscillating = 1;
	}
}