int main(void){ //initialize Accelerometer and Gyroscope initAccGyro(); //initialize the Timer Interrupt initTIM(); //initialize SPI & RF init_timer(); init_protocol(); init_spi(); // slave_acknowledge_send(); //master_move_wait(); go_wait(); //master_sync_send(); //master_result_send(RF_CMD_PAPER); // while(1) move_m = get_move(); //rf_wait_command(); /* while(1){ if(newData){ update_Orientation(); if (updateGesture(accelX, accelY, accelZ, roll_fuse, &move) == SUCCESS); //write_byte (0x2C, 0x56); //readout = read_byte (0x2C); //rf_send_byte(0x17); newData = 0; } } */ }
int main(int argc, char *argv[]) { if (argc!=2) { fprintf(stderr,"usage: multi_ftp_server <server_local_path>\n"); exit(-1); } signal(SIGINT, sig_handler); getcwd(old_cwd,sizeof(old_cwd)); if (chdir(argv[1])==-1) { log_err("Bad Directory:"); exit(-1); } fd_set read_fds,write_fds; // temp file descriptor list for select() int listener; // listening socket descriptor FD_ZERO(&master); // clear the master and temp sets FD_ZERO(&w_master); FD_ZERO(&read_fds); FD_ZERO(&write_fds); init_protocol(); // get us a socket and bind it listener = do_bind(PORT); FD_SET(listener, &master); fdmax = listener + 1; for(;;) { read_fds = master; // copy it write_fds = w_master; if (select(fdmax+1, &read_fds, &write_fds, NULL, NULL) == -1) { perror("select"); exit(4); } // run through the existing connections looking for data to read int fdmax_nochange = fdmax; for(int i = 0; i <= fdmax_nochange; i++) { //debug("fdmax is %d",fdmax_nochange); if (FD_ISSET(i, &read_fds)) { if (i == listener) { fdmax = handle_new_client(listener) ; } else { fdmax = handle_recv_from_client(i); // handle data from a client } } if (FD_ISSET(i,&write_fds)) { fdmax = handle_send_to_client(i); } }//end run thrugh read fd_set } }
int main(void) { uint8_t i; init_protocol(); init_rotary0(); init_led(); init_adc(); step3=0; sei(); txbuffer[0]=3;//index txbuffer[1]=130; txbuffer[2]=0xff; i=nout; while(1) { while(i==nout); i=nout; send(0x42); } }
void loop() { uint32_t timeout; // reset / rebind //Serial.println("begin loop"); if(reset || ppm[AUX8] > PPM_MAX_COMMAND) { reset = false; Serial.println("selecting protocol"); selectProtocol(); Serial.println("selected protocol."); NRF24L01_Reset(); Serial.println("nrf24l01 reset."); NRF24L01_Initialize(); Serial.println("nrf24l01 init."); init_protocol(); Serial.println("init protocol."); } // process protocol //Serial.println("processing protocol."); switch(current_protocol) { case PROTO_CG023: case PROTO_YD829: timeout = process_CG023(); break; case PROTO_V2X2: timeout = process_V2x2(); break; case PROTO_CX10_GREEN: case PROTO_CX10_BLUE: timeout = process_CX10(); // returns micros()+6000 for time to next packet. break; case PROTO_H7: timeout = process_H7(); break; case PROTO_BAYANG: timeout = process_Bayang(); break; case PROTO_SYMAX5C1: timeout = process_SymaX(); break; case PROTO_H8_3D: timeout = process_H8_3D(); break; } // updates ppm values out of ISR //update_ppm(); overrun_cnt=0; if (stringComplete) { //Serial.println(inputString); // process string p = strtok_r(record,",",&i); while (p !=0){ Serial.print(p); Serial.print("c"); p = strtok_r(NULL,",",&i); } Serial.println("X"); //ppm[0]= // clear the string: inputString = ""; stringComplete = false; } while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); // if the incoming character is a newline, set a flag // so the main loop can do something about it: if (inChar == '\n') { stringComplete = true; } else { // add it to the inputString: inputString += inChar; } } // wait before sending next packet while(micros() < timeout) // timeout for CX-10 blue = 6000microseconds. { overrun_cnt+=1; }; if ((overrun_cnt<1000)||(stringComplete)) { Serial.println(overrun_cnt); } }
/* == FUNCTION init_simulator ================================================= * Sets up input and output FIFOs and waits for port width information from * the simulator. * * Reading on file descriptors (or sockets) is blocking, but we can still * quit Simulink as long as we're blocked in here (i.e. not in a foreign * call). * * TODO: Fix the string command allocations which are arbitrarily declared to * a length of 256. */ void init_simulator(SimStruct *S) { if (!sim_running) { //-- Open FIFOs ---------------------------------------------------------// bool arsim_driver = (getenv("ARSIM_DRIVER") != NULL); if(!arsim_driver) { if (mkfifo(hs_input_fifo, 0666) < 0) { ssSetErrorStatus(S, "Error creating Haskell input FIFO."); return; } if (mkfifo(hs_output_fifo, 0666) < 0) { ssSetErrorStatus(S, "Error creating Haskell output FIFO."); return; } //-- Get simulator path and attempt system call -------------------------// size_t buflen = mxGetN(ssGetSFcnParam(S, 0)) * sizeof(mxChar) + 1; path = malloc(buflen); if (mxGetString(ssGetSFcnParam(S, 0), path, buflen)) { ssSetErrorStatus(S, "Error getting path string parameter."); return; } /* Check that path exists, and that it points to something * that is an executable regular file (i.e. not a directory). */ struct stat sb; bool is_exec = stat(path, &sb) == 0 && sb.st_mode & S_IXUSR && S_ISREG(sb.st_mode); if (!is_exec) { ssSetErrorStatus(S, "Path does not point to a valid executable file."); return; } char *name = basename(path); if (name == NULL) { ssSetErrorStatus(S, "Call to basename() failed."); return; } char *const argv[] = {name, hs_input_fifo, hs_output_fifo, NULL}; pid_t child = fork(); if (child < 0) { ssSetErrorStatus(S, "Call to fork() failed."); return; } if (child > 0) { init_protocol(S); } if (child == 0) execv(path, argv); } else { init_protocol(S); } } return; }
/*************************************************************************** Declaration : int main(void) Function : Main Loop ***************************************************************************/ int main(void) { init_mcu(); init_rf(); init_buffer(); init_protocol(); init_freq(); #ifdef TEST_TX_CW test_rf_transmitter(78); #endif #ifdef TEST_TX_MOD test_rf_modulator(81); #endif #ifdef TEST_RX test_rf_receiver(78); #endif /* Main Background loop */ call_state = CALL_IDLE; while(1) { /* Call States */ switch (call_state) { case CALL_IDLE: #ifdef DONGLE sleep(WDT_TIMEOUT_60MS,STANDBY_MODE); call_status = CALL_NO_ACTIVITY; #ifdef USB SET_VOLUME_DOWN; SET_VOLUME_UP; SET_MUTE_PLAY; SET_MUTE_REC; if(CALL_ACTIVITY_PIN) call_status = CALL_ACTIVITY; #else if(!CALL_SETUP_KEY) call_status = CALL_ACTIVITY; #endif if(call_status == CALL_ACTIVITY) call_state = CALL_SETUP; #endif #ifdef HEADSET sleep(WDT_TIMEOUT_1S,POWER_DOWN_MODE); call_state = CALL_SETUP; #endif break; case CALL_SETUP: #ifdef DONGLE LED_ON; call_status = call_setup(&setup_freq[0],N_FREQ_SETUP); LED_OFF; if(call_status != CALL_SETUP_FAILURE) { init_buffer(); init_rf(); init_protocol(); init_codec(); start_codec(); #ifdef USB // Enable watchdog to handle USB Suspend Mode wdt_enable(WDT_TIMEOUT_15MS); #else start_timer1(0,FRAME_PERIOD, DIV1); #endif call_state = CALL_CONNECTED; } else call_state = CALL_IDLE; #endif #ifdef HEADSET LED_ON; call_status = call_detect(&setup_freq[0],N_FREQ_SETUP,N_REP_SETUP); LED_OFF; if(call_status != CALL_SETUP_FAILURE) { init_buffer(); init_rf(); init_protocol(); init_codec(); call_status &= ~MASTER_SYNC; start_timer1(0,FRAME_PERIOD, DIV1); call_state = CALL_CONNECTED; } else call_state = CALL_IDLE; #endif break; case CALL_CONNECTED: #ifdef DONGLE while(1) { // USB Dongle clears watchdog handling USB Suspend Mode #ifdef USB wdt_reset(); #endif // Send and receive audio packet audio_transfer(); // Handle key code from HEADSET key_code = (signal_in[1] & 0x1F); if(key_code != 0) LED_ON; else LED_OFF; #ifdef USB if(key_code & VOLUME_DOWN) CLEAR_VOLUME_DOWN; else SET_VOLUME_DOWN; if(key_code & VOLUME_UP) CLEAR_VOLUME_UP; else SET_VOLUME_UP; if(key_code & MUTE_PLAY) CLEAR_MUTE_PLAY; else SET_MUTE_PLAY; if(key_code & MUTE_REC) CLEAR_MUTE_REC; else SET_MUTE_REC; #endif // Check if call is to be cleared #ifdef USB if(!CALL_ACTIVITY_PIN) { call_activity_timer += 1; if(call_activity_timer >= TIMEOUT_CALL_ACTIVITY) call_status = CALL_CLEAR; } else call_activity_timer = 0; #else if(!CALL_CLEAR_KEY) call_status = CALL_CLEAR; #endif // Call clearing by HEADSET or DONGLE if((key_code == CALL_CLEARING) || (call_status == CALL_CLEAR)) { signal_out[0] |= SIGNAL_CALL_CLEAR; call_timer += 1; if(call_timer >= TIMEOUT_CALL_CLEAR_MASTER) { call_state = CALL_IDLE; stop_codec(); init_buffer(); init_rf(); init_protocol(); init_codec(); eeprom_write(freq[0],EEPROM_ADR_FREQ0); eeprom_write(freq[1],EEPROM_ADR_FREQ1); LED_OFF; #ifdef USB // Disable watchdog used to handle USB Suspend Mode wdt_disable(); #endif break; } } else signal_out[0] &= ~SIGNAL_CALL_CLEAR; // Call clearing due to Frame Loss if(frame_loss >= TIMEOUT_FRAME_LOSS) { #ifdef USB call_state = CALL_RECONNECT; init_rf(); init_protocol(); // Disable watchdog used to handle USB Suspend Mode wdt_disable(); #else call_state = CALL_RECONNECT; stop_codec(); init_buffer(); init_rf(); init_protocol(); init_codec(); #endif break; } } #endif #ifdef HEADSET while(1) { if(call_status & MASTER_SYNC) { audio_transfer(); } else { call_status = get_sync(); if(call_status & MASTER_SYNC) start_codec(); else frame_loss += 10; } // Read and handle keys key_code = read_key(); signal_out[1] &= 0xE0; signal_out[1] |= key_code; // Call cleared by DONGLE if(signal_in[0] & SIGNAL_CALL_CLEAR) { call_timer += 1; if(call_timer >= TIMEOUT_CALL_CLEAR_SLAVE) { call_state = CALL_IDLE; stop_codec(); init_buffer(); init_rf(); init_protocol(); init_codec(); break; } } else call_timer = 0; // Call clearing due to Frame Loss if(frame_loss >= TIMEOUT_FRAME_LOSS) { call_state = CALL_RECONNECT; stop_codec(); init_buffer(); init_rf(); init_protocol(); init_codec(); break; } } #endif break; case CALL_RECONNECT: #ifdef DONGLE LED_ON; call_status = call_setup(&setup_freq[0],N_FREQ_SETUP); LED_OFF; if(call_status != CALL_SETUP_FAILURE) { #ifdef USB init_rf(); init_protocol(); reset_codec(); call_state = CALL_CONNECTED; #else init_buffer(); init_rf(); init_protocol(); init_codec(); start_codec(); start_timer1(0,FRAME_PERIOD, DIV1); call_state = CALL_CONNECTED; #endif } else { stop_codec(); init_buffer(); init_rf(); init_protocol(); init_codec(); call_state = CALL_IDLE; } #endif #ifdef HEADSET LED_ON; call_status = call_detect(&setup_freq[0],N_FREQ_SETUP,N_REP_RECONNECT); LED_OFF; if(call_status != CALL_SETUP_FAILURE) { init_buffer(); init_rf(); init_protocol(); init_codec(); call_status &= ~MASTER_SYNC; start_timer1(0,FRAME_PERIOD, DIV1); call_state = CALL_CONNECTED; } else call_state = CALL_IDLE; #endif break; default: break; } } }
int main(int argc, char** argv) { status_t status = init_timers(); if (status < B_OK) { fprintf(stderr, "tcp_tester: Could not initialize timers: %s\n", strerror(status)); return 1; } _add_builtin_module((module_info*)&gNetStackModule); _add_builtin_module((module_info*)&gNetBufferModule); _add_builtin_module((module_info*)&gNetSocketModule); _add_builtin_module((module_info*)&gNetDatalinkModule); _add_builtin_module(modules[0]); if (_get_builtin_dependencies() < B_OK) { fprintf(stderr, "tcp_tester: Could not initialize modules: %s\n", strerror(status)); return 1; } sockaddr_in interfaceAddress; interfaceAddress.sin_len = sizeof(sockaddr_in); interfaceAddress.sin_family = AF_INET; interfaceAddress.sin_addr.s_addr = htonl(0xc0a80001); gInterface.address = (sockaddr*)&interfaceAddress; gInterface.domain = &sDomain; status = get_module("network/protocols/tcp/v1", (module_info **)&gTCPModule); if (status < B_OK) { fprintf(stderr, "tcp_tester: Could not open TCP module: %s\n", strerror(status)); return 1; } net_protocol* client = init_protocol(&gClientSocket); if (client == NULL) return 1; net_protocol* server = init_protocol(&gServerSocket); if (server == NULL) return 1; setup_context(sClientContext, false); setup_context(sServerContext, true); printf("*** Server: %p (%ld), Client: %p (%ld)\n", server, sServerContext.thread, client, sClientContext.thread); setup_server(); while (true) { printf("> "); fflush(stdout); char line[1024]; if (fgets(line, sizeof(line), stdin) == NULL) break; argc = 0; argv = build_argv(line, &argc); if (argv == NULL || argc == 0) continue; int length = strlen(argv[0]); #if 0 char *newLine = strchr(line, '\n'); if (newLine != NULL) newLine[0] = '\0'; #endif if (!strcmp(argv[0], "quit") || !strcmp(argv[0], "exit") || !strcmp(argv[0], "q")) break; bool found = false; for (cmd_entry* command = sBuiltinCommands; command->name != NULL; command++) { if (!strncmp(command->name, argv[0], length)) { command->func(argc, argv); found = true; break; } } if (!found) fprintf(stderr, "Unknown command \"%s\". Type \"help\" for a list of commands.\n", argv[0]); free(argv); } close_protocol(client); close_protocol(server); snooze(2000000); cleanup_context(sClientContext); cleanup_context(sServerContext); put_module("network/protocols/tcp/v1"); uninit_timers(); return 0; }