Ejemplo n.º 1
0
void on_app_server_GET_CONFIG (IvyClientPtr app, void *user_data, int argc, char *argv[]) {

  int i=0;

  int RmId[2];
  /*
   * RmId[0] >> ProcessID of incoming MsgProcessId
   * RmId[1] >> RequestID of incoming MsgProcessId
   */

  //Split arg0 to get process id and request id
  char * mtok;
  mtok = strtok (argv[0],"_");
  while (mtok != NULL || i>2)
  {
    RmId[i]= atoi(mtok);
    i++;
    mtok = strtok (NULL, "_");
  }

  //Check whether process id and request id matches or not
  if ( RmId[0]== ProcessID && RmId[1] <= RequestID) {
    int inc_device_id=atoi(argv[1]);

    //Save Device Name
    strcpy(DevNames[inc_device_id].name, argv[7] );

    //Save color
    strcpy(DevNames[inc_device_id].color, argv[6]);

    //Save Flight Plan Path
    //check if file is local
    if ((strncmp( argv[2], "file://", strlen("file://"))) == 0) {
      sprintf(DevNames[inc_device_id].flight_plan_path, "%s", argv[2]+7);
    }
    else {
      printf("App Server: App server only works with local files! (Flight Plan Path:%s)\n", argv[2]);
      return;
    }

    //Save Airframe Path
    //check if file is local
    if ((strncmp( argv[3], "file://", strlen("file://"))) == 0) {
      sprintf(DevNames[inc_device_id].airframe_path, "%s", argv[3]+7);
    }
    else {
      printf("App Server: App server works only with local files! (Airframe Path:%s)\n", argv[3]);
      return;
    }

    //Save Settings Path
    //check if file is local
    if ((strncmp( argv[5], "file://", strlen("file://"))) == 0) {
      sprintf(DevNames[inc_device_id].settings_path, "%s", argv[5]+7);
    }
    else {
      printf("App Server: App server works only with local files! (Settings Path:%s)\n", argv[5]);
      return;
    }

    // Init some variables (-1 means no settings in xml file)
    DevNames[inc_device_id].dl_launch_ind = -1;
    DevNames[inc_device_id].kill_thr_ind = -1;
    DevNames[inc_device_id].flight_altitude_ind = -1;

    //Parse airframe files..
    parse_ac_af(inc_device_id, DevNames[inc_device_id].airframe_path);

    //Parse flight plan
    parse_ac_fp(inc_device_id, DevNames[inc_device_id].flight_plan_path);

    //Parse settings
    parse_ac_settings(inc_device_id, DevNames[inc_device_id].settings_path);

    if (verbose) {
      printf("%s configuration saved. : (Id: %d Color:%s)\n", DevNames[inc_device_id].name,inc_device_id, DevNames[inc_device_id].color);
      fflush(stdout);
      printf("\tFlight_P Path:\t %s \n", DevNames[inc_device_id].flight_plan_path);
      fflush(stdout);
      printf("\tAirframe Path:\t %s \n", DevNames[inc_device_id].airframe_path);
      fflush(stdout);
      printf("\tSettings Path:\t %s \n", DevNames[inc_device_id].settings_path);
      fflush(stdout);
    }
    //everything is awesome! AC data is ready to be served.

  }

}
Ejemplo n.º 2
0
//Parse ac data from conf.xml
void parse_ac_data (char *PprzFolder) {
  xmlTextReaderPtr reader;
  int ret;

  //Create full file path
  char xmlFileName[BUFLEN];
  strcpy(xmlFileName, PprzFolder);
  strcat(xmlFileName, "/conf/conf.xml");

  reader = xmlReaderForFile(xmlFileName, NULL, XML_PARSE_NOWARNING | XML_PARSE_NOERROR); /* Dont validate with the DTD */

  xmlChar *AcName, *AcInd, *FpPath, *AcColor, *name, *AfPath;
  if (reader != NULL) {
    ret = xmlTextReaderRead(reader);
    int AcId;

    while (ret == 1) {
      name = xmlTextReaderName(reader);
      if (name == NULL) {
        name = xmlStrdup(BAD_CAST "--");
      }
      //read waypoint names

      if (xmlStrEqual(name, (const xmlChar *)"aircraft")) {

        xmlTextReaderMoveToAttribute(reader,(const xmlChar *)"ac_id");
        AcInd = xmlTextReaderValue(reader);

        xmlTextReaderMoveToAttribute(reader,(const xmlChar *)"name");
        AcName = xmlTextReaderValue(reader);

        xmlTextReaderMoveToAttribute(reader,(const xmlChar *)"airframe");
        AfPath = xmlTextReaderValue(reader);

        xmlTextReaderMoveToAttribute(reader,(const xmlChar *)"flight_plan");
        FpPath = xmlTextReaderValue(reader);

        xmlTextReaderMoveToAttribute(reader,(const xmlChar *)"gui_color");
        AcColor = xmlTextReaderValue(reader);

        //Get Device Id
        AcId = atoi(((char *) AcInd));

        //Save Device Name
        strcpy(DevNames[AcId].name, ((char *) AcName));

        //Save color
        strcpy(DevNames[AcId].color, (char *) AcColor);

        //Save Flight Plan Path
        strcpy(DevNames[AcId].flight_plan_path, "/conf/");
        strcat(DevNames[AcId].flight_plan_path , (char *) FpPath);

        //Save airframe  Path
        strcpy(DevNames[AcId].airframe_path, "/conf/");
        strcat(DevNames[AcId].airframe_path , (char *) AfPath);

        //Save Settings Path
        sprintf(DevNames[AcId].settings_path, "/var/aircrafts/%s/settings.xml", (char *) AcName);

        //parse flight plan file for waypoint and block names
        char FlightPlanPath[BUFLEN];
        strcpy(FlightPlanPath, PprzFolder);
        strcat(FlightPlanPath, DevNames[AcId].flight_plan_path);
        parse_ac_fp(AcId, FlightPlanPath);

        //parse airframe file
        char AirframePath[BUFLEN];
        strcpy(AirframePath, PprzFolder);
        strcat(AirframePath, DevNames[AcId].airframe_path);
        parse_ac_af(AcId, AirframePath);

        //parse dl_settings for launch & kill throttle
        char SettingsPath[BUFLEN];
        strcpy(SettingsPath, PprzFolder);
        strcat(SettingsPath, DevNames[AcId].settings_path);
        parse_dl_settings(AcId, SettingsPath);
      }

      ret = xmlTextReaderRead(reader);
    }

    xmlFreeTextReader(reader);
    if (ret != 0) {
      if (verbose) {
        printf("App Server: failed to parse %s\n", xmlFileName);
        fflush(stdout);
      }
    }
  }
  else{
    if (verbose) {
      printf("App Server: Unable to open %s\n", xmlFileName);
      fflush(stdout);
    }
  }

  return;
} // end of XMLParseDoc function