Exemple #1
0
int main(int argc, char **argv)
{
    int c = 0;
    int become_daemon = 1;
    int config_loaded = 0;
    config_t config;
    char *pidfile = NULL;

    opterr = 0;
    while ((c = getopt(argc, argv, "sc:p:")) != -1) {
        switch (c) {
            case 's':
                become_daemon = 0;
                break;
            case 'c':
                loadConfig(&config, optarg);
                config_loaded = 1;
                break;
            case 'p':
                pidfile = malloc(strlen(optarg) + 1);
                strcpy(pidfile, optarg);
                break;
            case 'h':
                printUsage();
                exit(0);
                break;
            case '?':
                printUsage();
                exit(EXIT_FAILURE);
                break;
            default:
                exit(EXIT_FAILURE);
        }
    }

    if (signal(SIGTERM, catch_signal) == SIG_ERR) {
        logError("Error while setting SIGTERM handler.\n");
        exit(EXIT_FAILURE);
    }

    if (become_daemon) {
        becomeDaemon();
    }

    if (pidfile != NULL) {
        writePID(pidfile);
        free(pidfile);
        pidfile = NULL;
    }


    if (!config_loaded) {
        loadConfig(&config, DEFAULT_CONFIG);
    }

    monitor(&config);

    exit(EXIT_SUCCESS);
}
Exemple #2
0
void writeEEPROM(){
  cli(); // Needed so that APM sensor data does not overflow
  writePID(XAXIS, ROLL_PID_GAIN_ADR);
  writePID(YAXIS, PITCH_PID_GAIN_ADR);
  writePID(ATTITUDE_XAXIS_PID_IDX, LEVELROLL_PID_GAIN_ADR);
  writePID(ATTITUDE_YAXIS_PID_IDX, LEVELPITCH_PID_GAIN_ADR);
  writePID(ZAXIS, YAW_PID_GAIN_ADR);
  writePID(HEADING_HOLD_PID_IDX, HEADING_PID_GAIN_ADR);
  writePID(ATTITUDE_GYRO_XAXIS_PID_IDX, LEVEL_GYRO_ROLL_PID_GAIN_ADR);
  writePID(ATTITUDE_GYRO_YAXIS_PID_IDX, LEVEL_GYRO_PITCH_PID_GAIN_ADR);
  
  writeFloat(rotationSpeedFactor,ROTATION_SPEED_FACTOR_ARD);
  
  #if defined AltitudeHoldBaro
    writePID(BARO_ALTITUDE_HOLD_PID_IDX, ALTITUDE_PID_GAIN_ADR);
    writeFloat(PID[BARO_ALTITUDE_HOLD_PID_IDX].windupGuard, ALTITUDE_WINDUP_ADR);
  #endif

  #if defined AltitudeHoldBaro || defined AltitudeHoldRangeFinder
    #if defined AltitudeHoldBaro
      writeFloat(baroSmoothFactor, ALTITUDE_SMOOTH_ADR);
    #else
      writeFloat(0.0, ALTITUDE_SMOOTH_ADR);
    #endif
    writeFloat(altitudeHoldBump, ALTITUDE_BUMP_ADR);
    writeFloat(altitudeHoldPanicStickMovement, ALTITUDE_PANIC_ADR);
    writeFloat(minThrottleAdjust, ALTITUDE_MIN_THROTTLE_ADR);
    writeFloat(maxThrottleAdjust, ALTITUDE_MAX_THROTTLE_ADR);
    writePID(ZDAMPENING_PID_IDX, ZDAMP_PID_GAIN_ADR);
  #else
    writeFloat(0.1, ALTITUDE_SMOOTH_ADR);
    writeFloat(90, ALTITUDE_BUMP_ADR);
    writeFloat(250, ALTITUDE_PANIC_ADR);
    writeFloat(-50, ALTITUDE_MIN_THROTTLE_ADR);
    writeFloat(50, ALTITUDE_MAX_THROTTLE_ADR);
    writeFloat(0.1, ALTITUDE_SMOOTH_ADR);
  #endif
  
  #ifdef HeadingMagHold
    writeFloat(magBias[XAXIS], XAXIS_MAG_BIAS_ADR);
    writeFloat(magBias[YAXIS], YAXIS_MAG_BIAS_ADR);
    writeFloat(magBias[ZAXIS], ZAXIS_MAG_BIAS_ADR);
  #endif
  writeFloat(windupGuard, WINDUPGUARD_ADR);
  writeFloat(receiverXmitFactor, XMITFACTOR_ADR);

	byte channel;
  for(channel = XAXIS; channel < LASTCHANNEL; channel++) {
    writeFloat(receiverSlope[channel],  RECEIVER_DATA[channel].slope);
    writeFloat(receiverOffset[channel], RECEIVER_DATA[channel].offset);
    writeFloat(receiverSmoothFactor[channel], RECEIVER_DATA[channel].smooth_factor);
  }

  writeFloat(minArmedThrottle, MINARMEDTHROTTLE_ADR);
  writeFloat(aref, AREF_ADR);
  writeFloat(flightMode, FLIGHTMODE_ADR);
  writeFloat(headingHoldConfig, HEADINGHOLD_ADR);
  writeFloat(accelOneG, ACCEL_1G_ADR);
  writeFloat(SOFTWARE_VERSION, SOFTWARE_VERSION_ADR);
  
  // Battery Monitor
  #ifdef BattMonitor
    writeFloat(batteryMonitorAlarmVoltage, BATT_ALARM_VOLTAGE_ADR);
    writeFloat(batteryMonitorThrottleTarget, BATT_THROTTLE_TARGET_ADR);
    writeFloat(batteryMonitorGoingDownTime, BATT_DOWN_TIME_ADR);
  #endif

  // Range Finder
  #if defined (AltitudeHoldRangeFinder)
    writeFloat(maxRangeFinderRange, RANGE_FINDER_MAX_ADR);
    writeFloat(minRangeFinderRange, RANGE_FINDER_MIN_ADR);
  #else
    writeFloat(0, RANGE_FINDER_MAX_ADR);
    writeFloat(0, RANGE_FINDER_MIN_ADR);
  #endif
  
  #if defined (UseGPSNavigator)
    writeFloat(missionNbPoint, GPS_MISSION_NB_POINT_ADR);
    writePID(GPSROLL_PID_IDX, GPSROLL_PID_GAIN_ADR);
    writePID(GPSPITCH_PID_IDX, GPSPITCH_PID_GAIN_ADR);
    writePID(GPSYAW_PID_IDX, GPSYAW_PID_GAIN_ADR);
    
    for (byte location = 0; location < MAX_WAYPOINTS; location++) {
      writeLong(waypoint[location].longitude, WAYPOINT_ADR[location].longitude);
      writeLong(waypoint[location].latitude, WAYPOINT_ADR[location].latitude);
      writeLong(waypoint[location].altitude, WAYPOINT_ADR[location].altitude);
    }       
  #endif

    // Camera Control
  #ifdef CameraControl
    writeFloat(cameraMode, CAMERAMODE_ADR);
    writeFloat(mCameraPitch, MCAMERAPITCH_ADR);
    writeFloat(mCameraRoll, MCAMERAROLL_ADR);    
    writeFloat(mCameraYaw, MCAMERAYAW_ADR);
    writeFloat(servoCenterPitch, SERVOCENTERPITCH_ADR);
    writeFloat(servoCenterRoll, SERVOCENTERROLL_ADR);
    writeFloat(servoCenterYaw, SERVOCENTERYAW_ADR);
    writeFloat(servoMinPitch, SERVOMINPITCH_ADR);
    writeFloat(servoMinRoll, SERVOMINROLL_ADR);
    writeFloat(servoMinYaw, SERVOMINYAW_ADR);
    writeFloat(servoMaxPitch, SERVOMAXPITCH_ADR);
    writeFloat(servoMaxRoll, SERVOMAXROLL_ADR);
    writeFloat(servoMaxYaw, SERVOMAXYAW_ADR);
    #ifdef CameraTXControl
      writeFloat(servoTXChannels, SERVOTXCHANNELS_ADR);
    #endif
  #endif 
  sei(); // Restart interrupts
}
Exemple #3
0
void server(const char *bindAddr, int port, int ssl) {
    int soc_ec = -1, maxfd, res, nc;
    fd_set set_read;
    fd_set set_write;
    struct sockaddr_in addrS;
    char methods[2];

#ifdef _WIN32
    WSADATA wsaData;
    int wsaInit = WSAStartup(MAKEWORD(2,2), &wsaData);
    if (wsaInit != 0) {
        ERROR(L_NOTICE, "WSAStartup failed: %d\n", wsaInit);
        exit(1);
    }
#endif

    s_socks_conf conf;
    s_socks_server_config config;
    conf.config.srv = &config;

    char versions[] = { SOCKS5_V,
                        SOCKS4_V
                      };

    config.allowed_version = versions;
    config.n_allowed_version = sizeof(versions);

    if ( globalArgsServer.fileauth[0] != 0 ) {
        methods[0] = 0x02;
        --config.n_allowed_version; /* Disable socks4 don't support auth */
    } else {
        methods[0] = 0x00;
    }


    config.allowed_method = methods;
    config.n_allowed_method = 1;
    config.check_auth = check_auth;

    /* Init client tab */
    for (nc = 0; nc < MAXCLI; nc++)
        init_client (&tc[nc], nc, M_SERVER, &conf);

    if(bindAddr[0] == 0)
        soc_ec = new_listen_socket (NULL, port, 0, &addrS);
    else
        soc_ec = new_listen_socket (bindAddr, port, 0, &addrS);

    if (soc_ec < 0) goto fin_serveur;


#ifndef _WIN32
    if ( globalArgsServer.daemon == 1 ) {
        TRACE(L_NOTICE, "server: mode daemon ...");
        if ( daemon(0, 0) != 0 ) {
            perror("daemon");
            exit(1);
        }
        writePID(PID_FILE);
    }

    bor_signal (SIGINT, capte_fin, SA_RESTART);

    /* Need in daemon to remove the PID file properly */
    bor_signal (SIGTERM, capte_fin, SA_RESTART);
    bor_signal (SIGPIPE, capte_sigpipe, SA_RESTART);
    /* TODO: Find a better way to exit the select and recall the init_select
     * SIGUSR1 is send by a thread to unblock the select */
    bor_signal (SIGUSR1, capte_usr1, SA_RESTART);
#endif

    while (boucle_princ) {
        init_select_server (soc_ec, tc, &maxfd, &set_read, &set_write);

        res = select (maxfd+1, &set_read, &set_write, NULL, NULL);

        if (res > 0) { /* Search eligible sockets */

            if (FD_ISSET (soc_ec, &set_read))
                new_connection (soc_ec, tc, ssl);

            for (nc = 0; nc < MAXCLI; nc++) {
                dispatch_server(&tc[nc], &set_read, &set_write);
            }

        } else if ( res == 0) {

        } else if (res < 0) {
            if (errno == EINTR) ; /* Received signal, it does nothing */
            else {
                perror ("select");
                goto fin_serveur;
            }
        }
    }

fin_serveur:
#ifdef HAVE_LIBSSL
    if (globalArgsServer.ssl == 1)
        ssl_cleaning();
#endif
    TRACE(L_NOTICE, "server: closing sockets ...");
    close_log();
    for (nc = 0; nc < MAXCLI; nc++) disconnection(&tc[nc]);
    if (soc_ec != -1) CLOSE_SOCKET(soc_ec);
    if ( globalArgsServer.daemon == 1 )	removePID(PID_FILE);

#ifdef _WIN32
        WSACleanup();
#endif
}