int main(int argc, const char* argv[]) { struct sockaddr_in addr; int bytes_read; struct tm sTime; tioInit("v0.1", "Сервер UDP", tp, argc, argv ); resSocket = socket(AF_INET, SOCK_DGRAM, 0); if(resSocket < 0) { perror("socket"); exit(1); } addr.sin_family = AF_INET; addr.sin_port = htons(tioGetDefL("PORT", 36000)); addr.sin_addr.s_addr = htonl(INADDR_ANY); if(bind(resSocket, (struct sockaddr *)&addr, sizeof(addr)) < 0) { perror("bind"); exit(2); } signal(SIGINT, sighandle); while(1) { bytes_read = recv(resSocket, &sTime, sizeof(sTime), 0); if(bytes_read <= 0) break; printf("%s", asctime(&sTime)); } return 0; }
int main( int argc, const char* argv[] ) { SRoots *Roots = malloc( sizeof(SRoots) ); //SRoots *RootsEtalon = malloc( sizeof(SRoots) ); //int myargc = 6; //const char* myargv[] = { //argv[0], //"-a", //"1", //"-b", //"2", //"-c", //"-3" //}; tio_param mypar [] = { {"a:", "A", "Параметр А"}, {"b:", "B", "Параметр B"}, {"c:", "C","Параметр C"}, {"root1:", "ROOT1", "Первый корень"}, {"root2:", "ROOT2", "Второй корень"}, {NULL, NULL, NULL} }; //puts( "Тест написал: Гусев Михаил" ); //puts( "Короткое описание теста:\nТестирование функции решения квадратного уровнения." ); tioInit( "v0.9 alpha", "This is test", mypar, argc, argv ); quad( tioGetL( "A" ),tioGetL( "B" ),tioGetL( "C" ), Roots ); void *td = tioTableBegin( "Имя параметра&Значение", TIOSTRING, TIOLONG ); tioTableRecord( td, "Аргумент A", tioGetL( "A" ) ); tioTableRecord( td, "Аргумент B", tioGetL( "B" ) ); tioTableRecord( td, "Аргумент C", tioGetL( "C" ) ); /*tioTableRecord( td, "The equation root 1", Roots->root1 );*/ /*tioTableRecord( td, "The equation root 2", Roots->root2 );*/ tioTableEnd( td ); puts( "Сравнение эталонных и возвращаемых функцией корней" ); td = tioTableBegin( "Эталонные корни&Корни, посчинанные функцией", TIOLONG, TIOLONG ); tioTableRecord( td, tioGetL( "ROOT1" ), Roots->root1 ); tioTableRecord( td, tioGetL( "ROOT2" ), Roots->root2 ); tioTableEnd( td ); free(Roots); tioFinish( 0 ); return 0; }
void trainTaskInit(void) { clockInitTask(); mioInit(); tioInit(); logInit(); Create(31, idlerTask); Delay(50); vtInit(); turnoutInit(); sensorInit(); parserInit(); clockDrawerInit(); controllerInit(); freightInit(); initTrackA(nodes, hashtbl); }
int main(int argc, const char* argv[] ) { int sock; struct sockaddr_in addr; tioInit("v0.1", "Клиент UDP", tp, argc, argv ); sock = socket(AF_INET, SOCK_DGRAM, 0); if(sock < 0) { perror("socket"); exit(1); } addr.sin_family = AF_INET; addr.sin_port = htons(tioGetDefL("PORT", 36000)); char buff[20]; tioGetDefS("IP","127.0.0.1", buff, 20); inet_aton(buff, &(addr.sin_addr)); if(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { perror("connect"); exit(2); } time(&rawTime); sTime = localtime(&rawTime); send(sock, sTime, sizeof(*sTime), 0); close(sock); tioFinish(0); return 0; }
int main(int argc, const char* argv[]) { pid_t server_child = 0; int fd; int res = 0, status; struct sigaction sigchildAction; tio_param sParam [] = { {"D:", "DURATION", "Duration"}, { "m:", "PORTSPEED", "Prot speed"}, { "s:", "SENDPACKSLENGTH", "Send pack length"}, { "d", "SERVERMODE", "Server mode" }, { "l", "CLIENTMODE", "Client mode" }, { "L", "CLIENTSERVERMODE", "Client/Server mode" }, {NULL, NULL, NULL} }; sigchildAction.sa_handler = termination_signal; sigchildAction.sa_flags = SA_NOCLDSTOP; sigemptyset(&(sigchildAction.sa_mask)); sigaddset(&(sigchildAction.sa_mask),SIGTERM); if (sigaction(SIGTERM, &sigchildAction, NULL)) { perror("Signal SIGTERM registration failed"); return -1; } if (sigaction(SIGINT, &sigchildAction, NULL)) { perror("Signal SIGINT registration failed"); return -1; } // Инициализация tio и разбор входных параметров командной строки tioInit( "alpha", "RS232 test", sParam, argc, argv); if (write_configuration(&config)) { fputs("Congiguration read error\n", stderr); return -1; } fd = open_serial_port( tio_argv[0], tioGetDefL( "PORTSPEED", 115200 )); if (fd < 0) { return -1; } config.outputDevice = fd; if ( tioGetL( "CLIENTSERVERMODE" ) > 0 ) { server_child = fork(); } if ((server_child == 0) && (tioGetL( "CLIENTSERVERMODE" ) || tioGetL( "SERVERMODE" ) ) ) { if (server_process(&config)) { return -1; } } else if ( tioGetL( "CLIENTSERVERMODE" ) || tioGetL( "CLIENTMODE" )) res = client_process(&config); else { DEBUGMSG("Undefined target action"); return -1; } if (server_child != 0) waitpid(server_child, &status, WNOHANG); // Завершение работы библиотеки tio tioFinish(0); return (int)(res || status); /*return 0;*/ }