Merge pull request #504 from jamez70/developer_mode_flag_handling

Developer mode flag handling
pull/512/head
cyoung 2016-10-18 20:19:04 -04:00 zatwierdzone przez GitHub
commit 2679c03472
12 zmienionych plików z 157 dodań i 12 usunięć

Wyświetl plik

@ -100,7 +100,6 @@ type ReadCloser interface {
io.Closer
}
var developerMode bool
type msg struct {
MessageClass uint
@ -995,6 +994,7 @@ type settings struct {
PPM int
OwnshipModeS string
WatchList string
DeveloperMode bool
}
type status struct {
@ -1057,6 +1057,7 @@ func defaultSettings() {
globalSettings.DisplayTrafficSource = false
globalSettings.ReplayLog = false //TODO: 'true' for debug builds.
globalSettings.OwnshipModeS = "F00000"
globalSettings.DeveloperMode = false
}
func readSettings() {
@ -1291,7 +1292,8 @@ func main() {
// replayESFilename := flag.String("eslog", "none", "ES Log filename")
replayUATFilename := flag.String("uatlog", "none", "UAT Log filename")
develFlag := flag.Bool("developer", false, "Developer mode")
// Removed here, but may replace later
// develFlag := flag.Bool("developer", false, "Developer mode")
replayFlag := flag.Bool("replay", false, "Replay file flag")
replaySpeed := flag.Int("speed", 1, "Replay speed multiplier")
stdinFlag := flag.Bool("uatin", false, "Process UAT messages piped to stdin")
@ -1301,11 +1303,6 @@ func main() {
timeStarted = time.Now()
runtime.GOMAXPROCS(runtime.NumCPU()) // redundant with Go v1.5+ compiler
if *develFlag == true {
log.Printf("Developer mode flag true!\n")
developerMode = true
}
// Duplicate log.* output to debugLog.
fp, err := os.OpenFile(debugLogf, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
@ -1340,6 +1337,10 @@ func main() {
globalSettings.ReplayLog = true
}
if globalSettings.DeveloperMode == true {
log.Printf("Developer mode set\n")
}
//FIXME: Only do this if data logging is enabled.
initDataLog()

Wyświetl plik

@ -290,6 +290,16 @@ func doReboot() {
syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART)
}
func handleDevelModeToggle(w http.ResponseWriter, r *http.Request) {
log.Printf("handleDevelModeToggle called!!!\n")
globalSettings.DeveloperMode = true
}
func handleRestartRequest(w http.ResponseWriter, r *http.Request) {
log.Printf("handleRestartRequest called\n")
go doRestartApp()
}
func handleRebootRequest(w http.ResponseWriter, r *http.Request) {
setNoCache(w)
setJSONHeaders(w)
@ -298,6 +308,17 @@ func handleRebootRequest(w http.ResponseWriter, r *http.Request) {
go delayReboot()
}
func doRestartApp() {
time.Sleep(1)
syscall.Sync()
out, err := exec.Command("/bin/systemctl", "restart", "stratux").Output()
if err != nil {
log.Printf("restart error: %s\n%s", err.Error(), out)
} else {
log.Printf("restart: %s\n", out)
}
}
// AJAX call - /getClients. Responds with all connected clients.
func handleClientsGetRequest(w http.ResponseWriter, r *http.Request) {
setNoCache(w)
@ -496,11 +517,13 @@ func managementInterface() {
http.HandleFunc("/getSatellites", handleSatellitesRequest)
http.HandleFunc("/getSettings", handleSettingsGetRequest)
http.HandleFunc("/setSettings", handleSettingsSetRequest)
http.HandleFunc("/restart", handleRestartRequest)
http.HandleFunc("/shutdown", handleShutdownRequest)
http.HandleFunc("/reboot", handleRebootRequest)
http.HandleFunc("/getClients", handleClientsGetRequest)
http.HandleFunc("/updateUpload", handleUpdatePostRequest)
http.HandleFunc("/roPartitionRebuild", handleroPartitionRebuild)
http.HandleFunc("/develmodetoggle", handleDevelModeToggle)
err := http.ListenAndServe(managementAddr, nil)

Wyświetl plik

@ -64,6 +64,7 @@
<script src="js/j3di-all.min.js"></script>
<script src="plates/js/ahrs.js"></script>
<script src="plates/js/gps.js"></script>
<script src="plates/js/developer.js"></script>
</head>
<body ng-app="stratux" ng-controller="MainCtrl" ui-prevent-touchmove-defaults>
@ -83,6 +84,9 @@
<a class="list-group-item" href="#/towers"><i class="fa fa-signal"></i> Towers <i class="fa fa-chevron-right pull-right"></i></a>
<a class="list-group-item" href="#/logs"><i class="fa fa-file-text-o"></i> Logs <i class="fa fa-chevron-right pull-right"></i></a>
<a class="list-group-item" href="#/settings"><i class="fa fa-gear"></i> Settings <i class="fa fa-chevron-right pull-right"></i></a>
<div ng-show="DeveloperMode">
<a class="list-group-item" href="#/developer"><i class="fa fa-tasks"></i> Developer <i class="fa fa-chevron-right pull-right"></i></a>
</div>
</div>
</div>
</div>

18
web/js/main.js 100755 → 100644
Wyświetl plik

@ -9,9 +9,12 @@ var URL_SATELLITES_GET = "http://" + URL_HOST_BASE + "/getSatellites"
var URL_STATUS_WS = "ws://" + URL_HOST_BASE + "/status"
var URL_TRAFFIC_WS = "ws://" + URL_HOST_BASE + "/traffic";
var URL_WEATHER_WS = "ws://" + URL_HOST_BASE + "/weather";
var URL_DEVELOPER_GET = "ws://" + URL_HOST_BASE + "/developer";
var URL_UPDATE_UPLOAD = "http://" + URL_HOST_BASE + "/updateUpload";
var URL_REBOOT = "http://" + URL_HOST_BASE + "/reboot";
var URL_SHUTDOWN = "http://" + URL_HOST_BASE + "/shutdown";
var URL_RESTARTAPP = "http://" + URL_HOST_BASE + "/restart";
var URL_DEV_TOGGLE_GET = "http://" + URL_HOST_BASE + "/develmodetoggle";
// define the module with dependency on mobile-angular-ui
//var app = angular.module('stratux', ['ngRoute', 'mobile-angular-ui', 'mobile-angular-ui.gestures', 'appControllers']);
@ -62,6 +65,12 @@ app.config(function ($stateProvider, $urlRouterProvider) {
templateUrl: 'plates/settings.html',
controller: 'SettingsCtrl',
reloadOnSearch: false
})
.state('developer', {
url: '/developer',
templateUrl: 'plates/developer.html',
controller: 'DeveloperCtrl',
reloadOnSearch: false
});
$urlRouterProvider.otherwise('/');
});
@ -72,6 +81,13 @@ app.run(function ($transform) {
});
// For this app we have a MainController for whatever and individual controllers for each page
app.controller('MainCtrl', function ($rootScope, $scope) {
app.controller('MainCtrl', function ($scope, $http) {
// any logic global logic
$http.get(URL_SETTINGS_GET)
.then(function(response) {
settings = angular.fromJson(response.data);
$scope.developerMode = settings.DeveloperMode;
}, function(response) {
//Second function handles error
});
});

Wyświetl plik

@ -100,6 +100,10 @@ a.bg-danger:hover {
text-decoration: none;
}
.btn-hidden:hover {
color: #000000;
}
.btn-default:hover {
color: #333333;
background-color: #e6e6e6;

Wyświetl plik

@ -0,0 +1,4 @@
<div class="section text-left help-page">
<p>The <strong>Developer</strong> page provides basic access to developer options</p>
<p></p>
</div>

Wyświetl plik

@ -0,0 +1,21 @@
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">
<span class="panel_label">Developer Mode Items</span>
</div>
<div class="panel-body">
<div class="panel-group col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Restart Stratux application</div>
<div class="panel-body">
<div class="form-group reset-flow">
<div class="col-xs-12">
<a ng-click="postRestart()" ui-turn-off="modalRestartApp" class="btn btn-primary">Restart Application</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

Wyświetl plik

@ -0,0 +1,18 @@
angular.module('appControllers').controller('DeveloperCtrl', DeveloperCtrl); // get the main module contollers set
DeveloperCtrl.$inject = ['$rootScope', '$scope', '$state', '$http', '$interval']; // Inject my dependencies
// create our controller function with all necessary logic
function DeveloperCtrl($rootScope, $scope, $state, $http, $interval) {
$scope.$parent.helppage = 'plates/developer-help.html';
$scope.postRestart = function () {
$http.post(URL_RESTARTAPP).
then(function (response) {
// do nothing
// $scope.$apply();
}, function (response) {
// do nothing
});
};
};

Wyświetl plik

@ -33,6 +33,7 @@ function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) {
$scope.PPM = settings.PPM;
$scope.WatchList = settings.WatchList;
$scope.OwnshipModeS = settings.OwnshipModeS;
$scope.DeveloperMode = settings.DeveloperMode;
}
function getSettings() {

Wyświetl plik

@ -101,6 +101,7 @@ function StatusCtrl($rootScope, $scope, $state, $http, $interval) {
$http.get(URL_SETTINGS_GET).
then(function (response) {
settings = angular.fromJson(response.data);
$scope.developerMode = settings.DeveloperMode;
$scope.visible_uat = settings.UAT_Enabled;
$scope.visible_es = settings.ES_Enabled;
$scope.visible_ping = settings.Ping_Enabled;
@ -139,7 +140,16 @@ function StatusCtrl($rootScope, $scope, $state, $http, $interval) {
getTowers();
}, (5 * 1000), 0, false);
var clicks = 0;
var clickSeconds = 0;
var developerModeClick = 0;
var clickInterval = $interval(function () {
if ((clickSeconds >= 3))
clicks=0;
clickSeconds++;
}, 1000);
$state.get('home').onEnter = function () {
// everything gets handled correctly by the controller
};
@ -150,7 +160,26 @@ function StatusCtrl($rootScope, $scope, $state, $http, $interval) {
}
$interval.cancel(updateTowers);
};
$scope.VersionClick = function() {
if (clicks==0)
{
clickSeconds = 0;
}
++clicks;
if ((clicks > 7) && (clickSeconds < 3))
{
clicks=0;
clickSeconds=0;
developerModeClick = 1;
$http.get(URL_DEV_TOGGLE_GET);
location.reload();
}
}
$scope.GetDeveloperModeClick = function() {
return developerModeClick;
}
// Status Controller tasks
setHardwareVisibility();
connect($scope); // connect - opens a socket and listens for messages

Wyświetl plik

@ -134,6 +134,19 @@
</div>
</div>
<!-- Developer mode area -->
<div class="col-sm-12">
<div ng-show="DeveloperMode" class="panel-group col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Developer Options</div>
<div class="panel-body">
<div class="col-xs-12">
<p>Coming soon</p>
</div>
</div>
</div>
</div>
</div>
<!--

Wyświetl plik

@ -1,7 +1,7 @@
<div class="col-sm-12">
<div class="text-center">
<p><strong>Version: <span>{{Version}} ({{Build}})</span></strong></p>
</div>
<a ng-click="VersionClick()" class="btn btn-hidden"<strong>Version: <span>{{Version}} ({{Build}})</span></strong></a>
</div>
<div class="panel panel-default">
<div class="panel-heading" ng-class="{'section_invisible': !visible_errors}">
<span class="panel_label">Errors</span>
@ -17,6 +17,7 @@
<span class="panel_label">Status</span>
<span ng-show="ConnectState == 'Connected'" class="label label-success">{{ConnectState}}</span>
<span ng-hide="ConnectState == 'Connected'" class="label label-danger">{{ConnectState}}</span>
<span ng-show="DeveloperMode == true" class="label label-warning">Developer Mode</span>
</div>
<div class="panel-body">
<div class="form-horizontal">
@ -132,6 +133,16 @@
</div>
</div>
</div>
<div class="row" ng-class="{'section_invisible': !DeveloperMode}">
<div class="separator"></div>
<div class="row"><span class="col-xs-1">&nbsp;</span></div>
<div class="separator"></div>
<div class="row">
<div class="col-sm-4 label_adj">
<span class="col-xs-5"><strong>Developer</strong></span>
<span class="col-xs-7">Info Here</span>
</div>
</div>
</div>
</div>
</div>