Changeset 04de4a4 for src


Ignore:
Timestamp:
Aug 23, 2016, 12:05:09 AM (10 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
0.5, app-cordova, debian/bullseye, debian/jessie, master
Children:
3f77ad0
Parents:
2925c4a (diff), 9be4f3f (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.
Message:

Merge branch 'master' of ​https://svn.falaba.de/gnuboat

Location:
src
Files:
5 added
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • src/daemon/gnuboat

    r2925c4a r04de4a4  
    3131import getopt
    3232import sys
    33 from EPD import EPD
    34 from PIL import Image
    35 from PIL import ImageDraw
    36 from PIL import ImageFont
     33
     34try:
     35  from EPD import EPD
     36  from PIL import Image
     37  from PIL import ImageDraw
     38  from PIL import ImageFont
     39  epdEnabled = True
     40except:
     41  epdEnabled = False
    3742
    3843WHITE=1
    … …  
    4247
    4348# default values for command line arguments
    44 rrdfile = "/var/www/html/webservice/data/log-webservice.rrd"
     49rrdfile = "/usr/share/gnuboat/webservice/data/log-webservice.rrd"
    4550shutdownfile = "/var/spool/gnuboat/shutdown.request"
    4651logperiod = 1
    … …  
    4853
    4954shutdownRequested = None
     55latitude = None
     56longitude = None
     57speedThroughWater = None
     58speedOverGround = None
     59waterDepth = None
     60waterTemperature = None
     61gpsFix = None
    5062
    5163# Copied from https://gist.github.com/wolfg1969/4653340
    … …  
    8193      pass
    8294
     95"""@class DisplayHandler
     96"""
     97class DisplayHandler(threading.Thread):
     98  def __init__(self, displayperiod):
     99    threading.Thread.__init__(self)
     100    self._epd = EPD()
     101    self._epd.clear()
     102    self._updatePeriod = displayperiod
     103    self._running = True
     104   
     105  def stop(self):
     106    self._running = False
     107   
     108  def run(self):
     109    global latitude
     110    global longitude
     111    global speedThroughWater
     112    global speedOverGround
     113    global waterDepth
     114    global waterTemperature
     115    global gpsFix
     116
     117    try:
     118      while self._running:
     119        self.displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix)
     120        time.sleep(self._updatePeriod)
     121    except StopIteration:
     122      pass
     123
     124  def displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix):
     125    if not epdEnabled:
     126      return
     127
     128    # requires dejavu package!!!!
     129    fontValues = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf', 34)
     130    fontTitles = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 24)
     131
     132    # initially set all white background
     133    image = Image.new('1', epd.size, WHITE)
     134    width, height = image.size
     135
     136    rowHeightTitles = 25
     137    rowHeightValues = float(height - 2 * rowHeightTitles - 3 * marginVertical) / 2.0
     138    columnWidthUnit = 30
     139    columnWidthValues = int(float(width - 3 * marginHorizontal - 2 * columnWidthUnit) / 2.0)
     140
     141    draw = ImageDraw.Draw(image)
     142    # draw.rectangle((0, 0, width, height), fill=WHITE, outline=WHITE)
     143
     144    x = marginHorizontal
     145    y = marginVertical
     146    draw.text((x, y), "STW", fill=BLACK, font=fontTitles)
     147    if speedThroughWater is not None:
     148      draw.text((x, y + rowHeightTitles), str(speedThroughWater), fill=BLACK, font=fontValues)
     149    draw.text((x + columnWidthValues, y + rowHeightTitles * 1.4), "kts", fill=BLACK, font=fontTitles)
     150
     151    x = x + marginHorizontal + columnWidthValues + columnWidthUnit
     152    draw.text((x, y), "SOG", fill=BLACK, font=fontTitles)
     153    if speedOverGround is not None:
     154      draw.text((x, y + rowHeightTitles), str(speedOverGround), fill=BLACK, font=fontValues)
     155    draw.text((x + columnWidthValues, y + rowHeightTitles * 1.4), "kts", fill=BLACK, font=fontTitles)
     156
     157    x = marginHorizontal
     158    y = y + rowHeightTitles + rowHeightValues + marginVertical
     159    draw.text((x, y), "Depth", fill=BLACK, font=fontTitles)
     160    if waterDepth is not None:
     161      draw.text((x, y + rowHeightTitles), str(waterDepth), fill=BLACK, font=fontValues)
     162    draw.text((x + int(float(columnWidthValues) / 1.5), y + rowHeightTitles * 1.4), "m", fill=BLACK, font=fontTitles)
     163
     164    x = x + marginHorizontal + columnWidthValues + columnWidthUnit
     165    draw.text((x, y), "Water", fill=BLACK, font=fontTitles)
     166    if waterTemperature is not None:
     167      draw.text((x, y + rowHeightTitles), str(waterTemperature), fill=BLACK, font=fontValues)
     168    draw.text((x + int(float(columnWidthValues) / 1.5), y + rowHeightTitles * 1.4), "C", fill=BLACK, font=fontTitles)
     169
     170    x = int((x + marginHorizontal + columnWidthValues) * 0.93)
     171    draw.text((x, y), "Fix", fill=BLACK, font=fontTitles)
     172    if gpsFix is not None:
     173      draw.text((x, y + rowHeightTitles), str(gpsFix), fill=BLACK, font=fontValues)
     174 
     175    epd.display(image)
     176    epd.update()
     177
    83178def createDatabase(databaseFile):
    84179  rrdDataSources = [ 'DS:latitude:GAUGE:15:-90:90',
    … …  
    104199                   rrdDataSources,
    105200                   rrdArchives)
    106 
    107 def displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix):
    108   # requires dejavu package!!!!
    109   fontValues = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf', 34)
    110   fontTitles = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 24)
    111 
    112   # initially set all white background
    113   image = Image.new('1', epd.size, WHITE)
    114   width, height = image.size
    115 
    116   rowHeightTitles = 25
    117   rowHeightValues = float(height - 2 * rowHeightTitles - 3 * marginVertical) / 2.0
    118   columnWidthUnit = 30
    119   columnWidthValues = int(float(width - 3 * marginHorizontal - 2 * columnWidthUnit) / 2.0)
    120 
    121   draw = ImageDraw.Draw(image)
    122   # draw.rectangle((0, 0, width, height), fill=WHITE, outline=WHITE)
    123 
    124   x = marginHorizontal
    125   y = marginVertical
    126   draw.text((x, y), "STW", fill=BLACK, font=fontTitles)
    127   draw.text((x, y + rowHeightTitles), str(speedThroughWater), fill=BLACK, font=fontValues)
    128   draw.text((x + columnWidthValues, y + rowHeightTitles * 1.4), "kts", fill=BLACK, font=fontTitles)
    129 
    130   x = x + marginHorizontal + columnWidthValues + columnWidthUnit
    131   draw.text((x, y), "SOG", fill=BLACK, font=fontTitles)
    132   draw.text((x, y + rowHeightTitles), str(speedOverGround), fill=BLACK, font=fontValues)
    133   draw.text((x + columnWidthValues, y + rowHeightTitles * 1.4), "kts", fill=BLACK, font=fontTitles)
    134 
    135   x = marginHorizontal
    136   y = y + rowHeightTitles + rowHeightValues + marginVertical
    137   draw.text((x, y), "Depth", fill=BLACK, font=fontTitles)
    138   draw.text((x, y + rowHeightTitles), str(waterDepth), fill=BLACK, font=fontValues)
    139   draw.text((x + int(float(columnWidthValues) / 1.5), y + rowHeightTitles * 1.4), "m", fill=BLACK, font=fontTitles)
    140 
    141   x = x + marginHorizontal + columnWidthValues + columnWidthUnit
    142   draw.text((x, y), "Water", fill=BLACK, font=fontTitles)
    143   draw.text((x, y + rowHeightTitles), str(waterTemperature), fill=BLACK, font=fontValues)
    144   draw.text((x + int(float(columnWidthValues) / 1.5), y + rowHeightTitles * 1.4), "C", fill=BLACK, font=fontTitles)
    145 
    146   x = int((x + marginHorizontal + columnWidthValues) * 0.93)
    147   draw.text((x, y), "Fix", fill=BLACK, font=fontTitles)
    148   draw.text((x, y + rowHeightTitles), str(gpsFix), fill=BLACK, font=fontValues)
    149  
    150   epd.display(image)
    151   epd.update()
    152201
    153202def checkShutdownRequest(shutdownFile):
    … …  
    181230  global logperiod
    182231  global displayperiod
     232  global latitude
     233  global longitude
     234  global speedThroughWater
     235  global speedOverGround
     236  global waterDepth
     237  global waterTemperature
     238  global gpsFix
    183239
    184240  try:                               
    … …  
    229285  createDatabase(rrdfile)
    230286
    231   epd = EPD()
    232   epd.clear()
     287  displayHandler = None
     288  if epdEnabled:
     289    displayHandler = DisplayHandler(displayperiod)
    233290
    234291  gpsp = GpsdPoller()
    … …  
    249306      # update rrd database for the webservice
    250307      rrdtool.update(rrdfile, "N:%s:%s:%s:%s:%s:%s:%s" % (latitude, longitude, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix))
    251       # update display, if needed
    252       if round(time.time(),0) % displayperiod == 0:
    253         displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix)
    254308      #check for shutdown request
    255309      checkShutdownRequest(shutdownfile)
    … …  
    258312    gpsp.stop()
    259313    gpsp.join() # wait for the thread to finish what it's doing
     314    if displayHandler is not None:
     315      displayHandler.stop()
     316      displayHandler.join() # wait for the thread to finish what it's doing
    260317
    261318if __name__ == "__main__":
  • src/webapp/build.xml

    r2925c4a r04de4a4  
    1616                <fileset dir="./webclient/javascript" id="filesJavascript"/>
    1717                <fileset dir="./webclient/resources" id="filesResources"/>
     18                <fileset dir="../icon/" id="filesGnuboatIcons">
     19                        <include name="gnuboat-256-256-transparent.png"/>
     20                </fileset>
    1821
    1922                <copy todir="${builddir}/webclient">
    … …  
    2831                <copy todir="${builddir}/webclient/resources">
    2932                        <fileset refid="filesResources"/>
     33                        <fileset refid="filesGnuboatIcons"/>
    3034                </copy>
    3135        </target>
    3236        <target name="buildwebservice" depends="prepare">
    33                 <fileset dir="./webservice" id="filesWebservice"/>
     37                <fileset dir="./webservice" id="filesWebservice">
     38                        <exclude name="mbtiles/*"/>
     39                </fileset>
    3440                <fileset dir="./webservice/mbtiles" id="filesWebserviceMaps">
    3541                        <!-- <exclude name=""/> -->
  • src/webapp/webclient/css/main.css

    r2925c4a r04de4a4  
    1818body {
    1919        margin: 1em;
    20         width: 58.3mm;
     20        width: 14em;
     21        border-color: 1px solid black;
    2122}
    2223
    … …  
    2425        background-color: #93C0C0;
    2526        background-image: linear-gradient(#BCD9D9, #93C0C0);
     27}
     28
     29.backgroundgreen {
     30        background-color: #ACDFAC;
     31        background-image: linear-gradient(#CCECCC, #ACDFAC);
    2632}
    2733
    … …  
    3440}
    3541
     42#title img {
     43        height: 2em;
     44        width: auto;
     45        vertical-align: middle;
     46        margin: 0.1em;
     47        padding-left: 0em;
     48        margin-left: -0.3em;
     49}
     50
    3651#display {
    3752        background-color: #E6E6E6;
    3853        width: 100%;
    39         height: 38.2mm;
     54        height: 9em;
    4055        font-size: 12pt;
    4156        font-weight: normal;
    … …  
    6176#display #speedthroughwater {
    6277        position: absolute;
    63         top: 2mm;
    64         left: 2mm;
     78        top: 0.5em;
     79        left: 0.5em;
    6580}
    6681
    … …  
    7287#display #speedoverground {
    7388        position: absolute;
    74         top: 2mm;
    75         left: 30mm;
     89        top:  0.5em;
     90        left: 7em;
    7691}
    7792
    7893#display #waterdepth {
    7994        position: absolute;
    80         top: 21mm;
    81         left: 2mm;
     95        top: 5em;
     96        left: 0.5em;
     97}
     98
     99#display #watertemperature {
     100        position: absolute;
     101        top: 5em;
     102        left: 7em;
    82103}
    83104
    84105#display #gpsfix {
    85106        position: absolute;
    86         top: 21mm;
    87         left: 46mm;
    88 }
    89 
    90 #display #watertemperature {
    91         position: absolute;
    92         top: 21mm;
    93         left: 30mm;
     107        top: 5em;
     108        left: 11em;
    94109}
    95110
    96111#map {
    97112        width: 100%;
    98         height: 76mm;
     113        height: 24em;
    99114        border: 1px solid black;
    100115        margin-top: 1em;
    … …  
    105120}
    106121
     122form h2 {
     123        text-align: center;
     124        margin-top: 2em;
     125        margin-bottom: 0.5em;
     126        padding-top: 0.6em;
     127        height: 2em;
     128}
     129
    107130form p {
    108         margin-top: 1em;
    109131        height: 3em;
     132        margin: 0em;
    110133}
    111134
    … …  
    114137        height: 3em;
    115138        width: 100%;
     139        font-weight: normal;
     140        margin-top: 1em;
    116141}
    117142
    118143.formButtons {
    119144        text-align: center;
    120         margin-top: 2em;
     145        margin-top: 3em;
    121146}
    122147
  • src/webapp/webclient/javascript/main.js

    r2925c4a r04de4a4  
    3838                        var value = lastValid[key];
    3939                        if($.isNumeric(value)){
     40                                var text = value.toFixed(1);
    4041                                if(key == "watertemperature"){
    41                                         value = Math.round(value);
     42                                        text = value.toFixed(0);
    4243                                }
    43                                 $("#display #"+ keys[i] +" #value").text(value.toString());
     44                                $("#display #"+ keys[i] +" #value").text(text);
    4445                        }
    4546                        else if(key == "gpsfix"){
  • src/webapp/webclient/root/inc/header.php

    r2925c4a r04de4a4  
    3737        <!DOCTYPE HTML>
    3838        <html>
    39                 <head>
     39                <head profile="http://www.w3.org/2005/10/profile">
    4040                        <meta charset="utf-8"/>
     41                        <link rel="icon" type="image/png" href="resources/gnuboat-256-256-transparent.png"/>
    4142                        <title>GNUBoat <?php echo (empty($headerTitle)) ? "" : " - ". $headerTitle; ?></title>
    4243                        <link rel="stylesheet" href="css/main.css" type="text/css"/>
  • src/webapp/webclient/root/index.php

    r2925c4a r04de4a4  
    6565require_once("inc/header.php");
    6666?>
    67         <h2 id="title" class="backgroundblue">GNUBoat</h2>
     67        <h2 id="title" class="backgroundblue"><img src="resources/gnuboat-256-256-transparent.png" />Boat</h2>
    6868        <div id="display">
    6969                <div id="speedthroughwater">
    … …  
    8989        </div>
    9090        <div id="map"></div>
     91        <div id="shutdown">
     92                <p id="shutdownMessage"/>
     93                <form>
     94                        <button type="button" id="shutdownButton">SHUTDOWN</button>
     95                </form>
     96        </div>
    9197        <form method="post" action="./" enctype="multipart/form-data">
    9298                <div class="formTable">
     99                        <h2 class="backgroundgreen">Map Upload</h2>
    93100                        <p>
    94                                 <label>Upload Map (mbtiles format):</label><br/>
     101                                <label>MBTiles File:</label><br/>
    95102                                <input class="file" type="file" name="mapFile" value=""/>
    96103                        </p>
    … …  
    100107                </div>
    101108        </form>
    102         <div id="shutdown">
    103                 <p id="shutdownMessage"/>
    104                 <form>
    105                         <button type="button" id="shutdownButton">SHUTDOWN</button>
    106                 </form>
    107         </div>
    108109<?php
    109110require_once("inc/footer.php");
  • src/webapp/webservice/inc/Config.php

    r2925c4a r04de4a4  
    3838        }
    3939       
     40        public function shutdownRequestFile(){
     41                if(array_key_exists("shutdownfile", $this->_config))
     42                        return $this->_config["shutdownfile"];
     43                return "/var/spool/gnuboat/shutdown.request";
     44        }
     45       
    4046        public function dataDirectory(){
    4147                if(array_key_exists("datadirectory", $this->_config))
  • src/webapp/webservice/index.php

    r2925c4a r04de4a4  
    9292                                if(!is_numeric($tmp[$key]) || is_nan($tmp[$key])){
    9393                                        $allValid = false;
     94                                        if($debug > 1){
     95                                                echo "Invalid value ". $key ." (". $tmp[$key] .") at time ". $time ."<br/>";
     96                                        }
    9497                                }
    9598                                elseif(array_key_exists($key, $configRound) && is_integer($configRound[$key]))
    … …  
    98101                }
    99102                // only add the timeframe to the track, if the values are valid and we had a gps fix at that time
    100                 if($allValid && $tmp["gpsfix"] != "-"){
    101                         echo "want to add ". $time ."<br/>\n";
    102                         if(!array_key_exists($time, $result["track"])){
     103                if($allValid){
     104                        if(!array_key_exists($time, $result["track"])){
    103105                                $result["track"][$time] = $tmp;
    104                         }
     106                        }
    105107                        $lastTime = $time;
    106108                }
    … …  
    131133$result = array();
    132134if($request == REQUEST_SHUTDOWN){
    133         $handle = @fopen("/var/spool/gnuboat/shutdown.request", "w");
     135        $handle = @fopen($config->shutdownRequestFile(), "w");
    134136        if($handle === false){
    135                 $message = "Could not create file to indicate shutdown to the daemon (Timezone: ". date_default_timezone_get() .")";
     137                $message = "Could not create file (". $config->shutdownRequestFile() .") to indicate shutdown to the daemon (Timezone: ". date_default_timezone_get() .")";
    136138                if($debug > 0)
    137139                        echo $message;
Note: See TracChangeset for help on using the changeset viewer.