Skip to content

Commit

Permalink
WIP #598
Browse files Browse the repository at this point in the history
- first pass at radio marker queuing (while sts doesn't exist) is working
  • Loading branch information
caver456 committed Dec 5, 2022
1 parent cc59e7c commit 256dfca
Showing 1 changed file with 40 additions and 14 deletions.
54 changes: 40 additions & 14 deletions radiolog.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
import csv
import os.path
import os
import json
import glob
import requests
import subprocess
Expand Down Expand Up @@ -1023,6 +1024,7 @@ def __init__(self,parent):
self.sartopoURL=''
self.sartopoLink=None
self.radioMarkerDict={}
self.radioMarkerFID=None

## if develMode:
## self.comPortTryList=[serial.Serial("\\\\.\\CNCB0")] # DEVEL
Expand Down Expand Up @@ -1945,8 +1947,8 @@ def fsParse(self):
# otherwise, append the callsign now, as a sign to send immediately
if not devTxt.startswith("Radio "):
self.getString=self.getString+devTxt
if self.optionsDialog.ui.sartopoRadioMarkersCheckBox.isChecked() and self.sts:
self.sendRadioMarker(devTxt,lat,lon)
# if self.optionsDialog.ui.sartopoRadioMarkersCheckBox.isChecked() and self.sts:
self.sendRadioMarker(devTxt,lat,lon) # always send or queue
# was this a response to a location request for this device?
if self.fsAwaitingResponse and [int(fleet),int(dev)]==[int(x) for x in self.fsAwaitingResponse[0:2]]:
try:
Expand Down Expand Up @@ -2094,6 +2096,7 @@ def fsParse(self):
self.sendPendingGet()

def sendPendingGet(self,suffix=""):
rprint('sendPendingGet called')
# NOTE that requests.get can cause a blocking delay; so, do it AFTER spawning the newEntryDialog
# if sarsoft is not running to handle this get request, Windows will complain with nested exceptions:
# ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
Expand Down Expand Up @@ -2121,18 +2124,31 @@ def sendPendingGet(self,suffix=""):
self.getString=''

def sendRadioMarker(self,label,lat,lon):
if not self.sts:
return
existingId=self.radioMarkerDict.get(label,'') # can be None in newer sartopo_python
id=self.sts.addMarker(lat,lon,label,time.strftime('%H:%M:%S'),existingId=existingId)
if not existingId:
self.radioMarkerDict[label]=id

# if existingId:
# pass
# else:
# id=self.sts.addMarker(lat,lon,label,time.strftime('%H:%M:%S'))
# self.radioMarkerDict[label]=id
rprint('sendRadioMarker called')
# mimic the old 'Locator Group' behavior:
# - create a 'Radios' folder on the first call to this function; place markers in that folder
# - if a marker for the callsign already exists, move it (and update the time)
# - if a marker for the callsign does not yet exist, add one (with updated time)
# questions:
# - how to deal with radios that change callsigns - should we have one marker per device ID,
# or one marker per callsign?
# - should radio markers be deleted at any point?
# - should radio marker colors be changed, as a function of team status, or time since last call?
# self.radioMarkerDict - keys are callsigns, values are lists [id,latestTimeString,lat,lon]
# existingId=self.radioMarkerDict.get(label,'') # can be None in newer sartopo_python
# id=None
entry=self.radioMarkerDict.get(label,[''])
existingId=entry[0]
id=''
latestTimeString=time.strftime('%H:%M:%S')
if self.sts:
if not self.radioMarkerFID:
self.radioMarkerFID=self.sts.addFolder('Radios')
id=self.sts.addMarker(lat,lon,label,latestTimeString,folderId=self.radioMarkerFID,existingId=existingId)
self.radioMarkerDict[label]=[id,latestTimeString,lat,lon] # queued markers will be added during createSTS
rprint(json.dumps(self.radioMarkerDict,indent=3))

# process this marker, and also any other entries without id

# for fsLog, a dictionary would probably be easier, but we have to use an array
# since we will be displaying in a QTableView
Expand Down Expand Up @@ -5031,16 +5047,26 @@ def createSTS(self):
print(" creating online session for user "+self.sartopoAccountName)
self.sts=SartopoSession(domainAndPort=domainAndPort,mapID=mapID,
configpath="../sts.ini",
# sync=False,syncTimeout=0.001,
account=self.accountName)
else:
self.sts=SartopoSession(domainAndPort=domainAndPort,mapID=mapID)
# self.sts=SartopoSession(domainAndPort=domainAndPort,mapID=mapID,sync=False,syncTimeout=0.001)
self.sartopoLink=self.sts.apiVersion
print("link status:"+str(self.sartopoLink))
# self.updateLinkIndicator()
# if self.link>0:
# self.ui.linkIndicator.setText(self.sts.mapID)
# self.updateFeatureList("Folder")
# self.optionsDialog.ui.folderComboBox.setHeader("Select a Folder...")
# process any queued radio markers
if not self.radioMarkerFID:
self.radioMarkerFID=self.sts.addFolder('Radios')
for (key,val) in self.radioMarkerDict.items():
if not val[0]:
rprint('adding deferred marker "'+key+'"')
id=self.sts.addMarker(val[2],val[3],key,val[1],folderId=self.radioMarkerFID)
self.radioMarkerDict[key][0]=id

class helpWindow(QDialog,Ui_Help):
def __init__(self, *args):
Expand Down

0 comments on commit 256dfca

Please sign in to comment.