Guest User

Untitled

a guest
Sep 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. import aprslib
  2. import location
  3. import time
  4. from math import sin, cos, sqrt, atan2, radians
  5.  
  6. last = None
  7. count = 0
  8.  
  9. location.start_updates()
  10.  
  11. aprs = aprslib.IS('CALLSIGN',aprslib.passcode('CALLSIGN'))
  12. aprs.connect()
  13. packet = aprslib.packets.PositionReport()
  14. packet.fromcall='CALLSIGN' #Insert your hamradio call sign
  15. packet.tocall='WIDE1'
  16. packet.comment=' '
  17. packet.symbol='>'
  18.  
  19. def dist(locA,locB):
  20. lat1 = radians(locA['latitude'])
  21. lon1 = radians(locA['longitude'])
  22. lat2 = radians(locB['latitude'])
  23. lon2 = radians(locB['longitude'])
  24.  
  25. dlon = lon2 - lon1
  26. dlat = lat2 - lat1
  27.  
  28. a = sin(dlat / 2.0)**2.0 + cos(lat1) * cos(lat2) * sin(dlon / 2.0)**2.0
  29. c = 2.0 * atan2(sqrt(a), sqrt(1.0 - a))
  30.  
  31. return 6373.0 * c * 0.621371
  32.  
  33. def sendLoc(aprs,loc):
  34. packet.timestamp=loc['timestamp']
  35. packet.latitude=loc['latitude']
  36. packet.longitude=loc['longitude']
  37. aprs.sendall(packet)
  38.  
  39. print 'Location Updated!'
  40.  
  41.  
  42. def course(last,loc):
  43. old = last['course']
  44. new = loc['course']
  45. if old <0:
  46. return False
  47. if new < 0:
  48. return False
  49. delta = abs(new-old)
  50. if delta <= 180:
  51. delta = delta
  52. else:
  53. delta= 360-delta
  54. if delta > 60:
  55. print 'Course Changed!',new,old,delta
  56. return True
  57.  
  58. loc = location.get_location()
  59. sendLoc(aprs,loc)
  60. last=loc
  61. while True:
  62. loc = location.get_location()
  63. if (dist(last,loc) > 0.25 and count >= 4) or dist(last,loc) > 1 or count >24 or course(last,loc):
  64. count = 0
  65. last=loc
  66. try:
  67. sendLoc(aprs,loc)
  68. except:
  69. aprs.connect()
  70. sendLoc(aprs,loc)
  71. else:
  72. count +=1
  73. time.sleep(10
Add Comment
Please, Sign In to add comment