void rfSendData(void) { uint8 pTxData[20] ={'l','i','y','a','n','f','e','n','g','v','5','8','7','a','b',0}; uint8 ret; uint8 recvCnt=0; uint8 ch=0; // Keep Receiver off when not needed to save power basicRfReceiveOff(); // Main loop while (TRUE) { recvCnt=0; ret = basicRfSendPacket(0xffff, pTxData, sizeof pTxData); //广播地址 if (ret == SUCCESS) { printf("send msg ok\r\n"); hal_led_on(1); halMcuWaitMs(100); hal_led_off(1); halMcuWaitMs(900); } else { printf("send msg error\r\n"); hal_led_on(1); halMcuWaitMs(1000); hal_led_off(1); } } }
void rfSendData(void) { uint8 pTxData[20]; uint8 ret; // Keep Receiver off when not needed to save power basicRfReceiveOff(); //sprintf(pTxData,"distince:%u CM.", uWaveDistance()); printf("goto while...\r\n"); // Main loop while (TRUE) { printf("in while...\r\n"); dht11_update(pTxData); printf("get data ok...\r\n"); ret = basicRfSendPacket(RECV_ADDR, pTxData, sizeof pTxData); if (ret == SUCCESS) { printf("send msg ok!!!\r\n"); hal_led_on(1); halMcuWaitMs(100); hal_led_off(1); halMcuWaitMs(900); } else { printf("send msg error!!!\r\n"); hal_led_on(1); halMcuWaitMs(1000); hal_led_off(1); } } }
static void appSwitch() { /****************************************************************by boo halLcdWriteLine(HAL_LCD_LINE_1, "Switch"); halLcdWriteLine(HAL_LCD_LINE_2, "Joystick Push"); halLcdWriteLine(HAL_LCD_LINE_3, "Send Command");*/ #ifdef ASSY_EXP4618_CC2420 halLcdClearLine(1); halLcdWriteSymbol(HAL_LCD_SYMBOL_TX, 1); #endif // Initialize BasicRF basicRfConfig.myAddr = SWITCH_ADDR; if(basicRfInit(&basicRfConfig)==FAILED) { HAL_ASSERT(FALSE); } pTxData[0] = LIGHT_TOGGLE_CMD; // Keep Receiver off when not needed to save power basicRfReceiveOff(); // Main loop while (TRUE) { //if( halJoystickPushed() )**********************by boo if(halButtonPushed()==HAL_BUTTON_1)//**************by boo { basicRfSendPacket(LIGHT_ADDR, pTxData, APP_PAYLOAD_LENGTH); P1_1=~P1_1; // Put MCU to sleep. It will wake up on joystick interrupt halIntOff(); halMcuSetLowPowerMode(HAL_MCU_LPM_3); // Will turn on global // interrupt enable halIntOn(); } } }
void rfSendData(void) { char pTxData[20]={0}; unsigned int recvCnt=0; unsigned int ch=0,i=0; unsigned int tmp=0; // Keep Receiver off when not needed to save power basicRfReceiveOff(); // Main loop while (TRUE) { recvCnt=0; Uart_Send_String("input num/+/- must end with @\r\n"); tmp=0; while(TRUE) { ch = Uart_Recv_char(); if (ch == '@' || recvCnt >= 256) { pTxData[recvCnt] = 0; Uart_Send_String(pTxData); Uart_Send_String("\r\n"); // recvCnt = 0; printf("get string finish...\r\n"); break; } else { pTxData[recvCnt++] = ch; } } //recvCnt= sizeof pTsxData; printf("input num:%s,length:%d",pTxData,recvCnt); if(pTxData[0]=='+') { myrate-=2; continue; } if(pTxData[0]=='-') { myrate+=2; continue; } for(i=0;i<recvCnt;i++) { if(pTxData[i]>='0'&&pTxData[i]<='9') { tmp*=10; tmp+=(pTxData[i]-'0'); } else { printf("input num error\r\n"); i=256; } } if(tmp!=0) { myrate=60*tmp; counter=0; } printf("myrate:%d,f:%d\r\n",myrate,tmp); } }
int main(void) { #error "Hi, Currently not working, still to be tested! - I didn't find time to debug it! " //halIntOn(); unsigned long pktsSent = 0; perConfig.mode = PER_MODE_TX; perConfig.state = PER_IDLE; perConfig.channel = 26; perConfig.txPower = 0; // Index 0. Max output perConfig.burstSize = 1000000; // Max value perConfig.pktRate = 20; // 20 pkts per second perConfig.gainMode = PER_GAIN_MODE_NONE; // No PA/LNA // // Config basicRF // basicRfConfig.panId = PAN_ID; basicRfConfig.ackRequest = false; if(basicRfInit(&basicRfConfig) == FAILED) { while(1); } basicRfReceiveOff(); halRfSetTxPower(0); // appTimerConfig(20); halTimer32kInit(32768/20); halTimer32kIntConnect(&appTimerIsr); // Connect ISR halTimer32kIntEnable(); // Enable interrupts while(1) { if(perConfig.state == PER_TRANSMIT) { if(pktsSent < perConfig.burstSize) { // // Make sure sequence number has network byte order // UINT32_HTON(tTxPacket.seqNumber); basicRfSendPacket(RX_ADDR, (unsigned char*)&tTxPacket, PACKET_SIZE); // // Change byte order back to host order before increment // UINT32_NTOH(tTxPacket.seqNumber); // // Update variables // tTxPacket.seqNumber++; pktsSent++; perConfig.state = PER_PACKET_RECEIVED; // // Update LED // // bspLedToggle(BSP_LED_1); } else { // // Done sending packets, exit TX loop // break; } } } }
/*********************************************************************************** * @fn main */ void main(void) { // Initalise board peripherals halBoardInit(); basicRfSetUp(); // Initalise hal_rf if(halRfInit()==FAILED) { HAL_ASSERT(FALSE); } // Indicate that device is powered halLedSet(1); halMcuWaitMs(350); configureUSART0forUART_ALT1(); uartStartRxForIsr(); while(TRUE) { //---------------------- // INITIALIZE //---------------------- if(initFlag) { while(!start); //waiting for 'a' key from PC //respond to PC -- going to try to start up WRS start=0; pTxData[0] = INIT_COMM_CMD; basicRfReceiveOff(); if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS) { state=1; } basicRfReceiveOn(); //wait for ACK from WRS pTxData[0] = INIT_COEF_CMD; basicRfReceiveOff(); if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS) { basicRfReceiveOn(); //WAIT FOR COEFFICIENTS FROM WRS while(!basicRfPacketIsReady());//wait to receive acknowledgement if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) { if(pRxData[0] == 'C') { //Pass to PC for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++) { U0CSR &= ~0x02; //SET U0TX_BYTE to 0 U0DBUF = pRxData[uartTxIndex]; while (!(U0CSR&0x02)); } } } } //finished sending coefficients to PC basicRfReceiveOn(); initFlag=0; } if(turnOnMotorFlag){ if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send command to WRS { turnOnMotorFlag=0; } } if(sendInitFlag){ if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send command to WRS { initFlag=1; sendInitFlag=0; //Pass to PC for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++) { pRxData[0] == 'R'; U0CSR &= ~0x02; //SET U0TX_BYTE to 0 U0DBUF = pRxData[uartTxIndex]; while (!(U0CSR&0x02)); } } } //Receive package from WRS if(basicRfPacketIsReady()) { if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, myRSSI)>0) { getRSSI = basicRfGetRssi(); pRxData[104]=getRSSI; if(pRxData[0] == 'D')//||(pRxData[0] == 'I')) { //SEND DATA TO PC for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++) { U0CSR &= ~0x02; //SET U0TX_BYTE to 0 U0DBUF = pRxData[uartTxIndex]; while (!(U0CSR&0x02)); } } } } } }
/*********************************************************************************** * @fn main */ void main(void) { // Initalise board peripherals halBoardInit(); basicRfSetUp(); // Initalise hal_rf if(halRfInit()==FAILED) { HAL_ASSERT(FALSE); } // Indicate that device is powered halLedSet(1); halMcuWaitMs(350); configureUSART0forUART_ALT1(); uartStartRxForIsr(); while(!start); //waiting for 'a' key from PC //respond to PC -- going to try to start up WRS pTxData[0] = INIT_COMM_CMD; basicRfReceiveOff(); if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS) { state=1; } basicRfReceiveOn(); //wait for ACK from WRS pTxData[0] = INIT_COEF_CMD; basicRfReceiveOff(); if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS) { basicRfReceiveOn(); state=2;//continuous? //WAIT FOR COEFFICIENTS FROM WRS while(!basicRfPacketIsReady());//wait to receive acknowledgement if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) { if(pRxData[0] == 'C') { //Pass to PC for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++) { U0CSR &= ~0x02; //SET U0TX_BYTE to 0 U0DBUF = pRxData[uartTxIndex]; while (!(U0CSR&0x02)); } // while(!ACK);//waiting for acknowledgement } } } //finished sending coefficients to PC basicRfReceiveOn(); while(TRUE) { //Receive package from WRS if(basicRfPacketIsReady()) { if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, myRSSI)>0) { getRSSI = basicRfGetRssi(); pRxData[104]=getRSSI; if((pRxData[0] == 'P')||(pRxData[0] == 'A')) { //SEND DATA TO PC for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++) { U0CSR &= ~0x02; //SET U0TX_BYTE to 0 U0DBUF = pRxData[uartTxIndex]; while (!(U0CSR&0x02)); } } } } //Receive CMD from PC if(changePWMflag)//have this be set in interrupt { //basicRfReceiveOff(); if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send PWM info to WRS { changePWMflag=0; } //basicRfReceiveOn(); // while(changePWMflag)//Keep receiving until PWM acknowledge is sent // { // while(!basicRfPacketIsReady());//waiting for acknowledgement -- important here i think // // if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) // { // if(pRxData[0] == 'Z') // { // //receive current duty cycle and send back to PC // for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++) // { // U0CSR &= ~0x02; //SET U0TX_BYTE to 0 // U0DBUF = pRxData[uartTxIndex]; // while (!(U0CSR&0x02)); // } // changePWMflag = 0; // } // //else send pressure? // } // } // } } }//END OF MAIN WHILE LOOP }