Changeset 7549de9 for src/daemon
- Timestamp:
- Jul 20, 2016, 8:37:58 PM (10 years ago)
- Branches:
- 0.5, app-cordova, debian/bullseye, debian/jessie, master
- Children:
- c53f31a
- Parents:
- 0c7eb83 (diff), 10edeb0 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/daemon
- Files:
-
- 1 added
- 1 edited
-
gnuboat (modified) (5 diffs)
-
gnuboat-splashscreen (added)
Legend:
- Unmodified
- Added
- Removed
-
src/daemon/gnuboat
r0c7eb83 r7549de9 1 1 #!/usr/bin/python 2 # -*- coding: utf-8 -*- 2 3 ''' 3 4 Copyright (C) 2016 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. … … 22 23 import time 23 24 import threading 24 import os.path 25 import re 26 import os 27 import dateutil 28 from EPD import EPD 29 from PIL import Image 30 from PIL import ImageDraw 31 from PIL import ImageFont 25 32 26 rrdFile = "/home/jlan11/public_html/gnuboat/webservice/data/log-webservice.rrd" 33 WHITE=1 34 BLACK=0 35 marginVertical = 10 36 marginHorizontal = marginVertical 37 rrdFile = "/home/joachim/public_html/gnuboat/webservice/data/log-webservice.rrd" 38 shutdownFile = "/var/spool/gnuboat/shutdown.request" 27 39 logPeriod = 1 40 displayPeriod = 5 41 42 shutdownRequested = None 28 43 29 44 # Copied from https://gist.github.com/wolfg1969/4653340 … … 58 73 pass 59 74 60 def createDatabase(databaseFile) 75 def createDatabase(databaseFile): 61 76 rrdDataSources = [ 'DS:latitude:GAUGE:15:-90:90', 62 77 'DS:longitude:GAUGE:15:-180:180', … … 82 97 rrdArchives) 83 98 99 def displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix): 100 # requires dejavu package!!!! 101 fontValues = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf', 34) 102 fontTitles = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 24) 103 104 # initially set all white background 105 image = Image.new('1', epd.size, WHITE) 106 width, height = image.size 107 108 rowHeightTitles = 25 109 rowHeightValues = float(height - 2 * rowHeightTitles - 3 * marginVertical) / 2.0 110 columnWidthUnit = 30 111 columnWidthValues = int(float(width - 3 * marginHorizontal - 2 * columnWidthUnit) / 2.0) 112 113 draw = ImageDraw.Draw(image) 114 # draw.rectangle((0, 0, width, height), fill=WHITE, outline=WHITE) 115 116 x = marginHorizontal 117 y = marginVertical 118 draw.text((x, y), "STW", fill=BLACK, font=fontTitles) 119 draw.text((x, y + rowHeightTitles), str(speedThroughWater), fill=BLACK, font=fontValues) 120 draw.text((x + columnWidthValues, y + rowHeightTitles * 1.4), "kts", fill=BLACK, font=fontTitles) 121 122 x = x + marginHorizontal + columnWidthValues + columnWidthUnit 123 draw.text((x, y), "SOG", fill=BLACK, font=fontTitles) 124 draw.text((x, y + rowHeightTitles), str(speedOverGround), fill=BLACK, font=fontValues) 125 draw.text((x + columnWidthValues, y + rowHeightTitles * 1.4), "kts", fill=BLACK, font=fontTitles) 126 127 x = marginHorizontal 128 y = y + rowHeightTitles + rowHeightValues + marginVertical 129 draw.text((x, y), "Depth", fill=BLACK, font=fontTitles) 130 draw.text((x, y + rowHeightTitles), str(waterDepth), fill=BLACK, font=fontValues) 131 draw.text((x + int(float(columnWidthValues) / 1.5), y + rowHeightTitles * 1.4), "m", fill=BLACK, font=fontTitles) 132 133 x = x + marginHorizontal + columnWidthValues + columnWidthUnit 134 draw.text((x, y), "Water", fill=BLACK, font=fontTitles) 135 draw.text((x, y + rowHeightTitles), str(waterTemperature), fill=BLACK, font=fontValues) 136 draw.text((x + int(float(columnWidthValues) / 1.5), y + rowHeightTitles * 1.4), "C", fill=BLACK, font=fontTitles) 137 138 x = int((x + marginHorizontal + columnWidthValues) * 0.93) 139 draw.text((x, y), "Fix", fill=BLACK, font=fontTitles) 140 draw.text((x, y + rowHeightTitles), str(gpsFix), fill=BLACK, font=fontValues) 141 142 epd.display(image) 143 epd.update() 144 145 def checkShutdownRequest(): 146 global shutdownRequest 147 # have look for new shutdown requests 148 if os.path.isfile(shutdownFile): 149 with open(shutdownFile, "r") as fileHandler: 150 shutdownStart = fileHandler.read().strip() 151 os.remove(shutdownFile) 152 shutdownRequested = dateutil.parser.parse(shutdownStart) 153 # check existing shutdown requests 154 if shutdownRequested is not None: 155 if (datetime.now() - shutdownRequested) > timedelta(seconds = 0): 156 os.system("sudo shutdown -r now") 157 84 158 if __name__ == '__main__': 85 159 createDatabase(rrdFile) 160 161 epd = EPD() 162 epd.clear() 86 163 87 164 gpsp = GpsdPoller() 88 165 try: 89 166 gpsp.start() 90 print "Collecting data..."91 167 # gpsp now polls every .2 seconds for new data, storing it in self.current_value 92 168 while True: 93 # In the main thread, every 5seconds print the current value169 # In the main thread, every logPeriod seconds print the current value 94 170 time.sleep(logPeriod) 95 171 latitude = gpsp.latitude() … … 100 176 waterTemperature = random.randrange(15, 25) + 0.5; 101 177 gpsFix = gpsp.gpsFix() 178 179 # update rrd database for the webservice 102 180 rrdtool.update(rrdFile, "N:%s:%s:%s:%s:%s:%s:%s" % (latitude, longitude, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix)) 181 # update display, if needed 182 if time.time() % displayPeriod == 0: 183 displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix) 184 #check for shutdown request 185 checkShutdownRequest() 103 186 104 187 except (KeyboardInterrupt, SystemExit): #when you press ctrl+c 105 print "\nKilling Thread..."106 188 gpsp.stop() 107 189 gpsp.join() # wait for the thread to finish what it's doing 108 print "Done.\nExiting."
Note:
See TracChangeset
for help on using the changeset viewer.
