</head>
<body>
<div id="speed" class="speed">77</div>
-<div id="cc" class="speed">12</div>
+<div id="cctrl" class="speed">12</div>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myObj = JSON.parse(this.responseText);
- document.getElementById("speed").innerHTML = myObj.speed;
- document.getElementById("cc").innerHTML = myObj.cc;
+ console.log(this.responseText);
+ document.getElementById("speed").innerHTML = Math.round(myObj.speed * 3.6);
+ document.getElementById("cctrl").innerHTML = Math.round(myObj.cctrl * 3.6);
}
};
xhttp.open("GET", "/json", true);
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
+#include <inttypes.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
r_none
};
+static void write_telejson( int fd ) {
+ char buf[512];
+ write(fd, buf, sprintf( buf, "{\n" ) );
+ write(fd, buf, sprintf( buf, " \"timestamp\": %"PRIu64",\n", telemetry->timestamp ) );
+ write(fd, buf, sprintf( buf, " \"x\": %f,\n", telemetry->x ) );
+ write(fd, buf, sprintf( buf, " \"y\": %f,\n", telemetry->y ) );
+ write(fd, buf, sprintf( buf, " \"z\": %f,\n", telemetry->z ) );
+ write(fd, buf, sprintf( buf, " \"heading\": %f,\n", telemetry->heading ) );
+ write(fd, buf, sprintf( buf, " \"pitch\": %f,\n", telemetry->pitch ) );
+ write(fd, buf, sprintf( buf, " \"roll\": %f,\n", telemetry->roll ) );
+ write(fd, buf, sprintf( buf, " \"speed\": %f,\n", telemetry->speed ) );
+ write(fd, buf, sprintf( buf, " \"rpm\": %f,\n", telemetry->rpm ) );
+ write(fd, buf, sprintf( buf, " \"gear\": %d,\n", telemetry->gear ) );
+ write(fd, buf, sprintf( buf, " \"cctrl\": %f,\n", telemetry->cctrl ) );
+ write(fd, buf, sprintf( buf, " \"fc_avg\": %f,\n", telemetry->fc_avg ) );
+ // add more here
+ write(fd, buf, sprintf( buf, " \"dummy\": 0\n" ) );
+ write(fd, buf, sprintf( buf, "}\n" ) );
+}
+
static void respond(int fd, const char *req, int code) {
char buf[4096];
char origin[256] = "http://localhost";
write(fd, buf, sprintf (buf, "Access-Control-Allow-Origin: %s\r\n", origin));
write(fd, buf, sprintf (buf, "Content-type: text/json\r\n"));
write(fd, buf, sprintf (buf, "Connection: close\r\n\r\n"));
- write(fd, buf, sprintf (buf, "{ \"fc_avg\": %3.2f, \"speed\": %3.2f, \"cc\": %3.2f }",
- 100.0 * telemetry->fc_avg , telemetry -> speed * 3.6, telemetry -> cc * 3.6));
+ write_telejson(fd);
} else {
struct file_info_t fi;
if (0 == fserv_open_server("index.html", &fi)){
log_line(
";%3.2f;%3.2f;%f;%d",
telemetry->speed * 3.6,
- telemetry->cc * 3.6,
+ telemetry->cctrl * 3.6,
telemetry->rpm,
telemetry->gear
);
version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_speed, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->speed);
version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_engine_rpm, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->rpm);
version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_engine_gear, SCS_U32_NIL, SCS_VALUE_TYPE_s32, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_s32, &telemetry->gear);
- version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_cruise_control, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->cc);
+ version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_cruise_control, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->cctrl);
version_params->register_for_channel(SCS_TELEMETRY_TRUCK_CHANNEL_fuel_average_consumption, SCS_U32_NIL, SCS_VALUE_TYPE_float, SCS_TELEMETRY_CHANNEL_FLAG_none, telemetry_store_float, &telemetry->fc_avg);
// Set the structure with defaults.