int main(void) { printf("*** Connecting to server...\n"); if (connect_to("server1.example.com", &ch) < 0) { perror("Connection failed"); exit(EXIT_FAILURE); } setup_signals(); printf("*** Connected!\n"); printf(" This is a client connected to an echo server.\n" " Any lines you enter will be echoed back by the server.\n" " To quit, send EOF (usually Ctrl+D).\n\n"); static char buf[512]; while (fgets(buf, sizeof(buf), stdin) != NULL) { size_t line_len = strlen(buf); if (send_info(&ch, buf, line_len) < 0) { perror("Error sending data to server"); continue; } printf("*** Sent: %s", buf); int n; if ((n = recv_info(&ch, buf, sizeof(buf)-1)) < 0) { perror("Error receiving data from server\n"); continue; } buf[n] = '\0'; printf("*** Received: %s", buf); } sprintf(buf, "__QUIT__NOW__\n"); if (send_info(&ch, buf, strlen(buf)) < 0) { perror("Unable to notify server of client disconnect"); } printf("*** Goodbye\n"); disconnect_from(&ch); return 0; }
BOOL castle_integrity(struct t_board *board) { BOOL ok = TRUE; //-- Loop round for each possible type of castle for (int i = 0; i < 4; i++) { struct t_move_record *move = &xmove_list[i]; //-- Is this type of castling relevant in this position? if (castle[i].mask & board->castling) { //-- Is the king in its square? if (PIECETYPE(board->square[castle[i].king_from]) != KING) ok = FALSE; //-- Is the rook on its square? if (PIECETYPE(board->square[castle[i].rook_from]) != ROOK) ok = FALSE; if (move->from_square != castle[i].king_from) ok = FALSE; } } if (!ok) send_info("Castling Messed Up!!"); return ok; }
void GAMECLIENT::on_connected() { layers_init(); col_init(); render_tilemap_generate_skip(); for(int i = 0; i < all.num; i++) { all.components[i]->on_mapload(); all.components[i]->on_reset(); } SERVER_INFO current_server_info; client_serverinfo(¤t_server_info); servermode = SERVERMODE_PURE; // send the inital info send_info(true); freeview = true; spectate_cid = -1; last_game_over = false; last_warmup = false; last_flag_carrier[0] = -1; last_flag_carrier[1] = -1; }
// try to send a message, return false if it won't fit in the serial tx buffer bool GCS_MAVLINK_Sub::try_send_message(enum ap_message id) { // if we don't have at least 250 micros remaining before the main loop // wants to fire then don't send a mavlink message. We want to // prioritise the main flight control loop over communications if (sub.scheduler.time_available_usec() < 250 && sub.motors.armed()) { gcs().set_out_of_time(true); return false; } switch (id) { case MSG_NAMED_FLOAT: send_info(); break; case MSG_SYS_STATUS: // send extended status only once vehicle has been initialised // to avoid unnecessary errors being reported to user if (!vehicle_initialised()) { return true; } CHECK_PAYLOAD_SIZE(SYS_STATUS); sub.send_sys_status(chan); break; case MSG_NAV_CONTROLLER_OUTPUT: CHECK_PAYLOAD_SIZE(NAV_CONTROLLER_OUTPUT); sub.send_nav_controller_output(chan); break; case MSG_RPM: #if RPM_ENABLED == ENABLED CHECK_PAYLOAD_SIZE(RPM); sub.send_rpm(chan); #endif break; case MSG_TERRAIN: #if AP_TERRAIN_AVAILABLE && AC_TERRAIN CHECK_PAYLOAD_SIZE(TERRAIN_REQUEST); sub.terrain.send_request(chan); #endif break; case MSG_PID_TUNING: CHECK_PAYLOAD_SIZE(PID_TUNING); sub.send_pid_tuning(chan); break; default: return GCS_MAVLINK::try_send_message(id); } return true; }
/** * * It receives the handVector and adds them to the trainingData with given class label. * */ void brain::train(vector< double > rightHand, vector< double > leftHand, websocket_server* ws_socket){ BOOST_LOG_TRIVIAL(info) << "RIGHT :" << rightHand[0] <<", " << rightHand[1] <<", " << rightHand[2] ; BOOST_LOG_TRIVIAL(info) << "LEFT : " << leftHand[0] <<", " << leftHand[1] <<", " << leftHand[2] ; vector<double> inputVector(SAMPLE_DIMENSION); inputVector[3] = rightHand[0]; inputVector[4] = rightHand[1]; inputVector[5] = rightHand[2]; inputVector[0] = leftHand[0]; inputVector[1] = leftHand[1]; inputVector[2] = leftHand[2]; if(trainingTimer.getInRecordingMode()){ trainingData.addSample(trainingClassLabel, inputVector); BOOST_LOG_TRIVIAL(debug) << "Training Class Label : " << trainingClassLabel; BOOST_LOG_TRIVIAL(debug) << "Training Time Remaining : " << trainingTimer.getSeconds() << "\n"; std::string message = "Recording : " + std::to_string(trainingTimer.getSeconds()); send_info(message, ws_socket); } else if(trainingTimer.getRecordingStopped()){ BOOST_LOG_TRIVIAL(debug) << "Training Timer Stopped"; saveTrainingDataSetToFile(); trainingModeActive = false; std::string message = "Training of class " + std::to_string(trainingClassLabel) + " stopped"; send_info(message, ws_socket); } else if(trainingTimer.getInPrepMode()){ BOOST_LOG_TRIVIAL(debug) << "Preparation Time Remaining : " << trainingTimer.getSeconds() << "\n"; std::string message = "Preparing : " + std::to_string(trainingTimer.getSeconds()); send_info(message, ws_socket); } else { BOOST_LOG_TRIVIAL(debug) << "Error In Training"; } }
int main() { send_info("aaa","aaa","ok\t"); printf("The status in this function of this module is OK!\n"); send_warning("aaa","aaa","warning\t"); printf("This function of this module sending its warning\n"); send_error("aaa","aaa","error\t"); printf("This function of this module sending its error\n"); return 0; }
void send_current(u8 status) { u8 i; for(i = 0; i < 9; i++) { if(car.current == locate[i]) { car_send[3] = i; break; } car_send[4] = status; send_info(car_send, 5); } }
int main(void) { int clientfd; setup_signals(); printf("*** Creating a server...\n"); if ((serverfd = new_server("server1.example.com")) < 0) { perror("Couldn't create server"); exit(EXIT_FAILURE); } printf("*** Created!\n" " This is an echo server.\n" " Anything received will be echoed back to the client.\n\n"); /* Accept a client */ if ((clientfd = accept_client(serverfd)) < 0) { perror("Couldn't accept client"); destroy_server(serverfd); exit(EXIT_FAILURE); } printf("*** Accepted incoming connection request.\n"); static char buf[512+1]; int n; while ((n = recv_info(clientfd, buf, sizeof(buf)-1)) > 0) { buf[n] = '\0'; if (!strcmp(buf, "__QUIT__NOW__\n")) { printf("*** Got disconnect request from client, leaving...\n"); disconnect_from(clientfd); break; } printf("*** Received: %s", buf); if (send_info(clientfd, buf, n) < 0) { perror("Error sending message to client"); } else { printf("*** Sent: %s", buf); } } printf("*** Goodbye\n"); destroy_server(serverfd); return 0; }
void GAMECLIENT::on_connected() { layers_init(); col_init(); render_tilemap_generate_skip(); for(int i = 0; i < all.num; i++) { all.components[i]->on_mapload(); all.components[i]->on_reset(); } SERVER_INFO current_server_info; client_serverinfo(¤t_server_info); servermode = SERVERMODE_PURE; // send the inital info send_info(true); }
void Outbound::send_error(PacketList &complete_list,Net::PTP::ServerDevice *ptp,ErrorIdType error_id) { Net::PTP::Result result(serv_func,error_id); auto len=SaveLen(result); if( packet.checkDataLen(len) ) { PtrLen<uint8> info=packet.setDataLen(len); BufPutDev dev(info.ptr); dev(result); send_info(complete_list,ptp,info); } else { send_cancel(complete_list,ptp); } }
BOOL test_book() { struct t_move_record *move; uci_set_mode(); uci_isready(); uci_position(position, "position startpos moves"); search_start_time = time_now(); uci.opening_book.book_selectivity = BOOK_TOURNAMENT; for (int i = 0; i < 5; i++) move = probe_book(position); search_start_time = time_now() - search_start_time; char s[1024]; sprintf(s, "Time = %d", search_start_time); send_info(s); return TRUE; }
netplay_t *netplay_new(const char *server, uint16_t port, unsigned frames, const struct retro_callbacks *cb, bool spectate, const char *nick) { unsigned i; if (frames > UDP_FRAME_PACKETS) frames = UDP_FRAME_PACKETS; netplay_t *handle = (netplay_t*)calloc(1, sizeof(*handle)); if (!handle) return NULL; handle->fd = -1; handle->udp_fd = -1; handle->cbs = *cb; handle->port = server ? 0 : 1; handle->spectate = spectate; handle->spectate_client = server != NULL; strlcpy(handle->nick, nick, sizeof(handle->nick)); if (!init_socket(handle, server, port)) { free(handle); return NULL; } if (spectate) { if (server) { if (!get_info_spectate(handle)) goto error; } for (i = 0; i < MAX_SPECTATORS; i++) handle->spectate_fds[i] = -1; } else { if (server) { if (!send_info(handle)) goto error; } else { if (!get_info(handle)) goto error; } handle->buffer_size = frames + 1; init_buffers(handle); handle->has_connection = true; } return handle; error: if (handle->fd >= 0) close(handle->fd); if (handle->udp_fd >= 0) close(handle->udp_fd); free(handle); return NULL; }
void shutdown_handler(int signo) { static char quitmsg[] = "__QUIT__NOW__\n"; send_info(&ch, quitmsg, sizeof(quitmsg)-1); disconnect_from(&ch); exit(0); }
// Main function void main(void) { reset_peripheral(); initClock(); initTimer(); initDisplay(); initPin(); initGPIO(); initADC(); initConsole(); int i = 0; //init_password(); send_data(); initCircBuf (&speed_buffer, BUF_SIZE); init_set_speed_data(&speed_set_data); int screen = 0; int screen_prev = 0; float speed = 0; float buffed_speed = 0; int fake_speed = 0; float acc = 0; float max_acc = 0; //float fuel_eco = 0; float distance = 0; bool fix = 0; uint8_t satillite = 0; float quality = 0; clock time; int aim_pos = 0; unsigned long adc = 0; //int error_stepper = 0; IntMasterEnable(); while(1){ //reading data read_data = split_data(UART_char_data_old, read_data); // decode data speed = read_speed(); //read data into variables adc = run_adc()/7; //calculations aim_pos = speed_feedback(buffed_speed, encoder_1/40, speed_set_data.speed); if (speed_set_data.enable == 1){ step_motor_control(encoder_1/40, aim_pos); } //sending fake data fake_speed = (int)adc;//= random_at_most(100/1.852); send_info(fake_speed);//knots //storing data store_speed(speed); buffed_speed = analysis_speed(); acc = read_acceleration(buffed_speed); max_acc = max_acc_func(acc, max_acc); time = read_time(); satillite = read_satillite(); fix = read_fix(); quality = read_quality(); debounce_button(); // debounce buttons screen = read_button_screen(screen, fix); distance = read_distance(); select_read(); //need a mosfet for turning power off // select adds a an on and off switch yo if (screen == 1){ if(screen_prev != 1 && screen == 1){ speed_set_data.speed = buffed_speed; } speed_set_data.speed = set_speed(speed_set_data.speed); // set the speed to cruise at } if (screen == 2){ //0 to 100 acceleration_test(speed); } // refresh chainging if (fix == 1 && speed_set_data.old == speed_set_data.speed && refresh_rate < 4){ UARTSend((unsigned char *)PMTK_SET_NMEA_UPDATE_5HZ, 18, 0); refresh_rate += 1; } if (i >= 50){ display(screen, buffed_speed, acc, max_acc, speed_set_data.speed, satillite, encoder_1/40, time, distance, quality, UART_char_data_old, aim_pos, adc, acc_times); i = 0; } screen_prev = screen; i++; } }
void xboard2uci_engine_step(char string[]) { int event; board_t board[1]; event = uci_parse(Uci,string); // react to events if ((event & EVENT_READY) != 0) { // the engine is now ready if (!Uci->ready) { Uci->ready = TRUE; // if (XB->proto_ver >= 2) xboard_send(XBoard,"feature done=1"); } if (!DelayPong && XB->ping >= 0) { gui_send(GUI,"pong %d",XB->ping); XB->ping = -1; } } if ((event & EVENT_MOVE) != 0 && State->state == THINK) { // the engine is playing a move // MEGA HACK: estimate remaining time because XBoard won't send it! my_timer_stop(State->timer); XB->my_time -= my_timer_elapsed_real(State->timer); XB->my_time += XB->inc; if (XB->mps != 0 && (game_move_nb(Game) + 1) % XB->mps == 0) XB->my_time += XB->base; if (XB->my_time < 0.0) XB->my_time = 0.0; // make sure to remember the ponder move State->hint_move=Uci->ponder_move; // play the engine move comp_move(Uci->best_move); } if ((event & EVENT_PV) != 0) { // the engine has sent a new PV send_pv(); } if ((event & EVENT_INFO) != 0) { // the engine has sent info send_info(); } if((event & (EVENT_DRAW|EVENT_RESIGN))!=0){ my_log("POYGLOT draw offer/resign from engine\n"); if(option_find(Uci->option,"UCI_DrawOffers")){ if(event & EVENT_DRAW) gui_send(GUI,"offer draw"); else gui_send(GUI,"resign"); } } if(((event & EVENT_ILLEGAL_MOVE)!=0) && (State->state == THINK)){ game_get_board(Game,board); if(board->turn==White){ gui_send(GUI,"0-1 {polyglot: resign" " (illegal engine move by white: %s)}",Uci->bestmove); }else{ gui_send(GUI,"1-0 {polyglot: resign" " (illegal engine move by black: %s)}",Uci->bestmove); } board_disp(board); XB->result = TRUE; mess(); } }
/** * netplay_new: * @server : IP address of server. * @port : Port of server. * @frames : Amount of lag frames. * @cb : Libretro callbacks. * @spectate : If true, enable spectator mode. * @nick : Nickname of user. * * Creates a new netplay handle. A NULL host means we're * hosting (user 1). * * Returns: new netplay handle. **/ netplay_t *netplay_new(const char *server, uint16_t port, unsigned frames, const struct retro_callbacks *cb, bool spectate, const char *nick) { unsigned i; netplay_t *netplay = NULL; if (frames > UDP_FRAME_PACKETS) frames = UDP_FRAME_PACKETS; netplay = (netplay_t*)calloc(1, sizeof(*netplay)); if (!netplay) return NULL; netplay->fd = -1; netplay->udp_fd = -1; netplay->cbs = *cb; netplay->port = server ? 0 : 1; netplay->spectate.enabled = spectate; netplay->spectate.client = server != NULL; strlcpy(netplay->nick, nick, sizeof(netplay->nick)); if (!init_socket(netplay, server, port)) { free(netplay); return NULL; } if (spectate) { if (server) { if (!get_info_spectate(netplay)) goto error; } for (i = 0; i < MAX_SPECTATORS; i++) netplay->spectate.fds[i] = -1; } else { if (server) { if (!send_info(netplay)) goto error; } else { if (!get_info(netplay)) goto error; } netplay->buffer_size = frames + 1; if (!init_buffers(netplay)) goto error; netplay->has_connection = true; } return netplay; error: if (netplay->fd >= 0) socket_close(netplay->fd); if (netplay->udp_fd >= 0) socket_close(netplay->udp_fd); free(netplay); return NULL; }
int send_info_end(char *username) { #ifdef TEST //printf("Send end info %s, %d, %d\n", username, sd.socket, sd.status); #endif return send_info(username, 1); }
// TODO: add player payments for chance/chest int main(int argc, char ** argv) { struct timeval t1, t2; MPI_Init(&argc, &argv); gettimeofday(&t1, NULL); int rank, size; MPI_Comm_rank(MPI_COMM_WORLD, &globalrank); MPI_Comm_size(MPI_COMM_WORLD, &size); globalsize = size; srand(time(NULL) + globalrank); struct location board[BSIZE]; struct player players[NUMPLAYERS]; int itr = 10000; long long bills[4]; // how much you owe each player at end of round init_players(players); init_board(board); char plocation; int pvalue; int numcomms = 1; MPI_Group world_group; MPI_Comm_group(MPI_COMM_WORLD, &world_group); playerdata d; d.money[0] = 0; d.money[1] = 0; d.money[2] = 0; d.money[3] = 0; output = (FILE **) malloc(size * sizeof(FILE *)); // if 1 process created just run sequentially if (size == 1) { int done[4] = {1, 1, 1, 1}; while (itr) { itr--; int i; for (i = 0; i < NUMPLAYERS; i++) { plocation = 0; pvalue = 0; if (players[i].money > 0) { move(players, board, i, &pvalue, &plocation); if (plocation) { board[plocation].owner = i; players[i].money -= pvalue; } } else { players[i].order = -1; if (done[i]) { remove_properties(board, i); done[i] = 0; } } } } gettimeofday(&t2, NULL); results(players, board); double exectime = (t2.tv_sec - t1.tv_sec) * 1000000 + ((t2.tv_usec - t1.tv_usec)); printf("Exec Time %lf\n", exectime); return 0; } // create a communicator for each monopoly game (for n > 4) MPI_Group * gamesel; MPI_Comm * games; int ranksel[4]; if (size > 4) { numcomms = size / 4; games = (MPI_Comm *) malloc(numcomms * sizeof(MPI_Comm)); gamesel = (MPI_Group *) malloc(numcomms * sizeof(MPI_Group)); int i; for (i = 0; i < numcomms; i++) { ranksel[0] = 4 * i; ranksel[1] = 4 * i + 1; ranksel[2] = 4 * i + 2; ranksel[3] = 4 * i + 3; MPI_Group_incl(world_group, 4, ranksel, &gamesel[i]); MPI_Comm_create(MPI_COMM_WORLD, gamesel[i], &games[i]); } } else { // n < 4 so use MPI_COMM_WORLD games = (MPI_Comm *) malloc(1 * sizeof(MPI_Comm)); games[0] = MPI_COMM_WORLD; numcomms = 1; } // create an MPI type so that we can use our player data struct in MPI communication calls const int nitems = 5; int blocklengths[5] = {4, 1, 1, 1, 1}; MPI_Datatype types[5] = {MPI_LONG_LONG, MPI_INT, MPI_CHAR, MPI_CHAR, MPI_CHAR}; MPI_Datatype MPI_MONO_DATA; MPI_Aint offsets[5]; offsets[0] = offsetof(playerdata, money); offsets[1] = offsetof(playerdata, pvalue); offsets[2] = offsetof(playerdata, plocation); offsets[3] = offsetof(playerdata, order); offsets[4] = offsetof(playerdata, trade); MPI_Type_create_struct(nitems, blocklengths, offsets, types, &MPI_MONO_DATA); MPI_Type_commit(&MPI_MONO_DATA); MPI_Comm_rank(games[globalrank / 4], &rank); #ifdef DEBUG char fname[10]; snprintf(fname, 10, "mon%d.dbg", globalrank); output[globalrank] = fopen(fname, "w"); fprintf(output[globalrank], "MAIN begin loop\n"); print_board_info(board); #endif // run the game for 40000 turns (10000 per player) while (itr > 0) { itr--; pvalue = 0; plocation = 0; d.trade = 0; d.order = rank; #ifdef DEBUG fprintf(output[globalrank], "MAIN tag 1 rank %d\n", rank); #endif move(players, board, rank, &pvalue, &plocation); d.pvalue = pvalue; d.plocation = plocation; #ifdef DEBUG fprintf(output[globalrank], "using comm %d\n", globalrank / 4); if (games[globalrank / 4] != MPI_COMM_WORLD) { fprintf(output[globalrank], "COMM ERROR\n"); } #endif send_info(&d, players, board, rank, games[globalrank / 4], MPI_MONO_DATA); #ifdef DEBUG fprintf(output[globalrank], "MAIN tag 3 rank %d\n", rank); print_board_info(board); #endif } #ifdef DEBUG fprintf(output[globalrank], "MAIN last tag rank %d\n", rank); #endif // get results from each process gather_results(players, board, games, numcomms, globalrank); gettimeofday(&t2, NULL); if (globalrank == 0) { results(players, board); } #ifdef DEBUG fclose(output[globalrank]); #endif double exectime = (t2.tv_sec - t1.tv_sec) * 1000000 + ((t2.tv_usec - t1.tv_usec)); if (globalrank == 0) { printf("Exec Time %lf\n", exectime); } MPI_Finalize(); return 0; }