int tc_read_byteswap(TCDevice * device, char *buffer, int size, ATTRIBUTES * attr) { char local_byteorder; int ret = 0; static char swap[65536]; if (!device) { TrickErrorHndlr *temp_error_hndlr = NULL; trick_error_report(temp_error_hndlr, TRICK_ERROR_ALERT, __FILE__, __LINE__, "Trying to read_byteswap to a NULL device"); return (-1); } TRICK_GET_BYTE_ORDER(local_byteorder) if (device->byte_info[TC_BYTE_ORDER_NDX] != local_byteorder) { memset(swap, 0, (size_t) size); ret = tc_read(device, (char *) swap, size); trick_bswap_buffer(buffer, swap, attr, 0); return (ret); } else { return (tc_read(device, (char *) buffer, size)); } return 0; }
int dr_comm_receive( TCDevice* connection, char** file_name, char** msg ) { int size_filename ; int size_msg ; tc_read(connection, (char*) &size_filename, 4); tc_read(connection, (char*) &size_msg, 4); tc_read(connection, *file_name, size_filename); tc_read(connection, *msg, size_msg); return( size_msg ) ; }
void move_ball() { int nbytes ; if ( tc_isValid(&connection) && tc_pending(&connection) ) { nbytes = tc_read(&connection, (char*) &ball_position.x, sizeof(double)); nbytes = tc_read(&connection, (char*) &ball_position.y, sizeof(double)); } glutPostRedisplay(); }
LOCAL void ICACHE_FLASH_ATTR mod_tc_mk2_read(i2c_config *config, char *response, bool poll) { poll = true; tc_config_data *config_data = (tc_config_data *)config->data; char address_str[MAX_I2C_ADDRESS]; json_i2c_address(address_str, config->address); i2c_status status = tc_read(config); if (status == I2C_OK) { char poll_str[WEBSERVER_MAX_VALUE]; if (poll) { json_poll_str(poll_str, tc_refresh / 1000, tc_each, tc_threshold); } else { poll_str[0] = '\0'; } char data_str[WEBSERVER_MAX_VALUE]; json_data( response, MOD_TC_MK2, OK_STR, json_sprintf( data_str, "\"Temperature\" : %s %s", config_data->temperature_str, poll_str ), address_str ); } else { json_error(response, MOD_TC_MK2, i2c_status_str(status), address_str); } }
void comm_read() { int nbytes; double packet[15]; if ( tc_isValid( &connection) && tc_pending( &connection)) { nbytes = tc_read(& connection, (char*)&packet, sizeof(packet)); // Satellite Position // satellite->pos[0] = packet[0]; // satellite->pos[1] = packet[1]; // satellite->pos[2] = packet[2]; satellite->pos[0] = 0.0; satellite->pos[1] = 0.0; satellite->pos[2] = 0.0; planet->pos[0] = -packet[0]; planet->pos[1] = -packet[1]; planet->pos[2] = -packet[2]; // Satellite Velocity satellite->vel[0] = packet[3]; satellite->vel[1] = packet[4]; satellite->vel[2] = packet[5]; // Vehicle Body to World Rotation Matrix satellite->R[0][0] = packet[6]; satellite->R[0][1] = packet[7]; satellite->R[0][2] = packet[8]; satellite->R[1][0] = packet[9]; satellite->R[1][1] = packet[10]; satellite->R[1][2] = packet[11]; satellite->R[2][0] = packet[12]; satellite->R[2][1] = packet[13]; satellite->R[2][2] = packet[14]; // The camera position is relative to the satellite position. satellite_camera->pos[0] = satellite->pos[0] + camera_range * sin(camera_azimuth * (PI/180.0)); satellite_camera->pos[1] = satellite->pos[1] + camera_range * cos(camera_azimuth * (PI/180.0)); satellite_camera->pos[2] = satellite->pos[2] + 0.0; // The camera is looking at the satellite. satellite_camera->tgt[0] = satellite->pos[0]; satellite_camera->tgt[1] = satellite->pos[1]; satellite_camera->tgt[2] = satellite->pos[2]; // Camera up is in the positive World-Z direction; satellite_camera->up[0] = 0.0; satellite_camera->up[1] = 0.0; satellite_camera->up[2] = 1.0; glutPostRedisplay(); } }
int cannon_post_master( CANNON_AERO* C, AMOEBA* A ) { CANNON_AERO C_curr ; // remove warning about unused parameter C (void)C ; /* Read slave's results */ tc_read( mc_get_connection_device(),(char*) &C_curr, sizeof(CANNON_AERO) ); fprintf(stderr, "%03d> F(", mc_get_current_run()); amoeba_print_point(4, A->curr_point) ; fprintf(stderr, "= %.6lf\n", C_curr.pos[0]); /* * Load function result for either: * simplex vertice, centroid, reflection, contraction or expansion point */ A->curr_point[A->num_dims] = C_curr.pos[0] ; return(0) ; }
int Trick::MonteCarlo::read(char* data, int size) { return tc_read(&connection_device, data, size); }
int main( int argc, char *argv[] ) { int ctr; int tc_rc; BUFFER buffer ; char other_tag[256] = "test_tag" ; TrickErrorHndlr err_hndlr; int *me ; int status ; if (argc >= 2) { if (!strcmp(argv[1] , "-h")) { fprintf(stderr,"usage: %s [tag_name]\n",argv[0]); exit(0) ; } else { strcpy(other_tag , argv[1]) ; } } #ifndef __WIN32__ /* Register the interupt signal handler. */ { struct sigaction sigact; /* sigaction() sys call parm */ memset ( &sigact , 0 , sizeof(struct sigaction)) ; sigact.sa_flags = 0; sigact.sa_handler = (void(*)())sigint_hndlr; if ( sigaction( SIGINT, &sigact, NULL ) < 0 ) perror("sigaction() failed for SIGINT"); #if (__sun) sigact.sa_handler = (void(*)())stupid; if ( sigaction( SIGALRM, &sigact, NULL ) < 0 ) perror("sigaction() failed for SIGALRM"); #endif } #endif memset((void *)&err_hndlr,'\0',sizeof(TrickErrorHndlr)); trick_error_init(&err_hndlr, (TrickErrorFuncPtr)NULL, (TrickErrorDataPtr)NULL, TRICK_ERROR_TRIVIAL); /* It is possible for multiple multiconnects to try and initiate simultaneously causing some of the connects to fail. This happens if all of the clients have the same tag and are connecting to the same server. This is the V.R. scenario. Continue trying to connect until successful. */ do { device = malloc(sizeof(TCDevice)) ; memset((void *)device,'\0',sizeof(TCDevice)); status = tc_multiconnect(device , "client" , other_tag , &err_hndlr); if (status != TC_SUCCESS) { fprintf(stderr,"Error from tc_multiconnect... trying again\n"); } } while (status != TC_SUCCESS) ; ctr = 1; me = ((int *)&buffer.f1 +1) ; while( 1 ) { while ( (tc_isValid(device)) && (!tc_pending(device)) ) #if __WIN32__ Sleep(1); #else usleep(1000); #endif if (tc_isValid(device)) { tc_rc = tc_read(device,(char *)&buffer,sizeof(buffer)); if (tc_rc != 0) { fprintf(stderr,"client: read msg %d from server:\n",ctr++); fprintf(stderr," i1 = %08x, s1 = %d, c1 = %d, f1 = %f, d1 = %f\n", buffer.i1, buffer.s1, buffer.c1, buffer.f1, buffer.d1 ) ; fprintf(stderr," b1 = %d , b2 = %d, b3 = %d, b4 = %d, b5 = %d\n", buffer.b1, buffer.b2, buffer.b3, buffer.b4, buffer.b5 ) ; fprintf(stderr," me = %08x\n", *me ) ; #if __WIN32__ Sleep(500) ; #else usleep(500000); #endif } } else { fprintf(stderr,"Server side disconnected... exiting\n"); tc_disconnect(device); break ; } } } /* end main */
int main( int narg, char** args ) { TCDevice listen_device ; TCDevice connection ; int verbose ; int nbytes ; int num_packets ; char *msg ; int msg_len ; int i ; #if __WIN32__ FILETIME start, stop; LARGE_INTEGER temp_start, temp_stop, total ; #else struct timeval tp ; double time1, time2; #endif double sum_time ; #if __WIN32__ memset(&total,0,sizeof(LARGE_INTEGER)); #endif /* Parse args */ verbose = 0 ; if ( narg < 3 || narg > 4 ) { fprintf(stderr, "USAGE: tc_server <num_packets> <packet_size> [-v]\n"); exit(-1); } if ( narg == 4 ) { verbose = 1 ; } num_packets = atoi(args[1]) ; msg_len = atoi(args[2]) ; if ( msg_len < 1 || num_packets < 1 ) { fprintf(stderr, "USAGE: tc_server <num_packets> <packet_size> [-v]\n"); } /* Create message */ msg = (char*) malloc ( msg_len * sizeof(char)) ; for ( i = 0 ; i < msg_len ; i++ ) { msg[i] = '#' ; } /* Zero out devices */ memset(&listen_device, '\0', sizeof(TCDevice)); memset(&connection, '\0', sizeof(TCDevice)); /* Get an error handler */ if ( verbose ) { tc_error(&connection, 1) ; tc_error(&listen_device, 1) ; } /* Accept connection */ listen_device.port = 7000 ; tc_init(&listen_device) ; tc_accept(&listen_device, &connection); sum_time = 0 ; for ( i = 0 ; i < num_packets ; i++ ) { /* Get initial time */ #if __WIN32__ GetSystemTimeAsFileTime(&start); #else gettimeofday( &tp , (struct timezone *)NULL ) ; time1 = (double)(tp.tv_sec) + ( (double)(tp.tv_usec) / 1000000.0 ) ; #endif nbytes = tc_read(&connection, msg, msg_len) ; nbytes = tc_write(&connection, msg, msg_len) ; /* Get final time */ #if __WIN32__ GetSystemTimeAsFileTime(&stop); temp_start.LowPart = start.dwLowDateTime ; temp_start.HighPart = start.dwHighDateTime ; temp_stop.LowPart = stop.dwLowDateTime ; temp_stop.HighPart = stop.dwHighDateTime ; total.QuadPart = total.QuadPart + temp_stop.QuadPart - temp_start.QuadPart ; #else gettimeofday( &tp , (struct timezone *)NULL ) ; time2 = (double)(tp.tv_sec) + ((double)(tp.tv_usec) / 1000000.0 ) ; time2 = (double)(tp.tv_sec) + ((double)(tp.tv_usec) / 1000000.0 ) ; sum_time = sum_time + ( time2 - time1 ) ; #endif } #if __WIN32__ sum_time = (double)(total.QuadPart * 0.0000001 ) ; #endif fprintf(stderr, "Avg packet round trip : %lf \n", sum_time/(double)num_packets ); return 0 ; }