static void OnFlarmLockClicked(gcc_unused WndButton &button) { TCHAR newTeamFlarmCNTarget[4]; _tcsncpy(newTeamFlarmCNTarget, XCSoarInterface::SetSettingsComputer().TeamFlarmCNTarget, 4); if (!dlgTextEntryShowModal(newTeamFlarmCNTarget, 4)) return; _tcsncpy(XCSoarInterface::SetSettingsComputer().TeamFlarmCNTarget, newTeamFlarmCNTarget, 4); XCSoarInterface::SetSettingsComputer().TeammateCodeValid = false; if (string_is_empty(XCSoarInterface::SettingsComputer().TeamFlarmCNTarget)) { XCSoarInterface::SetSettingsComputer().TeamFlarmTracking = false; XCSoarInterface::SetSettingsComputer().TeamFlarmIdTarget.clear(); return; } FlarmId flarmId = FlarmDetails::LookupId( XCSoarInterface::SettingsComputer().TeamFlarmCNTarget); if (!flarmId.defined()) { MessageBoxX(_("Unknown Competition Number"), _("Not Found"), MB_OK | MB_ICONINFORMATION); XCSoarInterface::SetSettingsComputer().TeamFlarmTracking = false; XCSoarInterface::SetSettingsComputer().TeamFlarmIdTarget.clear(); XCSoarInterface::SetSettingsComputer().TeamFlarmCNTarget[0] = 0; } else { XCSoarInterface::SetSettingsComputer().TeamFlarmIdTarget = flarmId; XCSoarInterface::SetSettingsComputer().TeamFlarmTracking = true; } }
FlarmId FLARMNetRecord::GetId() const { FlarmId id; id.parse(this->id, NULL); return id; };
static void OnFlarmLockClicked() { TeamCodeSettings &settings = CommonInterface::SetComputerSettings().team_code; TCHAR newTeamFlarmCNTarget[settings.team_flarm_callsign.MAX_SIZE]; _tcscpy(newTeamFlarmCNTarget, settings.team_flarm_callsign.c_str()); if (!dlgTextEntryShowModal(newTeamFlarmCNTarget, 4)) return; if (StringIsEmpty(newTeamFlarmCNTarget)) { settings.team_flarm_id.Clear(); settings.team_flarm_callsign.clear(); return; } LoadFlarmDatabases(); FlarmId ids[30]; unsigned count = FlarmDetails::FindIdsByCallSign(newTeamFlarmCNTarget, ids, 30); if (count == 0) { ShowMessageBox(_("Unknown Competition Number"), _("Not Found"), MB_OK | MB_ICONINFORMATION); return; } const FlarmId id = PickFlarmTraffic(_("Set new teammate"), ids, count); if (!id.IsDefined()) return; TeamActions::TrackFlarm(id, newTeamFlarmCNTarget); }
void InputEvents::eventFlarmDetails(gcc_unused const TCHAR *misc) { LoadFlarmDatabases(); StaticString<4> callsign; callsign.clear(); if (!TextEntryDialog(CommonInterface::main_window, callsign, _("Competition ID")) || callsign.empty()) return; FlarmId ids[30]; unsigned count = FlarmDetails::FindIdsByCallSign(callsign, ids, 30); if (count > 0) { FlarmId id = dlgFlarmDetailsListShowModal( XCSoarInterface::main_window, _("Show details:"), ids, count); if (id.IsDefined()) dlgFlarmTrafficDetailsShowModal(id); } else { ShowMessageBox(_("Unknown competition number"), _("Not found"), MB_OK | MB_ICONINFORMATION); } }
void FlarmDatabase::Insert(const FlarmRecord &record) { FlarmId id = record.GetId(); if (!id.IsDefined()) /* ignore malformed records */ return; map.insert(std::make_pair(id, record)); }
static void LoadSecondaryFile(TLineReader &reader) { TCHAR *line; while ((line = reader.read()) != NULL) { TCHAR *endptr; FlarmId id; id.parse(line, &endptr); if (endptr > line && endptr[0] == _T('=') && endptr[1] != _T('\0')) { TCHAR *Name = endptr + 1; TrimRight(Name); if (!FlarmDetails::AddSecondaryItem(id, Name)) break; // cant add anymore items ! } } }
/** * Find an existing item by its FLARM id. This is a simple linear * search that doesn't scale well with a large list. */ gcc_pure ItemList::iterator FindItem(FlarmId id) { assert(id.IsDefined()); return std::find_if(items.begin(), items.end(), [id](const Item &item) { return item.id == id; }); }
// Used by TeamCode, to select a CN and get back the Id int LookupFLARMDetails(TCHAR *cn) { // try to find flarm from userFile int index = LookupSecondaryFLARMId(cn); if (index != -1) { return FLARM_Names[index].ID; } // try to find flarm from FLARMNet.org File FlarmId* flarmId = file.GetFlarmIdItem(cn); if (flarmId != NULL) { return flarmId->GetId(); } return 0; }
bool FlarmDetails::AddSecondaryItem(FlarmId id, const TCHAR *name) { assert(id.IsDefined()); assert(traffic_databases != nullptr); return traffic_databases->flarm_names.Set(id, name); }
FlarmId FlarmDetails::LookupId(const TCHAR *cn) { // try to find flarm from userFile int index = LookupSecondaryIndex(cn); if (index != -1) return FLARM_Names[index].ID; // try to find flarm from FlarmNet.org File const FlarmNet::Record *record = FlarmNet::FindFirstRecordByCallSign(cn); if (record != NULL) return record->GetId(); FlarmId id; id.clear(); return id; }
FlarmId TrafficDatabases::FindIdByName(const TCHAR *name) const { assert(name != nullptr); assert(!StringIsEmpty(name)); // try to find flarm from userFile const FlarmId id = flarm_names.Get(name); if (id.IsDefined()) return id; // try to find flarm from FlarmNet.org File const FlarmNetRecord *record = flarm_net.FindFirstRecordByCallSign(name); if (record != NULL) return record->GetId(); return FlarmId::Undefined(); }
FlarmIdFile::FlarmIdFile(void) { TCHAR path[MAX_PATH]; LKSound(_T("LK_CONNECT.WAV")); TCHAR flarmIdFileName[MAX_PATH] = TEXT("\0"); #if NOSIM if (SIMMODE) return; #else #ifdef _SIM_ return; #endif #endif LocalPath(path); wsprintf(flarmIdFileName, TEXT("%s\\%s\\%s"), path, TEXT(LKD_CONF), TEXT(LKF_FLARMNET)); FILE* hFile = _wfopen(flarmIdFileName, TEXT("rt")); if (hFile == NULL) { wsprintf(flarmIdFileName, TEXT("%s\\%s\\data.fln"), path, TEXT(LKD_CONF)); hFile = _wfopen(flarmIdFileName, TEXT("rt")); if (hFile == NULL) return; } DWORD fileLength; fseek (hFile , 0 , SEEK_END); fileLength = ftell (hFile); fseek (hFile , 7 , SEEK_SET); int itemCount = 0; while( ( (signed)fileLength - ftell(hFile)) > 87) { FlarmId *flarmId = new FlarmId; GetItem(hFile, flarmId); flarmIds[flarmId->GetId()] = flarmId; itemCount++; } FlarmNetCount=itemCount; fclose(hFile); }
void LoadFlarmNameFile(TLineReader &reader, FlarmNameDatabase &db) { TCHAR *line; while ((line = reader.ReadLine()) != NULL) { TCHAR *endptr; FlarmId id = FlarmId::Parse(line, &endptr); if (!id.IsDefined()) /* ignore malformed records */ continue; if (endptr > line && endptr[0] == _T('=') && endptr[1] != _T('\0')) { TCHAR *Name = endptr + 1; TrimRight(Name); if (!db.Set(id, Name)) break; // cant add anymore items ! } } }
FlarmIdFile::FlarmIdFile(void) { TCHAR path[MAX_PATH]; TCHAR flarmIdFileName[MAX_PATH] = TEXT("\0"); LocalPath(path); _stprintf(flarmIdFileName, TEXT("%s%s%s%s%s"), path, _T(DIRSEP), TEXT(LKD_CONF), _T(DIRSEP), TEXT(LKF_FLARMNET)); FILE* hFile = _tfopen(flarmIdFileName, TEXT("rt")); if (hFile == NULL) { _stprintf(flarmIdFileName, TEXT("%s%s%s%sdata.fln"), path, _T(DIRSEP), TEXT(LKD_CONF), _T(DIRSEP)); hFile = _tfopen(flarmIdFileName, TEXT("rt")); if (hFile == NULL) return; } fseek (hFile , 0 , SEEK_END); long int fileLength = ftell (hFile); fseek (hFile , 7 , SEEK_SET); int itemCount = 0; while( ( fileLength - ftell(hFile)) > 87) { FlarmId *flarmId = new FlarmId; _tcscpy(flarmId->id,_T("")); _tcscpy(flarmId->name,_T("")); _tcscpy(flarmId->airfield,_T("")); _tcscpy(flarmId->type,_T("")); _tcscpy(flarmId->reg,_T("")); _tcscpy(flarmId->cn,_T("")); _tcscpy(flarmId->freq,_T("")); GetItem(hFile, flarmId); flarmIds[flarmId->GetId()] = flarmId; itemCount++; } FlarmNetCount=itemCount; fclose(hFile); }
static void LoadColor(FlarmColorDatabase &db, const char *key, FlarmColor color) { const char *ids = Profile::Get(key); if (ids == nullptr) return; const char *p = ids; while (true) { char *endptr; FlarmId id = FlarmId::Parse(p, &endptr); if (id.IsDefined()) db.Set(id, color); p = strchr(endptr, ','); if (p == nullptr) break; ++p; } }
explicit Item(FlarmId _id) :id(_id), #ifdef HAVE_SKYLINES_TRACKING_HANDLER skylines_id(0), #endif color(FlarmColor::COUNT), loaded(false), location(GeoPoint::Invalid()), vector(GeoVector::Invalid()) { assert(id.IsDefined()); assert(IsFlarm()); }
FlarmId TrafficDatabases::FindIdByName(const TCHAR *name) const { #if !CLANG_CHECK_VERSION(3,6) /* disabled on clang due to -Wtautological-pointer-compare */ assert(name != nullptr); #endif assert(!StringIsEmpty(name)); // try to find flarm from userFile const FlarmId id = flarm_names.Get(name); if (id.IsDefined()) return id; // try to find flarm from FlarmNet.org File const FlarmNetRecord *record = flarm_net.FindFirstRecordByCallSign(name); if (record != NULL) return record->GetId(); return FlarmId::Undefined(); }
void FlarmFriends::LoadColor(const TCHAR *key, Color color) { const TCHAR *ids = Profile::Get(key); if (ids == NULL || StringIsEmpty(ids)) return; FlarmId id; TCHAR *endptr; const TCHAR *p = ids; while (p != NULL && *p) { id = FlarmId::Parse(p, &endptr); if (id.IsDefined()) { SetFriendColor(id, color); id.Clear(); } p = _tcschr(endptr, _T(',')); if (p != NULL) p++; } }
/** * Checks whether the selection is still on the valid target and if not tries * to select the next one */ void FlarmTrafficWindow::UpdateSelector(const FlarmId id, const RasterPoint pt) { // Update #selection if (!id.IsDefined()) SetTarget(-1); else SetTarget(id); // If we don't have a valid selection and we can't find // a target close to to the RasterPoint we select the next one // on the internal list if (selection < 0 && ( pt.x < 0 || pt.y < 0 || !SelectNearTarget(pt.x, pt.y, radius * 2)) ) NextTarget(); }
/** * Updates all the dialogs fields. * Should be called on dialog opening as it closes the dialog when the * target does not exist. */ void FlarmTrafficDetailsWidget::Update() { TCHAR tmp[200], tmp_id[7]; const TCHAR *value; // Set the dialog caption StringFormatUnsafe(tmp, _T("%s (%s)"), _("FLARM Traffic Details"), target_id.Format(tmp_id)); dialog.SetCaption(tmp); // Try to find the target in the FLARMnet database /// @todo: make this code a little more usable const FlarmNetRecord *record = FlarmDetails::LookupRecord(target_id); if (record) { // Fill the pilot name field SetText(PILOT, record->pilot); // Fill the frequency field if (!StringIsEmpty(record->frequency)) value = UnsafeBuildString(tmp, record->frequency.c_str(), _T(" MHz")); else value = _T("--"); SetText(RADIO, value); // Fill the home airfield field SetText(AIRPORT, record->airfield); // Fill the plane type field SetText(PLANE, record->plane_type); } else { // Fill the pilot name field SetText(PILOT, _T("--")); // Fill the frequency field SetText(RADIO, _T("--")); // Fill the home airfield field SetText(AIRPORT, _T("--")); // Fill the plane type field const FlarmTraffic* target = CommonInterface::Basic().flarm.traffic.FindTraffic(target_id); const TCHAR* actype; if (target == nullptr || (actype = FlarmTraffic::GetTypeString(target->type)) == nullptr) actype = _T("--"); SetText(PLANE, actype); } // Fill the callsign field (+ registration) // note: don't use target->Name here since it is not updated // yet if it was changed const TCHAR* cs = FlarmDetails::LookupCallsign(target_id); if (cs != nullptr && cs[0] != 0) { StringBuilder<TCHAR> builder(tmp, ARRAY_SIZE(tmp)); builder.Append(cs); if (record) builder.Append(_T(" ("), record->registration.c_str(), _T(")")); value = tmp; } else value = _T("--"); SetText(CALLSIGN, value); // Update the frequently changing fields too UpdateChanging(CommonInterface::Basic()); }
static void PaintListItem(Canvas &canvas, const PixelRect rc, unsigned index) { assert(array[index].IsDefined()); const FlarmId id = array[index]; const DialogLook &look = UIGlobals::GetDialogLook(); const Font &name_font = *look.list.font; const Font &small_font = *look.small_font; canvas.SetTextColor(COLOR_BLACK); TCHAR tmp_id[10]; id.Format(tmp_id); const FlarmRecord *record = FlarmNet::FindRecordById(id); const TCHAR *callsign = FlarmDetails::LookupCallsign(id); canvas.Select(name_font); StaticString<256> tmp; if (record != NULL) tmp.Format(_T("%s - %s - %s"), callsign, record->registration, tmp_id); else if (callsign != NULL) tmp.Format(_T("%s - %s"), callsign, tmp_id); else tmp.Format(_T("%s"), tmp_id); canvas.text_clipped(rc.left + Layout::FastScale(2), rc.top + Layout::FastScale(2), rc, tmp); canvas.Select(small_font); tmp.clear(); if (record != NULL) { if (!StringIsEmpty(record->pilot)) tmp = record->pilot; if (!StringIsEmpty(record->plane_type)) { if (!tmp.empty()) tmp.append(_T(" - ")); tmp.append(record->plane_type); } if (!StringIsEmpty(record->airfield)) { if (!tmp.empty()) tmp.append(_T(" - ")); tmp.append(record->airfield); } } if (tmp.empty()) tmp = _("No further information"); canvas.text_clipped(rc.left + Layout::FastScale(2), rc.top + name_font.GetHeight() + Layout::FastScale(4), rc, tmp); }
/** * Does this object describe a FLARM? */ bool IsFlarm() const { return id.IsDefined(); }
/** * Updates all the dialogs fields. * Should be called on dialog opening as it closes the dialog when the * target does not exist. */ static void Update() { TCHAR tmp[200], tmp_id[7]; // Set the dialog caption _stprintf(tmp, _T("FLARM Traffic Details (%s)"), target_id.format(tmp_id)); wf->SetCaption(tmp); // Try to find the target in the FLARMnet database /// @todo: make this code a little more usable const FlarmNet::Record *record = FlarmDetails::LookupRecord(target_id); if (record) { // Fill the pilot name field _tcscpy(tmp, record->pilot); ((WndProperty *)wf->FindByName(_T("prpPilot")))->SetText(tmp); // Fill the frequency field _tcscpy(tmp, record->frequency); _tcscat(tmp, _T("MHz")); ((WndProperty *)wf->FindByName(_T("prpFrequency")))->SetText(tmp); // Fill the home airfield field _tcscpy(tmp, record->airfield); ((WndProperty *)wf->FindByName(_T("prpAirport")))->SetText(tmp); // Fill the plane type field _tcscpy(tmp, record->plane_type); ((WndProperty *)wf->FindByName(_T("prpPlaneType")))->SetText(tmp); } else { // Fill the pilot name field ((WndProperty *)wf->FindByName(_T("prpPilot")))->SetText(_T("--")); // Fill the frequency field ((WndProperty *)wf->FindByName(_T("prpFrequency")))->SetText(_T("--")); // Fill the home airfield field ((WndProperty *)wf->FindByName(_T("prpAirport")))->SetText(_T("--")); // Fill the plane type field const FLARM_TRAFFIC* target = XCSoarInterface::Basic().flarm.FindTraffic(target_id); const TCHAR* actype; if (target == NULL || (actype = FLARM_TRAFFIC::GetTypeString(target->type)) == NULL) actype = _T("--"); ((WndProperty *)wf->FindByName(_T("prpPlaneType")))->SetText(actype); } // Fill the callsign field (+ registration) // note: don't use target->Name here since it is not updated // yet if it was changed const TCHAR* cs = FlarmDetails::LookupCallsign(target_id); if (cs != NULL && cs[0] != 0) { _tcscpy(tmp, cs); if (record) { _tcscat(tmp, _T(" (")); _tcscat(tmp, record->registration); _tcscat(tmp, _T(")")); } } else _tcscpy(tmp, _T("--")); ((WndProperty *)wf->FindByName(_T("prpCallsign")))->SetText(tmp); // Update the frequently changing fields too UpdateChanging(); }