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)); } }
// ------------------------------------- // 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(send_process, ev, data) { PROCESS_BEGIN(); static struct etimer timer; static uint16_t counter = 0; while (1) { PRINTF("Sending %i\n", counter); radioSend(&counter, sizeof(counter)); ++counter; redLedToggle(); waitTimer(timer, TIMER_INTERRUPT_HZ); } PROCESS_END(); }