void Board_start() { int experimentEndTime; int updateFlag; int quitFlag; Board b; BoardThreadParams threadParams[MAX_N_ROBOTS]; BoardDatabase *db; #ifdef IS_WIN CvSize szGlobal = {ENVIR_DIMS, ENVIR_DIMS}; CvSize szLocal = {LOC_MAP_DIMS, LOC_MAP_DIMS}; IplImage *globMapIplImage; IplImage *localMapIplImage; #endif setupExperimentDir(); // Do this before setting up the database SET_N_ROBOTS(1) #ifdef SETUP_TEST_COALITION SET_N_ROBOTS(2) SET_N_ROBOTS_THREADS_FOR_TEST_COAL(1) #endif #ifdef IS_WIN globMapIplImage = cvCreateImage (szGlobal, 8, 1); localMapIplImage = cvCreateImage (szLocal, 8, 1); b = initBoard (globMapIplImage, localMapIplImage); #else b = initBoard(); #endif db = &b.db; #ifdef SETUP_TEST_COALITION Board_setupTestCoalRobots (&b.db); #endif #ifdef SHOW_IMGS Visualisation_showSim (db); Visualisation_showMap (db); // printf ("Adjust windows and click to start\n"); cvWaitKey (0); #endif if (-1 == setupSockets (db, threadParams)) { goto cleanupBoard; } experimentEndTime = clock() + 10000; printf ("Experiment ends at %d.\n", experimentEndTime); if (-1 == setupThreads (db, threadParams)) { goto cleanupBoard; } printf ("All threads started. Entering blackboard server loop.\n"); quitFlag = 0; while (!quitFlag) { enterBoardData(); checkTime (db, experimentEndTime, &updateFlag); if (updateFlag) { Board_processData (&b, 1); //! \todo Allocate coalitions quitFlag = checkIfAllFinished (db); } leaveBoardData(); if (!updateFlag) { SLEEP_FOR_MS(10) } } printf ("Finished loop. Closing sockets.\n"); closeSockets (db); Board_finish (&b); cleanupBoard: clearBoard (&b); #ifdef IS_WIN cvReleaseImage (&globMapIplImage); cvReleaseImage (&localMapIplImage); cvCleanup(); #endif }
int main(int argc, char *argv[]) { int i; uint8_t brightnessMsg[] = { 0xa3, 32, 0, 0, 0 }; char buf[192*3] = {0}; for (i = 3; i < sizeof buf; i+= 3) buf[i] = 255; buf[0] = 0xb3; buf[1] = 0; buf[2] = 5; if (argc == 2) brightnessMsg[1] = atoi (argv[1]); if (setupSockets () == -1) { printf ("setupSockets failed\n"); return 1; } for (;;) { int r; for (r = 0; r < 16; ++r) { buf[2] = r; int ret = sendto ( ctrlFd, buf, sizeof buf, 0, (struct sockaddr*)&bcastAddr, sizeof bcastAddr); if(ret == -1) { printf ("send data: ret == -1: %s\n", strerror (errno)); break; } struct timeval tv = { 0, 4000 }; select (0, 0, 0, 0, &tv); } int ret = sendto ( ctrlFd, brightnessMsg, sizeof brightnessMsg, 0, (struct sockaddr*)&bcastAddr, sizeof bcastAddr); if(ret == -1) { printf ("send brightness: ret == -1: %s\n", strerror (errno)); break; } sleep (3); } }