/** * Opens XCSoars own FLARM details file, parses it and * adds its entries as FlarmLookupItems * @see AddFlarmLookupItem */ void OpenFLARMDetails() { StartupStore(TEXT("OpenFLARMDetails\n")); // if (FLARM Details already there) delete them; if (NumberOfFLARMNames) { CloseFLARMDetails(); } TCHAR filename[MAX_PATH]; LocalPath(filename, TEXT("xcsoar-flarm.txt")); FILE *file = _tfopen(filename, TEXT("rt")); if (file == NULL) return; TCHAR line[READLINE_LENGTH]; while (ReadStringX(file, READLINE_LENGTH, line)) { long id; TCHAR Name[MAX_PATH]; if (_stscanf(line, TEXT("%lx=%s"), &id, Name) == 2) { if (AddFlarmLookupItem(id, Name, false) == false) { break; // cant add anymore items ! } } } fclose(file); }
void OpenFLARMDetails() { static FlarmIdFile flarmidfile; file=&flarmidfile; LKASSERT(file!=NULL); StartupStore(_T(". FLARMNET database, found %d IDs%s"),FlarmNetCount,NEWLINE); if (NumberOfFLARMNames) { CloseFLARMDetails(); } TCHAR filename[MAX_PATH]; LocalPath(filename,TEXT(LKD_CONF)); _tcscat(filename,_T(DIRSEP)); _tcscat(filename,_T(LKF_FLARMIDS)); #if TESTBENCH StartupStore(TEXT("... OpenFLARMDetails: <%s>%s"),filename,NEWLINE); #endif FILE * stream = _tfopen(filename, _T("rt")); if( !stream ) { #if TESTBENCH StartupStore(_T("... No flarm details local file found%s"),NEWLINE); #endif return; } TCHAR line[READLINE_LENGTH]; charset cs = charset::unknown; while (ReadStringX(stream,READLINE_LENGTH, line, cs)) { long id; TCHAR Name[MAX_PATH]; if (_stscanf(line, TEXT("%lx=%s"), &id, Name) == 2) { if (AddFlarmLookupItem(id, Name, false) == false) { break; // cant add anymore items ! } } } if (NumberOfFLARMNames>0) { StartupStore(_T(". Local IDFLARM, found %d IDs%s"),NumberOfFLARMNames,NEWLINE); } fclose(stream); }
static void OnSetCNClicked(WindowControl * Sender) { (void)Sender; int index = wDetails->GetItemIndex(); if (index != -1) { TCHAR newName[21]; newName[0] = 0; dlgTextEntryShowModal(newName, 4); AddFlarmLookupItem(XCSoarInterface::Basic().FLARM_Traffic[index].ID, newName, true); } }
void OpenFLARMDetails() { StartupStore(_T(". FlarmNet ids found: %d%s"),FlarmNetCount,NEWLINE); StartupStore(TEXT(". OpenFLARMDetails: \"")); if (NumberOfFLARMNames) { CloseFLARMDetails(); // BUGFIX TESTFIX 091020 attempt NOT to reset flarmnet preloaded list 100321 NO } TCHAR filename[MAX_PATH]; LocalPath(filename,TEXT(LKD_CONF)); // 091103 _tcscat(filename,_T("\\")); _tcscat(filename,_T(LKF_FLARMIDS)); StartupStore(filename); StartupStore(_T("\"%s"),NEWLINE); HANDLE hFile = CreateFile(filename,GENERIC_READ,0,NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if( hFile == INVALID_HANDLE_VALUE) { StartupStore(_T("... No flarm details local file found%s"),NEWLINE); return; } TCHAR line[READLINE_LENGTH]; while (ReadString(hFile,READLINE_LENGTH, line)) { long id; TCHAR Name[MAX_PATH]; if (_stscanf(line, TEXT("%lx=%s"), &id, Name) == 2) { if (AddFlarmLookupItem(id, Name, false) == false) { break; // cant add anymore items ! } } } _stprintf(filename,_T(". Local Flarm ids found=%d%s"),NumberOfFLARMNames,NEWLINE); StartupStore(filename); CloseHandle(hFile); }
static void OnTargetClicked(WindowControl * Sender) { (void)Sender; if (SelectedTraffic<0 || SelectedTraffic>MAXTRAFFIC) { StartupStore(_T("--- Invalid traffic selected to Target, out of range%s"),NEWLINE); DoStatusMessage(_T("ERR-126 invalid TARGET traffic")); return; } if ( GPS_INFO.FLARM_Traffic[SelectedTraffic].ID <1 ) { DoStatusMessage(gettext(TEXT("_@M879_"))); // SORRY TARGET JUST DISAPPEARED return; } if ( LKTraffic[SelectedTraffic].Locked ) { #if 0 if (MessageBoxX(hWndMapWindow, gettext(TEXT("_@M880_")), // UNLOCK current target? gettext(TEXT("_@M881_")), // Target selection MB_YESNO|MB_ICONQUESTION) == IDYES) { #endif LockFlightData(); GPS_INFO.FLARM_Traffic[SelectedTraffic].Locked=false; UnlockFlightData(); LKTargetIndex=-1; LKTargetType=LKT_TYPE_NONE; WayPointList[RESWP_FLARMTARGET].Latitude = RESWP_INVALIDNUMBER; WayPointList[RESWP_FLARMTARGET].Longitude = RESWP_INVALIDNUMBER; WayPointList[RESWP_FLARMTARGET].Altitude = RESWP_INVALIDNUMBER; _tcscpy(WayPointList[RESWP_FLARMTARGET].Name,_T(RESWP_FLARMTARGET_NAME) ); DoStatusMessage(gettext(TEXT("_@M882_"))); // TARGET RELEASED wf->SetModalResult(mrOK); return; } #if 0 if (MessageBoxX(hWndMapWindow, gettext(TEXT("_@M884_")), // LOCK this target? gettext(TEXT("_@M881_")), // Target selection MB_YESNO|MB_ICONQUESTION) == IDYES) { #endif // one more check for existance if ( GPS_INFO.FLARM_Traffic[SelectedTraffic].ID <1 ) { DoStatusMessage(gettext(TEXT("_@M883_"))); // TARGET DISAPPEARED! return; } LockFlightData(); // unlock previous target, if any if (LKTargetIndex>=0 && LKTargetIndex<MAXTRAFFIC) { GPS_INFO.FLARM_Traffic[LKTargetIndex].Locked=false; } GPS_INFO.FLARM_Traffic[SelectedTraffic].Locked=true; UnlockFlightData(); // LKTOKEN _@M675_ = "TARGET LOCKED" DoStatusMessage(gettext(TEXT("_@M675_"))); LKTargetIndex=SelectedTraffic; LKTargetType=LKT_TYPE_MASTER; // Remember that we need to update the virtual waypoint constantly when we receive FLARM data of target // Probably name is not updated if changed from Flarm menu... OvertargetMode=OVT_FLARM; WayPointList[RESWP_FLARMTARGET].Latitude = GPS_INFO.FLARM_Traffic[LKTargetIndex].Latitude; WayPointList[RESWP_FLARMTARGET].Longitude = GPS_INFO.FLARM_Traffic[LKTargetIndex].Longitude; WayPointList[RESWP_FLARMTARGET].Altitude = GPS_INFO.FLARM_Traffic[LKTargetIndex].Altitude; if (_tcslen(GPS_INFO.FLARM_Traffic[LKTargetIndex].Name) == 1) { _stprintf(WayPointList[RESWP_FLARMTARGET].Name,_T("%0x"),GPS_INFO.FLARM_Traffic[LKTargetIndex].ID); } else { _stprintf(WayPointList[RESWP_FLARMTARGET].Name,_T("%s"),GPS_INFO.FLARM_Traffic[LKTargetIndex].Name); } SetModeType(LKMODE_TRF, IM_TARGET); wf->SetModalResult(mrOK); } static void OnRenameClicked(WindowControl * Sender){ (void)Sender; if (SelectedTraffic<0 || SelectedTraffic>MAXTRAFFIC) { StartupStore(_T("--- Invalid traffic selected to rename, out of range%s"),NEWLINE); DoStatusMessage(_T("ERR-126 invalid traffic")); return; } if ( LKTraffic[SelectedTraffic].ID <1 ) { StartupStore(_T("--- Invalid traffic selected to rename, invalid ID%s"),NEWLINE); DoStatusMessage(_T("ERR-127 invalid traffic")); return; } TCHAR newName[MAXFLARMNAME+1]; newName[0] = 0; dlgTextEntryShowModal(newName, 7); // 100322 raised from 3 to 6 (+1) newName[MAXFLARMNAME] = 0; #ifdef DEBUG_LKT StartupStore(_T("************ dlgLK RenameClicked for slot=%d id=%lx status=%d oldname=<%s> newName=<%s>\n"), SelectedTraffic, GPS_INFO.FLARM_Traffic[SelectedTraffic].ID, GPS_INFO.FLARM_Traffic[SelectedTraffic].Status, GPS_INFO.FLARM_Traffic[SelectedTraffic].Name, newName); #endif int newnamelen=_tcslen(newName); if (newnamelen>0) { LockFlightData(); // Since we don-t know if a new PFLAA with this ID will arrive, and the UpdateNameFlag will be used, // we must change the name here now. _tcscpy(GPS_INFO.FLARM_Traffic[SelectedTraffic].Name,newName); // ... and here also, because SetValues is using this copy _tcscpy(LKTraffic[SelectedTraffic].Name,newName); // we assume that no Cn is available, or in any case cannot be kept // If newName is smaller or equal to possible Cn, we use it entirely if (newnamelen<=MAXFLARMCN) { _tcscpy( GPS_INFO.FLARM_Traffic[SelectedTraffic].Cn, newName); } else { // else we create a fake Cn GPS_INFO.FLARM_Traffic[SelectedTraffic].Cn[0]=newName[0]; GPS_INFO.FLARM_Traffic[SelectedTraffic].Cn[1]=newName[newnamelen-2]; GPS_INFO.FLARM_Traffic[SelectedTraffic].Cn[2]=newName[newnamelen-1]; GPS_INFO.FLARM_Traffic[SelectedTraffic].Cn[3]=_T('\0'); } // update it temporarily so that it appears updated leaving the edit page _tcscpy(LKTraffic[SelectedTraffic].Cn,GPS_INFO.FLARM_Traffic[SelectedTraffic].Cn); // It will be useless, because we already updated the name.. but never mind. GPS_INFO.FLARM_Traffic[SelectedTraffic].UpdateNameFlag=true; // This will create the local flarmid entry, but won't update the structure in GPS_INFO // until a new PFLAA arrives from this ID. AddFlarmLookupItem(GPS_INFO.FLARM_Traffic[SelectedTraffic].ID, newName, true); UnlockFlightData(); #ifdef DEBUG_LKT StartupStore(_T("...... dlgLK RENAMED slot=%d id=%lx status=%d name=<%s>\n"), SelectedTraffic, GPS_INFO.FLARM_Traffic[SelectedTraffic].ID, GPS_INFO.FLARM_Traffic[SelectedTraffic].Status, GPS_INFO.FLARM_Traffic[SelectedTraffic].Name); #endif // reload the name... SetValues(SelectedTraffic); } } static void OnCloseClicked(WindowControl * Sender){ (void)Sender; wf->SetModalResult(mrOK); }