int saveSettings() { int res = 0; //char temp[100]; char iniFilePath[MAX_FILE_NAME_LEN]; FILE* configFile; // Save the configuration data XPLMGetSystemPath(iniFilePath); strcat(iniFilePath, "Resources\\plugins\\" PLUGIN_NAME "\\" PLUGIN_NAME ".ini"); configFile = fopen(iniFilePath, "w+t"); if(NULL == configFile) { logMessageEx("*** Error saving configuration data"); return -1; } fprintf(configFile, "%s\n", "[" INI_SECTION_POSITION "]"); fprintf(configFile, "x=%d\n", g_pos_x); fprintf(configFile, "y=%d\n", g_pos_y); fprintf(configFile, "zoom=%f\n", g_zoom); fclose(configFile); logMessageEx("--- Configuration data saved"); return res; }
int loadSettings() { int res = 0; char iniFilePath[MAX_FILE_NAME_LEN]; // Load the configuration data XPLMGetSystemPath(iniFilePath); strcat(iniFilePath, "Resources\\plugins\\" PLUGIN_NAME "\\" PLUGIN_NAME ".ini"); // Read data from ini file CIniReader configReader(iniFilePath); logMessageEx("--- Configuration data loaded"); g_pos_x = configReader.ReadInteger(INI_SECTION_POSITION, "x", 0); g_pos_y = configReader.ReadInteger(INI_SECTION_POSITION, "y", 0); g_zoom = configReader.ReadFloat(INI_SECTION_POSITION, "zoom", 100); logMessageEx("--- x=%d", g_pos_x); logMessageEx("--- y=%d", g_pos_y); logMessageEx("--- zoom=%f", g_zoom); return res; }
int openLogFile() { int res = 0; char outputPath[MAX_FILE_NAME_LEN]; // Open the plugin's log file XPLMGetSystemPath(outputPath); strcat(outputPath, "Resources\\plugins\\" PLUGIN_NAME "\\" PLUGIN_NAME ".log"); logInit(outputPath); return res; }
PLUGIN_API int XPluginStart( char * outName, char * outSig, char * outDesc) { char outputPath[255]; strcpy(outName, "TimedProcessing"); strcpy(outSig, "xplanesdk.examples.timedprocessing"); strcpy(outDesc, "A plugin that records sim data."); vis_amount = 5000; /* Open a file to write to. We locate the X-System directory * and then concatenate our file name. This makes us save in * the X-System directory. Open the file. */ XPLMGetSystemPath(outputPath); strcat(outputPath, "TimedProcessing.txt"); gOutputFile = fopen(outputPath, "w"); /* Find the data refs we want to record. */ gPlaneLat = XPLMFindDataRef("sim/flightmodel/position/latitude"); gPlaneLon = XPLMFindDataRef("sim/flightmodel/position/longitude"); gPlaneEl = XPLMFindDataRef("sim/flightmodel/position/elevation"); gPlaneVis = XPLMFindDataRef("sim/weather/visibility_reported_m"); /* Register our callback for once a second. Positive intervals * are in seconds, negative are the negative of sim frames. Zero * registers but does not schedule a callback for time. */ XPLMRegisterFlightLoopCallback( MyFlightLoopCallback, /* Callback */ 1.0, /* Interval */ NULL); /* refcon not used. */ return 1; }
void XSATouchNavDB(const d_XSAWorldPoint point) { static const char delim[] = "|"; static FILE *f = NULL; static char file_dlm[1024]; static bool init = true; static bool nav_db_load = false; static bool usgs_db_load = false; static bool report = false; static int report_load_dbnav = 0; static int report_alloc_node = 0; static int report_alloc_link = 0; static XPLMNavRef navref_current = XPLM_NAV_NOT_FOUND; static node_navinfo* ptr_navlist = NULL; static navinfo_t navinfo; static int id = 0; if (init) { navlist = (node_navinfo*) malloc(sizeof (node_navinfo)); memset(navlist, 0, sizeof (node_navinfo)); ptr_navlist = navlist; XPLMGetSystemPath(file_dlm); strcat(file_dlm, "xdata.dlm"); f = fopen(file_dlm, "r"); if (!f) { XPLMDebugString("xdata.dlm file not found.\n"); } init = false; XPLMDebugString("init()\n"); } if (XSADistance(point, db_center, 'N') > 30.0) { XPLMDebugString("XSATouchNavDB : (re)set center\n"); report = true; report_load_dbnav = 0; if (nav_db_load) { nav_db_load = false; navref_current = XPLM_NAV_NOT_FOUND; } if (usgs_db_load) { usgs_db_load = false; } if (!nav_db_load && !usgs_db_load) { report = true; id = 0; ptr_navlist = navlist; nav_db_load = true; if (f) { fseek(f, 0, SEEK_SET); usgs_db_load = true; } db_center.lat = point.lat; db_center.lon = point.lon; XPLMDebugString("db_load start\n"); } } int loop = 0; while ((nav_db_load || usgs_db_load) && loop < 100) { loop++; // XPLMDebugString("ptr_navlist->node\n"); if (!ptr_navlist->node) { ptr_navlist->node = (navinfo_t*) malloc(sizeof (navinfo_t)); memset(ptr_navlist->node, 0, sizeof (navinfo_t)); report_alloc_node++; } // XPLMDebugString("ptr_navlist->next\n"); if (!ptr_navlist->next) { ptr_navlist->next = (node_navinfo*) malloc(sizeof (node_navinfo)); memset(ptr_navlist->next, 0, sizeof (node_navinfo)); report_alloc_link++; ptr_navlist->next->node = NULL; } memset(&navinfo, 0, sizeof (navinfo_t)); id++; navinfo.dbid = id; if (nav_db_load) { // XPLMDebugString("nav_db_load\n"); if (navref_current == XPLM_NAV_NOT_FOUND) { navref_current = XPLMGetFirstNavAid(); } else { navref_current = XPLMGetNextNavAid(navref_current); } if (navref_current == XPLM_NAV_NOT_FOUND) { nav_db_load = false; XPLMDebugString("nav_db_load done.\n"); continue; } XSALoadNavRef(navref_current, &navinfo); navinfo.ref = navref_current; if (navinfo.xsaType == xsaNavTypeUnknown) { continue; } d_XSAWorldPoint nav_point; nav_point.lat = navinfo.lat; nav_point.lon = navinfo.lon; if (XSADistance(nav_point, db_center, 'N') < 50.0) { // XPLMDebugString("found navdb point\n"); memcpy(ptr_navlist->node, &navinfo, sizeof (navinfo_t)); report_load_dbnav++; ptr_navlist = ptr_navlist->next; // char s[1024]; // sprintf(s,"XSATouchNavDB() : loaded navdb name : %s\n",navinfo.name); // XPLMDebugString(s); } } // nav_db_load if (!nav_db_load && usgs_db_load) { char s[1024]; fgets(s, sizeof (s), f); if (feof(f)) { // close things up fseek(f, 0, SEEK_SET); usgs_db_load = false; XPLMDebugString("nav_db_load done.\n"); continue; } s[strlen(s) - 1] = '\0'; char* layer = strtok(s, delim); navinfo.lat = atof(strtok(NULL, delim)); navinfo.lon = atof(strtok(NULL, delim)); d_XSAWorldPoint nav_point; nav_point.lat = navinfo.lat; nav_point.lon = navinfo.lon; if (XSADistance(nav_point, db_center, 'N') < 50.0) { navinfo.height = atof(strtok(NULL, delim)); navinfo.xsaType = xsaNavTypeUnknown; switch (atoi(strtok(NULL, delim))) { case 21: navinfo.xsaType = xsaNavTypeUSGSMunicipal; break; case 22: navinfo.xsaType = xsaNavTypeUSGSTerrain; break; case 23: navinfo.xsaType = xsaNavTypeUSGSCivil; break; } strcpy(navinfo.id, strtok(NULL, delim)); strcpy(navinfo.name, strtok(NULL, delim)); // for(int idx = 0;idx < strlen(navinfo.name);idx++) { // if(navinfo.name[idx] < 0x20 || navinfo.name[idx] > 0x7E) { // memset(navinfo.name,0,sizeof(navinfo.name)); // navinfo.name[0] = '\0'; // } // } memcpy(ptr_navlist->node, &navinfo, sizeof (navinfo_t)); report_load_dbnav++; ptr_navlist = ptr_navlist->next; // char s[1024]; // sprintf(s,"XSATouchNavDB() : loaded usgs db name %s\n",navinfo.name); // XPLMDebugString(s); } // usgs in range } // usgs_db_load } // while if (!nav_db_load && !usgs_db_load && report) { // do report here char s[1024]; sprintf(s, "loaded %i, nodes %i, links %i\n", report_load_dbnav, report_alloc_node, report_alloc_link); XPLMDebugString(s); report = false; } }