aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuta Doi <yuta-d@witz-inc.co.jp>2018-05-11 13:23:53 +0900
committerYuta Doi <yuta-d@witz-inc.co.jp>2018-05-11 13:23:53 +0900
commit160b8947d684ce037120cf5237bd221bd9ea9785 (patch)
tree7b523f91da6516502528ad737e13d9eda847fd12
parentf73c5f5ff5cd4b424eed1a757c7bc8d3e34ec0e9 (diff)
LowCanClient can receive accelerator.pedal.position signal
Change-Id: Ia6d4ad7888ec764fcd8dec696f6eda9d826cb62d Signed-off-by: Yuta Doi <yuta-d@witz-inc.co.jp>
-rw-r--r--src/json_helper.cpp15
-rw-r--r--src/json_helper.hpp1
-rw-r--r--src/low_can_client.cpp141
-rw-r--r--src/low_can_client.hpp22
-rw-r--r--src/main.cpp18
5 files changed, 143 insertions, 54 deletions
diff --git a/src/json_helper.cpp b/src/json_helper.cpp
index cbbf564..4b35952 100644
--- a/src/json_helper.cpp
+++ b/src/json_helper.cpp
@@ -134,6 +134,21 @@ int getIntFromJson(json_object* obj, const char* key) {
return json_object_get_int(tmp);
}
+double getDoubleFromJson(json_object* obj, const char* key) {
+ if ((nullptr == obj) || (nullptr == key)) {
+ HMI_ERROR("wm:jh", "Argument is nullptr!!!");
+ return 0;
+ }
+
+ json_object* tmp;
+ if (!json_object_object_get_ex(obj, key, &tmp)) {
+ HMI_DEBUG("wm:jh", "Not found key \"%s\"", key);
+ return 0;
+ }
+
+ return json_object_get_double(tmp);
+}
+
json_bool getBoolFromJson(json_object* obj, const char* key) {
if ((nullptr == obj) || (nullptr == key)) {
HMI_ERROR("wm:jh", "Argument is nullptr!!!");
diff --git a/src/json_helper.hpp b/src/json_helper.hpp
index 408a701..cad129f 100644
--- a/src/json_helper.hpp
+++ b/src/json_helper.hpp
@@ -29,6 +29,7 @@ json_object *to_json(std::vector<uint32_t> const &v);
namespace jh {
const char* getStringFromJson(json_object* obj, const char* key);
int getIntFromJson(json_object* obj, const char* key);
+double getDoubleFromJson(json_object* obj, const char* key);
json_bool getBoolFromJson(json_object* obj, const char* key);
int inputJsonFilie(const char* file, json_object** obj);
} // namespace jh
diff --git a/src/low_can_client.cpp b/src/low_can_client.cpp
index 451fa24..01a7340 100644
--- a/src/low_can_client.cpp
+++ b/src/low_can_client.cpp
@@ -29,17 +29,21 @@ namespace wm {
LowCanClient::LowCanClient() :
vehicle_speed_(0),
trans_gear_pos_(0),
- parking_brake_status_(TRUE),
headlamp_status_(FALSE),
+ parking_brake_status_(TRUE),
+ accel_pedal_pos_(0),
+ prv_lamp_state_("lamp_off"),
+ crr_lamp_state_("lamp_off"),
prv_parking_brake_state_("parking_brake_on"),
crr_parking_brake_state_("parking_brake_on"),
+ prv_accel_pedal_state_("accel_pedal_off"),
+ crr_accel_pedal_state_("accel_pedal_off"),
prv_car_state_("car_stop"),
crr_car_state_("car_stop"),
- prv_lamp_state_("lamp_off"),
- crr_lamp_state_("lamp_off"),
+ is_changed_lamp_state_(false),
is_changed_parking_brake_state_(false),
- is_changed_car_state_(false),
- is_changed_lamp_state_(false)
+ is_changed_accel_pedal_state_(false),
+ is_changed_car_state_(false)
{
HMI_DEBUG("wm:lcc", "Call");
}
@@ -61,7 +65,9 @@ void LowCanClient::initialize() {
// low-can subscribe { "event": "transmission_gear_position" }
// low-can subscribe { "event": "headlamp_status" }
// low-can subscribe { "event": "parking_brake_status" }
- for (int i=0; i<this->kNumEvent_; i++) {
+ // low-can subscribe { "event": "accelerator.pedal.position" }
+ int num_event = this->kEventName_.size();
+ for (int i=0; i<num_event; i++) {
json_object *json_obj = json_object_new_object();
json_object_object_add(json_obj, "event", json_object_new_string(this->kEventName_[i]));
HMI_DEBUG("wm:lcc", "subscribe message:%s", json_object_get_string(json_obj));
@@ -70,7 +76,6 @@ void LowCanClient::initialize() {
ret = afb_service_call_sync("low-can", "subscribe", json_obj, &json_result);
if (0 > ret) {
HMI_INFO("wm:lcc", "Could not subscribe to \"low-can\" :%d", ret);
- return;
}
HMI_DEBUG("wm:lcc", "subscribe result:%s", json_object_get_string(json_result));
}
@@ -84,8 +89,8 @@ void LowCanClient::analyzeCanSignal(struct json_object *object) {
const char* name = jh::getStringFromJson(object, "name");
HMI_DEBUG("wm:lcc", "CAN signal name:%s", name);
- if (strstr(name, "vehicle.speed")) {
- HMI_DEBUG("wm:lcc", "Receive vehicle speed");
+ if (strstr(name, this->kEventName_[0])) {
+ HMI_DEBUG("wm:lcc", "Receive %s", this->kEventName_[0]);
// Update vehicle speed
int speed = jh::getIntFromJson(object, "value");
if (this->vehicle_speed_ != speed) {
@@ -93,8 +98,8 @@ void LowCanClient::analyzeCanSignal(struct json_object *object) {
HMI_DEBUG("wm:lcc", "Update vehicle speed:%d", this->vehicle_speed_);
}
}
- else if (strstr(name, "transmission_gear_position")) {
- HMI_DEBUG("wm:lcc", "Receive transmission gear position");
+ else if (strstr(name, this->kEventName_[1])) {
+ HMI_DEBUG("wm:lcc", "Receive %s", this->kEventName_[1]);
// Update transmission gear position
int gear_pos = jh::getIntFromJson(object, "value");
if (this->trans_gear_pos_ != gear_pos) {
@@ -102,8 +107,17 @@ void LowCanClient::analyzeCanSignal(struct json_object *object) {
HMI_DEBUG("wm:lcc", "Update transmission gear position:%d", this->trans_gear_pos_);
}
}
- else if (strstr(name, "parking_brake_status")) {
- HMI_DEBUG("wm:lcc", "Receive parking brake status");
+ else if (strstr(name, this->kEventName_[2])) {
+ HMI_DEBUG("wm:lcc", "Receive %s", this->kEventName_[2]);
+ // Update headlamp status
+ json_bool headlamp = jh::getBoolFromJson(object, "value");
+ if (this->headlamp_status_ != headlamp) {
+ this->headlamp_status_ = headlamp;
+ HMI_DEBUG("wm:lcc", "Update headlamp status:%d", this->headlamp_status_);
+ }
+ }
+ else if (strstr(name, this->kEventName_[3])) {
+ HMI_DEBUG("wm:lcc", "Receive %s", this->kEventName_[3]);
// Update parking gear status
json_bool parking_brake = jh::getBoolFromJson(object, "value");
if (this->parking_brake_status_ != parking_brake) {
@@ -111,16 +125,25 @@ void LowCanClient::analyzeCanSignal(struct json_object *object) {
HMI_DEBUG("wm:lcc", "Update parking brake status:%d", this->parking_brake_status_);
}
}
- else if (strstr(name, "headlamp_status")) {
- HMI_DEBUG("wm:lcc", "Receive headlamp status");
- // Update headlamp status
- json_bool headlamp = jh::getBoolFromJson(object, "value");
- if (this->headlamp_status_ != headlamp) {
- this->headlamp_status_ = headlamp;
- HMI_DEBUG("wm:lcc", "Update headlamp status:%d", this->headlamp_status_);
+ else if (strstr(name, this->kEventName_[4])) {
+ HMI_DEBUG("wm:lcc", "Receive %s", this->kEventName_[4]);
+ // Update accelerator pedal status
+ double accel_pedal_pos = jh::getDoubleFromJson(object, "value");
+ if (this->accel_pedal_pos_ != accel_pedal_pos) {
+ this->accel_pedal_pos_ = accel_pedal_pos;
+ HMI_DEBUG("wm:lcc", "Update accelerator pedal status:%lf", this->accel_pedal_pos_);
}
}
+ // Update lamp state
+ if (true == this->headlamp_status_) {
+ this->crr_lamp_state_ = "lamp_on";
+ }
+ else {
+ this->crr_lamp_state_ = "lamp_off";
+ }
+ HMI_DEBUG("wm:lcc", "Current lamp state:%s", this->crr_lamp_state_.c_str());
+
// Update parking brake state
if (this->parking_brake_status_) {
this->crr_parking_brake_state_ = "parking_brake_on";
@@ -130,6 +153,15 @@ void LowCanClient::analyzeCanSignal(struct json_object *object) {
}
HMI_DEBUG("wm:lcc", "Current parking brake state:%s", this->crr_parking_brake_state_.c_str());
+ // Update accelerator pedal state
+ if (0 == this->accel_pedal_pos_) {
+ this->crr_accel_pedal_state_ = "accel_pedal_off";
+ }
+ else {
+ this->crr_accel_pedal_state_ = "accel_pedal_on";
+ }
+ HMI_DEBUG("wm:lcc", "Current accelerator pedal state:%s", this->crr_accel_pedal_state_.c_str());
+
// Update car state
if ((0 == this->vehicle_speed_) || (true == this->parking_brake_status_)) {
this->crr_car_state_ = "car_stop";
@@ -139,14 +171,14 @@ void LowCanClient::analyzeCanSignal(struct json_object *object) {
}
HMI_DEBUG("wm:lcc", "Current car state:%s", this->crr_car_state_.c_str());
- // Update lamp state
- if (true == this->headlamp_status_) {
- this->crr_lamp_state_ = "lamp_on";
- }
- else {
- this->crr_lamp_state_ = "lamp_off";
+ // If lamp state is changed,
+ // backup current state for previous state and set flag
+ if (this->prv_lamp_state_ != this->crr_lamp_state_) {
+ HMI_DEBUG("wm:lcc", "Lamp state is changed: %s -> %s",
+ this->prv_lamp_state_.c_str(), this->crr_lamp_state_.c_str());
+ this->prv_lamp_state_ = this->crr_lamp_state_;
+ this->is_changed_lamp_state_ = true;
}
- HMI_DEBUG("wm:lcc", "Current lamp state:%s", this->crr_lamp_state_.c_str());
// If parking brake state is changed,
// backup current state for previous state and set flag
@@ -157,6 +189,15 @@ void LowCanClient::analyzeCanSignal(struct json_object *object) {
this->is_changed_parking_brake_state_ = true;
}
+ // If accelerator pedal state is changed,
+ // backup current state for previous state and set flag
+ if (this->prv_accel_pedal_state_ != this->crr_accel_pedal_state_) {
+ HMI_DEBUG("wm:lcc", "Accelerator Pedal is changed: %s -> %s",
+ this->prv_accel_pedal_state_.c_str(), this->crr_accel_pedal_state_.c_str());
+ this->prv_accel_pedal_state_ = this->crr_accel_pedal_state_;
+ this->is_changed_accel_pedal_state_ = true;
+ }
+
// If car state is changed,
// backup current state for previous state and set flag
if (this->prv_car_state_ != this->crr_car_state_) {
@@ -165,15 +206,13 @@ void LowCanClient::analyzeCanSignal(struct json_object *object) {
this->prv_car_state_ = this->crr_car_state_;
this->is_changed_car_state_ = true;
}
+}
- // If lamp state is changed,
- // backup current state for previous state and set flag
- if (this->prv_lamp_state_ != this->crr_lamp_state_) {
- HMI_DEBUG("wm:lcc", "Lamp state is changed: %s -> %s",
- this->prv_lamp_state_.c_str(), this->crr_lamp_state_.c_str());
- this->prv_lamp_state_ = this->crr_lamp_state_;
- this->is_changed_lamp_state_ = true;
- }
+bool LowCanClient::isChangedLampState() {
+ HMI_DEBUG("wm:lcc", "Call");
+
+ // Return changed flag
+ return this->is_changed_lamp_state_;
}
bool LowCanClient::isChangedParkingBrakeState() {
@@ -183,6 +222,13 @@ bool LowCanClient::isChangedParkingBrakeState() {
return this->is_changed_parking_brake_state_;
}
+bool LowCanClient::isChangedAccelPedalState() {
+ HMI_DEBUG("wm:lcc", "Call");
+
+ // Return changed flag
+ return this->is_changed_accel_pedal_state_;
+}
+
bool LowCanClient::isChangedCarState() {
HMI_DEBUG("wm:lcc", "Call");
@@ -190,11 +236,14 @@ bool LowCanClient::isChangedCarState() {
return this->is_changed_car_state_;
}
-bool LowCanClient::isChangedLampState() {
+const char* LowCanClient::getCurrentLampState() {
HMI_DEBUG("wm:lcc", "Call");
- // Return changed flag
- return this->is_changed_lamp_state_;
+ // Clear changed flag
+ this->is_changed_lamp_state_ = false;
+
+ // Return current lamp state
+ return this->crr_lamp_state_.c_str();
}
const char* LowCanClient::getCurrentParkingBrakeState() {
@@ -207,24 +256,24 @@ const char* LowCanClient::getCurrentParkingBrakeState() {
return this->crr_parking_brake_state_.c_str();
}
-const char* LowCanClient::getCurrentCarState() {
+const char* LowCanClient::getCurrentAccelPedalState() {
HMI_DEBUG("wm:lcc", "Call");
// Clear changed flag
- this->is_changed_car_state_ = false;
+ this->is_changed_accel_pedal_state_ = false;
- // Return current car state
- return this->crr_car_state_.c_str();
+ // Return current accelerator pedal state
+ return this->crr_accel_pedal_state_.c_str();
}
-const char* LowCanClient::getCurrentLampState() {
+const char* LowCanClient::getCurrentCarState() {
HMI_DEBUG("wm:lcc", "Call");
// Clear changed flag
- this->is_changed_lamp_state_ = false;
+ this->is_changed_car_state_ = false;
- // Return current lamp state
- return this->crr_lamp_state_.c_str();
+ // Return current car state
+ return this->crr_car_state_.c_str();
}
diff --git a/src/low_can_client.hpp b/src/low_can_client.hpp
index 04220f5..2941e6e 100644
--- a/src/low_can_client.hpp
+++ b/src/low_can_client.hpp
@@ -33,12 +33,14 @@ public:
void initialize();
void analyzeCanSignal(struct json_object *object);
+ bool isChangedLampState();
bool isChangedParkingBrakeState();
+ bool isChangedAccelPedalState();
bool isChangedCarState();
- bool isChangedLampState();
+ const char* getCurrentLampState();
const char* getCurrentParkingBrakeState();
+ const char* getCurrentAccelPedalState();
const char* getCurrentCarState();
- const char* getCurrentLampState();
private:
// Disable copy and move
@@ -47,29 +49,33 @@ private:
LowCanClient(LowCanClient &&) = delete;
LowCanClient &operator=(LowCanClient &&) = delete;
- const int kNumEvent_ = 4;
const std::vector<const char*> kEventName_{
"vehicle.speed",
"transmission_gear_position",
"headlamp_status",
- "parking_brake_status"
+ "parking_brake_status",
+ "accelerator.pedal.position",
};
int vehicle_speed_;
int trans_gear_pos_;
- json_bool parking_brake_status_;
json_bool headlamp_status_;
+ json_bool parking_brake_status_;
+ double accel_pedal_pos_;
+ std::string prv_lamp_state_;
+ std::string crr_lamp_state_;
std::string prv_parking_brake_state_;
std::string crr_parking_brake_state_;
+ std::string prv_accel_pedal_state_;
+ std::string crr_accel_pedal_state_;
std::string prv_car_state_;
std::string crr_car_state_;
- std::string prv_lamp_state_;
- std::string crr_lamp_state_;
+ bool is_changed_lamp_state_;
bool is_changed_parking_brake_state_;
+ bool is_changed_accel_pedal_state_;
bool is_changed_car_state_;
- bool is_changed_lamp_state_;
};
} // namespace wm
diff --git a/src/main.cpp b/src/main.cpp
index 7abdfb0..99e7a7c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -683,6 +683,24 @@ void on_event(const char *event, struct json_object *object){
}
});
}
+ if (g_afb_instance->lcc_.isChangedAccelPedalState()) {
+ // If accelerator pedal state is changed
+ HMI_DEBUG("wm", "Accelerator Pedal state is changed");
+
+ // Get parking brake state
+ const char* accel_pedal_state = g_afb_instance->lcc_.getCurrentAccelPedalState();
+
+#if 0 // TODO: PolicyManager can not use accelerator pedal state
+ // Allocate window resource
+ g_afb_instance->app.allocateWindowResource(accel_pedal_state, nullptr,
+ nullptr, nullptr,
+ [](const char* errmsg){
+ if (errmsg != nullptr) {
+ HMI_ERROR("wm", errmsg);
+ }
+ });
+#endif
+ }
else if (g_afb_instance->lcc_.isChangedCarState()) {
// If car state is changed
HMI_DEBUG("wm", "Car state is changed");