/**************************************************************************** NAME sinkEnableMultipointConnectable DESCRIPTION when in multi point mode check to see if device can be made connectable, this will be when only one AG is currently connected. this function will be called upon certain button presses which will reset the 60 second timer and allow a second AG to connect should the device have become non discoverable RETURNS none */ void sinkEnableMultipointConnectable( void ) { /* only applicable to multipoint devices and don't go connectable when taking or making an active call, allow connectable in streaming music state */ if((theSink.MultipointEnable)&&(stateManagerGetState() != deviceLimbo)) { /* if only one hfp instance is connected then set connectable to active */ if(deviceManagerNumConnectedDevs() < 2) { MAIN_DEBUG(("MP Go Conn \n" )); /* make device connectable */ sinkEnableConnectable(); /* cancel any currently running timers that would disable connectable mode */ MessageCancelAll( &theSink.task, EventSysConnectableTimeout ); /* remain connectable for a further 'x' seconds to allow a second AG to be connected if non-zero, otherwise stay connecatable forever */ if(theSink.conf1->timeouts.ConnectableTimeout_s) { MessageSendLater(&theSink.task, EventSysConnectableTimeout, 0, D_SEC(theSink.conf1->timeouts.ConnectableTimeout_s)); } } /* otherwise do nothing */ } }
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done. void user_init(void) { wifi_station_set_auto_connect(FALSE); stdoutInit(); CFG_Load(); ioInit(); MAIN_DEBUG("\nInitialise ENC stack, dhcp if requested\n"); stack_init(); /* This DNS is only for the wifi interface, as wired never acts as an 'AP' */ captdnsInit(); // 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position // where image is written in flash that is defined in Makefile. #ifdef ESPFS_POS espFsInit((void*)(0x40200000 + ESPFS_POS)); #else espFsInit((void*)(webpages_espfs_start)); #endif httpdInit(builtInUrls, 80); #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); os_timer_arm(&prHeapTimer, 3000, 1); #endif os_timer_disarm(&websockTimer); os_timer_setfn(&websockTimer, websockTimerCb, NULL); os_timer_arm(&websockTimer, 1000, 1); os_printf("\nReady\n"); }
/**************************************************************************** NAME sinkEnableDiscoverable DESCRIPTION Make the device discoverable. RETURNS void */ void sinkEnableDiscoverable( void ) { const uint32 giac = 0x9E8B33; const uint32 liac = 0x9E8B00; hci_scan_enable scan = hci_scan_enable_off; MAIN_DEBUG(("MP Enable Discoverable %cp\n", theSink.page_scan_enabled ? '+' : '-')); /* Set inquiry access code to respond to */ if ((theSink.inquiry.session == inquiry_session_normal) || (!theSink.features.PeerUseLiac)) { ConnectionWriteInquiryAccessCode(&theSink.task, &giac, 1); } else { ConnectionWriteInquiryAccessCode(&theSink.task, &liac, 1); } /* Set the inquiry scan params */ ConnectionWriteInquiryscanActivity(theSink.conf2->radio.inquiry_scan_interval, theSink.conf2->radio.inquiry_scan_window); /* Make sure that if we're page scanning we don't disable it */ if (theSink.page_scan_enabled) scan = hci_scan_enable_inq_and_page; else scan = hci_scan_enable_inq; /* Enable scan mode */ ConnectionWriteScanEnable(scan); /* Set the flag to indicate we're page scanning */ theSink.inquiry_scan_enabled = TRUE; }
/**************************************************************************** NAME sinkDisableDiscoverable DESCRIPTION Make the device non-discoverable. RETURNS void */ void sinkDisableDiscoverable( void ) { hci_scan_enable scan; MAIN_DEBUG(("MP Disable Discoverable %cp\n", theSink.page_scan_enabled ? '+' : '-')); /* Make sure that if we're page scanning we don't disable it */ if (theSink.page_scan_enabled) scan = hci_scan_enable_page; else scan = hci_scan_enable_off; /* Enable scan mode */ ConnectionWriteScanEnable(scan); /* Set the flag to indicate we're page scanning */ theSink.inquiry_scan_enabled = FALSE; }
/**************************************************************************** NAME sinkDisableConnectable DESCRIPTION Take device out of connectable mode. RETURNS void */ void sinkDisableConnectable( void ) { hci_scan_enable scan; MAIN_DEBUG(("MP Disable Connectable %ci\n", theSink.inquiry_scan_enabled ? '+' : '-')); /* Make sure that if we're inquiry scanning we don't disable it */ if (theSink.inquiry_scan_enabled) scan = hci_scan_enable_inq; else scan = hci_scan_enable_off; /* Enable scan mode */ ConnectionWriteScanEnable(scan); if (theSink.page_scan_enabled) { /* Clear the flag to indicate we're not page scanning */ theSink.page_scan_enabled = FALSE; } }
/**************************************************************************** NAME sinkEnableConnectable DESCRIPTION Make the device connectable RETURNS void */ void sinkEnableConnectable( void ) { hci_scan_enable scan = hci_scan_enable_off; MAIN_DEBUG(("MP Enable Connectable %ci\n", theSink.inquiry_scan_enabled ? '+' : '-')); /* Set the page scan params */ ConnectionWritePagescanActivity(theSink.conf2->radio.page_scan_interval, theSink.conf2->radio.page_scan_window); /* Make sure that if we're inquiry scanning we don't disable it */ if (theSink.inquiry_scan_enabled) scan = hci_scan_enable_inq_and_page; else scan = hci_scan_enable_page; /* Enable scan mode */ ConnectionWriteScanEnable(scan); /* Set the flag to indicate we're page scanning */ theSink.page_scan_enabled = TRUE; }
void main_loop( void ) { int listenfd,fd, nready; struct sockaddr client; ssize_t client_len; fd_set read_set; struct timeval timeout, timeofday_old, timeofday_new; struct timezone tz; listenfd = net_listen(NULL,g_server.port); if( listenfd < 0 ) return; max_fd=listenfd; FD_ZERO(&all_set); FD_SET(listenfd,&all_set); if( g_server.with_console ) { FD_SET(CONSOLE_FD, &all_set); } #define TIMEOUT_SEC (180) /* 3 minutes */ /* 5 minutes */ timeout.tv_sec = TIMEOUT_SEC; timeout.tv_usec = 0; gettimeofday( &timeofday_old, &tz ); memset( &tz, 0, sizeof(tz) ); while(1) { read_set = all_set; nready = select( max_fd+1, &read_set, NULL, NULL, &timeout ); /* recompute the timeout */ if( gettimeofday( &timeofday_new, &tz ) == 0 ) { int s = timeofday_new.tv_sec - timeofday_old.tv_sec; if( TIMEOUT_SEC > s ) timeout.tv_sec = TIMEOUT_SEC - s; else timeout.tv_sec = TIMEOUT_SEC; /* it is aprox 3 minutes */ if( s == 0 ) timeout.tv_usec = timeofday_new.tv_usec - timeofday_old.tv_usec; else timeout.tv_usec = 0; /* may occur sometimes */ if( s > TIMEOUT_SEC ) { timeout.tv_sec = TIMEOUT_SEC; timeout.tv_usec = 0; gettimeofday( &timeofday_old, &tz ); server_is_idle(); } } /* error ?*/ if( nready == -1 ) { if(errno!=EINTR) { fprintf(stderr,_("tegserver: Abnormal error in select()\n")); perror("tegserver:"); } continue; /* timeout ? */ } else if( nready == 0 ) { MAIN_DEBUG("timeout\n"); timeout.tv_sec = TIMEOUT_SEC; timeout.tv_usec = 0; gettimeofday( &timeofday_old, &tz ); server_is_idle(); continue; } /* new client */ if(FD_ISSET( listenfd, &read_set) ) { MAIN_DEBUG("new client\n"); client_len = sizeof( client ); fd = accept( listenfd, (struct sockaddr *)&client, &client_len ); if( fd != -1 ) fd_add( fd ); if(--nready <= 0) continue; } /* input from console */ if( g_server.with_console && FD_ISSET(CONSOLE_FD, &read_set)) { TEG_STATUS ts = console_handle(CONSOLE_FD); if(ts==TEG_STATUS_GAMEOVER || ts==TEG_STATUS_CONNCLOSED) server_exit(listenfd); if(--nready <= 0) continue; } /* input from players */ for(fd=0;fd<=max_fd;fd++) { if( (fd!=listenfd && fd!=CONSOLE_FD) && FD_ISSET(fd,&read_set) ) { if(play_teg( fd )==TEG_STATUS_CONNCLOSED) { MAIN_DEBUG("closing connection\n"); /* kick robots if they are alone */ player_kick_unparent_robots(); } if(--nready <= 0) break; } } } }