/*------------------------------------------------------------------------- Send a packet each time the user hits a key. -------------------------------------------------------------------------*/ test3(commInitReq_t *init_req, commTermReq_t *term_req) { char buf[512]; int nGot = 0; int c; commTxPktReq_t txReq; commTxPktResp_t txResp; commInitResp_t init_resp; if (!commInit(init_req,&init_resp)) { printf("Test Failed--Couldn't init: status %d\n", init_resp.status); exit(0); } while (((c = getch()) != EOF) && (c != 27)) { buf[0] = c; txReq.dest = PLAYER_BROADCAST; txReq.buffer = buf; txReq.length = 1; txReq.flags = 0; if (!commTxPkt(&txReq, &txResp)) { printf("Test Failed--Couldn't send packet\n"); printf("txResp->status = %d\n", txResp.status); quitAll(); } printf("test3: sent pkt; dest %d, length %d, contents %02x\n", txReq.dest, txReq.length, buf[0]); } commTerm(term_req,NULL); if (!nGot) { printf("Warning: no packet received!\n"); return; } printf("."); }
void systemTask(void *arg) { bool pass = true; //Init the high-levels modules systemInit(); #ifndef USE_UART_CRTP #ifdef UART_OUTPUT_TRACE_DATA debugInitTrace(); #endif #ifdef HAS_UART uartInit(); #endif #endif //ndef USE_UART_CRTP commInit(); DEBUG_PRINT("Crazyflie is up and running!\n"); DEBUG_PRINT("Build %s:%s (%s) %s\n", V_SLOCAL_REVISION, V_SREVISION, V_STAG, (V_MODIFIED) ? "MODIFIED" : "CLEAN"); DEBUG_PRINT("I am 0x%X%X%X and I have %dKB of flash!\n", *((int* )(0x1FFFF7E8 + 8)), *((int* )(0x1FFFF7E8 + 4)), *((int* )(0x1FFFF7E8 + 0)), *((short* )(0x1FFFF7E0))); commanderInit(); stabilizerInit(); //Test the modules pass &= systemTest(); pass &= commTest(); pass &= commanderTest(); pass &= stabilizerTest(); //Start the firmware if (pass) { systemStart(); ledseqRun(LED_RED, seq_alive); ledseqRun(LED_GREEN, seq_testPassed); } else { if (systemTest()) { while (1) { ledseqRun(LED_RED, seq_testPassed); //Red passed == not passed! vTaskDelay(M2T(2000) ); } } else { ledInit(); ledSet(LED_RED, true); } } workerLoop(); //Should never reach this point! while (1) vTaskDelay(portMAX_DELAY); }
void * canalThread (void *arg) { struct comm *a = arg; struct comm can[2]; struct comm listeClients[MAX_CLI]; commArrayInit (listeClients); switch (a->etat) { case STATE_INIT:; commCpy (&can[0], &a[0]); commInit (&can[1]); can[0].port = rand () % ESPACE_PORT + PLAGE_CANAL; serveur (can, &canalSub, listeClients); break; case STATE_CL_SUP:; // Le client 'me' ouvre un thread (can) // identification dédié à suppléer 'sup'. // On copie le nom du serveur à surveiller. strncpy (can[0].nom, a[1].nom, strlen (a[1].nom)); // On lui ajoute une petite extension pour le // distinguer. strncat (can[0].nom, SUFF_SUP, strlen (SUFF_SUP)); // On prend notre adresse et tire au sort un port. strncpy (can[0].padr, a[0].padr, strlen (a[0].padr)); can[0].port = rand () % ESPACE_PORT + PLAGE_CANAL; // On s'affecte l'etat 'watcher'. can[0].etat = STATE_CH_WAT; // On conserve l'identité du serveur à surveiller. commCpy (&can[1], &a[1]); serveur (can, &canalSub, listeClients); break; default:; printf ("/!\\ Etat invalide ! (canal)\n"); } pthread_exit (NULL); }
void systemTask(void *arg) { bool pass = true; /* Init the high-levels modules */ systemInit(); uartInit(); commInit(); stabilizerInit(); //Test the modules pass &= systemTest(); pass &= commTest(); // pass &= commanderTest(); pass &= stabilizerTest(); if (pass) { systemStart(); ledseqRun(LED_RED, seq_alive); ledseqRun(LED_GREEN, seq_testPassed); } else { if (systemTest()) { while(1) { ledseqRun(LED_RED, seq_testPassed); //Red passed == not passed! vTaskDelay(M2T(2000)); } } else { ledInit(); ledSet(LED_RED, true); } } pmSetChargeState(charge500mA); //Should never reach this point! while(1) vTaskDelay(portMAX_DELAY); }
/*------------------------------------------------------------------------- Send a 200 byte packet every 1/5th of a second -------------------------------------------------------------------------*/ test4(commInitReq_t *init_req, commTermReq_t *term_req) { char buf[512]; int nGot = 0; commTxPktReq_t txReq; commTxPktResp_t txResp; commInitResp_t init_resp; clock_t send_interval = CLOCKS_PER_SEC / 5; clock_t last_sent; int i; int pktnum; for (i=0; i<200; i++) buf[i] = i; if (!commInit(init_req,&init_resp)) { printf("Test Failed--Couldn't init: status %d\n", init_resp.status); exit(0); } last_sent = clock(); pktnum = 0; while (!kbhit()) { if (clock()-send_interval < last_sent) continue; buf[0] = pktnum++; last_sent += send_interval; txReq.dest = PLAYER_BROADCAST; txReq.buffer = buf; txReq.length = 200; txReq.flags = 0; if (!commTxPkt(&txReq, &txResp)) { printf("Test Failed--Couldn't send packet\n"); printf("txResp->status = %d\n", txResp.status); quitAll(); } printf("."); } commTerm(term_req,NULL); if (!nGot) { printf("Warning: no packet received!\n"); return; } }
PV_Init::PV_Init(int* argc, char ** argv[]){ //Initialize MPI initSignalHandler(); commInit(argc, argv); params = NULL; icComm = NULL; initialized = false; // if( rank == 0 ) { // printf("Hit enter to begin! "); // fflush(stdout); // int charhit = -1; // while(charhit != '\n') { // charhit = getc(stdin); // } // } // MPI_Barrier(icComm->globalCommunicator()); }
/*------------------------------------------------------------------------- Listen for packets and put them to the screen. -------------------------------------------------------------------------*/ test2(commInitReq_t *init_req, commTermReq_t *term_req) { char buf[512]; int nGot = 0; commRxPktReq_t rxReq; commRxPktResp_t rxResp; commInitResp_t init_resp; clock_t send_interval = CLOCKS_PER_SEC / 5; clock_t last_sent; if (!commInit(init_req,&init_resp)) { printf("Test Failed--Couldn't init: status %d\n", init_resp.status); exit(0); } last_sent = clock(); while (!kbhit()) { if (clock()-send_interval < last_sent) continue; last_sent += send_interval; rxReq.size = sizeof(buf); rxReq.buffer = buf; while (commRxPkt(&rxReq, &rxResp)) { nGot++; printf("src %d, length %d, data %02x%02x%02x%02x nGot %d\n", rxResp.src, rxResp.length, buf[0], buf[1], buf[2], buf[3], nGot); } if (rxResp.status != 0) printf("status %d\n", rxResp.status); } commTerm(term_req,NULL); if (!nGot) { printf("Warning: no packet received!\n"); return; } printf("."); }
void systemTask(void *arg) { bool pass = true; ledInit(); ledSet(CHG_LED, 1); uartInit(); //Init the high-levels modules systemInit(); #ifndef USE_RADIOLINK_CRTP #ifdef UART_OUTPUT_TRACE_DATA //debugInitTrace(); #endif #ifdef ENABLE_UART // uartInit(); #endif #endif //ndef USE_RADIOLINK_CRTP commInit(); DEBUG_PRINT("----------------------------\n"); DEBUG_PRINT("Crazyflie is up and running!\n"); DEBUG_PRINT("Build %s:%s (%s) %s\n", V_SLOCAL_REVISION, V_SREVISION, V_STAG, (V_MODIFIED)?"MODIFIED":"CLEAN"); DEBUG_PRINT("I am 0x%X%X%X and I have %dKB of flash!\n", *((int*)(MCU_ID_ADDRESS+8)), *((int*)(MCU_ID_ADDRESS+4)), *((int*)(MCU_ID_ADDRESS+0)), *((short*)(MCU_FLASH_SIZE_ADDRESS))); commanderInit(); stabilizerInit(); expbrdInit(); memInit(); //Test the modules pass &= systemTest(); pass &= configblockTest(); pass &= commTest(); pass &= commanderTest(); pass &= stabilizerTest(); pass &= expbrdTest(); pass &= memTest(); //Start the firmware if(pass) { selftestPassed = 1; systemStart(); ledseqRun(SYS_LED, seq_alive); ledseqRun(LINK_LED, seq_testPassed); } else { selftestPassed = 0; if (systemTest()) { while(1) { ledseqRun(SYS_LED, seq_testPassed); //Red passed == not passed! vTaskDelay(M2T(2000)); // System can be forced to start by setting the param to 1 from the cfclient if (selftestPassed) { DEBUG_PRINT("Start forced.\n"); systemStart(); break; } } } else { ledInit(); ledSet(SYS_LED, true); } } DEBUG_PRINT("Free heap: %d bytes\n", xPortGetFreeHeapSize()); workerLoop(); //Should never reach this point! while(1) vTaskDelay(portMAX_DELAY); }
void systemTask(void *arg) { bool pass = true; ledInit(); ledSet(CHG_LED, 1); #ifdef DEBUG_QUEUE_MONITOR queueMonitorInit(); #endif #ifdef ENABLE_UART1 uart1Init(); #endif #ifdef ENABLE_UART2 uart2Init(); #endif //Init the high-levels modules systemInit(); commInit(); commanderInit(); StateEstimatorType estimator = anyEstimator; deckInit(); estimator = deckGetRequiredEstimator(); stabilizerInit(estimator); if (deckGetRequiredLowInterferenceRadioMode()) { platformSetLowInterferenceRadioMode(); } soundInit(); memInit(); #ifdef PROXIMITY_ENABLED proximityInit(); #endif //Test the modules pass &= systemTest(); pass &= configblockTest(); pass &= commTest(); pass &= commanderTest(); pass &= stabilizerTest(); pass &= deckTest(); pass &= soundTest(); pass &= memTest(); pass &= watchdogNormalStartTest(); //Start the firmware if(pass) { selftestPassed = 1; systemStart(); soundSetEffect(SND_STARTUP); ledseqRun(SYS_LED, seq_alive); ledseqRun(LINK_LED, seq_testPassed); } else { selftestPassed = 0; if (systemTest()) { while(1) { ledseqRun(SYS_LED, seq_testPassed); //Red passed == not passed! vTaskDelay(M2T(2000)); // System can be forced to start by setting the param to 1 from the cfclient if (selftestPassed) { DEBUG_PRINT("Start forced.\n"); systemStart(); break; } } } else { ledInit(); ledSet(SYS_LED, true); } } DEBUG_PRINT("Free heap: %d bytes\n", xPortGetFreeHeapSize()); workerLoop(); //Should never reach this point! while(1) vTaskDelay(portMAX_DELAY); }
void systemTask(void *arg) { bool pass = true; ledInit(); ledSet(CHG_LED, 1); #ifdef DEBUG_QUEUE_MONITOR queueMonitorInit(); #endif uartInit(); #ifdef ENABLE_UART1 uart1Init(); #endif #ifdef ENABLE_UART2 uart2Init(); #endif //Init the high-levels modules systemInit(); #ifndef USE_RADIOLINK_CRTP #ifdef UART_OUTPUT_TRACE_DATA //debugInitTrace(); #endif #ifdef ENABLE_UART // uartInit(); #endif #endif //ndef USE_RADIOLINK_CRTP commInit(); commanderAdvancedInit(); stabilizerInit(); #ifdef PLATFORM_CF2 deckInit(); #endif soundInit(); memInit(); #ifdef PROXIMITY_ENABLED proximityInit(); #endif //Test the modules pass &= systemTest(); pass &= configblockTest(); pass &= commTest(); pass &= commanderAdvancedTest(); pass &= stabilizerTest(); #ifdef PLATFORM_CF2 pass &= deckTest(); #endif pass &= soundTest(); pass &= memTest(); pass &= watchdogNormalStartTest(); //Start the firmware if(pass) { selftestPassed = 1; systemStart(); soundSetEffect(SND_STARTUP); ledseqRun(SYS_LED, seq_alive); ledseqRun(LINK_LED, seq_testPassed); } else { selftestPassed = 0; if (systemTest()) { while(1) { ledseqRun(SYS_LED, seq_testPassed); //Red passed == not passed! vTaskDelay(M2T(2000)); // System can be forced to start by setting the param to 1 from the cfclient if (selftestPassed) { DEBUG_PRINT("Start forced.\n"); systemStart(); break; } } } else { ledInit(); ledSet(SYS_LED, true); } } DEBUG_PRINT("Free heap: %d bytes\n", xPortGetFreeHeapSize()); workerLoop(); //Should never reach this point! while(1) vTaskDelay(portMAX_DELAY); }
int main (int argc, char *argv[]) { srand ((unsigned int) time (NULL)); commInit (&annuaire); commInit (&moi[0]); commInit (&moi[1]); annuaire.etat = STATE_ANNUAIRE; strncpy (annuaire.nom, "NULL", sizeof "NULL"); #if DEBUG == 1 || DEBUG == 2 //strncpy (annuaire.padr, "::1", sizeof "::1"); strncpy (annuaire.padr, "127.0.0.1", sizeof "127.0.0.1"); annuaire.port = 9000; printf (" -------- Mode DEBUG -------- \n"); if (argc == 2) { if (strcmp (argv[1], "--annuaire") == 0) { // Lancement de l'annuaire printf ("Annuaire\n"); annuaireThread (NULL); } else if (strcmp (argv[1], "--canal") == 0) { printf ("Canal\n"); moi[0].etat = STATE_INIT; strncpy (moi[0].padr, "::1", sizeof "::1"); strncpy (moi[0].nom, "Channel1", sizeof "Channel1"); canalThread (&moi); } else if (strcmp (argv[1], "--simple") == 0) { printf ("Client Simple \n"); moi[0].etat = STATE_CL_SIM_INIT; strncpy (moi[0].padr, "::1", sizeof "::1"); strncpy (moi[0].nom, "Alice", sizeof "Alice"); clientThread (&moi); } else if (strcmp (argv[1], "--classique") == 0) { printf ("Client Classique \n"); moi[0].etat = STATE_CL_SUP_INIT; strncpy (moi[0].padr, "::1", sizeof ("::1")); strncpy (moi[0].nom, "Bob", sizeof ("Bob")); clientThread (&moi); } else if (strcmp (argv[1], "--test") == 0) { tests (); } else { printf ("Argument invalide\n"); } } else { printf ("Nombre d'arguments invalide\n"); } #else #endif exit (0); }
void canalSub (struct comm *me, struct comm *src, char *buf, void *arg) { struct comm *listeClients = arg; // INITIALISATION if ((int) buf == INIT_FLAG) { if (me->etat == STATE_INIT) { printf ("Initialisation du canal %s...\n", me->nom); printf ("Sur : %s:%i\n", me->padr, me->port); printf ("Prise de contact avec le serveur annuaire...\n"); pthread_mutex_lock (&annuaire.mutex); envoiUDP (me, &annuaire, CODE_AN_addChan); pthread_mutex_unlock (&annuaire.mutex); // Si la liste n'est pas vide on, BroadCast à tous les clients // le changement d'adresse du canal. if (listeClients[0].port != 0) { char remp[MAXLEN]; char chan[MAXLEN]; memset (remp, '\0', sizeof remp); strncpy (remp, CODE_CL_replace, strlen (CODE_CL_replace)); commToString (&me[1], chan); strncat (remp, chan, strlen (chan)); int i; for (i = 0; i < MAX_CHAN && listeClients[i].port != 0; i++) { envoiUDP (me, &listeClients[i], remp); printf ("Envoie à %s\n", listeClients[i].nom); } } commInit (&me[1]); me->etat = STATE_CH_ASK; } else if (me->etat == STATE_CH_WAT) { printf ("Initialisation du canal suppléant : %s...\n", me->nom); printf ("Sur : %s:%i\n", me->padr, me->port); envoiUDP (&me[0], &me[1], CODE_CH_supID); // On thread un "watcher" pour surveiller // l'etat du serveur pthread_mutex_lock (&ALIVE_mutex); ALIVE_SHARED = 0; pthread_mutex_unlock (&ALIVE_mutex); pthread_t watcher; if (pthread_create (&watcher, NULL, &watchingThread, me)) { printf ("Impossible de demarrer un surveillant.\n"); } } } // Reception du flag special ('alarme par le thread') else if ((strncmp (buf, CODE_CH_SPECIAL, SIZE_CODE) == 0)) { // Si je suis channel suppléé : if (me->etat == STATE_CH_SUP) { // Je pleure printf ("%s n'est plus suppléant.\n", me[1].nom); // TODO Je l'efface mon suppléant de la liste // je redeviens demandeur de suppléant me->etat = STATE_CH_ASK; canalSub (me, NULL, (char *) INIT_FLAG, arg); } // Si je suis un surveillant : else if (me->etat == STATE_CH_WAT) { // Je change d'état... me->etat = STATE_INIT; // ...pour m''initialiser canalSub (me, NULL, (char *) INIT_FLAG, arg); } else printf ("Erreur 'Alarme' : etat incongru !"); } // Inscription sur l'annuaire effective else if (strncmp (buf, CODE_OK, SIZE_CODE) == 0) { printf ("...Inscription ok ! :)\n"); } // Demande d'abonnement d'un client else if (strncmp (buf, CODE_CH_addCli, SIZE_CODE) == 0 || strncmp (buf, CODE_CH_addSup, SIZE_CODE) == 0) { // Ajout du nouveau client int i; for (i = 0; i < MAX_CHAN && listeClients[i].port != 0; i++); if (strncmp (buf, CODE_CH_addSup, SIZE_CODE) == 0) src->etat = STATE_CL_SUP; else { src->etat = STATE_CL_SIM; } commCpy (&listeClients[i], src); if (me->etat != STATE_CH_WAT) envoiUDP (me, src, CODE_OK); printf ("Nouveau client : %s \n", src->nom); // Recherche d'un canal suppléant if (me->etat == STATE_CH_ASK) { #if DEBUG == 1 printf ("Recherche canal supp'\n"); #endif for (i = 0; i < MAX_CHAN && listeClients[i].etat != STATE_CL_SUP; i++) { #if DEBUG == 1 printf ("(%i) : %i\n", i, listeClients[i].etat); #endif } if (listeClients[i].etat == STATE_CL_SUP) { envoiUDP (me, &listeClients[i], CODE_CL_desSup); #if DEBUG == 2 printf ("Demande à %s de me suppléer.\n", listeClients[i].nom); #endif me->etat = STATE_CH_SUP_INIT; } } // Pour tous les messsages, si je suis suppléé // je redirige le message vers mon suppléant else if (me->etat == STATE_CH_SUP) { envoiUDP (src, &me[1], buf); } } // Reception d'un message provenant d'un channel de secours // identifiant la suppléance qu'il propose (i.e. : qui il est) else if (strncmp (buf, CODE_CH_supID, SIZE_CODE) == 0) { if (me->etat == STATE_CH_SUP_INIT) { #if DEBUG == 2 printf ("Je suis suppléé par : %s \n", src->nom); #endif // On envoie la liste des clients char listeStr[MAX_ARRAY_COM_STR]; memset (listeStr, '\0', sizeof listeStr); strncpy (listeStr, CODE_CH_ListAns, strlen (CODE_CH_ListAns)); strncat (listeStr, "\n", strlen ("\n")); commArrayToString (listeClients, listeStr); printf ("Envoi de la liste : %s", listeStr); // Envoi de la liste des clients au suppléant envoiUDP (me, src, listeStr); // Association du suppléant à moi meme en vu de l'observer commCpy (&me[1], src); // Démarrage d'un thread pour surveiller le suppléant. pthread_mutex_lock (&ALIVE_mutex); ALIVE_SHARED = 0; pthread_mutex_unlock (&ALIVE_mutex); pthread_t watcher; if (pthread_create (&watcher, NULL, &watchingThread, me)) { printf ("Thread error : canal vers surveillant.\n"); } me->etat = STATE_CH_SUP; } else { printf ("Erreur : Suppléance inatendue.\n"); } } // Reception + Diffusion d'un message provenant de la // part d'un client else if (strncmp (buf, CODE_CH_msgCli, SIZE_CODE) == 0) { char msg[MAXLEN]; memset (msg, '\0', sizeof msg); strncpy (msg, CODE_CL_msgCha, SIZE_CODE); strncat (msg, src->nom, strlen (src->nom)); strncat (msg, " : ", strlen (" : ")); strncat (msg, &buf[SIZE_CODE], strlen (buf) - SIZE_CODE); int i; for (i = 0; i < MAX_CHAN && listeClients[i].port != 0; i++) if (commCompare (&listeClients[i], src)) envoiUDP (me, &listeClients[i], msg); } // Reception d'un signal ALIVE : question else if (strncmp (buf, CODE_AliveReq, SIZE_CODE) == 0) { envoiUDP (me, src, CODE_AliveAns); } // Reception d'un signal ALIVE : reponse else if (strncmp (buf, CODE_AliveAns, SIZE_CODE) == 0) { pthread_mutex_lock (&ALIVE_mutex); ALIVE_SHARED++; #if DEBUG == 1 printf ("Valeur alive : %i \n", ALIVE_SHARED); #endif pthread_mutex_unlock (&ALIVE_mutex); } else if (strncmp (buf, CODE_CH_ListAns, SIZE_CODE) == 0) { // On réalise une copie compléte des clients commStringToArray (&buf[SIZE_CODE + 1], listeClients); } }
test1(commInitReq_t *init_req, commTermReq_t *term_req) { clock_t rope; int j; char buf[512]; int nGot = 0; commRxPktReq_t rxReq; commRxPktResp_t rxResp; commTxPktReq_t txReq; commTxPktResp_t txResp; commInitResp_t init_resp; if (!commInit(init_req,&init_resp)) { printf("Test Failed--Couldn't init: status %d\n", init_resp.status); exit(0); } #if 1 // Call ipx2_get, even though we don't expect any packets, to start // listening. rxReq.size = sizeof(buf); rxReq.buffer = buf; if (commRxPkt(&rxReq,&rxResp)) { printf("Test Failed--Buffer not empty at start\n"); quitAll(); } #endif #if 1 printf("test1: loop beginning now!\n"); for (j=0; j<3; j++) { txReq.dest = PLAYER_BROADCAST; txReq.buffer = "Hello World\n"; txReq.length = 12; txReq.flags = 0; if (!commTxPkt(&txReq, &txResp)) { printf("Test Failed--Couldn't send packet\n"); printf("txResp->status = %d\n", txResp.status); quitAll(); } txReq.dest = PLAYER_BROADCAST; txReq.buffer = "Goodbye World\n"; txReq.length = 15; txReq.flags = 0; // r = ipx2_put(, "Goodbye World\n", 15, ipx2_HDL_BROADCAST); if (!commTxPkt(&txReq, &txResp)) { printf("Test Failed--Couldn't send second packet\n"); quitAll(); } for (rope=clock()+CLOCKS_PER_SEC; rope>clock(); ) { if (kbhit()) break; rxReq.size = sizeof(buf); rxReq.buffer = buf; commRxPkt(&rxReq, &rxResp); if (rxResp.status == 2) { printf("Test Failed--Error receiving packet\n"); quitAll(); } if (rxResp.status != 0) continue; nGot++; if (rxResp.length != 12 && rxResp.length != 15) { printf("Test Failed-- j %d, Length %d received not as sent\n", j, rxResp.length); quitAll(); } if (memcmp(buf, "Hello World\n", 12) != 0 && memcmp(buf, "Goodbye World\n", 15) != 0) { printf("Test Failed--Bad data received\n"); quitAll(); } fwrite(buf, 1, rxResp.length, stdout); } } commTerm(term_req,NULL); if (!nGot) { printf("Warning: no packet received!\n"); return; } #endif printf("."); }
/*------------------------------------------------------------------------- Send a 200 byte packet every 1/5th of a second -------------------------------------------------------------------------*/ test5(commInitReq_t *init_req, commTermReq_t *term_req, int reInitOften) { char buf[512]; int nGot = 0; commTxPktReq_t txReq; commTxPktResp_t txResp; commInitResp_t init_resp; commRxPktReq_t rxReq; commRxPktResp_t rxResp; clock_t send_interval = CLOCKS_PER_SEC / 5; clock_t last_sent; int i; int pktnum; for (i=0; i<200; i++) buf[i] = i; if (!commInit(init_req,&init_resp)) { printf("Test Failed--Couldn't init: status %d\n", init_resp.status); exit(0); } last_sent = clock(); pktnum = 0; while (!kbhit()) { if (clock()-send_interval < last_sent) continue; buf[0] = pktnum++; last_sent += send_interval; txReq.dest = PLAYER_BROADCAST; txReq.buffer = buf; txReq.length = 200; txReq.flags = 0; if (!commTxPkt(&txReq, &txResp)) { printf("Test Failed--Couldn't send packet\n"); printf("txResp->status = %d\n", txResp.status); quitAll(); } printf("."); rxReq.size = sizeof(buf); rxReq.buffer = buf; while (commRxPkt(&rxReq, &rxResp)) { nGot++; printf("src %d, length %d, data %02x%02x%02x%02x nGot %d\n", rxResp.src, rxResp.length, buf[0], buf[1], buf[2], buf[3], nGot); } if (rxResp.status != 0) printf("status %d\n", rxResp.status); if (reInitOften) { commTermReq_t termReq; init_req->flags = 0; termReq.flags = 0; if (!commTerm(&termReq,NULL)) { printf("commTerm failed!\n"); exit(1); } sleep(1); printf("test5: about to call commInit()\n"); if (!commInit(init_req,NULL)) { printf("comm re-init failed!\n"); exit(1); } } } commTerm(term_req,NULL); if (!nGot) { printf("Warning: no packet received!\n"); return; } }