Changeset c53f31a
- Timestamp:
- Jul 20, 2016, 9:15:08 PM (10 years ago)
- Branches:
- 0.5, app-cordova, debian/bullseye, debian/jessie, master
- Children:
- 0272b16
- Parents:
- 7549de9
- File:
-
- 1 edited
-
src/daemon/gnuboat (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/daemon/gnuboat
r7549de9 rc53f31a 26 26 import os 27 27 import dateutil 28 import getopt 29 import sys 28 30 from EPD import EPD 29 31 from PIL import Image … … 35 37 marginVertical = 10 36 38 marginHorizontal = marginVertical 37 rrdFile = "/home/joachim/public_html/gnuboat/webservice/data/log-webservice.rrd" 38 shutdownFile = "/var/spool/gnuboat/shutdown.request" 39 logPeriod = 1 40 displayPeriod = 5 39 40 # default values for command line arguments 41 rrdfile = "/var/www/gnuboat/webservice/data/log-webservice.rrd" 42 shutdownfile = "/var/spool/gnuboat/shutdown.request" 43 logperiod = 1 44 displayperiod = 5 41 45 42 46 shutdownRequested = None … … 66 70 67 71 def run(self): 72 global logperiod 68 73 try: 69 74 while self._running: 70 75 self._currentValue = self._session.next() 71 time.sleep(float(log Period)/2.0)76 time.sleep(float(logperiod)/2.0) 72 77 except StopIteration: 73 78 pass … … 89 94 90 95 if not os.path.isfile(databaseFile): 91 rrdtool.create( rrdFile,96 rrdtool.create(databaseFile, 92 97 "--start", 93 98 "N", … … 143 148 epd.update() 144 149 145 def checkShutdownRequest( ):146 global shutdownRequest 150 def checkShutdownRequest(shutdownFile): 151 global shutdownRequested 147 152 # have look for new shutdown requests 148 153 if os.path.isfile(shutdownFile): … … 156 161 os.system("sudo shutdown -r now") 157 162 158 if __name__ == '__main__': 159 createDatabase(rrdFile) 163 def usage(): 164 print "Usage of gnuboat daemon:" 165 print " gnuboat -r PATH_TO_RRD_DATABAE_FILE -s PATH_TO_SHUTDOWN_REQUEST_FILE [-l [LOG_UPDATE_PERIOD] [-d DISPLAY_UPDATE_PERIOD]" 166 print "" 167 print " -h --help Display this help" 168 print " -r --rrdfile Path to the rrd database used by the webservice to serve the clients" 169 print " -s --shutdownfile Path to the shutdown request file, used by the webservice to request a shutdown of the system running gnuboat" 170 print " -l --logperiod Time in seconds to update the logs" 171 print " -d --displayperiod Timein seconds to update the display" 172 173 def main(argv): 174 global rrdfile 175 global shutdownfile 176 global logperiod 177 global displayperiod 178 179 try: 180 opts, args = getopt.getopt(argv, "hr:s:l:d:", ["help", "rrdfile=", "shutdownfile=", "logperiod=", "displayperiod="]) 181 except getopt.GetoptError: 182 usage() 183 sys.exit(2) 184 185 for option, argument in opts: 186 if option == ("-h", "--help"): 187 usage() 188 sys.exit() 189 elif option in ("-r", "--rrdfile"): 190 rrdfile = argument 191 elif option in ("-s", "--shutdownfile"): 192 shutdownfile = argument 193 elif option in ("-l", "--logperiod"): 194 logperiod = argument 195 elif option in ("-d", "--displayperiod"): 196 displayperiod = argument 197 else: 198 assert False, "unhandled option" 199 200 if not os.path.exists(os.path.dirname(rrdfile)): 201 print "rrd database directory not found %s" % os.path.dirname(rrdfile) 202 print "" 203 usage() 204 sys.exit(2) 205 206 if not os.path.exists(os.path.dirname(shutdownfile)): 207 print "Shutdown request directory not found %s" % os.path.dirname(shutdownfile) 208 print "" 209 usage() 210 sys.exit(2) 211 212 if logperiod < 1: 213 print "Log period must be >= 1" 214 print "" 215 usage() 216 sys.exit(2) 217 218 if displayperiod < 1 or displayperiod < logperiod: 219 print "Display period must be >= 1 and could not be faster than log period" 220 print "" 221 usage() 222 sys.exit(2) 223 224 createDatabase(rrdfile) 160 225 161 226 epd = EPD() … … 168 233 while True: 169 234 # In the main thread, every logPeriod seconds print the current value 170 time.sleep(log Period)235 time.sleep(logperiod) 171 236 latitude = gpsp.latitude() 172 237 longitude = gpsp.longitude() … … 178 243 179 244 # update rrd database for the webservice 180 rrdtool.update(rrd File, "N:%s:%s:%s:%s:%s:%s:%s" % (latitude, longitude, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix))245 rrdtool.update(rrdfile, "N:%s:%s:%s:%s:%s:%s:%s" % (latitude, longitude, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix)) 181 246 # update display, if needed 182 if time.time() % displayPeriod == 0:247 if round(time.time(),0) % displayperiod == 0: 183 248 displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix) 184 249 #check for shutdown request 185 checkShutdownRequest( )250 checkShutdownRequest(shutdownfile) 186 251 187 252 except (KeyboardInterrupt, SystemExit): #when you press ctrl+c 188 253 gpsp.stop() 189 254 gpsp.join() # wait for the thread to finish what it's doing 255 256 if __name__ == "__main__": 257 main(sys.argv[1:])
Note:
See TracChangeset
for help on using the changeset viewer.
