void appMain(void) { static uint8_t buffer[100]; radioSetTxPower(TX_POWER); radioSetReceiveHandle(rcvRadio); radioOn(); uint32_t lastTime = getTimeMs(); for (;;) { int8_t rssi = radioGetLastRSSI(); if ((int32_t) getTimeMs() - (int32_t) lastTime > 1000) { radioSend(buffer, sizeof(buffer)); PRINTF("rssi=%d\n", rssi); lastTime = getTimeMs(); if (rxOk) --rxOk; if (!rxOk) redLedOn(); else redLedOff(); } greenLedToggle(); busyWait(getWaitInterval(rssi)); } }
// Application entry point void appMain(void) { // setup our radio packet buffer radioPacketBuffer = (RadioPacketBuffer_t *) &realBuf; // turn on radio listening radioOn(); for (;;) { if (isRadioPacketError()) { // error occured last time the packet was received PRINTF("radio receive failed, error code %u\n", (uint16_t) -radioPacketBuffer->receivedLength); } else if (isRadioPacketReceived()) { // a packet is received from the radio PRINTF("received %u byte packet\n", (uint16_t) radioPacketBuffer->receivedLength); // dump the contents of the buffer debugHexdump(radioPacketBuffer->buffer, radioPacketBuffer->receivedLength); } // reset our radio buffer in any case radioBufferReset(); // do nothing for a while msleep(1000); } }
static void roStartListeningTimerCb(void *x) { // PRINTF("%lu: (%c) LISTEN START\n", getSyncTimeMs(), isRoutingInfoValid() ? '+' : '-'); if (!isListening) { TPRINTF("+++ start\n"); } alarmSchedule(&roStartListeningTimer, timeToNextFrame() + 2000); radioOn(); isListening = true; alarmSchedule(&roStopListeningTimer, 2000 + 2 * MOTE_TIME_FULL * MAX_MOTES); }
// ------------------------------------- // Main function // ------------------------------------- void appMain(void) { uint16_t i; // timers (used to get an extra interrupt context) alarmInit(&timer, onTimer, NULL); alarmSchedule(&timer, 1000); // radio radioSetReceiveHandle(radioRecvCb); radioOn(); for (i = 0; i < BUFFER_SIZE; i++) { buffer[i] = i; } randomInit(); // SELECT_FLASH; // extFlashBulkErase(); // UNSELECT_FLASH; for (i = 0; ; i++) { uint32_t address = i * 64ul; SELECT_FLASH; if (IS_ALIGNED(address, EXT_FLASH_SECTOR_SIZE)) { PRINTF("erase address %lu\n", address); flashErase(address); } PRINTF("write address %lu\n", address); flashWrite(address); if (address > 0) { PRINTF("verify...\n"); flashRead(address - 64); } UNSELECT_FLASH; msleep(randomInRange(400, 1000)); PRINTF("send smth to radio...\n"); radioSend("hello world", sizeof("hello world")); greenLedToggle(); } }
/*---------------------------------------------------------------------*/ PROCESS_THREAD(receive_process, ev, data) { PROCESS_BEGIN(); radioOn(); while (1) { waitRadioPacket(ev); if (radioPacketBuffer->receivedLength >= 2) { uint16_t counter = ((uint16_t *) radioPacketBuffer->buffer)[0]; PRINTF("Received counter %i\n", counter); greenLedToggle(); } } PROCESS_END(); }
// -------------------------------------------- // -------------------------------------------- void appMain(void) { serialEnableRX(PRINTF_SERIAL_ID); // serialSetReceiveHandle(PRINTF_SERIAL_ID, onSerRecv); serialSetPacketReceiveHandle(PRINTF_SERIAL_ID, onSerRecv, serBuffer, SER_BUF_SIZE); radioSetReceiveHandle(onRadioRecv); radioOn(); mdelay(200); // Send restart message to the phaser send_ctrl_msg(MSG_ACT_RESTART); while (1) { mdelay(RATE_DELAY); led0Toggle(); } }
static void roRequestTimerCb(void *x) { // check if already found the info static uint8_t cnt; if (isRoutingInfoValid() && cnt > 5) return; cnt++; if (isRoutingInfoValid()) return; // add jitter routingRequestTimeout += randomNumberBounded(100); alarmSchedule(&roRequestTimer, routingRequestTimeout); if (routingRequestTimeout < ROUTING_REQUEST_MAX_EXP_TIMEOUT) { // use exponential increments routingRequestTimeout *= 2; } else if (routingRequestTimeout < ROUTING_REQUEST_MAX_TIMEOUT) { // use linear increments routingRequestTimeout += ROUTING_REQUEST_MAX_EXP_TIMEOUT; } else { // move back to initial (small) timeout routingRequestTimeout = ROUTING_REQUEST_INIT_TIMEOUT; } TPRINTF("SEND ROUTING REQUEST\n"); radioOn(); // wait for response isListening = true; RoutingRequestPacket_t req; req.packetType = ROUTING_REQUEST; req.senderType = SENDER_COLLECTOR; socketSendEx(&roSocket, &req, sizeof(req), MOS_ADDR_BROADCAST); alarmSchedule(&roStopListeningTimer, ROUTING_REPLY_WAIT_TIMEOUT); }