Skip to content

Commit

Permalink
Bug fix and additional nav types
Browse files Browse the repository at this point in the history
Added additional nav types, so people can add them in the .ini
Fixed some text spacing issues on the navs and aircraft
Fixed issue identified by mariosteve around the casting of floats to int in setHSV.
  • Loading branch information
Skipper-is committed Apr 13, 2023
1 parent e4f4c50 commit 3a35aec
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 91 deletions.
16 changes: 3 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
__pycache__/FieldParser.cpython-39.pyc
__pycache__/ysconnect.cpython-39.pyc
__pycache__/resources.cpython-39.pyc
*.toc
*.pyc
*.zip
*.pyz
*.manifest
*.pkg
build/qt/warn-qt.txt
build/qt/xref-qt.html
*.ini
*.exe
build/
dist/
__pycache__/
3 changes: 2 additions & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
version = [20181124, 20180930, 20150425, 20130817, 20130805, 20120701, 20110207]
defaultversion = 20150425
port = 7915
host = 192.168.0.138
host = localhost
username = radar
groundfeatures = {"ILS[CJAP]": "ILS", "ILS2[CJAP]": "ILS", "LDA[CJAP]": "NDB"}

36 changes: 25 additions & 11 deletions qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
serverWeather = None


version = "0.0.12"
version = "0.0.13"


class MainWindow(QMainWindow):
Expand Down Expand Up @@ -136,6 +136,10 @@ def __init__(self, parent=None):

self.show()

#Add the ground object list to the flight director's ysconnect.
self.flightDirector.updateNavTypes(self.config.groundFeatures)


def statusBarUpdate(self, message):
if type(message)== list:
msgType = message[0]
Expand Down Expand Up @@ -263,7 +267,8 @@ def __init__(self, parent=None):
'DefaultVersion': '20180930',
'Port': '7915',
'Host': 'localhost',
'USername': 'radar'
'Username': 'radar',
'GroundFeatures': json.dumps({'ILS[CJAP]':'ILS', 'ILS2[CJAP]':'ILS', 'LDA[CJAP]':'NDB'}),
}
self.config.write(open('config.ini', 'w'))

Expand All @@ -273,6 +278,7 @@ def __init__(self, parent=None):
self.port = self.config['QRadar']['Port']
self.host = self.config['QRadar']['Host']
self.username = self.config['QRadar']['Username']
self.groundFeatures = json.loads(self.config['QRadar']['GroundFeatures'])



Expand Down Expand Up @@ -306,6 +312,9 @@ def setHost(self, host):
def setUsername(self, username):
self.config['QRadar']['Username'] = username
self.config.write(open('config.ini', 'w'))

def getGroundFeatures(self):
return self.groundFeatures


class LoginForm(QDialog):
Expand Down Expand Up @@ -936,8 +945,6 @@ def updateWeather(self,weather):
self.windScene.update()




class EditCallsignDialog(QDialog):
def __init__(self, currentPlane, parent=None):
super(EditCallsignDialog, self).__init__(parent)
Expand Down Expand Up @@ -1008,7 +1015,7 @@ def paint(self, painter, option, widget):

painter.setFont(QFont("Arial", 8))
painter.drawText(6, 10, self.callsign)
painter.drawText(6, 18, 'FL' + mToFL(self.altitude))
painter.drawText(6, 25, 'FL' + mToFL(self.altitude))
painter.setPen(QPen(Qt.white))

arrowsvg = QSvgRenderer(":icons/arrow.svg")
Expand All @@ -1020,7 +1027,7 @@ def paint(self, painter, option, widget):
arrowsvg.render(painter, QRectF(-4, -16, 4, 8))
painter.rotate(-180)

painter.drawText(6, 28, str(int(self.speed * 1.94384)) + 'kts')
painter.drawText(6, 40, str(int(self.speed * 1.94384)) + 'kts')

if self.clicked:
painter.setPen(QPen(Qt.white))
Expand Down Expand Up @@ -1051,7 +1058,7 @@ def paint(self, painter, option, widget):
painter.setPen(QPen(Qt.white))
painter.setFont(QFont("Arial",8))
painter.drawText(6,10,self.name)
painter.drawText(0,20,self.type)
painter.drawText(0,30,self.type)
pen = QPen(Qt.white)
pen.setWidth(1)
painter.setPen(pen)
Expand Down Expand Up @@ -1247,6 +1254,9 @@ def update(self):

def sendMessage(self, message):
self.client.sendMessage(message)

def updateNavTypes(self,navTypes):
self.client.updateNavTypes(navTypes)


def mToNm(m):
Expand Down Expand Up @@ -1469,7 +1479,7 @@ def updateBasemap(mainWindow):
colour = QColor(80,80,80)
colour = colour.toHsv()
h, s, v, a = colour.getHsv()
colour.setHsv(h, s/3, v/3, a)
colour.setHsv(int(h), int(s/3), int(v/3), int(a))
pen = QPen(colour)
brush = QBrush(colour)

Expand Down Expand Up @@ -1544,9 +1554,13 @@ def updateNav(mainWindow, nav):
navSymbol.rotation = nav.rotation

nav.symbol = navSymbol
if nav.type == "ILS":
polygonLight = QPolygonF([QPointF(-50,0),QPointF(-50,9260),QPointF(-300,9260+100),QPointF(-50,0)])
polygonDark = QPolygonF([QPointF(-50,0),QPointF(-50,9260),QPointF(250,9260+100),QPointF(-50,0)])
if nav.type == "ILS": # Classing LDAs as NDBs for now...
if nav.type == "ILS":
offset = -50
else:
offset = 0
polygonLight = QPolygonF([QPointF(offset,0),QPointF(offset,9260),QPointF(-300,9260+100),QPointF(offset,0)])
polygonDark = QPolygonF([QPointF(offset,0),QPointF(offset,9260),QPointF(250,9260+100),QPointF(offset,0)])
transform = QTransform()
transform.translate(nav.x,nav.z)
transform.rotate(nav.rotation)
Expand Down
23 changes: 0 additions & 23 deletions weather.ui

This file was deleted.

34 changes: 0 additions & 34 deletions weather.ui.autosave

This file was deleted.

31 changes: 22 additions & 9 deletions ysconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"FSNETREADBACK_USEUNGUIDEDWEAPON",
"FSNETREADBACK_CTRLSHOWUSERNAME"]

navTypes = ["ILS", "VORDME","NDB"]
navTypes = {'ILS':'ILS', 'VORDME':'VORDME', 'NDB':'NDB'}

def returnYSMessage(connection):
try:
Expand Down Expand Up @@ -218,15 +218,19 @@ def parseGroundObject(message):
name2 = 'unknown'
return {"type":type,"id":id,"iff":iff,"x":x,"y":y,"z":z,"yaw":yaw,"pitch":pitch,"roll":roll,"name":name,"name2":name2}

def createRadarPoints(ground_object):
def createRadarPoints(ground_object, updatednavTypes):
radarPoint = {}
if type(ground_object) == type(None):
return None #If it's empty, return nothing
if ground_object["type"] == 65537: #Check it is actually a ground object
if ground_object["name"] in navTypes: #It is a type of nav point, you can add more at the top in the declaration
if ground_object["name"] in updatednavTypes: #It is a type of nav point, you can add more at the top in the declaration
radarPoint['id'] = ground_object["id"] # Set the ID of the point
radarPoint["type"] = ground_object["name"] # Set the type of point as the original name, so ILS, VORDME etc
radarPoint["type"] = updatednavTypes[ground_object["name"]] # This will set the type with the simplified nav type.
#So for example, if a modded nav has come in with the name ILS[CJAP],
#but the type is ILS, it will set the type to ILS.
radarPoint["name"] = ground_object["name2"] # The name is then set to the name of the nav point - eg HILO
if radarPoint["name"].startswith("@") or radarPoint["name"].startswith("B"): #Beacons or ILS/VOR sometimes start with them for the ai nav
radarPoint["name"] = radarPoint["name"][1:] # Remove the @ or B
radarPoint["x"] = ground_object["x"] #Positions....
radarPoint["y"] = ground_object["y"]
radarPoint["z"] = -ground_object["z"]
Expand Down Expand Up @@ -273,6 +277,7 @@ def __init__(self, callback=None):
self.lastStayAlive = time.time()
self.callback = callback
self.map = None
self.navTypes = navTypes

def connect(self, host, port=7915, username="radar", version=20180930):
self.username = createLogin(username, version)
Expand Down Expand Up @@ -368,16 +373,12 @@ def connection(self):
if len(message[2])> 8:
day, flags, windX, windVert, windZ, visibility = struct.unpack("IIffff",message[2])
windSpeed = round(math.sqrt(windX**2 + windZ**2) * 1.94384,2) #Convert to knots
print(windSpeed)
print(windX, windZ)
print(math.degrees(math.atan2(windX,windZ)))
windDirection = int(math.degrees(math.atan2(windX,windZ))+180)
if day == 1:
day = "Day"
else:
day = "Night"
returnMessage = ["weather",{"windDirection": windDirection, "windSpeed": windSpeed, "time": day, "visibility": visibility}]
print(returnMessage)
self.callback(returnMessage)
#Parse the packet, and create a weather message to send to the listener. message should be["weather",{"windDirection": windDirection, "windSpeed": windSpeed, "time": time, "visibility": visibility}]

Expand All @@ -404,7 +405,7 @@ def connection(self):

elif mesgType == "FSNETCMD_ADDOBJECT":
groundObject = parseGroundObject(message[2])
radarPoint = createRadarPoints(groundObject)
radarPoint = createRadarPoints(groundObject, self.navTypes)
if radarPoint != None:
self.navPoints[radarPoint["id"]] = NavPoint(radarPoint)

Expand Down Expand Up @@ -474,6 +475,11 @@ def sendMessage(self,message):
message = message.encode()
message = struct.pack("II",len(message)+13,messageTypes.index("FSNETCMD_TEXTMESSAGE")) + struct.pack("II",0,0) + message + b'\x00'
self.sock.send(message)

def updateNavTypes(self, newNavTypes):
currentNavs = self.navTypes
self.navTypes = {**currentNavs, **newNavTypes}



class UserList:
Expand Down Expand Up @@ -671,8 +677,15 @@ def __init__(self, data):
self.y = data["y"]
self.z = data["z"]
self.rotation = data["rotation"]
self.offset = 0

def getPosition(self):
return(self.x,self.z)

def setOffset(self, offset):
self.offset = offset

def getOffset(self):
return self.offset


0 comments on commit 3a35aec

Please sign in to comment.