Permalink
Browse files

Merge pull request #134 from Trevelopment/master

WiFi support, config file, HUD, version info
  • Loading branch information...
Trevelopment committed Jan 14, 2019
2 parents 96d3845 + 8283515 commit 61ee618f2a7a4ce8c8d07ef7a2690a3a81724ca4
Showing with 11,836 additions and 8,907 deletions.
  1. +2 −0 .gitignore
  2. +38 −22 common/command_server.cpp
  3. +2 −0 common/command_server.h
  4. +101 −0 common/config.cpp
  5. +24 −0 common/config.h
  6. +55 −1 hu/hu.proto
  7. +109 −17 hu/hu_aap.cpp
  8. +21 −2 hu/hu_aap.h
  9. +14 −7 hu/hu_tcp.cpp
  10. +2 −2 hu/hu_tcp.h
  11. +1 −0 mazda/.gitignore
  12. +12 −5 mazda/Makefile
  13. +100 −9 mazda/callbacks.cpp
  14. +9 −0 mazda/callbacks.h
  15. +10,675 −8,800 mazda/dbus/cmu_interfaces.xml
  16. BIN mazda/dbus/dbusxx-xml2cpp
  17. +3 −1 mazda/gps/mzd_gps.cpp
  18. +6 −0 mazda/headunit.json
  19. BIN mazda/hud-test
  20. +69 −0 mazda/hud-test.cpp
  21. +167 −0 mazda/hud/hud.cpp
  22. +98 −0 mazda/hud/hud.h
  23. BIN mazda/hud/icons/0001.jpg
  24. BIN mazda/hud/icons/0002.jpg
  25. BIN mazda/hud/icons/0003.jpg
  26. BIN mazda/hud/icons/0004.jpg
  27. BIN mazda/hud/icons/0005.jpg
  28. BIN mazda/hud/icons/0006.jpg
  29. BIN mazda/hud/icons/0007.jpg
  30. BIN mazda/hud/icons/0008.jpg
  31. BIN mazda/hud/icons/0009.jpg
  32. BIN mazda/hud/icons/0010.jpg
  33. BIN mazda/hud/icons/0011.jpg
  34. BIN mazda/hud/icons/0012.jpg
  35. BIN mazda/hud/icons/0013.jpg
  36. BIN mazda/hud/icons/0014.jpg
  37. BIN mazda/hud/icons/0015.jpg
  38. BIN mazda/hud/icons/0016.jpg
  39. BIN mazda/hud/icons/0017.jpg
  40. BIN mazda/hud/icons/0018.jpg
  41. BIN mazda/hud/icons/0019.jpg
  42. BIN mazda/hud/icons/0020.jpg
  43. BIN mazda/hud/icons/0021.jpg
  44. BIN mazda/hud/icons/0022.jpg
  45. BIN mazda/hud/icons/0023.jpg
  46. BIN mazda/hud/icons/0024.jpg
  47. BIN mazda/hud/icons/0025.jpg
  48. BIN mazda/hud/icons/0026.jpg
  49. BIN mazda/hud/icons/0027.jpg
  50. BIN mazda/hud/icons/0028.jpg
  51. BIN mazda/hud/icons/0029.jpg
  52. BIN mazda/hud/icons/0030.jpg
  53. BIN mazda/hud/icons/0031.jpg
  54. BIN mazda/hud/icons/0032.jpg
  55. BIN mazda/hud/icons/0033.jpg
  56. BIN mazda/hud/icons/0034.jpg
  57. BIN mazda/hud/icons/0035.jpg
  58. BIN mazda/hud/icons/0036.jpg
  59. BIN mazda/hud/icons/0037.jpg
  60. BIN mazda/hud/icons/0038.jpg
  61. BIN mazda/hud/icons/0039.jpg
  62. BIN mazda/hud/icons/0040.jpg
  63. BIN mazda/hud/icons/0041.jpg
  64. BIN mazda/hud/icons/0042.jpg
  65. BIN mazda/hud/icons/0043.jpg
  66. BIN mazda/hud/icons/0044.jpg
  67. BIN mazda/hud/icons/0045.jpg
  68. BIN mazda/hud/icons/0046.jpg
  69. BIN mazda/hud/icons/0047.jpg
  70. BIN mazda/hud/icons/0048.jpg
  71. BIN mazda/hud/icons/0049.jpg
  72. BIN mazda/hud/icons/0050.jpg
  73. BIN mazda/hud/icons/0051.jpg
  74. BIN mazda/hud/icons/0052.jpg
  75. BIN mazda/hud/icons/0053.jpg
  76. BIN mazda/hud/icons/0054.jpg
  77. BIN mazda/hud/icons/0055.jpg
  78. BIN mazda/hud/icons/0056.jpg
  79. BIN mazda/hud/icons/0057.jpg
  80. BIN mazda/hud/icons/0058.jpg
  81. BIN mazda/hud/icons/0059.jpg
  82. BIN mazda/hud/icons/0060.jpg
  83. +30 −0 mazda/installer/config/androidauto/data_persist/dev/bin/check-usb.sh
  84. +88 −3 mazda/installer/config/androidauto/data_persist/dev/bin/headunit-wrapper
  85. +10 −0 mazda/installer/config/androidauto/jci/gui/apps/_androidauto/js/_androidautoApp.js
  86. +7 −1 mazda/installer/tweaks.sh
  87. +38 −3 mazda/main.cpp
  88. +3 −0 mazda/nm/mzd_nightmode.cpp
  89. +34 −29 mazda/outputs.cpp
  90. +6 −2 ubuntu/Makefile
  91. +46 −0 ubuntu/callbacks.cpp
  92. +7 −0 ubuntu/callbacks.h
  93. +28 −0 ubuntu/command_server_test.sh
  94. +5 −0 ubuntu/headunit.json
  95. +12 −3 ubuntu/main.cpp
  96. +14 −0 ubuntu/outputs.cpp
@@ -8,3 +8,5 @@ CMakeLists.txt
cmake-build-debug/
mazda/installer/config/androidauto/data_persist/dev/bin/headunit
*.creator.user
bin/
*/version\.h
@@ -7,43 +7,59 @@ using json = nlohmann::json;

namespace
{
void AddCORSHeaders(WPP::Response& resp)
{
resp.headers.emplace("Access-Control-Allow-Origin", "*");
resp.headers.emplace("Access-Control-Allow-Methods", "POST, GET");
}
void AddCORSHeaders(WPP::Response& resp)
{
resp.headers.emplace("Access-Control-Allow-Origin", "*");
resp.headers.emplace("Access-Control-Allow-Methods", "POST, GET");
}
}

CommandServer::CommandServer(ICommandServerCallbacks &callbacks)
{
server.get("/status", [&callbacks](WPP::Request& req, WPP::Response& resp)
{
resp.type = "application/json";
json result;
result["connected"] = callbacks.IsConnected();
result["videoFocus"] = callbacks.HasVideoFocus();
result["audioFocus"] = callbacks.HasAudioFocus();
std::string logPath = callbacks.GetLogPath();
if (logPath.length() > 0)
result["logPath"] = logPath;
resp.type = "application/json";
json result;
result["connected"] = callbacks.IsConnected();
result["videoFocus"] = callbacks.HasVideoFocus();
result["audioFocus"] = callbacks.HasAudioFocus();
std::string logPath = callbacks.GetLogPath();
if (logPath.length() > 0)
{
result["logPath"] = logPath;
}
result["headunitVersion"] = callbacks.GetVersion();

resp.body << std::setw(4) << result;

logd("Got /status call. response:\n%s\n", resp.body.str().c_str());

AddCORSHeaders(resp);
});

server.get("/updateConfig", [&callbacks](WPP::Request& req, WPP::Response& resp)
{
resp.type = "application/json";
json result;
result["result"] = callbacks.ChangeParameterConfig(req.query["parameter"], req.query["value"], req.query["type"]);

resp.body << std::setw(4) << result;
resp.body << std::setw(4) << result;

logd("Got /status call. response:\n%s\n", resp.body.str().c_str());
logd("Got /updateConfig call. response:\n%s\n", resp.body.str().c_str());

AddCORSHeaders(resp);
AddCORSHeaders(resp);
});

server.post("/takeVideoFocus", [&callbacks](WPP::Request& req, WPP::Response& resp)
{
resp.type = "application/json";
callbacks.TakeVideoFocus();
json result;
resp.body << std::setw(4) << result;
resp.type = "application/json";
callbacks.TakeVideoFocus();
json result;
resp.body << std::setw(4) << result;

printf("Got /takeVideoFocus call. response:\n%s\n", resp.body.str().c_str());
printf("Got /takeVideoFocus call. response:\n%s\n", resp.body.str().c_str());

AddCORSHeaders(resp);
AddCORSHeaders(resp);
});
}

@@ -11,6 +11,8 @@ class ICommandServerCallbacks
virtual bool HasVideoFocus() const = 0;
virtual void TakeVideoFocus() = 0;
virtual std::string GetLogPath() const = 0;
virtual std::string GetVersion() const = 0;
virtual std::string ChangeParameterConfig(std::string param, std::string value, std::string type) const = 0;
};

//This is mostly designed as a way to recieve UI events from the CMU JS code via HTTP requests
@@ -0,0 +1,101 @@
#include <fstream>
#include "hu_aap.h"
#include "config.h"

//default settings
std::string config::configFile = "/tmp/root/headunit.json";
bool config::launchOnDevice = true;
bool config::carGPS = true;
HU_TRANSPORT_TYPE config::transport_type = HU_TRANSPORT_TYPE::USB;
bool config::reverseGPS = false;

void config::parseJson(json config_json)
{
if (config_json["launchOnDevice"].is_boolean())
{
config::launchOnDevice = config_json["launchOnDevice"];
}
if (config_json["carGPS"].is_boolean())
{
config::carGPS = config_json["carGPS"];
}
if (config_json["wifiTransport"].is_boolean())
{
config::transport_type = config_json["wifiTransport"] ? HU_TRANSPORT_TYPE::WIFI : HU_TRANSPORT_TYPE::USB;
}
if (config_json["reverseGPS"].is_boolean())
{
config::reverseGPS = config_json["reverseGPS"];
}
printf("json config parsed\n");
}

json config::readConfigFile()
{
std::ifstream ifs(config::configFile);
json config_json;
//config file exists, read it
if (ifs.good())
{
try
{
ifs >> config_json;
}catch (...)
{
printf("couldn't parse config file. possible corruption\n");
config_json = nullptr;
ifs.close();
}
ifs.close();
}
else
{
printf("couldn't read config file. check permissions\n");
}
return config_json;
}

void config::readConfig()
{
json config_json = readConfigFile();
if (config_json == nullptr) return;

config::parseJson(config_json);
}

void config::writeConfigFile(json config_json)
{
std::ofstream out_file(config::configFile);
if (out_file.good())
{
out_file << std::setw(4) << config_json << std::endl;
out_file.close();
printf("config file written\n");
}
else
{
printf("couldn't write config file. check permissions\n");
}
}

void config::updateConfigString(std::string parameter, std::string value)
{
printf("updating parameter [%s] = [%s]\n", parameter.c_str(), value.c_str());
json config_json = readConfigFile();
if (config_json == nullptr) return;

config_json[parameter]=value;
writeConfigFile(config_json);
config::parseJson(config_json);
}

void config::updateConfigBool(std::string parameter, bool value)
{
printf("updating parameter [%s] = [%s]\n", parameter.c_str(), value ? "true" : "false");
json config_json = readConfigFile();
if (config_json == nullptr) return;

config_json[parameter]=value;
writeConfigFile(config_json);
config::parseJson(config_json);
}
@@ -0,0 +1,24 @@
#pragma once

#include "json/json.hpp"
using json = nlohmann::json;

class config {
public:

static void readConfig();
static void updateConfigString(std::string parameter, std::string value);
static void updateConfigBool(std::string parameter, bool value);

static std::string configFile;
static bool launchOnDevice;
static bool carGPS;
static HU_TRANSPORT_TYPE transport_type;
static bool reverseGPS;

private:
static json readConfigFile();
static void writeConfigFile(json config_json);
static void parseJson(json config_json);
};

@@ -390,7 +390,12 @@ message ChannelDescriptor
}

required uint32 minimum_interval_ms = 1;
required uint32 type = 2;
enum CLUSTER_TYPE
{
CUSTOM_IMAGES_SUPPORTED = 1;
IMAGE_CODES_ONLY = 2;
}
required CLUSTER_TYPE type = 2;
optional ImageOptions image_options = 3;
}
optional NavigationStatusService navigation_status_service = 8;
@@ -694,3 +699,52 @@ message BluetoothAuthData
{
optional string data = 1;
}

message NAVMessagesStatus
{
optional int32 status = 1;
}

message NAVTurnMessage
{
optional string event_name = 1;
enum TURN_SIDE
{
TURN_LEFT = 1;
TURN_RIGHT = 2;
TURN_UNSPECIFIED = 3;
}
optional TURN_SIDE turn_side = 2;
enum TURN_EVENT
{
TURN_UNKNOWN = 0;
TURN_DEPART = 1;
TURN_NAME_CHANGE = 2;
TURN_SLIGHT_TURN = 3;
TURN_TURN = 4;
TURN_SHARP_TURN = 5;
TURN_U_TURN = 6;
TURN_ON_RAMP = 7;
TURN_OFF_RAMP = 8;
TURN_FORK = 9;
TURN_MERGE = 10;
TURN_ROUNDABOUT_ENTER = 11;
TURN_ROUNDABOUT_EXIT = 12;
TURN_ROUNDABOUT_ENTER_AND_EXIT = 13;
TURN_STRAIGHT = 14;
TURN_FERRY_BOAT = 16;
TURN_FERRY_TRAIN = 17;
TURN_DESTINATION = 19;
}
optional TURN_EVENT turn_event = 3;
optional bytes image = 4; // image in png format
optional int32 turn_number = 5;
optional int32 turn_angle = 6;
}

//32773 (0x8005)
message NAVDistanceMessage
{
optional int32 distance = 1; //meters
optional int32 time_until = 2; //seconds
}
Oops, something went wrong.

0 comments on commit 61ee618

Please sign in to comment.