From fcfe8adeafd7dbc06b62b2c6e735d094ad2548fe Mon Sep 17 00:00:00 2001 From: Christopher Young Date: Tue, 16 May 2017 23:40:48 -0400 Subject: [PATCH 1/7] Undo cab2a81c26f214709f8cda941ff8ea19ca4549ba. See commit comments: https://github.com/cyoung/stratux/commit/cab2a81c26f214709f8cda941ff8ea1 9ca4549ba. A static build of wiringPi is all that is needed to produce the static binary. Static linking is needed to produce a working binary on current production images. --- Makefile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index c5173108..672480d8 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,9 @@ ifeq "$(CIRCLECI)" "true" BUILDINFO= PLATFORMDEPENDENT= else - BUILDINFO=-ldflags "-X main.stratuxVersion=`git describe --tags --abbrev=0` -X main.stratuxBuild=`git log -n 1 --pretty=%H`" + LDFLAGS_VERSION=-X main.stratuxVersion=`git describe --tags --abbrev=0` -X main.stratuxBuild=`git log -n 1 --pretty=%H` + BUILDINFO=-ldflags "$(LDFLAGS_VERSION)" + BUILDINFO_STATIC=-ldflags "-extldflags -static $(LDFLAGS_VERSION)" $(if $(GOROOT),,$(error GOROOT is not set!)) PLATFORMDEPENDENT=fancontrol endif @@ -12,12 +14,12 @@ all: make xdump978 xdump1090 xgen_gdl90 $(PLATFORMDEPENDENT) xgen_gdl90: - go get -t -d -v ./main ./test ./godump978 ./uatparse ./sensors - go build $(BUILDINFO) -p 4 main/gen_gdl90.go main/traffic.go main/gps.go main/network.go main/managementinterface.go main/sdr.go main/ping.go main/uibroadcast.go main/monotonic.go main/datalog.go main/equations.go main/sensors.go main/cputemp.go + go get -t -d -v ./main ./test ./godump978 ./uatparse + go build $(BUILDINFO) -p 4 main/gen_gdl90.go main/traffic.go main/gps.go main/network.go main/managementinterface.go main/sdr.go main/ping.go main/uibroadcast.go main/monotonic.go main/datalog.go main/equations.go main/cputemp.go fancontrol: go get -t -d -v ./main - go build $(BUILDINFO) -p 4 main/fancontrol.go main/equations.go main/cputemp.go + go build $(BUILDINFO_STATIC) -p 4 main/fancontrol.go main/equations.go main/cputemp.go xdump1090: git submodule update --init @@ -59,3 +61,4 @@ clean: rm -f gen_gdl90 libdump978.so fancontrol cd dump1090 && make clean cd dump978 && make clean + From 069cb9e1fc617e124ee098df6e648c284289312b Mon Sep 17 00:00:00 2001 From: Christopher Young Date: Tue, 16 May 2017 23:50:35 -0400 Subject: [PATCH 2/7] Undo cab2a81. See commit comments: cab2a81 9ca4549ba. A static build of wiringPi is all that is needed to produce the static binary. Static linking is needed to produce a working binary on current production images. --- Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 672480d8..2ba09e93 100644 --- a/Makefile +++ b/Makefile @@ -14,8 +14,8 @@ all: make xdump978 xdump1090 xgen_gdl90 $(PLATFORMDEPENDENT) xgen_gdl90: - go get -t -d -v ./main ./test ./godump978 ./uatparse - go build $(BUILDINFO) -p 4 main/gen_gdl90.go main/traffic.go main/gps.go main/network.go main/managementinterface.go main/sdr.go main/ping.go main/uibroadcast.go main/monotonic.go main/datalog.go main/equations.go main/cputemp.go + go get -t -d -v ./main ./test ./godump978 ./uatparse ./sensors + go build $(BUILDINFO) -p 4 main/gen_gdl90.go main/traffic.go main/gps.go main/network.go main/managementinterface.go main/sdr.go main/ping.go main/uibroadcast.go main/monotonic.go main/datalog.go main/equations.go main/sensors.go main/cputemp.go fancontrol: go get -t -d -v ./main @@ -61,4 +61,3 @@ clean: rm -f gen_gdl90 libdump978.so fancontrol cd dump1090 && make clean cd dump978 && make clean - From 83f0c6843f1b296f0167464873f9204c120d0581 Mon Sep 17 00:00:00 2001 From: Christopher Young Date: Wed, 17 May 2017 15:12:22 -0400 Subject: [PATCH 3/7] Suppress detected ownship traffic target, but don't use received data for GDL90 ownship message. #590. --- main/traffic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/traffic.go b/main/traffic.go index a26afc86..d3842ff6 100755 --- a/main/traffic.go +++ b/main/traffic.go @@ -223,7 +223,7 @@ func sendTrafficUpdates() { if globalSettings.DEBUG { log.Printf("Ownship target detected for code %X\n", code) } - OwnshipTrafficInfo = ti + // OwnshipTrafficInfo = ti } else { cur_n := len(msgs) - 1 if len(msgs[cur_n]) >= 35 { From 0d146d17470dd7ee6da75cc5187b124396ffbc7d Mon Sep 17 00:00:00 2001 From: Christopher Young Date: Wed, 17 May 2017 15:25:14 -0400 Subject: [PATCH 4/7] Set GDL90 traffic alert bit always when bearing/distance is not available. #580, #582. --- main/traffic.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main/traffic.go b/main/traffic.go index d3842ff6..bb49edc7 100755 --- a/main/traffic.go +++ b/main/traffic.go @@ -259,6 +259,10 @@ func registerTrafficUpdate(ti TrafficInfo) { func isTrafficAlertable(ti TrafficInfo) bool { // Set alert bit if possible and traffic is within some threshold // TODO: Could be more intelligent, taking into account headings etc. + if !ti.BearingDist_valid { + // If not able to calculate the distance to the target, let the alert bit be set always. + return true + } if ti.BearingDist_valid && ti.Distance < 3704 { // 3704 meters, 2 nm. return true From f2c311db6d79611c6e7b4fbba7effc3653c6a23d Mon Sep 17 00:00:00 2001 From: Christopher Young Date: Wed, 17 May 2017 17:18:00 -0400 Subject: [PATCH 5/7] If temperature rises after ramping to 100% PWM, then stop controlling the fan and set it to full ON. #599, #595, #593. --- main/fancontrol.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/main/fancontrol.go b/main/fancontrol.go index f8507139..58b552f2 100644 --- a/main/fancontrol.go +++ b/main/fancontrol.go @@ -63,19 +63,37 @@ func fanControl(pwmDutyMin int, pin int, tempTarget float32) { } }) pwmDuty := 0 + + tempWhenRampStarted := float32(0.) for { if temp > (tempTarget + hysteresis) { + if tempWhenRampStarted < 1. { + tempWhenRampStarted = temp + } pwmDuty = iMax(iMin(pwmDutyMax, pwmDuty+1), pwmDutyMin) + if pwmDuty == pwmDutyMax { + // At the maximum duty cycle currently. + // Has the temperature increased "substantially" since the ramp-up started? + if temp > (tempWhenRampStarted + hysteresis) { + // Give up. The fan does not like the PWM control. + break + } + } } else if temp < (tempTarget - hysteresis) { pwmDuty = iMax(pwmDuty-1, 0) if pwmDuty < pwmDutyMin { pwmDuty = 0 + tempWhenRampStarted = 0. } } //log.Println(temp, " ", pwmDuty) C.pwmWrite(cPin, C.int(pwmDuty)) time.Sleep(delaySeconds * time.Second) } + + // Default to "ON". + C.pinMode(cPin, C.OUTPUT) + C.digitalWrite(cPin, C.HIGH) } // Service has embedded daemon From e8273544aeeb6b1b35ba0e187fa62a949f32f3c0 Mon Sep 17 00:00:00 2001 From: Eric Westphal Date: Wed, 17 May 2017 17:32:05 -0400 Subject: [PATCH 6/7] mySituation tracks min/max G Load. --- main/gps.go | 2 ++ main/sensors.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/main/gps.go b/main/gps.go index 4c73ab93..16728ce7 100644 --- a/main/gps.go +++ b/main/gps.go @@ -94,6 +94,8 @@ type SituationData struct { AHRSSlipSkid float32 AHRSTurnRate float32 AHRSGLoad float32 + AHRSGLoadMin float32 + AHRSGLoadMax float32 AHRSLastAttitudeTime time.Time AHRSStatus uint8 } diff --git a/main/sensors.go b/main/sensors.go index 9c50c59d..00a9f736 100644 --- a/main/sensors.go +++ b/main/sensors.go @@ -262,6 +262,12 @@ func sensorAttitudeSender() { mySituation.AHRSSlipSkid = float32(s.SlipSkid()) mySituation.AHRSTurnRate = float32(s.RateOfTurn()) mySituation.AHRSGLoad = float32(s.GLoad()) + if mySituation.AHRSGLoad < mySituation.AHRSGLoadMin || mySituation.AHRSGLoadMin == 0 { + mySituation.AHRSGLoadMin = mySituation.AHRSGLoad + } + if mySituation.AHRSGLoad > mySituation.AHRSGLoadMax { + mySituation.AHRSGLoadMax = mySituation.AHRSGLoad + } mySituation.AHRSLastAttitudeTime = t } else { @@ -273,6 +279,8 @@ func sensorAttitudeSender() { mySituation.AHRSSlipSkid = invalid mySituation.AHRSTurnRate = invalid mySituation.AHRSGLoad = invalid + mySituation.AHRSGLoadMin = invalid + mySituation.AHRSGLoadMax = 0 mySituation.AHRSLastAttitudeTime = time.Time{} } mySituation.muAttitude.Unlock() @@ -367,6 +375,12 @@ func CageAHRS() { cage <- true } +// ResetAHRSGLoad resets the min and max to the current G load value. +func ResetAHRSGLoad() { + mySituation.AHRSGLoadMax = mySituation.AHRSGLoad + mySituation.AHRSGLoadMin = mySituation.AHRSGLoad +} + func updateAHRSStatus() { var ( msg uint8 From 8aeb5d285b0ac55c24296c0263fda3b1feb0a9e6 Mon Sep 17 00:00:00 2001 From: Eric Westphal Date: Wed, 17 May 2017 17:54:32 -0400 Subject: [PATCH 7/7] Web UI G-Meter uses mySituation min/max G Load. --- main/managementinterface.go | 16 ++++++++++++++++ web/js/main.js | 1 + web/plates/js/ahrs.js | 16 +++++----------- web/plates/js/gps.js | 14 +++++++++++--- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/main/managementinterface.go b/main/managementinterface.go index 7807ce29..9344cb05 100644 --- a/main/managementinterface.go +++ b/main/managementinterface.go @@ -482,6 +482,21 @@ func handleCageAHRS(w http.ResponseWriter, r *http.Request) { } } +func handleResetGMeter(w http.ResponseWriter, r *http.Request) { + // define header in support of cross-domain AJAX + setNoCache(w) + w.Header().Set("Content-Type", "text/plain") + w.Header().Set("Access-Control-Allow-Origin", "*") + w.Header().Set("Access-Control-Allow-Method", "GET, POST, OPTIONS") + w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept") + + // For an OPTION method request, we return header without processing. + // This ensures we are recognized as supporting cross-domain AJAX REST calls. + if r.Method == "POST" { + ResetAHRSGLoad() + } +} + func doRestartApp() { time.Sleep(1) syscall.Sync() @@ -731,6 +746,7 @@ func managementInterface() { http.HandleFunc("/orientAHRS", handleOrientAHRS) http.HandleFunc("/cageAHRS", handleCageAHRS) + http.HandleFunc("/resetGMeter", handleResetGMeter) http.HandleFunc("/deletelogfile", handleDeleteLogFile) http.HandleFunc("/downloadlog", handleDownloadLogRequest) diff --git a/web/js/main.js b/web/js/main.js index 23eaa64d..26502120 100755 --- a/web/js/main.js +++ b/web/js/main.js @@ -17,6 +17,7 @@ var URL_RESTARTAPP = "http://" + URL_HOST_BASE + "/restart"; var URL_DEV_TOGGLE_GET = "http://" + URL_HOST_BASE + "/develmodetoggle"; var URL_AHRS_ORIENT = "http://" + URL_HOST_BASE + "/orientAHRS"; var URL_AHRS_CAGE = "http://" + URL_HOST_BASE + "/cageAHRS"; +var URL_GMETER_RESET = "http://" + URL_HOST_BASE + "/resetGMeter"; var URL_DELETELOGFILE = "http://" + URL_HOST_BASE + "/deletelogfile"; var URL_DOWNLOADLOGFILE = "http://" + URL_HOST_BASE + "/downloadlog"; var URL_DOWNLOADDB = "http://" + URL_HOST_BASE + "/downloaddb"; diff --git a/web/plates/js/ahrs.js b/web/plates/js/ahrs.js index 5fffd555..728e4544 100644 --- a/web/plates/js/ahrs.js +++ b/web/plates/js/ahrs.js @@ -143,7 +143,7 @@ AHRSRenderer.prototype = { } }; -function GMeterRenderer(locationId, plim, nlim) { +function GMeterRenderer(locationId, plim, nlim, resetCallback) { this.plim = plim; this.nlim = nlim; this.nticks = Math.floor(plim+1) - Math.floor(nlim) + 1; @@ -215,7 +215,7 @@ function GMeterRenderer(locationId, plim, nlim) { reset.text('RESET').cx(0).cy(0).addClass('text'); reset.on('click', function() { reset.animate(200).rotate(20, 0, 0); - this.reset(); + resetCallback(); reset.animate(200).rotate(0, 0, 0); }, this); } @@ -235,19 +235,13 @@ GMeterRenderer.prototype = { } }, - update: function (g) { + update: function (g, gmin, gmax) { this.g = g; - this.max = g > this.max ? g : this.max; - this.min = g < this.min ? g : this.min; + this.min = gmin; + this.max = gmax; this.pointer_el.animate(50).rotate((g-1)/this.nticks*360, 0, 0); this.max_el.animate(50).rotate((this.max-1)/this.nticks*360, 0, 0); this.min_el.animate(50).rotate((this.min-1)/this.nticks*360, 0, 0); - }, - - reset: function() { - this.g = 1; - this.max = 1; - this.min = 1; } }; diff --git a/web/plates/js/gps.js b/web/plates/js/gps.js index 9e760060..d68e811f 100644 --- a/web/plates/js/gps.js +++ b/web/plates/js/gps.js @@ -175,7 +175,7 @@ function GPSCtrl($rootScope, $scope, $state, $http, $interval) { if ($scope.ahrs_gload > 360) { $scope.ahrs_gload = "--"; } else { - gMeter.update(situation.AHRSGLoad); + gMeter.update(situation.AHRSGLoad, situation.AHRSGLoadMin, situation.AHRSGLoadMax); } if (situation.AHRSTurnRate > 360) { @@ -204,7 +204,7 @@ function GPSCtrl($rootScope, $scope, $state, $http, $interval) { } if (situation.AHRSStatus & 0x02) { if (statusIMU.classList.contains("off")) { - setTimeout(gMeter.reset(), 1000); + setTimeout($scope.GMeterReset, 1000); } statusIMU.classList.remove("off"); statusIMU.classList.add("on"); @@ -357,7 +357,15 @@ function GPSCtrl($rootScope, $scope, $state, $http, $interval) { return caging; }; - var gMeter = new GMeterRenderer("gMeter_display", 4.4, -1.76); + $scope.GMeterReset = function() { + $http.post(URL_GMETER_RESET).then(function (response) { + // do nothing + }, function (response) { + // do nothing + }); + }; + + var gMeter = new GMeterRenderer("gMeter_display", 4.4, -1.76, $scope.GMeterReset); // GPS Controller tasks connect($scope); // connect - opens a socket and listens for messages