////////////////////////////////////////////////////////////////////////////// /// Inizialization. This function is called once before entering /// main loop. /// ////////////////////////////////////////////////////////////////////////////// void init() { VMC_INT_16 motorID; init_aisc167b(); init_asccom(); init_cycletime_counter(); i2c_init(); init_bioport(); if (can_init(CAN_BAUD, 0)) while(1){led_swap_green();} led_set_green(0); led_set_red(0); ledseq_init(); ais_system_init(); //init_Thermic(); init_error(); init_calculatestate(); init_motorcontrol(); init_controller(); init_current_limiter(); mpwr_init(); set_default_configuration(); for (motorID = 0; motorID < 3; motorID++) { // init_Limiter(i, 100); init_encoder(motorID); } }
void new_thread() { AllocateConsole(); Sleep(1500); init_controller(); }
int main() { uint8_t refTemp = 30; // reference uint8_t check, prev_check = 0; short up = 1, down = 1; uint16_t adc_in; // ADC value uint8_t temp = 1; // real temperature init_controller(); init_PWM(); lcd_init(); sei(); // turn on interrupts lcd_clrscr(); lcd_puts("Spinning"); Delay_s(2); // 2 seconds delay init_ADC(); refTemp = eeprom_read_byte((uint8_t*)0); if (!(refTemp >= TMIN && refTemp <= TMAX)) refTemp = 30; while(1) { if (C_CHECKBIT(Minus_REF)) down = 0; if (C_CHECKBIT(Minus_REF) == 0 && down ==0) { down = 1; if (refTemp > TMIN) refTemp--; } if (C_CHECKBIT(Plus_REF)) up = 0; if (C_CHECKBIT(Plus_REF) == 0 && up ==0) { up = 1; if (refTemp < TMAX) refTemp++; } eeprom_write_byte ((uint8_t *)0, refTemp); adc_in = ReadADC(0); temp = adc_in/2; lcd_puts2("T%d-R%dC", temp, refTemp); if ((temp - refTemp) > TOL) check = 3; else if ((refTemp - temp) > TOL) check = 1; else check = 2; switch(check) { case 1: if (prev_check == 1) break; setDutyCycle1(); prev_check = 1; break; case 2: if (prev_check == 2) break; setDutyCycle2(); prev_check = 2; break; case 3: if (prev_check == 3) break; setDutyCycle3(); prev_check = 3; break; } } return 1; }
/****Initialize DEVICE*****/ void ecrobot_device_initialize() { ecrobot_init_bt_slave(DEVICE_PWD); ecrobot_init_sonar_sensor(NXT_PORT_S4); /* timestamp = 0; bt_conn_status = 0; num_packets = 0; stream_size = 0; o_stream = 0; enable_streaming = 0; reset_data_structs(); */ reset_motor_power(); init_controller(&left_motor); init_controller(&right_motor); initUnicycle(&unicycle_controller); }
static void rna_Controller_type_set(struct PointerRNA *ptr, int value) { bController *cont = (bController *)ptr->data; if (value != cont->type) { cont->type = value; init_controller(cont); } }
PyObject *init_guava(void) { PyObject *guava_module = NULL; PyObject *request_module = NULL; PyObject *server_module = NULL; PyObject *handler_module = NULL; PyObject *controller_module = NULL; PyObject *router_module = NULL; PyObject *session_module = NULL; PyObject *cookie_module = NULL; PyEval_InitThreads(); guava_module = Py_InitModule("guava", NULL); request_module = init_request(); if (!register_module(guava_module, "request", request_module)) { return NULL; } server_module = init_server(); if (!register_module(guava_module, "server", server_module)) { return NULL; } handler_module = init_handler(); if (!register_module(guava_module, "handler", handler_module)) { return NULL; } router_module = init_router(); if (!register_module(guava_module, "router", router_module)) { return NULL; } controller_module = init_controller(); if (!register_module(guava_module, "controller", controller_module)) { return NULL; } session_module = init_session(); if (!register_module(guava_module, "session", session_module)) { return NULL; } cookie_module = init_cookie(); if (!register_module(guava_module, "cookie", cookie_module)) { return NULL; } PyModule_AddStringConstant(guava_module, "version", GUAVA_VERSION); return guava_module; }
int main(int argc, char *argv[]) { unsigned port = CPORT; /* Actual number of workers & routers */ int nworkers = 1; int nrouters = 1; /* Max number of clients */ int c; int level = 1; bool console = true; while ((c = getopt(argc, argv, "hv:p:r:w:c:C")) != -1) { switch (c) { case 'h': usage(argv[0]); break; case 'v': level = atoi(optarg); break; case 'p': port = atoi(optarg); break; case 'r': nrouters = atoi(optarg); break; case 'w': nworkers = atoi(optarg); break; case 'c': maxclients = atoi(optarg); break; case 'C': console = false; break; default: printf("Unknown option '%c'\n", c); usage(argv[0]); break; } } set_verblevel(level); if (signal(SIGTERM, sigterm_handler) == SIG_ERR) err(false, "Couldn't install signal handler"); init_controller(port, nrouters, nworkers); if (!console) block_console(); run_controller(NULL); mem_status(stdout); chunk_status(stdout); return 0; }
bController *new_controller(int type) { bController *cont; cont= MEM_callocN(sizeof(bController), "Controller"); cont->type= type; cont->flag= CONT_SHOW; init_controller(cont); strcpy(cont->name, "cont"); // XXX make_unique_prop_names(cont->name); return cont; }
void keyer_init() { char keyerbuff[3]; if (cwkeyer == NET_KEYER) { showmsg("CW-Keyer is cwdaemon"); if (netkeyer_init() < 0) { showmsg("Cannot open NET keyer daemon "); refreshp(); sleep(1); } else { netkeyer(K_RESET, "0"); sprintf(weightbuf, "%d", weight); write_tone(); snprintf(keyerbuff, 3, "%2d", GetCWSpeed()); netkeyer(K_SPEED, keyerbuff); // set speed netkeyer(K_WEIGHT, weightbuf); // set weight if (*keyer_device != '\0') netkeyer(K_DEVICE, keyer_device); // set device sprintf(keyerbuff, "%d", txdelay); netkeyer(K_TOD, keyerbuff); // set TOD if (sc_sidetone != 0) // set soundcard output netkeyer(K_SIDETONE, ""); if (*sc_volume != '\0') // set soundcard volume netkeyer(K_STVOLUME, sc_volume); } } if (cwkeyer == MFJ1278_KEYER || digikeyer == MFJ1278_KEYER || digikeyer == GMFSK) { init_controller(); } }
bool filter::Move_to(int next_node){ int motor_one_status, motor_two_status, motor_one_steps, motor_two_steps; int dir = 1; int steps_to=distance_to[current_node][next_node]; // if(steps_to <=0) // checks the direction { dir = 0; steps_to= -1*steps_to; } std::cout<<steps_to<<" " << distance_to[current_node][next_node]<< std::endl; int time_interval=10; // time interval between ticks the motor 10 ms int reply; //used to call methods from stepper_bee_interface reply = init_controller(); // turns the board reply = set_modes(1,1,1,1); // allows the board to report back to use reply = move_motor(1, dir, steps_to, time_interval, 0, 0, 0); // moves motor stepper_bee_interface just change the first int from a 1 to a 0 int wait=0; //built in for the delay that will occur on the usb do{ reply = get_motor_status(&motor_one_status, &motor_two_status, &motor_one_steps, &motor_two_steps) ; std::cout<<"MOTOR - steps left = "<< motor_two_steps<< " \n"; //CTM: change to motor_one_steps if using other motor j++; }while(motor_one_status == 1 || motor_two_status == 1|| wait<5); //this how we wait for the motor std::cout<<"DONE !! \n"; current_node=next_node; // so the class knows where it is at reply=close_controller(); //prevent bad signals being sent to the motor return true; }
/* * Setup function for CAN_IO. Arguments are a FilterInfo struct and a pointer to a place to raise error flags. */ void CAN_IO::Setup(byte interrupts) { // default interrupts are RX0IE | RX1IE | TX1IE | TX2IE | TX0IE. // SPI setup SPI.setClockDivider(10); SPI.setDataMode(SPI_MODE0); SPI.setBitOrder(MSBFIRST); SPI.begin(); // reset tx tracker tx_open = 0x07; // Set as main can main_CAN = this; pinMode(INT_pin,INPUT_PULLUP); // Copy filters and interrupts to internal variables this->my_interrupts = interrupts; // init the controller init_controller(); //private helper function }
/***************************************************************************************** * Initialize the FMU for co-simulation. * @param c The FMU. * @param relativeTolerance Suggested (local) tolerance in case the slave utilizes a * numerical integrator with variable step size and error estimation (ignored by this FMU). * @param tStart The start time (ignored by this FMU). * @param stopTimeDefined fmi2True to indicate that the stop time is defined (ignored by this FMU). * @param tStop The stop time (ignored if stopTimeDefined is fmi2False) (ignored by this FMU). * @return fmi2OK */ fmi2Status fmiInitializeSlave(fmi2Component c, fmi2Real relativeTolerance, fmi2Real tStart, fmi2Boolean stopTimeDefined, fmi2Real tStop) { ModelInstance* component = (ModelInstance *) c; printf("%s: Invoked fmiIntializeSlave: start: %g, StopTimeDefined: %d, tStop: %g..\n", component->instanceName, tStart, stopTimeDefined, tStop); fflush(stdout); component->lastSuccessfulTime = tStart; component->atBreakpoint = fmi2False; init_controller(component->controller); printf("successful init controller\n"); fflush(stdout); output_function(component->controller,component->output); return fmi2OK; }
int main() { usb_workaround(); // because the arduino bootloader is a piece of shit init_controller(&SControl); blinky(); // zero the motor for (int i = 0; i < 945; i++) { advance_motor(&(SControl.MControl), UP); _delay_us(3000); } SControl.MControl.current_pos = 0; initInput(); sei(); while (true) { controller_thread(&SControl); input_thread(&SControl); } /* while (true) { set_gauge_target(&SControl, (315<<4)); while (SControl.MControl.current_pos != SControl.target_pos) controller_thread(&SControl); set_gauge_target(&SControl, (0)); while (SControl.MControl.current_pos != SControl.target_pos) controller_thread(&SControl); platform_toggle_status_led(); } */ return 0; }
/** * Main function for this power supply module */ void main_fac_2p4s_acdc(void) { init_controller(); init_peripherals_drivers(); init_interruptions(); enable_controller(); /// TODO: check why first sync_pulse occurs g_ipc_ctom.counter_sync_pulse = 0; /// TODO: include condition for re-initialization while(1) { check_interlocks(); } turn_off(0); disable_controller(); term_interruptions(); reset_controller(); term_peripherals_drivers(); }
/* ######################################################################### Main ######################################################################### */ int main(int argc, char *argv[]) { struct sockaddr_in addr; int on = 1, disable_control_port = 0; pthread_t client, cam, cntrl, mind, uart_control; char *dev = "/dev/video0"; int fps = 5, daemon = 0; cd.width = 640; cd.height = 480; cdata = &cd; cd.control_port = htons(8081); cd.stream_port = htons(8080); while (1) { int option_index = 0, c = 0; static struct option long_options[] = \ { {"h", no_argument, 0, 0}, {"help", no_argument, 0, 0}, {"d", required_argument, 0, 0}, {"device", required_argument, 0, 0}, {"r", required_argument, 0, 0}, {"resolution", required_argument, 0, 0}, {"f", required_argument, 0, 0}, {"fps", required_argument, 0, 0}, {"p", required_argument, 0, 0}, {"port", required_argument, 0, 0}, {"v", no_argument, 0, 0}, {"version", no_argument, 0, 0}, {"b", no_argument, 0, 0}, {"background", no_argument, 0, 0}, {"c", required_argument, 0, 0}, {"control_port", required_argument, 0, 0}, {"disable_control", no_argument, 0, 0}, {"C", no_argument, 0, 0}, {"calibrate", no_argument, 0, 0}, {0, 0, 0, 0} }; c = getopt_long_only(argc, argv, "", long_options, &option_index); /* no more options to parse */ if (c == -1) break; /* unrecognized option */ if (c == '?') { help(argv[0]); return 0; } switch (option_index) { /* h, help */ case 0: case 1: help(argv[0]); return 0; break; /* d, device */ case 2: case 3: dev = strdup(optarg); break; /* r, resolution */ case 4: case 5: if (strcmp("960x720", optarg) == 0) { cd.width = 960; cd.height = 720; } else if (strcmp("640x480", optarg) == 0) { cd.width = 640; cd.height = 480; } else if (strcmp("320x240", optarg) == 0) { cd.width = 320; cd.height = 240; } else if (strcmp("160x120", optarg) == 0) { cd.width = 160; cd.height = 120; } else { fprintf(stderr, "ignoring unsupported resolution\n"); } break; /* f, fps */ case 6: case 7: fps = atoi(optarg); break; /* p, port */ case 8: case 9: cd.stream_port = htons(atoi(optarg)); break; /* v, version */ case 10: case 11: printf("UVC Streamer Version: %s\n" \ "Compilation Date....: %s\n" \ "Compilation Time....: %s\n", SOURCE_VERSION, __DATE__, __TIME__); return 0; break; /* v, version */ case 12: case 13: daemon = 1; break; /* c, control_port */ case 14: case 15: cd.control_port = htons(atoi(optarg)); break; /* disable_control */ case 16: disable_control_port = 1; break; case 17: case 18: disable_control_port = 1; break; default: help(argv[0]); return 0; } } /* ignore SIGPIPE (send if transmitting to closed sockets) */ signal(SIGPIPE, SIG_IGN); if (signal(SIGINT, signal_handler) == SIG_ERR) { fprintf(stderr, "could not register signal handler\n"); exit(1); } /* fork to the background */ if (daemon) { daemon_mode(); } /* allocate webcam datastructure */ cd.videoIn = (struct vdIn *) calloc(1, sizeof(struct vdIn)); fprintf(stderr, "Using V4L2 device.....: %s\n", dev); fprintf(stderr, "Resolution............: %i x %i\n", cdata->width, cdata->height); fprintf(stderr, "frames per second.....: %i\n", fps); fprintf(stderr, "TCP port..............: %i\n", ntohs(cd.stream_port)); if (disable_control_port == 1) { fprintf(stderr, "motor control server..: disabled\n"); } else { fprintf(stderr, "motor control TCP port: %i\n", ntohs(cd.control_port)); } /* open video device and prepare data structure */ cd.video_dev = init_videoIn(cd.videoIn, dev, cd.width, cd.height, fps, V4L2_PIX_FMT_MJPEG, 1); if (cd.video_dev < 0) { fprintf(stderr, "init_VideoIn failed\n"); exit(1); } /* open socket for server */ sd = socket(PF_INET, SOCK_STREAM, 0); if (sd < 0) { fprintf(stderr, "socket failed\n"); exit(1); } /* ignore "socket already in use" errors */ if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) { perror("setsockopt(SO_REUSEADDR) failed"); exit(1); } /* configure server address to listen to all local IPs */ memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = cd.stream_port; addr.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(sd, (struct sockaddr*) &addr, sizeof(addr)) != 0) { fprintf(stderr, "bind failed\n"); perror("Bind"); exit(1); } /* start listening on socket */ if (listen(sd, 10) != 0) { fprintf(stderr, "listen failed\n"); exit(1); } /* start to read the camera, push picture buffers into global buffer */ cd.videoIn->tmpbuffer = (unsigned char *) calloc(1, (size_t) cd.videoIn->framesizeIn); g_buf = (unsigned char *) calloc(1, (size_t) cd.videoIn->framesizeIn); vision_control_init(); //must be first to call; pthread_create(&cam, 0, cam_thread, NULL); pthread_detach(cam); pthread_create(&mind, 0, mind_thread, NULL); pthread_detach(mind); init_vision(); init_controller(); pthread_create(&uart_control, 0, &uart_control_read, NULL); pthread_detach(uart_control); /* start control server */ if (disable_control_port == 0) { pthread_create(&cntrl, NULL, &uvcstream_control, cdata); pthread_detach(cntrl); } /* create a child for every client that connects */ while (1) { int *pfd = (int *) calloc(1, sizeof(int)); *pfd = accept(sd, 0, 0); pthread_create(&client, NULL, &client_thread, pfd); pthread_detach(client); } return 0; }
/*---------------------------------------------------------------------------* * program entry *---------------------------------------------------------------------------*/ int main(int argc, char **argv) { int i; msg_vr_req_t mvr; #ifdef I4B_EXTERNAL_MONITOR int sockfd = -1; /* local monitor socket */ #ifndef I4B_NOTCPIP_MONITOR int remotesockfd = -1; /* tcp/ip monitor socket */ #endif #endif setlocale (LC_ALL, ""); while ((i = getopt(argc, argv, "mc:d:fFlL:Pr:s:t:u:")) != -1) { switch (i) { #ifdef I4B_EXTERNAL_MONITOR case 'm': inhibit_monitor = 1; break; #endif case 'c': configfile = optarg; break; #ifdef DEBUG case 'd': if(*optarg == 'n') debug_noscreen = 1; else if((sscanf(optarg, "%i", &debug_flags)) == 1) do_debug = 1; else usage(); break; #endif case 'f': do_fullscreen = 1; do_fork = 0; #ifndef USE_CURSES fprintf(stderr, "Sorry, no fullscreen mode available - daemon compiled without USE_CURSES\n"); exit(1); #endif break; case 'F': do_fork = 0; break; case 'l': uselogfile = 1; break; case 'L': strlcpy(logfile, optarg, sizeof(logfile)); break; case 'P': do_print = 1; break; case 'r': rdev = optarg; do_rdev = 1; break; case 's': if(isdigit(*optarg)) { int facility; logfacility = strtoul(optarg, NULL, 10); facility = logfacility << 3; if((facility < LOG_KERN) || (facility > LOG_FTP && facility < LOG_LOCAL0) || (facility > LOG_LOCAL7)) { fprintf(stderr, "Error, option -s has invalid logging facility %d", logfacility); usage(); } logfacility = facility; } else { fprintf(stderr, "Error: option -s requires a numeric argument!\n"); usage(); } break; case 't': ttype = optarg; do_ttytype = 1; break; case 'u': if(isdigit(*optarg)) { unit_length = strtoul(optarg, NULL, 10); if(unit_length < ULSRC_CMDLMIN) unit_length = ULSRC_CMDLMIN; else if(unit_length > ULSRC_CMDLMAX) unit_length = ULSRC_CMDLMAX; got_unitlen = 1; } else { fprintf(stderr, "Error: option -T requires a numeric argument!\n"); usage(); } break; case '?': default: usage(); break; } } #ifdef DEBUG if(!do_debug) debug_noscreen = 0; #endif if(!do_print) { umask(UMASK); /* set our umask ... */ init_log(); /* initialize the logging subsystem */ } check_pid(); /* check if we are already running */ if(!do_print) { if(do_fork || (do_fullscreen && do_rdev)) /* daemon mode ? */ daemonize(); write_pid(); /* write our pid to file */ /* set signal handler(s) */ signal(SIGCHLD, sigchild_handler); /* process handling */ signal(SIGHUP, rereadconfig); /* reread configuration */ signal(SIGUSR1, reopenfiles); /* reopen acct/log files*/ signal(SIGPIPE, SIG_IGN); /* handled manually */ signal(SIGINT, do_exit); /* clean up on SIGINT */ signal(SIGTERM, do_exit); /* clean up on SIGTERM */ signal(SIGQUIT, do_exit); /* clean up on SIGQUIT */ } /* open isdn device */ if((isdnfd = open(I4BDEVICE, O_RDWR)) < 0) { dolog(LL_ERR, "main: cannot open %s: %s", I4BDEVICE, strerror(errno)); exit(1); } /* check kernel and userland have same version/release numbers */ if((ioctl(isdnfd, I4B_VR_REQ, &mvr)) < 0) { dolog(LL_ERR, "main: ioctl I4B_VR_REQ failed: %s", strerror(errno)); do_exit(1); } if(mvr.version != VERSION) { dolog(LL_ERR, "main: version mismatch, kernel %d, daemon %d", mvr.version, VERSION); do_exit(1); } if(mvr.release != REL) { dolog(LL_ERR, "main: release mismatch, kernel %d, daemon %d", mvr.release, REL); do_exit(1); } if(mvr.step != STEP) { dolog(LL_ERR, "main: step mismatch, kernel %d, daemon %d", mvr.step, STEP); do_exit(1); } /* init controller state array */ init_controller(); /* read runtime configuration file and configure ourselves */ configure(configfile, 0); if(config_error_flag) { dolog(LL_ERR, "there were %d error(s) in the configuration file, terminating!", config_error_flag); exit(1); } /* set controller ISDN protocol */ init_controller_protocol(); /* init active controllers, if any */ signal(SIGCHLD, SIG_IGN); /*XXX*/ init_active_controller(); signal(SIGCHLD, sigchild_handler); /*XXX*/ /* handle the rates stuff */ if((i = readrates(ratesfile)) == ERROR) { if(rate_error != NULL) dolog(LL_ERR, "%s", rate_error); exit(1); } if(i == GOOD) { got_rate = 1; /* flag, ratesfile read and ok */ DBGL(DL_RCCF, (dolog(LL_DBG, "ratesfile %s read successfully", ratesfile))); } else { if(rate_error != NULL) dolog(LL_WRN, "%s", rate_error); } /* if writing accounting info, open file, set unbuffered */ if(useacctfile) { if((acctfp = fopen(acctfile, "a")) == NULL) { dolog(LL_ERR, "ERROR, can't open acctfile %s for writing, terminating!", acctfile); exit(1); } setvbuf(acctfp, NULL, _IONBF, 0); } /* initialize alias processing */ if(aliasing) init_alias(aliasfile); /* init holidays */ init_holidays(holidayfile); /* init remote monitoring */ #ifdef I4B_EXTERNAL_MONITOR if(do_monitor) { monitor_init(); sockfd = monitor_create_local_socket(); #ifndef I4B_NOTCPIP_MONITOR remotesockfd = monitor_create_remote_socket(monitorport); #endif } #endif /* in case fullscreendisplay, initialize */ #ifdef USE_CURSES if(do_fullscreen) { init_screen(); } #endif /* init realtime priority */ #ifdef USE_RTPRIO if(rt_prio != RTPRIO_NOTUSED) { struct rtprio rtp; rtp.type = RTP_PRIO_REALTIME; rtp.prio = rt_prio; if((rtprio(RTP_SET, getpid(), &rtp)) == -1) { dolog(LL_ERR, "rtprio failed: %s", strerror(errno)); do_exit(1); } } #endif starttime = time(NULL); /* get starttime */ srandom(580403); /* init random number gen */ mloop( /* enter loop of no return .. */ #ifdef I4B_EXTERNAL_MONITOR sockfd #ifndef I4B_NOTCPIP_MONITOR , remotesockfd #endif #endif ); do_exit(0); return(0); }
void XboxdrvMain::run() { m_controller = create_controller(); m_controller->set_disconnect_cb(boost::bind(&XboxdrvMain::on_controller_disconnect, this)); init_controller(m_controller); if (m_opts.instant_exit) { usleep(1000); } else { ControllerSlotConfigPtr config_set; if (m_opts.no_uinput) { if (!m_opts.quiet) { std::cout << "Starting without uinput" << std::endl; } } else { log_debug("creating UInput"); m_uinput.reset(new UInput(m_opts.extra_events)); m_uinput->set_device_names(m_opts.uinput_device_names); m_uinput->set_device_usbids(m_opts.uinput_device_usbids); log_debug("creating ControllerSlotConfig"); config_set = ControllerSlotConfig::create(*m_uinput, 0, m_opts.extra_devices, m_opts.get_controller_slot()); // After all the ControllerConfig registered their events, finish up // the device creation log_debug("finish UInput creation"); m_uinput->finish(); } if (!m_opts.quiet) { std::cout << "\nYour Xbox/Xbox360 controller should now be available as:" << std::endl << " /dev/input/js" << m_jsdev_number << std::endl << " /dev/input/event" << m_evdev_number << std::endl; if (m_opts.silent) { std::cout << "\nPress Ctrl-c to quit" << std::endl; } else { std::cout << "\nPress Ctrl-c to quit, use '--silent' to suppress the event output" << std::endl; } } { ControllerThread thread(m_controller, config_set, m_opts); log_debug("launching thread"); pid_t pid = 0; if (!m_opts.exec.empty()) { pid = spawn_exe(m_opts.exec); g_child_watch_add(pid, &XboxdrvMain::on_child_watch_wrap, this); } log_debug("launching main loop"); g_main_loop_run(m_gmain); m_controller.reset(); } if (!m_opts.quiet) { std::cout << "Shutdown complete" << std::endl; } } }
int main(int argc, char **argv) { int option_index = 0; if (argc < 2) { show_help(argv); return EXIT_FAILURE; } gru_status_t status = gru_status_new(); options_t *options = options_new(&status); if (!options) { fprintf(stderr, "Unable to create options object: %s", status.message); return EXIT_FAILURE; } set_options_object(options); gru_logger_set(gru_logger_timed_printer); while (1) { static struct option long_options[] = {{"log-level", required_argument, 0, 'l'}, {"log-dir", required_argument, 0, 'L'}, {"maestro-url", required_argument, 0, 'm'}, {"name", required_argument, 0, 'n'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; int c = getopt_long(argc, argv, "l:L:m:n:h", long_options, &option_index); if (c == -1) { break; } switch (c) { case 'l': options_set_log_level(options, optarg); break; case 'L': if (!options_set_logdir(options, optarg)) { fprintf(stderr, "Unable to allocate memory for setting the log directory\n"); goto err_exit; } break; case 'm': if (!options_set_maestro_uri(options, optarg, &status)) { fprintf(stderr, "%s\n", status.message); goto err_exit; } break; case 'n': if (!options_set_name(options, optarg)) { fprintf(stderr, "Unable to allocate memory for setting the node name\n"); goto err_exit; } break; case 'h': show_help(argv); options_destroy(&options); return EXIT_SUCCESS; default: printf("Invalid or missing option\n"); show_help(argv); options_destroy(&options); return EXIT_FAILURE; } } if (!options_get_log_dir()) { fprintf(stderr, "Log directory is mandatory for the sender daemon\n"); goto err_exit; } if (!gru_path_mkdirs(options_get_log_dir(), &status)) { fprintf(stderr, "Unable to create log directory: %s\n", status.message); goto err_exit; } if (!options_get_maestro_host()) { fprintf(stderr, "Maestro host is mandatory for the sender daemon\n"); goto err_exit; } int cret = init_controller(options_get_log_dir(), "mpt-sender-daemon"); if (cret == 0) { if (senderd_worker_start(options) != 0) { logger_t logger = gru_logger_get(); logger(GRU_ERROR, "Unable to start the sender worker"); goto err_exit; } #ifdef __linux__ fcloseall(); #endif options_destroy(&options); return EXIT_SUCCESS; } if (cret > 0) { options_destroy(&options); return EXIT_SUCCESS; } err_exit: options_destroy(&options); return EXIT_FAILURE; }
void setup(){ init_ros(); init_imu(); init_controller(); init_encoder(); }
int main(int argc, char *argv[]) { int j; pthread_t thrd1, thrd2; int ret; int retval; char keyerbuff[3]; char tlfversion[80] = ""; int status; while ((argc > 1) && (argv[1][0] == '-')) { switch (argv[1][1]) { /* verbose option */ case 'f': if (strlen(argv[1] + 2) > 0) { if ((*(argv[1] + 2) == '~') && (*(argv[1] + 3) == '/')) { /* tilde expansion */ config_file = g_strconcat( g_get_home_dir(), argv[1] + 3, NULL); } else { config_file = g_strdup(argv[1] + 2); } } break; case 's': if (strlen(argv[1] + 2) > 0) strcpy(synclogfile, argv[1] + 2); break; case 'd': // debug rigctl debugflag = 1; break; case 'v': // verbose startup verbose = 1; break; case 'V': // output version printf("Version: tlf-%s\n", VERSION); exit(0); break; case 'n': // output version nopacket = 1; break; default: printf("Use: tlf [-v] Verbose\n"); printf(" [-V] Version\n"); printf(" [-f] Configuration file\n"); printf(" [-d] Debug mode\n"); printf(" [-h] This message\n"); printf(" [-n] Start without cluster hookup\n"); exit(0); break; } --argc; ++argv; } buffer[0] = '\0'; buffer[79] = '\0'; bufloc = 0; strcat(logline0, backgrnd_str); strcat(logline1, backgrnd_str); strcat(logline2, backgrnd_str); strcat(logline3, backgrnd_str); strcat(logline4, backgrnd_str); strcat(terminal1, backgrnd_str); strcat(terminal2, backgrnd_str); strcat(terminal3, backgrnd_str); strcat(terminal4, backgrnd_str); termbuf[0] = '\0'; hiscall[0] = '\0'; /* getting users terminal string and (if RXVT) setting rxvt colours on it */ /* LZ3NY hack :) */ if (strcasecmp(getenv("TERM"), "rxvt") == 0) { use_rxvt = 1; printf("terminal is:%s", getenv("TERM")); } else if (strcasecmp(getenv("TERM"), "xterm") == 0) { use_xterm = 1; use_rxvt = 1; } else putenv("TERM=rxvt"); /*or going to native console linux driver */ if ((mainscreen = newterm(NULL, stdout, stdin)) == NULL) { /* activate ncurses terminal control */ perror("initscr"); printf ("\n Sorry, wrong terminal type !!!!! \nTry a linux text terminal or set TERM=linux !!!"); sleep(5); exit(EXIT_FAILURE); } //keypad(stdscr,TRUE); InitSearchPanel(); /* at least one panel has to be defined for refreshp() to work */ getmaxyx(stdscr, ymax, xmax); if ((ymax < 25) || (xmax < 80)) { char c; showmsg( "!! TLF needs at least 25 lines and 80 columns !!"); showmsg( " Continue anyway? Y/(N)" ); c = toupper( getch() ); if (c != 'Y') { showmsg( "73 es cuagn" ); sleep(1); endwin(); exit(1); } showmsg(""); } noecho(); crmode(); strcpy(sp_return, message[12]); strcpy(cq_return, message[13]); refreshp(); if (has_colors()) { if (start_color() == ERR) { perror("start_color"); endwin(); printf ("\n Sorry, wrong terminal type !!!!! \n\nTry a linux text terminal or set TERM=linux !!!"); sleep(5); exit(EXIT_FAILURE); } sprintf(tlfversion, " Welcome to tlf-%s by PA0R!!" , VERSION); showmsg(tlfversion); showmsg(""); showmsg("reading country data"); readctydata(); /* read ctydb.dat */ showmsg("reading configuration data"); status = read_logcfg(); /* read the configuration file */ status |= read_rules(); /* read the additional contest rules in "rules/contestname" LZ3NY */ if (status != PARSE_OK) { showmsg( "Problems in logcfg.dat or rule file detected! Continue Y/(N)?"); if (toupper( getchar() ) != 'Y') { endwin(); exit(1); } } /* make sure logfile is there and has the right format */ if (checklogfile_new(logfile) != 0) { showmsg( "Giving up" ); sleep(2); endwin(); exit(1); } // if (strlen(synclogfile) > 0) // synclog(synclogfile); if (*call == '\0') { showmsg ("WARNING: No callsign defined in logcfg.dat! exiting...\n\n\n"); exit(1); } if (use_rxvt == 1) { // use rxvt colours init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_RED); if (use_xterm == 1) { init_pair(C_HEADER, COLOR_GREEN, COLOR_BLUE); init_pair(COLOR_RED, COLOR_WHITE, 8); init_pair(C_WINDOW, COLOR_CYAN, COLOR_MAGENTA); init_pair(C_DUPE, COLOR_WHITE, COLOR_MAGENTA); init_pair(C_INPUT, COLOR_BLUE, COLOR_WHITE); } else { init_pair(C_HEADER, COLOR_GREEN, COLOR_YELLOW); init_pair(COLOR_RED, COLOR_WHITE, COLOR_RED); init_pair(C_WINDOW, COLOR_CYAN, COLOR_RED); init_pair(C_DUPE, COLOR_RED, COLOR_MAGENTA); init_pair(C_INPUT, COLOR_BLUE, COLOR_YELLOW); } init_pair(C_LOG, COLOR_WHITE, COLOR_BLACK); init_pair(C_BORDER, COLOR_CYAN, COLOR_YELLOW); } else { // use linux console colours init_pair(COLOR_BLACK, tlfcolors[0][0], tlfcolors[0][1]); // b/w init_pair(C_HEADER, tlfcolors[1][0], tlfcolors[1][1]); // Gn/Ye init_pair(COLOR_RED, tlfcolors[2][0], tlfcolors[2][1]); // W/R init_pair(C_WINDOW, tlfcolors[3][0], tlfcolors[3][1]); // Cy/W init_pair(C_LOG, tlfcolors[4][0], tlfcolors[4][1]); // W/B init_pair(C_DUPE, tlfcolors[5][0], tlfcolors[5][1]); // W/Mag init_pair(C_INPUT, tlfcolors[6][0], tlfcolors[6][1]); // Bl/Y init_pair(C_BORDER, tlfcolors[7][0], tlfcolors[7][1]); // W/B } mults_possible = g_ptr_array_new(); if (multlist == 1) { showmsg("reading multiplier data "); load_multipliers(); } attron(COLOR_PAIR(COLOR_BLACK)); showmsg("reading callmaster data"); nr_callmastercalls = load_callmaster(); if (*exchange_list != '\0') { // read initial exchange file main_ie_list = make_ie_list(exchange_list); if (main_ie_list == NULL) { showmsg( "Problems in initial exchange file detected! Continue Y/(N)?"); if (toupper( getchar() ) != 'Y') { endwin(); exit(1); } else { showmsg( "Initial exchange data not loaded! Continuing ..."); sleep(2); } } } #ifdef HAVE_LIBHAMLIB // Code for hamlib interface showmsg("HAMLIB defined"); if (trx_control != 0) { shownr("Rignumber is", (int) myrig_model); shownr("Rig speed is", serial_rate); showmsg("Trying to start rig ctrl"); /** \todo fix exclusion of newer hamlib models */ if ((int) myrig_model > 1999) status = init_native_rig(); else status = init_tlf_rig(); } #else if (trx_control != 0) { // trx_control = 0; showmsg("No Hamlib library, using native driver"); shownr("Rignumber is", rignumber); shownr("Rig speed is", serial_rate); status = init_native_rig(); sleep(1); } #endif // end code for hamlib interface if (status != 0) { showmsg( "Continue without rig control Y/(N)?"); if (toupper( getchar() ) != 'Y') { endwin(); exit(1); } trx_control = 0; showmsg( "Disabling rig control!"); sleep(1); } if (keyerport == NET_KEYER) { showmsg("Keyer is cwdaemon"); } if (keyerport == MFJ1278_KEYER || keyerport == GMFSK) { init_controller(); } if (lan_active == 1) { retval = lanrecv_init(); if (retval < 0) /* set up the network */ shownr("LAN receive init failed", retval); else showmsg("LAN receive initialized"); if (lan_send_init() < 0) showmsg("LAN send init failed"); else showmsg("LAN send initialized"); } checkparameters(); /* check .paras file */ clear(); mvprintw(0, 0, " Welcome to tlf-%s by PA0R!!\n\n" , VERSION); refreshp(); getmessages(); /* read .paras file */ if (nopacket == 1) packetinterface = 0; set_term(mainscreen); refreshp(); if ((nopacket == 0) && (packetinterface != 0)) { if (init_packet() == 0) packet(); else cleanup_telnet(); } if (keyerport == NET_KEYER) { if (netkeyer_init() < 0) { mvprintw(24, 0, "Cannot open NET keyer daemon "); refreshp(); sleep(1); } else { netkeyer(K_RESET, "0"); sprintf(weightbuf, "%d", weight); write_tone(); snprintf(keyerbuff, 3, "%2d", GetCWSpeed()); netkeyer(K_SPEED, keyerbuff); // set speed netkeyer(K_WEIGHT, weightbuf); // set weight if (*keyer_device != '\0') netkeyer(K_DEVICE, keyer_device); // set device sprintf(keyerbuff, "%d", txdelay); netkeyer(K_TOD, keyerbuff); // set TOD if (sc_sidetone != 0) // set soundcard output netkeyer(K_SIDETONE, ""); if (*sc_volume != '\0') // set soundcard volume netkeyer(K_STVOLUME, sc_volume); } if (keyerport != NET_KEYER) write_tone(); } getwwv(); /* get the latest wwv info from packet */ scroll_log(); /* read the last 5 log lines and set the qso number */ nr_qsos = readcalls(); /* read the logfile for score and dupe */ clear_display(); /* tidy up the display */ qrb(); attron(COLOR_PAIR(C_LOG) | A_STANDOUT); for (j = 13; j <= 23; j++) { /* wipe lower window */ mvprintw(j, 0, backgrnd_str); } bm_init(); /* initialize bandmap */ /* Create the first thread */ ret = pthread_create(&thrd1, NULL, (void *) logit, NULL); if (ret) { perror("pthread_create: logit"); endwin(); exit(EXIT_FAILURE); } /* Create the second thread */ ret = pthread_create(&thrd2, NULL, (void *) background_process, NULL); if (ret) { perror("pthread_create: backgound_process"); endwin(); exit(EXIT_FAILURE); } pthread_join(thrd2, NULL); pthread_join(thrd1, NULL); endwin(); exit(EXIT_SUCCESS); } else { printf("Terminal does not support color\n"); printf("\nTry TERM=linux or use a text console !!\n"); refreshp(); sleep(2); } cleanup_telnet(); if (trxmode == CWMODE && keyerport == NET_KEYER) netkeyer_close(); else close(cfd); /* close keyer */ endwin(); return (0); }