Basic web interface.

pull/27/head
Christopher Young 2015-08-25 19:27:28 -04:00
rodzic 2a4dcc172e
commit 5323107a9e
4 zmienionych plików z 83 dodań i 4 usunięć

Wyświetl plik

@ -313,7 +313,7 @@ func updateStatus() {
}
// Update Uptime.
globalStatus.Uptime = time.Since(timeStarted)
globalStatus.Uptime = time.Since(timeStarted).String()
}
func parseInput(buf string) ([]byte, uint16) {
@ -384,7 +384,7 @@ type status struct {
GPS_satellites_locked uint16
GPS_connected bool
RY835AI_connected bool
Uptime time.Duration
Uptime string
}
var globalSettings settings
@ -440,7 +440,7 @@ func managementInterface() {
}
func defaultSettings() {
globalSettings.UAT_Enabled = true //TODO
globalSettings.UAT_Enabled = true //TODO
globalSettings.ES_Enabled = false //TODO
globalSettings.GPS_Enabled = false //TODO
globalSettings.NetworkOutputs = []networkConnection{{nil, "", 4000, NETWORK_GDL90_STANDARD}, {nil, "", 43211, NETWORK_GDL90_STANDARD | NETWORK_AHRS_GDL90}, {nil, "", 49002, NETWORK_AHRS_FFSIM}}
@ -494,7 +494,7 @@ func main() {
initTraffic()
globalStatus.Version = stratuxVersion
globalStatus.Devices = 0 //TODO
globalStatus.Devices = 0 //TODO
readSettings()

64
web/control.php 100644
Wyświetl plik

@ -0,0 +1,64 @@
<?php
function _str_send($sock, $str) {
return socket_send($sock, $str, strlen($str), 0);
}
function get_json($tp) {
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (!socket_connect($sock, '127.0.0.1', '9110')) {
throw new Exception("couldn't connect");
}
_str_send($sock, $tp);
$buf = "";
socket_recv($sock, $buf, 1024, 0);
$x = json_decode($buf, true);
socket_close($sock);
return $x;
}
function get_settings() {
return get_json("SETTINGS\n");
}
function get_status() {
return get_json("STATUS\n");
}
function set_settings($to_set) {
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if (!socket_connect($sock, '127.0.0.1', '9110')) {
print "couldn't connect\n";
exit;
}
$buf = json_encode($to_set);
_str_send($sock, $buf . "\n");
_str_send($sock, "QUIT\n");
}
$current_settings = get_settings();
// Copy over old settings to the new ones, such that if there is a field that doesn't change it gets sent over again.
if (isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] == 'POST')) {
$new_settings = $current_settings;
foreach ($_POST as $k => $v) {
if ($v === "true") $v = true;
else if ($v === "false") $v = false;
$new_settings[$k] = $v; //FIXME.
}
set_settings($new_settings);
$current_settings = get_settings();
}
$current_status = get_status();
$p = array_merge($current_settings, $current_status);
print json_encode($p) . "\n";
?>

4
web/js/jquery-2.1.4.min.js vendored 100644

File diff suppressed because one or more lines are too long

11
web/js/jquery.form.min.js vendored 100644

File diff suppressed because one or more lines are too long