int main(int argc, char **argv) { // eal args int num_args = rte_eal_init(argc, argv); if (num_args < 0) rte_exit(EXIT_FAILURE, "init failed"); argc -= num_args; argv += num_args; // our args: [-s] port1 port2 uint8_t port1, port2; char opt = getopt(argc, argv, "s"); bool simple_tx = opt == 's'; if (simple_tx) { printf("Requesting simple tx path\n"); argc--; argv++; } else { printf("Requesting full-featured tx path\n"); } if (argc != 3) { printf("usage: [-s] port1 port2\n"); return -1; } port1 = atoi(argv[1]); port2 = atoi(argv[2]); printf("Using ports %d and %d\n", port1, port2); if (!config_port(port1, simple_tx)) return -1; if (!config_port(port2, simple_tx)) return -1; struct rte_mempool* pool = make_mempool(); uint64_t sent = 0; uint64_t next_print = rte_get_tsc_hz(); uint64_t last_sent = 0; while (true) { sent += send_pkts(port1, pool); sent += send_pkts(port2, pool); uint64_t time = rte_rdtsc(); if (time >= next_print) { double elapsed = (time - next_print + rte_get_tsc_hz()) / rte_get_tsc_hz(); uint64_t pkts = sent - last_sent; printf("Packet rate: %.2f Mpps\n", (double) pkts / elapsed / 1000000); next_print = time + rte_get_tsc_hz(); last_sent = sent; } } return 0; }
int main(void) { // clock cfg RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE); config_port(); /* // var GPIO_InitTypeDef mycfgPD; // port D cfg mycfgPD.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; mycfgPD.GPIO_Mode = GPIO_Mode_OUT; mycfgPD.GPIO_Speed = GPIO_Speed_50MHz; mycfgPD.GPIO_OType = GPIO_OType_PP; mycfgPD.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD,&mycfgPD); */ while(1) { //int j; //int i = 100000; //GPIO_SetBits(GPIOD,GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15); liga_led(); //for (j=1; j<i; j++); delay(); //GPIO_ResetBits(GPIOD,GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15); desliga_led(); //for (j=1; j<i; j++); delay(); } }
int main(int argc, char *argv[]) { try { short port = config_port(); short proxy_port = config_proxy_port(); std::string proxy_hostname = config_proxy_hostname(); std::shared_ptr<SCTP::Server> server( new SCTP::Server(port)); auto connector = [&proxy_hostname, &proxy_port] () -> std::shared_ptr<TCP::Connection> { return TCP::connect(proxy_hostname, proxy_port); }; forward(server, connector); server->close(); } catch (char const* error) { std::cerr << "Exception: " << error << std::endl; } catch (...) { std::cerr << "Unknown exception" << std::endl; } }
int main(int argc, char *argv[]) { char ch; testmode_t mode = CONSOLE; FILE *fp; while ((ch=getopt(argc, argv, "p:r:t:b:v")) != -1) { switch(ch) { case 'p': serial_device = strdup(optarg); break; case 'b': if (!strcmp(optarg, "115200")) { port_speed = B115200; } else if (!strcmp(optarg, "38400")) { port_speed = B38400; } fprintf(stderr, "Using %s bps\n", optarg); break; default: fprintf(stderr, "Unknown option %c\n", ch); return -1; } } open_serial(); config_port(); }
redmine::result redmine::action::config(redmine::cl::args &args, redmine::options &options) { if (0 == args.count()) { fprintf(stderr, "usage: redmine config <action> [args]\n" "actions:\n" " new <name>\n" " browser [<path>]\n" " editor [<path>]\n" " profile [<name>]\n" " key [<key>]\n" " url [<url>]\n" " port [<port>]\n" " use-ssl [true|false]\n" " verify-ssl [true|false]\n"); return FAILURE; } if (!strcmp("new", args[0])) { return config_new(++args, options); } if (!strcmp("browser", args[0])) { return config_browser(++args, options); } if (!strcmp("editor", args[0])) { return config_editor(++args, options); } if (!strcmp("profile", args[0])) { return config_profile(++args, options); } if (!strcmp("key", args[0])) { return config_key(++args, options); } if (!strcmp("url", args[0])) { return config_url(++args, options); } if (!strcmp("port", args[0])) { return config_port(++args, options); } if (!strcmp("use-ssl", args[0])) { return config_use_ssl(++args, options); } if (!strcmp("verify-ssl", args[0])) { return config_verify_ssl(++args, options); } fprintf(stderr, "invalid argument: %s\n", args[0]); return INVALID_ARGUMENT; }
static int config(void) { if (config_module()) return -1; if (config_port()) return -1; if (config_service()) return -1; return 0; }
/****************************************************** * * Main; the master of functions, the definer of variables. * * ***************************************************/ int main( int argc, char **argv ) { int i, j; ros::init(argc, argv, "sonar"); ros::NodeHandle n; //ros::Publisher nodenameVariablenameMsg = handle.outsidness<libraryname::type>("nodenameVariablename", bufflen?); ros::Publisher sonarBearingMsg = n.advertise<std_msgs::Float32>("sonarBearing", 100); ros::Publisher sonarBinsMsg = n.advertise<std_msgs::Float32>("sonarBins", 100); std_msgs::Float32 sonarBearing; std_msgs::Float32 sonarBins; /* Open and Configure the Serial Port. */ open_port(); config_port(); //printf("dihqwdi %d\n", getU16(0x0A, 0x80)); /* Initilise the sonar */ initSonar(); /* optional, sendBBUser command, doesnt work :/ */ //sendBB(); /* Make and send the head parameters, currently defined at the top of this file */ headSetup(); /* ask for some data, will get datas */ for( i = 0; i < 200; i ++) { requestData(); //pass datas sonarBearing.data = (float) bearing; sonarBins.data = (float) bins; //publish sonarBearingMsg.publish(sonarBearing); sonarBinsMsg.publish(sonarBins); ros::spinOnce(); } /* close file and exit program */ close(fd); return 0; }
int main() { int radio = config_port("/dev/ttyUSB0"); char buff = '\0'; char read_in[256]; int n = 0; getchar(); while (buff!='\n'){ buff = radio_read(radio); read_in[n] = buff; n++; } printf("%s", read_in); close(radio); return 0; }
/****************************************************** * * Main; the master of functions, the definer of variables. * * ***************************************************/ int main( int argc, char **argv ) { int i, j; ros::init(argc, argv, "sonar"); ros::NodeHandle n; //ros::Publisher nodenameVariablenameMsg = handle.outsidness<libraryname::type>("nodenameVariablename", bufflen?); ros::Publisher sonarBearingMsg = n.advertise<std_msgs::Float32>("sonarBearing", 100); ros::Publisher sonarBinsMsg = n.advertise<std_msgs::Float32>("sonarBins", 100); ros::Publisher sonarBinsArrMsg = n.advertise<std_msgs::Int32MultiArray>("sonarBinsArr", 100); ros::Publisher sonarScanMsg = n.advertise<sensor_msgs::LaserScan>("sonarScan", 100); ros::Subscriber sub1 = n.subscribe("sonarCmd", 100, cmdCallback); ros::Subscriber sub2 = n.subscribe("sonarRange", 100, rangeCallback); ros::Subscriber sub3 = n.subscribe("sonarLeft", 100, leftCallback); std_msgs::Float32 sonarBearing; std_msgs::Float32 sonarBins; std_msgs::Int32MultiArray sonarBinsArr; sensor_msgs::LaserScan sonarScan; //ros::Time scan_time = ros::Time::now(); //Set up a LaserScan message: initLaserData(sonarScan); /* Open and Configure the Serial Port. */ open_port(); if( tcgetattr(fd, &orig_terimos) < 0) { ROS_ERROR("Probably didn't get the serial port (is it connected?).\n"); return 0; } config_port(); //makePacket(mtReBoot); //printf("dihqwdi %d\n", getU16(0x0A, 0x80)); /* Initilise the sonar */ initSonar(); /* optional, sendBBUser command, doesnt work :/ */ //sendBB(); while(ros::ok()) { ros::Time scan_time = ros::Time::now(); switchCmd = 1; //Stare LL if(switchCmd == 0) { /* Make and send the head parameters, currently defined at the top of this file */ if(switchFlag == 0) { //SCANSTARE = 0x2B; //RANGE = 5; LEFTANGLE = 3300; RIGHTANGLE = 3600; headSetup(); switchFlag = 1; ROS_INFO("Stare Initilized"); } // i = 0; //makePacket(mtStopAlive); /* ask for some data, will get datas */ // while(i < 30) // { requestData(); // //tcflush(fd, TCIFLUSH);//remove //pass datas sonarBearing.data = (float) bearing; //printf("%d", bearing); sonarBins.data = (float) bins; sonarBinsArr.data.clear(); for (int k = 0; k < 90; k++) { sonarBinsArr.data.push_back(tempBinArray[k]); } //publish sonarBearingMsg.publish(sonarBearing); sonarBinsMsg.publish(sonarBins); sonarBinsArrMsg.publish(sonarBinsArr); //ROS_INFO("Bearing: %f, Bins: %f", bearing, bins); //printf("%d - %d\n", bearing, bins); //ros::spinOnce(); i++; // } } //scanner else { /* Make and send the head parameters, currently defined at the top of this file */ if(switchFlag == 0) { SCANSTARE = 0xC0; RANGE = 45; LEFTANGLE = 0; RIGHTANGLE = 6399; headSetup(); switchFlag = 1; ROS_INFO("Scanner Activated"); } i = 0; //makePacket(mtStopAlive); /* ask for some data, will get datas */ // while(i < 30) // { requestData(); // //tcflush(fd, TCIFLUSH);//remove //pass datas /* Hack to fix the bearing mess up between ~3327-3599, dafuq. */ //printf("%d - ", bearing); if(sonarDirection == UP) { if( bearingOld != bearing - (STEPANGLE * 2) && bearingOld != 0) { if((bearing >= 0 && bearing <= 100) && (bearingOld <= 6399 && bearingOld >= 6300)) bearingFail = 0; else bearingFail = 1; } if( (bearing > bearingOld + 700) && bearingFail == 1) bearingFail = 0; } else { if( bearingOld != bearing + (STEPANGLE * 2) && bearingOld != 0) { if((bearingOld >= 0 && bearingOld <= 100) && (bearing <= 6399 && bearing >= 6300)) bearingFail = 0; else bearingFail = 1; } if( (bearing > bearingOld + 700) && bearingFail == 1) bearingFail = 0; } if(bearingFail == 1) { //bearing = bearing + 768; sonarBearing.data = (float) bearing + 768; } else { sonarBearing.data = (float) bearing; } //printf("%d -- %d\n", bearing, bearingFail); /* end fix */ //sonarBearing.data = (float) bearing; sonarBins.data = (float) bins; sonarBinsArr.data.clear(); for (int k = 0; k < 90; k++) { sonarBinsArr.data.push_back(tempBinArray[k]); } // Create laser scan data from the sonar bins array. createLaserData(sonarScan, tempBinArray, scan_time); //publish sonarBearingMsg.publish(sonarBearing); sonarBinsMsg.publish(sonarBins); sonarBinsArrMsg.publish(sonarBinsArr); sonarScanMsg.publish(sonarScan); //ROS_INFO("Bearing: %f, Bins: %f", bearing, bins); //printf("%d - %d\n", bearing, bins); //ros::spinOnce(); i++; bearingOld = bearing; // } } ros::spinOnce(); //sleep(1); } /* close file and exit program */ tcflush(fd, TCIFLUSH); tcsetattr(fd, TCSANOW, &(orig_terimos)); close(fd); return 0; }
static int client_setup_file(CONTEXT *ctx, char *who) { char *p; u_int16_t l, u; /* ** little bit sanity check */ if( !(ctx && who && *who)) { return -1; } /* ** Inform the auditor that we are using the config file */ syslog_write(U_INF, "reading data for '%s' from cfg-file", who); /* ** Evaluate DestinationAddress, except we have magic_addr */ if (INADDR_ANY != ctx->magic_addr) { ctx->srv_addr = ctx->magic_addr; } else { ctx->srv_addr = config_addr(who, "DestinationAddress", INADDR_ANY); #if defined(COMPILE_DEBUG) debug(2, "file DestAddr for %s: '%s'", ctx->cli_ctrl->peer, socket_addr2str(ctx->srv_addr)); #endif } /* ** Evaluate DestinationPort, except we have magic_port */ if (INPORT_ANY != ctx->magic_port) { ctx->srv_port = ctx->magic_port; } else { ctx->srv_port = config_port(who, "DestinationPort", IPPORT_FTP); #if defined(COMPILE_DEBUG) debug(2, "file DestPort for %s: %d", ctx->cli_ctrl->peer, (int) ctx->srv_port); #endif } /* ** Evaluate the destination transfer mode */ p = config_str(who, "DestinationTransferMode", "client"); if(0 == strcasecmp(p, "active")) { ctx->srv_mode = MOD_ACT_FTP; } else if(0 == strcasecmp(p, "passive")) { ctx->srv_mode = MOD_PAS_FTP; } else if(0 == strcasecmp(p, "client")) { ctx->srv_mode = MOD_CLI_FTP; } else { syslog_error("can't eval DestMode for %s", ctx->cli_ctrl->peer); return -1; } #if defined(COMPILE_DEBUG) debug(2, "file DestMode for %s: %s", ctx->cli_ctrl->peer, p); #endif /* ** Evaluate min/max destination port range */ l = config_port(who, "DestinationMinPort", INPORT_ANY); u = config_port(who, "DestinationMaxPort", INPORT_ANY); if (l > 0 && u > 0 && u >= l) { ctx->srv_lrng = l; ctx->srv_urng = u; } else { ctx->srv_lrng = INPORT_ANY; ctx->srv_urng = INPORT_ANY; } #if defined(COMPILE_DEBUG) debug(2, "file DestRange for %s: %u-%u", ctx->cli_ctrl->peer, ctx->srv_lrng, ctx->srv_urng); #endif /* ** Evaluate min/max active port range */ l = config_port(who, "ActiveMinDataPort", INPORT_ANY); u = config_port(who, "ActiveMaxDataPort", INPORT_ANY); if (l > 0 && u > 0 && u >= l) { ctx->act_lrng = l; ctx->act_urng = u; } else { /* do not try to bind a port < 1024 if running as UID != 0 */ if(0 == getuid()) { ctx->act_lrng = (IPPORT_FTP - 1); ctx->act_urng = (IPPORT_FTP - 1); } else { ctx->act_lrng = INPORT_ANY; ctx->act_urng = INPORT_ANY; } } #if defined(COMPILE_DEBUG) debug(2, "file ActiveRange for %s: %u-%u", ctx->cli_ctrl->peer, ctx->act_lrng, ctx->act_urng); #endif /* ** Evaluate min/max passive port range */ l = config_port(who, "PassiveMinDataPort", INPORT_ANY); u = config_port(who, "PassiveMaxDataPort", INPORT_ANY); if (l > 0 && u > 0 && u >= l) { ctx->pas_lrng = l; ctx->pas_urng = u; } else { ctx->pas_lrng = INPORT_ANY; ctx->pas_urng = INPORT_ANY; } #if defined(COMPILE_DEBUG) debug(2, "file PassiveRange for %s: %u-%u", ctx->cli_ctrl->peer, ctx->pas_lrng, ctx->pas_urng); #endif /* ** Setup other configuration options */ ctx->same_adr = config_bool(who, "SameAddress", 1); ctx->timeout = config_int (who, "TimeOut", 900); #if defined(COMPILE_DEBUG) debug(2, "file SameAddress for %s: %s", ctx->cli_ctrl->peer, ctx->same_adr ? "yes" : "no"); debug(2, "file TimeOut for %s: %d", ctx->cli_ctrl->peer, ctx->timeout); #endif /* ** Adjust the allow/deny flags for the commands */ p = config_str(who, "ValidCommands", NULL); cmds_set_allow(p); return 0; }
int main(int argc, char **argv){ //we need argc and argv for the rosInit function ros::init(argc, argv, "compass"); //inits the driver ros::NodeHandle n; //this is what ROS uses to connect to a node /*Advertises our various messages*/ ros::Publisher compassHeadingMsg = n.advertise<std_msgs::Float32>("compassHeading", 100); ros::Publisher compassPitchMsg = n.advertise<std_msgs::Float32>("compassPitch", 100); ros::Publisher compassRollMsg = n.advertise<std_msgs::Float32>("compassRoll", 100); /*Sets up the message structures*/ std_msgs::Float32 compassHeading; std_msgs::Float32 compassPitch; std_msgs::Float32 compassRoll; ros::Rate loop_rate(10); //how many times a second (i.e. Hz) the code should run if(!open_port()){ return 0; //we failed to open the port so end } config_port(); ROS_INFO("Compass Driver Online"); while (ros::ok()){ if(write_port()){ //if we send correctly if(read_port() != 0){ //if we read correctly parseBuffer(); //parse the buffer //printf("H: %f P: %f R: %f\n",heading,pitch,roll); /* Below here sets up the messages ready for transmission*/ compassHeading.data = heading; compassPitch.data = pitch; compassRoll.data = roll; ROS_DEBUG("H: %.3f P: %.3f R: %.3f",heading,pitch,roll); } else{ ROS_ERROR("Read no data"); } } else{ ROS_ERROR("Failed to write"); } /*Below here we publish our readings*/ compassHeadingMsg.publish(compassHeading); compassRollMsg.publish(compassRoll); compassPitchMsg.publish(compassPitch); /*Have a snooze*/ loop_rate.sleep(); } ros::spin(); close(fd); ROS_INFO("Shutting Down"); printf("Shutting Down\n"); return 0; }
int main(int argc, char **argv){ //we need argc and argv for the rosInit function ros::init(argc, argv, "picsubnet"); //inits the driver ros::NodeHandle picsubnetN; //this is what ROS uses to connect to a node /*Advertises our various messages*/ ros::Publisher pubReedSwitch = picsubnetN.advertise<std_msgs::Char>("reed_switch", 100); ros::Publisher pubBTShutdown = picsubnetN.advertise<std_msgs::Char>("bt_shutdown", 100); ros::Publisher pubBatteryVoltage1 = picsubnetN.advertise<std_msgs::Float32>("battery_voltage_1", 100); ros::Publisher pubBatteryVoltage2 = picsubnetN.advertise<std_msgs::Float32>("battery_voltage_2", 100); ros::Publisher pubAmbient = picsubnetN.advertise<std_msgs::Float32>("ambient_temperature", 100); ros::Publisher pubMotor1 = picsubnetN.advertise<std_msgs::Float32>("motor_temperature_1", 100); ros::Publisher pubMotor2 = picsubnetN.advertise<std_msgs::Float32>("motor_temperature_2", 100); ros::Publisher pubFitPC = picsubnetN.advertise<std_msgs::Float32>("fitpc_temperature", 100); ros::Publisher pubRouter = picsubnetN.advertise<std_msgs::Float32>("router_temperature", 100); ros::Publisher pubRoboard = picsubnetN.advertise<std_msgs::Float32>("roboard_temperature", 100); ros::Rate loop_rate(15); //how many times a second (i.e. Hz) the code should run if(!open_port()){ ROS_ERROR("FAILED TO CONNECT"); return 0; //we failed to open the port so end } config_port(); ROS_INFO("PIC SUBNET ONLINE"); while (ros::ok()){ //All on/All off led_test++; if (led_test == 1) write_port((unsigned char *)"$1N", 4); else if (led_test == 2) write_port((unsigned char *)"$2N", 4); else if (led_test == 3) write_port((unsigned char *)"$3N", 4); else if (led_test == 4) write_port((unsigned char *)"$4N", 4); else if (led_test == 5) write_port((unsigned char *)"$5N", 4); else if (led_test == 6) write_port((unsigned char *)"$6N", 4); else if (led_test == 7) write_port((unsigned char *)"$7N", 4); else if (led_test == 8) write_port((unsigned char *)"$1F", 4); else if (led_test == 9) write_port((unsigned char *)"$2F", 4); else if (led_test == 10) write_port((unsigned char *)"$3F", 4); else if (led_test == 11) write_port((unsigned char *)"$4F", 4); else if (led_test == 12) write_port((unsigned char *)"$5F", 4); else if (led_test == 13) write_port((unsigned char *)"$6F", 4); else if (led_test == 14) { write_port((unsigned char *)"$7F", 4); led_test = 0; } // Read data from the port if (read_port() == 1) { //if (bt_shutdown.data == (uint8_t)1) ROS_ERROR("BLUETOOTH SHUTDOWN ACTIVATED"); //if (reed_status.data == (uint8_t)-1) ROS_WARN("REED SWITCH - NO RESPONSE"); //There should only ever be 2 batteries connected... int battery_counter = 0; if (battery_voltage1.data != (float)-1.0) { battery1_publish_data.data = battery_voltage1.data; battery_counter++; } if (battery_voltage2.data != (float)-1.0) { if (battery_counter == 0) battery1_publish_data.data = battery_voltage2.data; else battery2_publish_data.data = battery_voltage2.data; battery_counter++; } if (battery_voltage3.data != (float)-1.0) { if (battery_counter == 0) battery1_publish_data.data = battery_voltage3.data; else if (battery_counter == 1) battery2_publish_data.data = battery_voltage3.data; //else //ROS_WARN("More than 2 batteries detected..."); battery_counter++; } if (battery_voltage4.data != (float)-1.0) { if (battery_counter == 0) battery1_publish_data.data = battery_voltage4.data; else if (battery_counter == 1) battery2_publish_data.data = battery_voltage4.data; //else //ROS_WARN("More than 2 batteries detected..."); battery_counter++; } if (battery_counter < 2) ; //ROS_WARN("Only %d Batteries found", battery_counter); else { pubBatteryVoltage1.publish(battery1_publish_data); pubBatteryVoltage2.publish(battery2_publish_data); } //Publish new data pubReedSwitch.publish(reed_status); pubBTShutdown.publish(bt_shutdown); pubAmbient.publish(ambient_temperature); pubMotor1.publish(motor1_temperature); pubMotor2.publish(motor2_temperature); pubFitPC.publish(fitpc_temperature); pubRouter.publish(router_temperature); pubRoboard.publish(roboard_temperature); } /*Have a snooze*/ loop_rate.sleep(); } close(fd); ROS_INFO("Shutting Down"); return 0; }
static int client_setup_file(CONTEXT *ctx, char *who) { char *p; u_int16_t l, u; /* ** little bit sanity check */ if( !(ctx && who && *who)) { return -1; } /* ** Inform the auditor that we are using the config file */ syslog_write(U_INF, "[ %s ] reading data for '%s' from cfg-file", ctx->cli_ctrl->peer, who); /* ** Evaluate DestinationAddress, except we have magic_addr */ if (INADDR_ANY != ctx->magic_addr) { ctx->srv_addr = ctx->magic_addr; } else { ctx->srv_addr = config_addr(who, "DestinationAddress", INADDR_ANY); #if defined(COMPILE_DEBUG) debug(2, "[ %s ] file DestAddr for %s: '%s'", ctx->cli_ctrl->peer, ctx->cli_ctrl->peer, socket_addr2str(ctx->srv_addr)); #endif } /* ** Evaluate DestinationPort, except we have magic_port */ if (INPORT_ANY != ctx->magic_port) { ctx->srv_port = ctx->magic_port; } else { ctx->srv_port = config_port(who, "DestinationPort", IPPORT_FTP); #if defined(COMPILE_DEBUG) debug(2, "[ %s ] file DestPort for %s: %d", ctx->cli_ctrl->peer, ctx->cli_ctrl->peer, (int) ctx->srv_port); #endif } /* ** Evaluate the destination transfer mode */ p = config_str(who, "DestinationTransferMode", "client"); if(0 == strcasecmp(p, "active")) { ctx->srv_mode = MOD_ACT_FTP; } else if(0 == strcasecmp(p, "passive")) { ctx->srv_mode = MOD_PAS_FTP; } else if(0 == strcasecmp(p, "client")) { ctx->srv_mode = MOD_CLI_FTP; } else { syslog_error("can't eval DestMode for %s", ctx->cli_ctrl->peer); return -1; } #if defined(COMPILE_DEBUG) debug(2, "file DestMode for %s: %s", ctx->cli_ctrl->peer, p); #endif /* ** Evaluate min/max destination port range */ l = config_port(who, "DestinationMinPort", INPORT_ANY); u = config_port(who, "DestinationMaxPort", INPORT_ANY); if (l > 0 && u > 0 && u >= l) { ctx->srv_lrng = l; ctx->srv_urng = u; } else { ctx->srv_lrng = INPORT_ANY; ctx->srv_urng = INPORT_ANY; } #if defined(COMPILE_DEBUG) debug(2, "file DestRange for %s: %u-%u", ctx->cli_ctrl->peer, ctx->srv_lrng, ctx->srv_urng); #endif /* ** Evaluate min/max active port range */ l = config_port(who, "ActiveMinDataPort", INPORT_ANY); u = config_port(who, "ActiveMaxDataPort", INPORT_ANY); if (l > 0 && u > 0 && u >= l) { ctx->act_lrng = l; ctx->act_urng = u; } else { /* do not try to bind a port < 1024 if running as UID != 0 */ if(0 == getuid()) { ctx->act_lrng = (IPPORT_FTP - 1); ctx->act_urng = (IPPORT_FTP - 1); } else { ctx->act_lrng = INPORT_ANY; ctx->act_urng = INPORT_ANY; } } #if defined(COMPILE_DEBUG) debug(2, "file ActiveRange for %s: %u-%u", ctx->cli_ctrl->peer, ctx->act_lrng, ctx->act_urng); #endif /* ** Evaluate min/max passive port range */ l = config_port(who, "PassiveMinDataPort", INPORT_ANY); u = config_port(who, "PassiveMaxDataPort", INPORT_ANY); if (l > 0 && u > 0 && u >= l) { ctx->pas_lrng = l; ctx->pas_urng = u; } else { ctx->pas_lrng = INPORT_ANY; ctx->pas_urng = INPORT_ANY; } #if defined(COMPILE_DEBUG) debug(2, "file PassiveRange for %s: %u-%u", ctx->cli_ctrl->peer, ctx->pas_lrng, ctx->pas_urng); #endif /* ** Setup other configuration options */ ctx->same_adr = config_bool(who, "SameAddress", 1); ctx->timeout = config_int (who, "TimeOut", 900); #if defined(COMPILE_DEBUG) debug(2, "file SameAddress for %s: %s", ctx->cli_ctrl->peer, ctx->same_adr ? "yes" : "no"); debug(2, "file TimeOut for %s: %d", ctx->cli_ctrl->peer, ctx->timeout); #endif /*** Adjust the allow/deny flags for the commands ** Fred patch */ char dest[17]; char ipdest[17]; char ipsrc[17]; strcpy (ipsrc,ctx->cli_ctrl->peer); strcpy (ipdest, socket_addr2str(ctx->srv_addr)); syslog_write(U_INF, "\n"); syslog_write(U_INF, "[ %s ] Fred Patch rules dest: %s src: %s", ipsrc, ipdest, ipsrc); char groupname[]="group"; char commandename[]="ValidCommands"; char *group; FILE *fp; group = "group1"; int ix; int ix2; u_int32_t dnsaddr; for(ix=1; group != NULL; ix++) { sprintf (&groupname[5],"%d",ix); group = config_str(who, groupname, NULL); } syslog_write(U_INF, "[ %s ] Number of groups: %d", ipsrc, ix-2); for (ix2=1; ix2 <= ix-2; ix2++) { sprintf (&groupname[5],"%d",ix2); group = config_str(who, groupname, NULL); syslog_write(U_INF, "[ %s ] Reading: %s",ipsrc, group ); if ((fp = fopen(group, "r")) == NULL) { syslog_write(U_INF, "File not found"); return 0; } else { fseek(fp, 0, SEEK_SET); while (fgets(dest, 17 , fp) != NULL) { // Pour une IP // Correction Bug Ligne sans \n dest[16] = '\n'; char *c = strchr (dest, '\n'); *c = 0; /* Dns resolution */ if (ipdest != dest) { dnsaddr = socket_str2addr(dest, INADDR_ANY); if (dnsaddr != 0) strcpy (dest, socket_addr2str(dnsaddr)); } if (strcmp(dest,ipdest) == 0 || strcmp(dest,ipsrc) == 0) { sprintf (&commandename[13],"%d",ix); p = config_str(who,commandename, NULL); cmds_set_allow(p); syslog_write(U_INF, "[ %s ] Apply rules for: %s dst: %s",ipsrc, ipsrc, ipdest); syslog_write(U_INF, "[ %s ] Server match %s ",ipsrc, group ); syslog_write(U_INF, "\n"); fclose(fp); return 0; } // Network if (strchr(dest, 'x') != NULL) { char *c = strchr(dest, 'x'); *c = 0; int longueur; longueur = strlen(dest); if (strncmp(dest,ipdest,longueur) == 0 || strncmp(dest,ipsrc,longueur) == 0) { sprintf (&commandename[13],"%d",ix); p = config_str(who,commandename, NULL); cmds_set_allow(p); syslog_write(U_INF, "[ %s ] Apply rules for Network: %s src: %s",ipsrc, ipdest, ipsrc); syslog_write(U_INF, "[ %s ] Server match %s ",ipsrc, group ); syslog_write(U_INF, "\n"); fclose(fp); return 0; } } } fclose(fp); } } syslog_write(U_INF, "[ %s ] Oh, Oh, no rule found -> defaultrules", ipsrc) ; p = config_str(who, "defaultrules", NULL); cmds_set_allow(p); return 0; }
int main(int argc, char **argv){ //we need argc and argv for the rosInit function float depthArr[10] = "00000000"; float velArr[10] = "00000000"; int i; ros::init(argc, argv, "svp"); //inits the driver ros::NodeHandle svpN; //this is what ROS uses to connect to a node /*Advertises our various messages*/ ros::Publisher svpDepthMsg = svpN.advertise<std_msgs::Float32>("svpDepth", 100); ros::Publisher svpVeloMsg = svpN.advertise<std_msgs::Float32>("svpVelocity", 100); /*Sets up the message structures*/ std_msgs::Float32 svpDepth; std_msgs::Float32 svpVelo; ros::Rate loop_rate(3); //how many times a second (i.e. Hz) the code should run if(!open_port()){ return 0; //we failed to open the port so end } config_port(); ROS_INFO("SVP Driver Online"); while (ros::ok()){ if(read_port() != 0){ //if we read correctly for (i = 0; i < 6; i++){ depthArr[i] = bufPos[i+1]; } depth = strtod(depth, &dEnd); depth -= SURFACE; //pressure - surface pressure = specific weight x depth depth /= DENSITY; svpDepth.data = depth; //dMsg = 1.01240;// //The Velocity for (i = 1; i < 10; i++){ velArr[i] = bufPos[i+7]; } velocity = strtod(velo, &vEnd); svpVelo.data = velocity; svpDepthMsg.publish(svpDepth); svpVeloMsg.publish(svpVelo); } else{ ROS_ERROR("Read no data"); } /*Below here we publish our readings*/ /*Have a snooze*/ loop_rate.sleep(); } ros::spin(); close(fd); ROS_INFO("Shutting Down"); printf("Shutting Down\n"); return 0; }