From c619efce223f54ff37eaa800851d54edd3cc791f Mon Sep 17 00:00:00 2001 From: Hayato Nakamura Date: Mon, 16 Sep 2013 18:28:48 +0900 Subject: [PATCH] Retry to Websocket connection failure. Change-Id: Id2fed6621489d6f2aa42d894d3d22fab7b857278 Signed-off-by: Hayato Nakamura --- G25.conf | 3 +- G27.conf | 3 +- packaging/ico-vic-carsimulator.changes | 9 +++++ packaging/ico-vic-carsimulator.spec | 6 +-- src/AmbpiComm.cpp | 13 +++++-- src/CConf.cpp | 3 ++ src/CGtCtrl.cpp | 70 ++++++++++++++++++++-------------- src/CGtCtrl.h | 1 + src/CJoyStick.h | 1 - src/CJoyStickEV.cpp | 64 +++++++++++++++++++++++++------ src/CJoyStickEV.h | 4 +- 11 files changed, 122 insertions(+), 55 deletions(-) diff --git a/G25.conf b/G25.conf index 6e6b854..f1fb17c 100644 --- a/G25.conf +++ b/G25.conf @@ -20,7 +20,7 @@ TYPE=1 NUMBER=301 [HEAD_LIGHT] TYPE=1 -NUMBER=2 +NUMBER=292 [STEERING] TYPE=2 NUMBER=0 @@ -35,4 +35,3 @@ NUMBER=2 LAT=35.717931 LNG=139.736518 - diff --git a/G27.conf b/G27.conf index 9908c1c..823f481 100644 --- a/G27.conf +++ b/G27.conf @@ -35,7 +35,7 @@ TYPE=1 NUMBER=710 [HEAD_LIGHT] TYPE=1 -NUMBER=2 +NUMBER=292 [STEERING] TYPE=2 NUMBER=0 @@ -50,4 +50,3 @@ NUMBER=5 LAT=35.717931 LNG=139.736518 - diff --git a/packaging/ico-vic-carsimulator.changes b/packaging/ico-vic-carsimulator.changes index adf8c6b..d257265 100644 --- a/packaging/ico-vic-carsimulator.changes +++ b/packaging/ico-vic-carsimulator.changes @@ -1,3 +1,12 @@ +* Mon Sep 16 2013 Shibata Makoto accepted/2.0alpha-wayland/20130612.174818@b57c2a9 +- 0.9.03 release. +-- Retry to Websocket connection failure. + +- 0.9.02 release +-- Corresponding to Tizen IVI 3.0 OS +-- Create an event definition file of G25 and G27 steering wheel +-- Set to head-light state operation to the right paddle shifter + * Fri Aug 30 2013 Shibata Makoto accepted/2.0alpha-wayland/20130612.174818@cbaa0e0 - release 0.9.01 -- Support G27 Racing Wheel. (Current Support device G27 Racing Wheel and Driving Force GT) diff --git a/packaging/ico-vic-carsimulator.spec b/packaging/ico-vic-carsimulator.spec index 5b2f967..7ab5900 100644 --- a/packaging/ico-vic-carsimulator.spec +++ b/packaging/ico-vic-carsimulator.spec @@ -1,6 +1,6 @@ Name: ico-vic-carsimulator Summary: CarSimulator -Version: 0.9.0 +Version: 0.9.03 Release: 1.1 Group: System Environment/Daemons License: Apache 2.0 @@ -13,10 +13,8 @@ Requires: ico-uxf-utilities BuildRequires: make BuildRequires: automake BuildRequires: boost-devel -#BuildRequires: libwebsockets-devel BuildRequires: glib2-devel BuildRequires: json-glib-devel -#BuildRequires: ico-uxf-utilities BuildRequires: ico-uxf-utilities-devel %description @@ -39,7 +37,6 @@ rm -rf %{buildroot} %define carsim_conf /usr/bin/ mkdir -p %{buildroot}/etc/carsim/ mkdir -p %{buildroot}/usr/lib/systemd/system/ -#install -m 0644 src/CarSim_Daemon.conf %{buildroot}%{carsim_conf} install -m 0644 G25.conf %{buildroot}/etc/carsim/ install -m 0644 G27.conf %{buildroot}/etc/carsim/ install -m 0644 carsim.service %{buildroot}/usr/lib/systemd/system/ @@ -52,4 +49,3 @@ install -m 0644 carsim.service %{buildroot}/usr/lib/systemd/system/ %{_bindir}/* /etc/carsim/* /usr/lib/systemd/system/carsim.service -#%{carsim_conf}/CarSim_Daemon.conf diff --git a/src/AmbpiComm.cpp b/src/AmbpiComm.cpp index 8b3c043..b50f974 100644 --- a/src/AmbpiComm.cpp +++ b/src/AmbpiComm.cpp @@ -19,6 +19,7 @@ using namespace std; static vector _commList; +const int RECONNECT_WS = 5; bool _addAmbCommIFList(AmbpiCommIF* comm); void _eraseAmbCommIFList(const AmbpiCommIF* comm); @@ -225,11 +226,15 @@ bool AmbpiCommIF::init(const char* uri, const char* protocolName) } m_uri = uri; m_pNm = protocolName; - m_context = ico_uws_create_context(uri, protocolName); - if (NULL == m_context) { + int loopcount = 0; + do { + m_context = ico_uws_create_context(uri, protocolName); + if (NULL != m_context) { + break; + } cerr << m_pNm << ":Failed to create context." << endl; - return false; - } + usleep (500 * 1000); + } while (m_context == NULL && ++loopcount < RECONNECT_WS); int r = ico_uws_set_event_cb(m_context, _icoUwsCallback, (void*)this); if (ICO_UWS_ERR_NONE != r) { cerr << m_pNm << ":Failed to callback entry(" << r << ")." << endl; diff --git a/src/CConf.cpp b/src/CConf.cpp index 0cea4b5..904baa0 100644 --- a/src/CConf.cpp +++ b/src/CConf.cpp @@ -52,6 +52,9 @@ void CConf::LoadConfig(const char*filePath) m_nAccel = CConf::GetConfig(m_strConfPath, "ACCEL", "NUMBER", 1); m_nBrake = CConf::GetConfig(m_strConfPath, "BRAKE", "NUMBER", 2); + m_nHeadLight = + CConf::GetConfig(m_strConfPath, "HEAD_LIGHT", "NUMBER", 292); + m_fLat = CConf::GetConfig(m_strConfPath, "LASTPOSITION", "LAT", 35.717931); m_fLng = diff --git a/src/CGtCtrl.cpp b/src/CGtCtrl.cpp index 75da1ca..f7fe957 100644 --- a/src/CGtCtrl.cpp +++ b/src/CGtCtrl.cpp @@ -123,6 +123,7 @@ bool CGtCtrl::Initialize() m_stVehicleInfo.nDirection = 0; m_stVehicleInfo.dVelocity = 0.0; m_stVehicleInfo.nAccel = 0; + m_stVehicleInfo.bHeadLight = false; // HEAD LIGHT OFF(false) m_bFirstOpen = true; @@ -237,7 +238,7 @@ void CGtCtrl::Run() int nAccPedalOpen = -1; int nSpeed = -1; CAvgCar pmCar(g_RPM_SAMPLE_SPACE_SIZE, g_SPEED_SAMPLE_SPACE_SIZE, - g_BREAKE_SAMPLE_SPACE_SIZE); + g_BREAKE_SAMPLE_SPACE_SIZE); pmCar.chgGear(CAvgGear::E_SHIFT_PARKING); /** * DIRECTION @@ -268,33 +269,21 @@ void CGtCtrl::Run() vi, m_stVehicleInfo.nSteeringAngle); } } - - if (number == myConf.m_nAccel) { - //printf("Accel[%d]\n", value); - if (gbDevJs) { - if (0 == value) { - pmCar.chgThrottle(32767); - pmCar.chgBrake(32767); - } - else if (0 < value) { - pmCar.chgThrottle(32767); - pmCar.chgBrake((value - 16384) * -2); - } - else { - pmCar.chgThrottle((abs(value) - 16384) * -2); - pmCar.chgBrake(32767); - } + else if (number == myConf.m_nAccel) { + if (0 >= value) { + pmCar.chgThrottle(32767); } else { - pmCar.chgThrottle((65535 - value) / 1.1 + 32767); - pmCar.chgBrake(32767); + pmCar.chgThrottle((value - 16384) * -2); } } - - if (number == myConf.m_nBrake) { - //printf("Brake[%d]\n", value); - pmCar.chgThrottle(32767); - pmCar.chgBrake((65535 - value) / 64 + 32767); + else if (number == myConf.m_nBrake) { + if (0 >= value) { + pmCar.chgBrake(32767); + } + else { + pmCar.chgBrake((value - 16384) * -2); + } } break; case JS_EVENT_BUTTON: @@ -425,7 +414,7 @@ void CGtCtrl::Run() /** * TURN SIGNAL(WINKER) & LIGHTSTATUS */ - bool bTurnSignal = false; + bool bLIGHTSTATUS = false; if (number == myConf.m_nWinkR) { if (value != 0) { @@ -440,7 +429,7 @@ void CGtCtrl::Run() int wpos = m_stVehicleInfo.nWinkerPos == WINKER_RIGHT ? 1 : 0; SendVehicleInfo(dataport_def, vi, wpos); - bTurnSignal = true; + bLIGHTSTATUS = true; } } @@ -457,14 +446,37 @@ void CGtCtrl::Run() int wpos = m_stVehicleInfo.nWinkerPos == WINKER_LEFT ? 2 : 0; SendVehicleInfo(dataport_def, vi, wpos); - bTurnSignal = true; + bLIGHTSTATUS = true; } } - if (true == bTurnSignal) { + if (number == myConf.m_nHeadLight) { + if (0 != value) { + if (false == m_stVehicleInfo.bHeadLight) { // HEAD LIGHT OFF(false) ? + m_stVehicleInfo.bHeadLight = true; // HEAD LIGHT ON(true) + } + else { + m_stVehicleInfo.bHeadLight = false; // HEAD LIGHT OFF(false) + } + bLIGHTSTATUS = true; + } + } + + if (true == bLIGHTSTATUS) { const size_t LSsz = 8; - char data[LSsz]; + char data[LSsz]; + // 0:LIGHT HEAD STATUS ON(1)/OFF(0) + // 1:LEFT WINKER STATUS ON(1)/OFF(0) + // 2:RIGHT WINKER STATUS ON(1)/OFF(0) + // 3:PARKING + // 4:FOG LAMP + // 5:HAZARD + // 6:BRAKE + // 7:HIGHBEAM memset(data, 0, sizeof(data)); + if (true == m_stVehicleInfo.bHeadLight) { // HEAD LIGHT ON ? + data[0] = 1; + } if (WINKER_LEFT == m_stVehicleInfo.nWinkerPos) { data[1] = 1; } diff --git a/src/CGtCtrl.h b/src/CGtCtrl.h index 3a627e8..cb57ac2 100644 --- a/src/CGtCtrl.h +++ b/src/CGtCtrl.h @@ -214,6 +214,7 @@ struct VehicleInfo double dVelocity; int nAccel; int nBrake; + bool bHeadLight; // HEAD LIGHT ON(true)/OFF(false) status }; enum SHIFT_POS diff --git a/src/CJoyStick.h b/src/CJoyStick.h index ac1ef0b..1423c8d 100644 --- a/src/CJoyStick.h +++ b/src/CJoyStick.h @@ -55,7 +55,6 @@ class CJoyStick std::vector& filesList) const; virtual bool getDeviceName(int fd, char* devNM, size_t sz); - protected: char m_strJoyStick[64]; int m_nJoyStickID; diff --git a/src/CJoyStickEV.cpp b/src/CJoyStickEV.cpp index e45479d..9e19c97 100644 --- a/src/CJoyStickEV.cpp +++ b/src/CJoyStickEV.cpp @@ -8,6 +8,17 @@ */ /** * @file CJoyStickEV.h + * + * Note: + * processing in the value of the joystick-event in Tizen IVI 2.0 + * joystick-event + * event-type is used JS_EVENT_BUTTON and JS_EVENT_AXIS + * axis/button number value is determine in configuration file + * G27.conf G25.conf + * event-value memo + * Steering value: -32767(Right) <-> 32767(Left) + * Accel value:0(full throttle) <-> 32767(free throttle) + * Brake value:0(full throttle) <-> 32767(free throttle) */ #include #include @@ -23,6 +34,7 @@ #include #include "CJoyStick.h" #include "CJoyStickEV.h" +#include "CConf.h" using namespace std; CJoyStickEV::CJoyStickEV() @@ -191,33 +203,35 @@ int CJoyStickEV::getJS_EVENT_AXIS(int& num, int& val, int r = -1; switch (s.code) { case ABS_X: + // Convert value Steering + // 0 to 16353 -> -32766 to 32767 r = JS_EVENT_AXIS; - num = 0; - val = calc2pm32767((int)s.value, m_absInf[E_ABSX]); + num = (int)s.code; + val = calc1pm32767((int)s.value, m_absInf[E_ABSX]); break; case ABS_Y: r = JS_EVENT_AXIS; - num = 1; - val = calc2pm32767((int)s.value, m_absInf[E_ABSY]); + num = (int)s.code; + val = calc1pm32767((int)s.value, m_absInf[E_ABSY]); break; case ABS_Z: r = JS_EVENT_AXIS; - num = 2; - val = calc2pm32767((int)s.value, m_absInf[E_ABSZ]); + num = (int)s.code; + val = calc3p32767Reverse((int)s.value, m_absInf[E_ABSZ]); break; case ABS_RZ: r = JS_EVENT_AXIS; - num = 5; - val = calc2pm32767((int)s.value, m_absInf[E_ABSRZ]); + num = (int)s.code; + val = calc3p32767Reverse((int)s.value, m_absInf[E_ABSRZ]); break; case ABS_HAT0X: r = JS_EVENT_AXIS; - num = 16; + num = (int)s.code; val = (int)s.value; break; case ABS_HAT0Y: r = JS_EVENT_AXIS; - num = 17; + num = (int)s.code; val = (int)s.value; break; defaulr: @@ -227,6 +241,7 @@ int CJoyStickEV::getJS_EVENT_AXIS(int& num, int& val, } /** * @brief calc value case 1 + * change to -32767 <-> 32767 */ int CJoyStickEV::calc1pm32767(int val, const struct input_absinfo& ai) { @@ -235,16 +250,43 @@ int CJoyStickEV::calc1pm32767(int val, const struct input_absinfo& ai) int c = ((int) (b * 65534)) - 32767; return c; } + /** * @brief calc value case 2 + * change to 0 <-> 65534 */ -int CJoyStickEV::calc2pm32767(int val, const struct input_absinfo& ai) +int CJoyStickEV::calc2p65535(int val, const struct input_absinfo& ai) { int a = ai.maximum - ai.minimum; double b = (double)val / (double)a; int c = (int) (b * 65534); return c; } + +/** + * @brief calc value case 3 + * change to 0 <-> 32767 + */ +int CJoyStickEV::calc3p32767(int val, const struct input_absinfo& ai) +{ + int a = ai.maximum - ai.minimum; + double b = (double)val / (double)a; + int c = (int) (b * 32767); + return c; +} + +/** + * @brief calc value case 3 + * change to 32767 <-> 0 + */ +int CJoyStickEV::calc3p32767Reverse(int val, const struct input_absinfo& ai) +{ + int a = ai.maximum - ai.minimum; + double b = (double)val / (double)a; + int c = abs(((int) (b * 32767)) - 32767); + return c; +} + /** * get device name */ diff --git a/src/CJoyStickEV.h b/src/CJoyStickEV.h index 4688545..802ce71 100644 --- a/src/CJoyStickEV.h +++ b/src/CJoyStickEV.h @@ -41,7 +41,9 @@ class CJoyStickEV : public CJoyStick int getJS_EVENT_BUTTON(int& num, int& val, const struct input_event& s); int getJS_EVENT_AXIS(int& num, int& val, const struct input_event& s); int calc1pm32767(int val, const struct input_absinfo& ai); - int calc2pm32767(int val, const struct input_absinfo& ai); + int calc2p65535(int val, const struct input_absinfo& ai); + int calc3p32767(int val, const struct input_absinfo& ai); + int calc3p32767Reverse(int val, const struct input_absinfo& ai); enum { E_ABSX = 0, /* ABS_X */ E_ABSY, /* ABS_Y */ -- 2.7.4