Browse code

minor revisions

Gandolf authored on 06/08/2021 19:02:58
Showing 1 changed files
... ...
@@ -46,21 +46,21 @@ import tmp102 # temperature sensor
46 46
 
47 47
     ### SENSOR BUS ADDRESSES ###
48 48
 
49
-# Set bus addresses of sensors
49
+# Set bus addresses of sensors.
50 50
 _PWR_SENSOR_ADDR = 0X40
51 51
 _BAT_TMP_SENSOR_ADDR = 0x48
52 52
 _AMB_TMP_SENSOR_ADDR = 0x4B
53
-# Set bus selector
53
+# Set bus selector.
54 54
 _BUS_SEL = 1
55 55
 
56 56
     ### FILE AND FOLDER LOCATIONS ###
57 57
 
58 58
 _USER = os.environ['USER']
59
-# folder for containing dynamic data objects
59
+# folder to contain dynamic data objects
60 60
 _DOCROOT_PATH = "/home/%s/public_html/power/" % _USER
61
-# folder for charts and output data file
61
+# folder to contain charts and output data file
62 62
 _CHARTS_DIRECTORY = _DOCROOT_PATH + "dynamic/"
63
-# location of data output file
63
+# location of JSON output data file
64 64
 _OUTPUT_DATA_FILE = _DOCROOT_PATH + "dynamic/powerData.js"
65 65
 # database that stores node data
66 66
 _RRD_FILE = "/home/%s/database/powerData.rrd" % _USER
... ...
@@ -82,13 +82,12 @@ _AVERAGE_LINE_COLOR = '#006600'
82 82
 
83 83
    ### GLOBAL VARIABLES ###
84 84
 
85
-# turn on or off of verbose debugging information
85
+# debug output options
86 86
 debugOption = False
87 87
 verboseDebug = False
88
-
89 88
 # frequency of data requests to sensors
90 89
 dataRequestInterval = _DEFAULT_DATA_REQUEST_INTERVAL
91
-# chart update interval
90
+# how often charts get updated
92 91
 chartUpdateInterval = _CHART_UPDATE_INTERVAL
93 92
 # last node request time
94 93
 lastDataPointTime = -1
... ...
@@ -127,9 +126,9 @@ def getEpochSeconds(sTime):
127 126
 ## end def
128 127
 
129 128
 def terminateAgentProcess(signal, frame):
130
-    """Send a message to log when the agent process gets killed
129
+    """Send a message to the log when the agent process gets killed
131 130
        by the operating system.  Inform downstream clients
132
-       by removing input and output data files.
131
+       by removing output data files.
133 132
        Parameters:
134 133
            signal, frame - dummy parameters
135 134
        Returns: nothing
... ...
@@ -145,10 +144,11 @@ def terminateAgentProcess(signal, frame):
145 144
   ###  PUBLIC METHODS  ###
146 145
 
147 146
 def getSensorData(dData):
148
-    """Poll sensors for data.
149
-       Parameters: none
150
-       Returns: a string containing the node signal data if successful,
151
-                or None if not successful
147
+    """Poll sensors for data. Store the data in a dictionary object for
148
+       use by other subroutines.  The dictionary object passed in should
149
+       an empty dictionary, i.e., dData = { }.
150
+       Parameters: dData - a dictionary object to contain the sensor data
151
+       Returns: True if successful, False otherwise
152 152
     """
153 153
     try:
154 154
         dData["time"] = getTimeStamp()
... ...
@@ -199,10 +199,10 @@ def updateDatabase(dData):
199 199
 
200 200
 def writeOutputDataFile(dData):
201 201
     """Write node data items to the output data file, formatted as 
202
-       a Javascript file.  This file may then be accessed and used by
203
-       by downstream clients, for instance, in HTML documents.
202
+       a Javascript file.  This file may then be requested and used by
203
+       by downstream clients, for instance, an HTML document.
204 204
        Parameters:
205
-           sData - a string object containing the data to be written
205
+           dData - a dictionary containing the data to be written
206 206
                    to the output data file
207 207
        Returns: True if successful, False otherwise
208 208
     """
... ...
@@ -238,8 +238,8 @@ def writeOutputDataFile(dData):
238 238
 ## end def
239 239
 
240 240
 def createGraph(fileName, dataItem, gLabel, gTitle, gStart,
241
-                lower, upper, trendLine, scaleFactor=1, autoScale=True, 
242
-                alertLine=""):
241
+                lower=0, upper=0, trendLine=0, scaleFactor=1,
242
+                autoScale=True, alertLine=""):
243 243
     """Uses rrdtool to create a graph of specified node data item.
244 244
        Parameters:
245 245
            fileName - name of file containing the graph
... ...
@@ -384,10 +384,11 @@ def getCLarguments():
384 384
     """Get command line arguments.  There are three possible arguments
385 385
           -d turns on debug mode
386 386
           -v turns on verbose debug mode
387
-          -t sets the sensor query interval
387
+          -p sets the sensor query period
388
+          -c sets the chart update period
388 389
        Returns: nothing
389 390
     """
390
-    global debugOption, verboseDebug, dataRequestInterval
391
+    global debugOption, verboseDebug, dataRequestInterval, chartUpdateInterval
391 392
 
392 393
     index = 1
393 394
     while index < len(sys.argv):
... ...
@@ -400,12 +401,20 @@ def getCLarguments():
400 401
             try:
401 402
                 dataRequestInterval = abs(int(sys.argv[index + 1]))
402 403
             except:
403
-                print "invalid polling period"
404
+                print "invalid sensor query period"
405
+                exit(-1)
406
+            index += 1
407
+        elif sys.argv[index] == '-c':
408
+            try:
409
+                chartUpdateInterval = abs(int(sys.argv[index + 1]))
410
+            except:
411
+                print "invalid chart update period"
404 412
                 exit(-1)
405 413
             index += 1
406 414
         else:
407 415
             cmd_name = sys.argv[0].split('/')
408
-            print "Usage: %s [-d] [-v] [-p seconds]" % cmd_name[-1]
416
+            print "Usage: %s [-d | v] [-p seconds] [-c seconds]" \
417
+                  % cmd_name[-1]
409 418
             exit(-1)
410 419
         index += 1
411 420
 ##end def