Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
-General bug fixes and improvements.
  • Loading branch information
Scratchcat1 authored Dec 3, 2017
1 parent dfad965 commit b51dd97
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 26 deletions.
8 changes: 4 additions & 4 deletions AATC_AStar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os,pickle,time,math,hashlib
from AATC_Coordinate import *
import os,pickle,time,math,hashlib#,AATC_Coordinate
#from AATC_Coordinate import *
try:
try:
import PriorityQueue.PriorityQueueC as PriorityQueue
Expand All @@ -26,7 +26,7 @@ class DynoGraph:
"""
def __init__(self,BlockSize = 500,FolderName = "GraphFolder",GraphFileName = "Graph",GraphFileSuffix = ".graph",BlockFileName = "GraphBlock",BlockFileSuffix = ".blk",Node_Cache_BlockSize = 10000000, ABInterval = 36000, ABSlot = 0, ABSlots = 2):
def __init__(self,BlockSize = 500,FolderName = "GraphFolder",GraphFileName = "Graph",GraphFileSuffix = ".graph",BlockFileName = "GraphBlock",BlockFileSuffix = ".blk",Node_Cache_BlockSize = 40, ABInterval = 36000, ABSlot = 0, ABSlots = 2):
self.Nodes = {}
self.BlockSize = BlockSize
self.cwd = os.getcwd()
Expand Down Expand Up @@ -166,7 +166,7 @@ def MapHash(self,value,div):
return int(value//div)

def Node_Cache_Hash(self,Key):
return int(int(hashlib.md5(str(Key).encode('utf8')).hexdigest()[:8],16)//self.Node_Cache_BlockSize) #Generates integer hash of key then int div by BlockSize
return int(int(hashlib.md5(str(Key).encode('utf8')).hexdigest()[:8],16)%self.Node_Cache_BlockSize) #Generates integer hash of key then int div by BlockSize

##################################

Expand Down
3 changes: 2 additions & 1 deletion AATC_Create_Graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ def CreationDialogue():
graph.Add_Edges(xRange,yRange,zRange)
graph.Build_Node_Cache()
graph.SaveGraph()
#return graph



if __name__ == "__main__":
CreationDialogue()
graph = CreationDialogue()



Expand Down
26 changes: 15 additions & 11 deletions AATC_DB.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import MySQLdb as sql
import time,codecs
from Crypto.Hash import SHA256
from Crypto.Protocol.KDF import PBKDF2
def GetTime():
return int(time.time())

Expand All @@ -16,8 +16,8 @@ def CoordLessThanOrEqual(Coord1,Coord2):# True if Coord1 <= Coord2
return all(BoolList)


def Hash(value):
return SHA256.new(codecs.encode(value)).hexdigest()
def Hash(value,salt):
return str(PBKDF2(codecs.encode(value),codecs.encode(salt))) #str(PBKDF2(codecs.encode(value),codecs.encode(salt),dkLen = 32))



Expand Down Expand Up @@ -145,14 +145,14 @@ def GetUsername(self,UserID):
def AddUser(self,Username,Password):
self.cur.execute("SELECT 1 FROM User WHERE Username = %s",(Username,))
if self.cur.fetchall() == ():
self.cur.execute("INSERT INTO User(Username,Password,PublicVisibleFlights,PermissionAdder,ZoneCreatorPermission,ZoneRemoverPermission,ZoneModifierPermission) VALUES(%s,%s,0,0,0,0,0)",(Username,Hash(Password)))
self.cur.execute("INSERT INTO User(Username,Password,PublicVisibleFlights,PermissionAdder,ZoneCreatorPermission,ZoneRemoverPermission,ZoneModifierPermission) VALUES(%s,%s,0,0,0,0,0)",(Username,Hash(Password,Username)))
self.db_con.commit()
return True,"Added User"
else:
return False,"User already exists"

def CheckCredentials(self,Username,Password):
self.cur.execute("SELECT UserID FROM User WHERE Username = %s AND Password = %s",(Username,Hash(Password)))
self.cur.execute("SELECT UserID FROM User WHERE Username = %s AND Password = %s",(Username,Hash(Password,Username)))
UserIDFetch = self.cur.fetchall()
if UserIDFetch != ():
return True,"Correct Credentials",UserIDFetch[0][0]
Expand All @@ -175,9 +175,11 @@ def SetAccountType(self,UserID,Permission,Value):
return True,"Set AccountType Value"

def UserChangePassword(self,UserID,OldPassword,NewPassword):
self.cur.execute("SELECT 1 FROM User WHERE UserID = %s and Password = %s",(UserID,Hash(OldPassword)))
self.cur.execute("SELECT Username from User WHERE UserID = ?",(UserID,))
Username = self.cur.fetchall()[0][0]
self.cur.execute("SELECT 1 FROM User WHERE UserID = %s and Password = %s",(UserID,Hash(OldPassword,Username)))
if self.cur.fetchall() != ():
self.cur.execute("UPDATE User SET Password = %s WHERE UserID = %s",(Hash(NewPassword),UserID))
self.cur.execute("UPDATE User SET Password = %s WHERE UserID = %s",(Hash(NewPassword,Username),UserID))
self.db_con.commit()
return True,"Changed password"
else:
Expand Down Expand Up @@ -299,24 +301,26 @@ def CleanCompletedFlightWaypoints(self,FlightID): #Server only command
def AddMonitor(self,MonitorName,MonitorPassword):
self.cur.execute("SELECT 1 FROM Monitor WHERE MonitorName = %s",(MonitorName,))
if self.cur.fetchall() == ():
self.cur.execute("INSERT INTO Monitor(MonitorName,MonitorPassword) VALUES(%s,%s)",(MonitorName,Hash(MonitorPassword)))
self.cur.execute("INSERT INTO Monitor(MonitorName,MonitorPassword) VALUES(%s,%s)",(MonitorName,Hash(MonitorPassword,MonitorName)))
self.db_con.commit()
return True,"Added Monitor"
else:
return False,"Monitor already exists"

def MonitorCheckCredentials(self,MonitorName,MonitorPassword):
self.cur.execute("SELECT MonitorID FROM Monitor WHERE MonitorName = %s AND MonitorPassword = %s",(MonitorName,Hash(MonitorPassword)))
self.cur.execute("SELECT MonitorID FROM Monitor WHERE MonitorName = %s AND MonitorPassword = %s",(MonitorName,Hash(MonitorPassword,MonitorName)))
MonitorIDFetch = self.cur.fetchall()
if MonitorIDFetch != ():
return True,"Correct Credentials",MonitorIDFetch[0][0]
else:
return False,"Incorrect Credentials",-1

def MonitorChangePassword(self,MonitorID,OldPassword,NewPassword):
self.cur.execute("SELECT 1 FROM Monitor WHERE MonitorID = %s AND MonitorPassword = %s",(MonitorID,Hash(OldPassword)))
self.cur.execute("SELECT MonitorName FROM Monitor WHERE MonitorID = ?",(MonitorID,))
MonitorName = self.cur.fetchall()[0][0]
self.cur.execute("SELECT 1 FROM Monitor WHERE MonitorID = %s AND MonitorPassword = %s",(MonitorID,Hash(OldPassword,MonitorName)))
if self.cur.fetchall() != ():
self.cur.execute("UPDATE Monitor SET MonitorPassword = %s WHERE MonitorID = %s",(Hash(NewPassword),MonitorID))
self.cur.execute("UPDATE Monitor SET MonitorPassword = %s WHERE MonitorID = %s",(Hash(NewPassword,MonitorName),MonitorID))
self.db_con.commit()
return True,"Password updated"
else:
Expand Down
1 change: 1 addition & 0 deletions AATC_Drone_Logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def Main(self):

except Exception as e:
print("Error occured in DroneLogic Main",e)
self.GPIO_Queue.put(("GREEN","Function",(AATC_GPIO.BlankFunction,())))
self.GPIO_Queue.put(("RED","Function",(AATC_GPIO.Blink,(11,3,30,False)))) #Let the Thread for RED LED blink on pin 11 at 3Hz 30 times and not repeat.
time.sleep(self.Sleep_Time) #To prevent spamming server

Expand Down
6 changes: 3 additions & 3 deletions AATC_GPIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def GPIO_Wait_Switch(pin,wait_time = 1, SWITCH_MODE= 1, Indicator_Pin = False):
GPIO.setup(pin,GPIO.IN)

if Indicator_Pin:
GPIO_Queue = Create_Controller()
GPIO_Queue = Create_Controller(Name = "AMBER_LED")
GPIO_Queue.put(("Controller","Create_Thread",("INDICATOR",)))

while GPIO.input(pin) != SWITCH_MODE:
Expand Down Expand Up @@ -162,13 +162,13 @@ def Reset(self,Wait_Join = False):



def Create_Controller(process = False):
def Create_Controller(process = False, Name = ""):
if process:
q = multiprocessing.Queue()
else:
q = queue.Queue()

TC = Thread_Controller(q)
TC = Thread_Controller(q,Name)

if process:
t = multiprocessing.Process(target = TC.Main)
Expand Down
11 changes: 9 additions & 2 deletions AATC_NoFlyZoneGrapher.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ def Main_Loop(self):
self.Exit = True

print("NoFlyZoneGrapher exiting...")

def Force_Write(self): #Cycles through all slots and writes current state.
graph = AATC_AStar.DynoGraph()
graph.ImportGraph()
NoFlyZoneData = self.GetNoFlyZones()
for Slot in range(len(graph.GetFolderNames())):
self.Make_Values(NoFlyZoneData,ABSlot = Slot)

def Mod(self,Coords):
return int(Coords.Get_X()//self.xSize),int(Coords.Get_Y()//self.ySize),int(Coords.Get_Z()//self.zSize)
Expand Down Expand Up @@ -97,9 +104,9 @@ def Make_Values(self,NoFlyZoneData,ABSlot = 1):


print("[NoFlyZoneGrapher] Length of Values:",len(Values))
for NodeID in list(Values.keys()):
for NodeID in list(Values.keys()): #CHECK THIS. Only using those involved with a new no fly zone may cause issues if a no fly zone was removed. Maybe should be set to all node IDs.
node = graph.GetNode(NodeID)
if node.NodeID in Values:
if node.Get_NodeID() in Values:
node.Set_Cost( Values[node.NodeID])
Values.pop(node.NodeID)# Reduce memory usage by evicting Node values which have been added already
else:
Expand Down
8 changes: 4 additions & 4 deletions AATC_Server_002.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def ProcessCommand(self,Command,Arguments):
#Else if command doesnt exist send back Failure
else:
Sucess,Message,Data = False,"Command does not exist",[]
print("User tried to use unregistered command")
print(self.Thread_Name,self.ClientID," tried to use unregistered command")
return Sucess,Message,Data

def Login(self,Arguments):
Expand Down Expand Up @@ -616,7 +616,7 @@ def ProcessCommand(self,Command,Arguments):
#Else if command doesnt exist send back Failure
else:
Sucess,Message,Data = False,"Command does not exist",[]
print("Monitor tried to use unregistered command")
print(self.Thread_Name,self.ClientID," tried to use unregistered command")
return Sucess,Message,Data

################################
Expand Down Expand Up @@ -721,6 +721,7 @@ def ProcessCommand(self,Command,Arguments):
Exit = True
else:
Sucess,Message,Data = False,"Command does not exist",[]


else:
if Command == "UpdateDroneStatus":
Expand All @@ -745,8 +746,7 @@ def ProcessCommand(self,Command,Arguments):
#Else if command doesnt exist send back Failure
else:
Sucess,Message,Data = False,"Command does not exist",[]
print("Drone tried to use unregistered command")
print(Command)
print(self.Thread_Name,self.ClientID," tried to use unregistered command")
return Sucess,Message,Data

def Login(self,Arguments):
Expand Down
2 changes: 2 additions & 0 deletions AATC_Weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def Get_Ajusted_Speed(self,CoordA,CoordB,Speed,At_Time = time.time()):
Vx = Speed*math.sin(AATC_Coordinate.toRadian(bearing))+ wind["speed"]*math.sin(AATC_Coordinate.toRadian(wind_bearing))
Vy = Speed*math.cos(AATC_Coordinate.toRadian(bearing))+ wind["speed"]*math.cos(AATC_Coordinate.toRadian(wind_bearing))
V = math.sqrt(Vx**2+Vy**2)
if V < 0: #To prevent estimating negative speeds
V = 1
return V
except:
return Speed
Expand Down
2 changes: 1 addition & 1 deletion HedaBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def CreateCommandDictionary():



BOT_TOKEN = "YOUR TOKEN HERE"
BOT_TOKEN = "472230564:AAEHTSJ446LE_BO_hQ8B4PeVmUTrB8gRsEA"
if __name__ == "__main__":
bot = telepot.Bot(BOT_TOKEN)
heda = Telebot()
Expand Down

0 comments on commit b51dd97

Please sign in to comment.