Supprot new Device(G27 Racing Wheel) 09/9009/1
authorNakamura Hayato <hayato.nakamura@mail.toyota-td.jp>
Fri, 30 Aug 2013 12:05:12 +0000 (21:05 +0900)
committerNakamura Hayato <hayato.nakamura@mail.toyota-td.jp>
Fri, 30 Aug 2013 12:17:21 +0000 (21:17 +0900)
Change-Id: Icff988517679f55f3d5850447497759665a3b318
Signed-off-by: Nakamura Hayato <hayato.nakamura@mail.toyota-td.jp>
20 files changed:
G25.conf [new file with mode: 0644]
G27.conf [new file with mode: 0644]
carsim.service [new file with mode: 0644]
packaging/ico-vic-carsimulator.changes
packaging/ico-vic-carsimulator.spec
src/CAvgCar.cpp
src/CAvgCar.h
src/CConf.cpp
src/CConf.h
src/CGtCtrl.cpp
src/CGtCtrl.h
src/CJoyStick.h
src/CJoyStickEV.cpp
src/CJoyStickEV.h
src/CJoyStickG25.cpp [new file with mode: 0644]
src/CJoyStickG25.h [new file with mode: 0644]
src/CJoyStickG27.cpp [new file with mode: 0644]
src/CJoyStickG27.h [new file with mode: 0644]
src/CarSim_Daemon.conf
src/Makefile.am

diff --git a/G25.conf b/G25.conf
new file mode 100644 (file)
index 0000000..6e6b854
--- /dev/null
+++ b/G25.conf
@@ -0,0 +1,38 @@
+[DEVICE]
+NAME=Driving Force GT
+[HAZARDLAMP]
+TYPE=1
+NUMBER=3
+[WINKER_RIGHT]
+TYPE=1
+NUMBER=294
+[WINKER_LEFT]
+TYPE=1
+NUMBER=295
+[AIRCON_TEMP]
+TYPE=2
+NUMBER=3
+[SHIFT_UP]
+TYPE=1
+NUMBER=300
+[SHIFT_DOWN]
+TYPE=1
+NUMBER=301
+[HEAD_LIGHT]
+TYPE=1
+NUMBER=2
+[STEERING]
+TYPE=2
+NUMBER=0
+[ACCEL]
+TYPE=2
+NUMBER=1
+[BRAKE]
+TYPE=2
+NUMBER=2
+
+[LASTPOSTION]
+LAT=35.717931
+LNG=139.736518
+
+
diff --git a/G27.conf b/G27.conf
new file mode 100644 (file)
index 0000000..9908c1c
--- /dev/null
+++ b/G27.conf
@@ -0,0 +1,53 @@
+[DEVICE]
+NAME=G27 Racing Wheel
+[HAZARDLAMP]
+TYPE=1
+NUMBER=3
+[WINKER_RIGHT]
+TYPE=1
+NUMBER=294
+[WINKER_LEFT]
+TYPE=1
+NUMBER=295
+[AIRCON_TEMP]
+TYPE=2
+NUMBER=3
+[SHIFT_1]
+TYPE=1
+NUMBER=300
+[SHIFT_2]
+TYPE=1
+NUMBER=301
+[SHIFT_3]
+TYPE=1
+NUMBER=302
+[SHIFT_4]
+TYPE=1
+NUMBER=303
+[SHIFT_5]
+TYPE=1
+NUMBER=704
+[SHIFT_6]
+TYPE=1
+NUMBER=705
+[SHIFT_R]
+TYPE=1
+NUMBER=710
+[HEAD_LIGHT]
+TYPE=1
+NUMBER=2
+[STEERING]
+TYPE=2
+NUMBER=0
+[ACCEL]
+TYPE=2
+NUMBER=2
+[BRAKE]
+TYPE=2
+NUMBER=5
+
+[LASTPOSTION]
+LAT=35.717931
+LNG=139.736518
+
+
diff --git a/carsim.service b/carsim.service
new file mode 100644 (file)
index 0000000..1ab7c84
--- /dev/null
@@ -0,0 +1,15 @@
+#
+# carsim systemd service unit file
+#
+
+[Unit]
+Description=Carsimulator supported by G25 and G27.
+After=ambd.service
+
+[Service]
+ExecStart=/usr/bin/carsim
+
+[Install]
+WantedBy=multi-user.target
+
+
index eb5bb5b..adf8c6b 100644 (file)
@@ -1,3 +1,8 @@
+* Fri Aug 30 2013 Shibata Makoto <shibata@mac.tec.toyota.co.jp> 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)
+-- Support systemctl.
+
 * Wed Jul 17 2013 Shibata Makoto <shibata@mac.tec.toyota.co.jp> accepted/2.0alpha-wayland/20130612.174818@8f21497
 - 0.1.4-2 release.
 - Change to ico-uxf-utilities from libwebsocket.
index 4859190..5b2f967 100644 (file)
@@ -1,7 +1,7 @@
 Name:       ico-vic-carsimulator
 Summary:    CarSimulator
-Version:    0.1.4
-Release:    2
+Version:    0.9.0
+Release:    1.1
 Group:      System Environment/Daemons
 License:    Apache 2.0
 Source0:    %{name}-%{version}.tar.bz2
@@ -37,7 +37,12 @@ rm -rf %{buildroot}
 
 # configurations
 %define carsim_conf /usr/bin/
-install -m 0644 src/CarSim_Daemon.conf %{buildroot}%{carsim_conf}
+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/
 
 %post -p /sbin/ldconfig
 %postun -p /sbin/ldconfig
@@ -45,4 +50,6 @@ install -m 0644 src/CarSim_Daemon.conf %{buildroot}%{carsim_conf}
 %files
 %defattr(-,root,root,-)
 %{_bindir}/*
-%{carsim_conf}/CarSim_Daemon.conf
+/etc/carsim/*
+/usr/lib/systemd/system/carsim.service
+#%{carsim_conf}/CarSim_Daemon.conf
index caea154..82f434b 100644 (file)
@@ -333,6 +333,7 @@ double CAvgBrake::getSpeed(double sourceSpeed)
 CAvgGear::CAvgGear()
 {
     m_transmission = E_SHIFT_PARKING;
+    m_transmissionOLD = m_transmission;
     m_transmissionValue = D_SHIFT_VALUE_PARKING;
 }
 
@@ -416,6 +417,24 @@ double CAvgGear::getGearRatio(double speed, bool bDown) const
     case E_SHIFT_NEUTRAL:
         gr = 0.0l;
         break;
+    case E_SHIFT_MT_FIRST:
+        gr = gr1;
+        break;
+    case E_SHIFT_MT_SECOND:
+        gr = grD1;
+        break;
+    case E_SHIFT_MT_THIRD:
+        gr = grD2;
+        break;
+    case E_SHIFT_MT_FOURTH:
+        gr = grD3;
+        break;
+    case E_SHIFT_MT_FIFTH:
+        gr = grD4;
+        break;
+    case E_SHIFT_MT_SIXTH:
+        gr = grD5;
+        break;
     default:
         gr = 0.0l;
         break;
@@ -430,30 +449,37 @@ void CAvgGear::setShiftDown()
 {
     switch (m_transmission) {
     case E_SHIFT_PARKING:
+        m_transmissionOLD = m_transmission;
         m_transmission = E_SHIFT_REVERSE; // PARKING -> REVERSE
         m_transmissionValue = D_SHIFT_VALUE_REVERSE;
         break;
     case E_SHIFT_REVERSE:
+        m_transmissionOLD = m_transmission;
         m_transmission = E_SHIFT_NEUTRAL; // REVERSE -> NEUTRAL
         m_transmissionValue = D_SHIFT_VALUE_NEUTRAL;
         break;
     case E_SHIFT_NEUTRAL:
+        m_transmissionOLD = m_transmission;
         m_transmission = E_SHIFT_DRIVE;   // NEUTRAL -> DRIVE
         m_transmissionValue = D_SHIFT_VALUE_DRIVE;
         break;
     case E_SHIFT_DRIVE:
+        m_transmissionOLD = m_transmission;
         m_transmission = E_SHIFT_THIRD;   // DRIVE   -> THIRD
         m_transmissionValue = D_SHIFT_VALUE_THIRD;
         break;
     case E_SHIFT_THIRD:
+        m_transmissionOLD = m_transmission;
         m_transmission = E_SHIFT_SECOND;  // THIRD   -> SECOND
         m_transmissionValue = D_SHIFT_VALUE_SECOND;
         break;
     case E_SHIFT_SECOND:
+        m_transmissionOLD = m_transmission;
         m_transmission = E_SHIFT_FIRST;   // SECOND  -> FIRST
         m_transmissionValue = D_SHIFT_VALUE_FIRST;
         break;
     case E_SHIFT_FIRST:
+        m_transmissionOLD = m_transmission;
         m_transmission = E_SHIFT_FIRST;   // NO CHANGE
         m_transmissionValue = D_SHIFT_VALUE_FIRST;
         break;
@@ -467,36 +493,90 @@ void CAvgGear::setShiftUp()
 {
     switch (m_transmission) {
     case E_SHIFT_FIRST:
+        m_transmissionOLD = m_transmission;
         m_transmission = E_SHIFT_SECOND;  // FIRST   -> SECOND
         m_transmissionValue = D_SHIFT_VALUE_SECOND;
         break;
     case E_SHIFT_SECOND:
+        m_transmissionOLD = m_transmission;
         m_transmission = E_SHIFT_THIRD;   // SECOND  -> THIRD
         m_transmissionValue = D_SHIFT_VALUE_THIRD;
         break;
     case E_SHIFT_THIRD:
+        m_transmissionOLD = m_transmission;
         m_transmission = E_SHIFT_DRIVE;   // THIRD -> DRIVE
         m_transmissionValue = D_SHIFT_VALUE_DRIVE;
         break;
     case E_SHIFT_DRIVE:
+        m_transmissionOLD = m_transmission;
         m_transmission = E_SHIFT_NEUTRAL; // DRIVE -> NEUTRAL
         m_transmissionValue = D_SHIFT_VALUE_NEUTRAL;
         break;
     case E_SHIFT_NEUTRAL:
+        m_transmissionOLD = m_transmission;
         m_transmission = E_SHIFT_REVERSE; // NEUTRAL -> REVERSE
         m_transmissionValue = D_SHIFT_VALUE_REVERSE;
         break;
     case E_SHIFT_REVERSE:
+        m_transmissionOLD = m_transmission;
         m_transmission = E_SHIFT_PARKING; // REVERSE  -> PARKING
         m_transmissionValue = D_SHIFT_VALUE_PARKING;
         break;
     case E_SHIFT_PARKING:
+        m_transmissionOLD = m_transmission;
         m_transmission = E_SHIFT_PARKING; // NO CHANGE
         m_transmissionValue = D_SHIFT_VALUE_PARKING;
         break;
     }
 }
 
+void CAvgGear::setShiftMT(E_AT_GEAR tm) {
+    switch(tm) {
+    case E_SHIFT_MT_FIRST :
+        m_transmissionOLD = m_transmission;
+        m_transmission = E_SHIFT_MT_FIRST;
+        m_transmissionValue = D_SHIFT_VALUE_FIRST;
+        break;
+    case E_SHIFT_MT_SECOND :
+        m_transmissionOLD = m_transmission;
+        m_transmission = E_SHIFT_MT_SECOND;
+        m_transmissionValue = D_SHIFT_VALUE_SECOND;
+        break;
+    case E_SHIFT_MT_THIRD :
+        m_transmissionOLD = m_transmission;
+        m_transmission = E_SHIFT_MT_THIRD;
+        m_transmissionValue = D_SHIFT_VALUE_THIRD;
+        break;
+    case E_SHIFT_MT_FOURTH :
+        m_transmissionOLD = m_transmission;
+        m_transmission = E_SHIFT_MT_FOURTH;
+        m_transmissionValue = D_SHIFT_VALUE_DRIVE;
+        break;
+    case E_SHIFT_MT_FIFTH :
+        m_transmissionOLD = m_transmission;
+        m_transmission = E_SHIFT_MT_FIFTH;
+        m_transmissionValue = D_SHIFT_VALUE_DRIVE;
+        break;
+    case E_SHIFT_MT_SIXTH :
+        m_transmissionOLD = m_transmission;
+        m_transmission = E_SHIFT_MT_SIXTH;
+        m_transmissionValue = D_SHIFT_VALUE_DRIVE;
+        break;
+    case E_SHIFT_REVERSE :
+        m_transmissionOLD = m_transmission;
+        m_transmission = E_SHIFT_REVERSE;
+        m_transmissionValue = D_SHIFT_VALUE_REVERSE;
+        break;
+    case E_SHIFT_NEUTRAL :
+        m_transmissionOLD = m_transmission;
+        m_transmission = E_SHIFT_NEUTRAL;
+        m_transmissionValue = D_SHIFT_VALUE_NEUTRAL;
+        break;
+    default :
+        break;
+    }
+}
+
 /******************************************
  * Average Car
 ******************************************/
@@ -619,10 +699,17 @@ void CAvgCar::calc()
             double x = 0 - m_currentRunMeter;
             m_currentRunMeter = x;
         }
+        else if (true == isNeutral()) {
+            if (true == isReverseLastTime()) {
+                double x = 0 - m_currentRunMeter;
+                m_currentRunMeter = x;
+            }
+        }
         m_tripmeter += m_currentRunMeter;
         m_odometer += m_currentRunMeter;
     }
     else {
+        reset_old();
         m_currentRunMeter = 0.0l;
     }
 }
index 68dda27..0f71289 100644 (file)
@@ -266,7 +266,13 @@ class CAvgGear
         E_SHIFT_DRIVE = 4,   // 4=N
         E_SHIFT_FIRST,       // 5=L
         E_SHIFT_SECOND,      // 6=2
-        E_SHIFT_THIRD        // 7=oem
+        E_SHIFT_THIRD,        // 7=oem
+        E_SHIFT_MT_FIRST = 11,
+        E_SHIFT_MT_SECOND,
+        E_SHIFT_MT_THIRD,
+        E_SHIFT_MT_FOURTH,
+        E_SHIFT_MT_FIFTH,
+        E_SHIFT_MT_SIXTH,
     };
 
             CAvgGear();
@@ -282,8 +288,15 @@ class CAvgGear
     bool    isReverse() const;
     bool    isNeutral() const;
     bool    isParking() const;
+
+    void    setShiftMT(E_AT_GEAR tm);
+
+    bool    isReverseLastTime() const;
+    void    reset_old();
+
   private:
     E_AT_GEAR m_transmission;
+    E_AT_GEAR m_transmissionOLD;
     int       m_transmissionValue;
 };
 
@@ -293,6 +306,7 @@ class CAvgGear
  */
 inline void CAvgGear::chgGear(E_AT_GEAR tm)
 {
+    m_transmissionOLD = m_transmission;
     m_transmission = tm;
 }
 
@@ -359,6 +373,27 @@ inline int CAvgGear::getMode() const
     return D_SHIFT_MODE_NORMAL;
 }
 
+/**
+ * @brief Reverse gear last time check
+ * @return true / false
+ */
+inline bool CAvgGear::isReverseLastTime() const
+{
+    if (E_SHIFT_REVERSE == m_transmissionOLD) {
+        return true;
+    }
+    return false;
+}
+
+/**
+ * @brief reset_old
+ * @return transmission old value clear
+ */
+inline void CAvgGear::reset_old()
+{
+    m_transmissionOLD = m_transmission;
+}
+
 /******************************************
  * Average Car
 ******************************************/
index 983f335..0cea4b5 100644 (file)
@@ -27,11 +27,13 @@ CConf::~CConf()
     // TODO Auto-generated destructor stub
 }
 
-void CConf::LoadConfig()
+void CConf::LoadConfig(const char*filePath)
 {
-    CConf::GetModulePath(m_strConfPath, sizeof(m_strConfPath));
+    //CConf::GetModulePath(m_strConfPath, sizeof(m_strConfPath));
 
-    strncat(m_strConfPath, "/CarSim_Daemon.conf", sizeof(m_strConfPath));
+    //strncat(m_strConfPath, filePath, sizeof(m_strConfPath));
+    memset(m_strConfPath, 0, sizeof(m_strConfPath));
+    strcpy(m_strConfPath, filePath);
     printf("ConfPath:%s\n", m_strConfPath);
 
     m_nWinkR = CConf::GetConfig(m_strConfPath, "WINKER_RIGHT", "NUMBER", 4);
@@ -39,6 +41,13 @@ void CConf::LoadConfig()
 
     m_nShiftU = CConf::GetConfig(m_strConfPath, "SHIFT_UP", "NUMBER", 11);
     m_nShiftD = CConf::GetConfig(m_strConfPath, "SHIFT_DOWN", "NUMBER", 10);
+    m_nShift1 = CConf::GetConfig(m_strConfPath, "SHIFT_1", "NUMBER", 300);
+    m_nShift2 = CConf::GetConfig(m_strConfPath, "SHIFT_2", "NUMBER", 301);
+    m_nShift3 = CConf::GetConfig(m_strConfPath, "SHIFT_3", "NUMBER", 302);
+    m_nShift4 = CConf::GetConfig(m_strConfPath, "SHIFT_4", "NUMBER", 303);
+    m_nShift5 = CConf::GetConfig(m_strConfPath, "SHIFT_5", "NUMBER", 704);
+    m_nShift6 = CConf::GetConfig(m_strConfPath, "SHIFT_6", "NUMBER", 705);
+    m_nShiftR = CConf::GetConfig(m_strConfPath, "SHIFT_R", "NUMBER", 710);
     m_nSteering = CConf::GetConfig(m_strConfPath, "STEERING", "NUMBER", 0);
     m_nAccel = CConf::GetConfig(m_strConfPath, "ACCEL", "NUMBER", 1);
     m_nBrake = CConf::GetConfig(m_strConfPath, "BRAKE", "NUMBER", 2);
@@ -47,9 +56,12 @@ void CConf::LoadConfig()
         CConf::GetConfig(m_strConfPath, "LASTPOSITION", "LAT", 35.717931);
     m_fLng =
         CConf::GetConfig(m_strConfPath, "LASTPOSITION", "LNG", 139.736518);
+    char devname[64];
+    memset(devname, 0, sizeof(devname));
+    CConf::GetConfig(m_strConfPath, "DEVICE", "NAME", "Driving Force GT", devname, sizeof(devname));
+    m_sDeviceName = std::string(devname);
 
-
-    printf("Configuration:\n");
+    printf("Configuration[%s]:\n",m_sDeviceName.c_str());
     printf("  WINKER(R) button:%d\tWINKER(L) button:%d\n", m_nWinkR,
            m_nWinkL);
     printf("  SHIFT(U) button:%d\tSHIFT(D) button:%d\n", m_nShiftU,
index debf157..3aae683 100644 (file)
@@ -47,7 +47,7 @@ class CConf
 
     static void GetModulePath(char *buf, int bufsize);
 
-    void LoadConfig();
+    void LoadConfig(const char*filePath);
 
 
     int m_nHazard;
@@ -60,8 +60,16 @@ class CConf
     int m_nSteering;
     int m_nAccel;
     int m_nBrake;
+    int m_nShift1;
+    int m_nShift2;
+    int m_nShift3;
+    int m_nShift4;
+    int m_nShift5;
+    int m_nShift6;
+    int m_nShiftR;
     double m_fLng;
     double m_fLat;
+    std::string m_sDeviceName;
 
 };
 
index 8b3d2b0..75da1ca 100644 (file)
@@ -29,7 +29,6 @@ int Daemon_MS;
 int nClient = 0;
 int nDelayedCallback = 0;
 
-
 int ReadPriv = 0;
 int WritePriv = 0;
 
@@ -69,6 +68,7 @@ const char* protocolsName[protocols_sz] = {
 
 CGtCtrl::CGtCtrl()
 {
+    m_strConfPath = "/usr/bin/CarSimDaemon.conf";
     // TODO Auto-generated constructor stub
     signal(SIGINT, CGtCtrl::signal_handler);
     signal(SIGQUIT, CGtCtrl::signal_handler);
@@ -78,12 +78,6 @@ CGtCtrl::CGtCtrl()
 
     m_bUseGps = false;
     myJS = NULL;
-    if (true == gbDevJs) {
-        myJS = new CJoyStick;
-    }
-    else {
-        myJS = new CJoyStickEV;
-    }
 }
 
 CGtCtrl::~CGtCtrl()
@@ -132,7 +126,48 @@ bool CGtCtrl::Initialize()
 
     m_bFirstOpen = true;
 
-    myConf.LoadConfig();
+    if (true == gbDevJs) {
+        myJS = new CJoyStick;
+        int nRet = myJS->Open();
+        if (nRet < 0) {
+            printf("JoyStick open error\n");
+            return false;
+        }
+    }
+    else {
+        int i = 0;
+        do {
+            switch (i) {
+            case 0 :
+                printf("Load class G27\n");
+                myJS = new CJoyStickG27;
+                m_strConfPath = g_ConfPathG27;
+                break;
+            case 1 :
+                printf("Load class G25\n");
+                myJS = new CJoyStickG25;
+                m_strConfPath = g_ConfPathG25;
+                break;
+            case 2 :
+                printf("Load class EV\n");
+                myJS = new CJoyStickEV;
+                m_strConfPath = g_ConfPathG27;
+                break;
+            default :
+                break;
+            }
+            int nRet = myJS->Open();
+            if (nRet > 0) {
+                break;
+            }
+            delete myJS;
+        } while ((++i) < g_JoyStickTypeNum);
+        if (myJS == NULL) {
+            return false;
+        }
+    }
+
+    myConf.LoadConfig(m_strConfPath.c_str());
 
     m_viList.init();
 
@@ -143,12 +178,6 @@ bool CGtCtrl::Initialize()
 
     m_sendMsgInfo.clear();
 
-    int nRet = myJS->Open();
-    if (nRet < 0) {
-        printf("JoyStick open error\n");
-        return false;
-    }
-
     char uri[128];
     for (int i = 0; i < protocols_sz; i++) {
         sprintf(uri, _D_URI_FORM, _D_HOST_STR, m_ambpicomm_port[i]);
@@ -171,7 +200,9 @@ bool CGtCtrl::Terminate()
 {
     bool b = true;
 
-    myJS->Close();
+    if (myJS != NULL) {
+        myJS->Close();
+    }
     return b;
 }
 
@@ -239,39 +270,156 @@ void CGtCtrl::Run()
             }
 
             if (number == myConf.m_nAccel) {
-                if (0 == value) {
-                    pmCar.chgThrottle(32767);
-                    pmCar.chgBrake(32767);
-                }
-                else if (0 < value) {
-                    pmCar.chgThrottle(32767);
-                    pmCar.chgBrake((value - 16384) * -2);
+                //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 {
-                    pmCar.chgThrottle((abs(value) - 16384) * -2);
+                    pmCar.chgThrottle((65535 - value) / 1.1 + 32767);
                     pmCar.chgBrake(32767);
                 }
             }
+
+            if (number == myConf.m_nBrake) {
+                //printf("Brake[%d]\n", value);
+                pmCar.chgThrottle(32767);
+                pmCar.chgBrake((65535 - value) / 64 + 32767);
+            }
             break;
         case JS_EVENT_BUTTON:
-            /**
-             * Gear Change SHIFT UP
-             */
-            if (number == myConf.m_nShiftU) {
-                if (value != 0) {
-                    pmCar.setShiftUp();
-                    m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
-                    shiftpos = pmCar.getValue();
+            if (myConf.m_sDeviceName == D_DEV_NAME_G25) {
+                /**
+                 * Gear Change SHIFT UP
+                 */
+                if (number == myConf.m_nShiftU) {
+                    //printf("Shift Up[%d]\n",value);
+                    if (value != 0) {
+                        pmCar.setShiftUp();
+                        m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
+                        shiftpos = pmCar.getValue();
+                    }
+                }
+                /**
+                 * Gear Change SHIFT DOWN
+                 */
+                if (number == myConf.m_nShiftD) {
+                    //printf("Shift Down[%d]\n",value);
+                    if (value != 0) {
+                        pmCar.setShiftDown();
+                        m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
+                        shiftpos = pmCar.getValue();
+                    }
                 }
             }
-            /**
-             * Gear Change SHIFT DOWN
-             */
-            if (number == myConf.m_nShiftD) {
-                if (value != 0) {
-                    pmCar.setShiftDown();
-                    m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
-                    shiftpos = pmCar.getValue();
+
+            else if (myConf.m_sDeviceName == D_DEV_NAME_G27) {
+                if (number == myConf.m_nShift1) {
+                    //printf("Shift 1[%d]\n",value);
+                    if (value != 0) {
+                        pmCar.setShiftMT(CAvgGear::E_SHIFT_MT_FIRST);
+                        m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
+                        shiftpos = pmCar.getValue();
+                    }
+                    else {
+                        pmCar.setShiftMT(CAvgGear::E_SHIFT_NEUTRAL);
+                        m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
+                        shiftpos = pmCar.getValue();
+                    }
+                }
+
+                if (number == myConf.m_nShift2) {
+                    //printf("Shift 2[%d]\n",value);
+                    if (value != 0) {
+                        pmCar.setShiftMT(CAvgGear::E_SHIFT_MT_SECOND);
+                        m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
+                        shiftpos = pmCar.getValue();
+                    }
+                    else {
+                        pmCar.setShiftMT(CAvgGear::E_SHIFT_NEUTRAL);
+                        m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
+                        shiftpos = pmCar.getValue();
+                    }
+                }
+
+                if (number == myConf.m_nShift3) {
+                    //printf("Shift 3[%d]\n",value);
+                    if (value != 0) {
+                        pmCar.setShiftMT(CAvgGear::E_SHIFT_MT_THIRD);
+                        m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
+                        shiftpos = pmCar.getValue();
+                    }
+                    else {
+                        pmCar.setShiftMT(CAvgGear::E_SHIFT_NEUTRAL);
+                        m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
+                        shiftpos = pmCar.getValue();
+                    }
+                }
+
+                if (number == myConf.m_nShift4) {
+                    //printf("Shift 4[%d]\n",value);
+                    if (value != 0) {
+                        pmCar.setShiftMT(CAvgGear::E_SHIFT_MT_FOURTH);
+                        m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
+                        shiftpos = pmCar.getValue();
+                    }
+                    else {
+                        pmCar.setShiftMT(CAvgGear::E_SHIFT_NEUTRAL);
+                        m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
+                        shiftpos = pmCar.getValue();
+                    }
+                }
+
+                if (number == myConf.m_nShift5) {
+                    //printf("Shift 5[%d]\n",value);
+                    if (value != 0) {
+                        pmCar.setShiftMT(CAvgGear::E_SHIFT_MT_FIFTH);
+                        m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
+                        shiftpos = pmCar.getValue();
+                    }
+                    else {
+                        pmCar.setShiftMT(CAvgGear::E_SHIFT_NEUTRAL);
+                        m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
+                        shiftpos = pmCar.getValue();
+                    }
+                }
+
+                if (number == myConf.m_nShift6) {
+                    //printf("Shift 6[%d]\n",value);
+                    if (value != 0) {
+                        pmCar.setShiftMT(CAvgGear::E_SHIFT_MT_SIXTH);
+                        m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
+                        shiftpos = pmCar.getValue();
+                    }
+                    else {
+                        pmCar.setShiftMT(CAvgGear::E_SHIFT_NEUTRAL);
+                        m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
+                        shiftpos = pmCar.getValue();
+                    }
+                }
+
+                if (number == myConf.m_nShiftR) {
+                    //printf("Shift R[%d]\n",value);
+                    if (value != 0) {
+                        pmCar.setShiftMT(CAvgGear::E_SHIFT_REVERSE);
+                        m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
+                        shiftpos = pmCar.getValue();
+                    }
+                    else {
+                        pmCar.setShiftMT(CAvgGear::E_SHIFT_NEUTRAL);
+                        m_stVehicleInfo.nShiftPos = pmCar.getSelectGear();
+                        shiftpos = pmCar.getValue();
+                    }
                 }
             }
             /**
@@ -379,6 +527,12 @@ void CGtCtrl::Run()
             int data[ShiftSz];                                                                    
             int val = pmCar.getValue();
             data[0] = pmCar.getSelectGear();
+            if (data[0] > 10) {
+                data[0] = data[0] - 10 + 4;
+                if (data[0] >= 8) {
+                    data[0] = 4;
+                }
+            }
             data[1] = pmCar.getValue();
             data[2] = pmCar.getMode();
             SendVehicleInfo(dataport_def, sSHIFT, &data[0], ShiftSz);
@@ -985,7 +1139,7 @@ bool CGtCtrl::LoadConfigJson(const char *fname)
         return false;
     }
 
-    g_type_init();
+    //g_type_init();
     printf("conf=%s\nvehicleinfo conf=%s\n", fname, confpath);
 
     parser = json_parser_new();
@@ -1061,7 +1215,7 @@ bool CGtCtrl::LoadConfigAMBJson(const char *fname, char *jsonfname, int size)
     JsonReader *rd = NULL;
 
     memset(jsonfname, 0x00, size);
-    g_type_init();
+    //g_type_init();
 
     ps = json_parser_new();
     GError *error = NULL;
index 1f47617..3a627e8 100644 (file)
@@ -20,6 +20,8 @@
 #include "CConf.h"
 #include "CJoyStick.h"
 #include "CJoyStickEV.h"
+#include "CJoyStickG25.h"
+#include "CJoyStickG27.h"
 
 #include <pthread.h>
 
@@ -48,6 +50,9 @@
 #endif
 
 const useconds_t g_sleeptime = 10000; // = 10milli sec = 0.01 sec
+const int g_JoyStickTypeNum = 3;
+const std::string g_ConfPathG25 = "/etc/carsim/G25.conf";
+const std::string g_ConfPathG27 = "/etc/carsim/G27.conf";
 #define D_RUNLOOP_INTERVAL_COUNT  5
 #define D_RUNLOOP_INTERVAL_COUNT2 50
 
@@ -277,6 +282,8 @@ class CGtCtrl
 
     bool m_bFirstOpen;
 
+    std::string m_strConfPath;
+
     VehicleInfo m_stVehicleInfo;
 
     int m_ambpicomm_port[4];
index e0ef2ee..ac1ef0b 100644 (file)
@@ -26,7 +26,8 @@
 
 #define D_DEV_DIR_PATH      "/dev/input/"
 #define D_DEV_NAME_PARTS_JS "js"
-#define D_DEV_NAME          "Driving Force GT"
+#define D_DEV_NAME_G25      "Driving Force GT"
+#define D_DEV_NAME_G27      "G27 Racing Wheel"
 
 class CJoyStick
 {
index 092c05e..e45479d 100644 (file)
@@ -30,6 +30,7 @@ CJoyStickEV::CJoyStickEV()
     // TODO Auto-generated constructor stub
     memset(m_absInf, 0, sizeof(m_absInf));
     m_grab = false;
+    m_devName = std::string(D_DEV_NAME_G27);
 }
 
 CJoyStickEV::~CJoyStickEV()
@@ -45,44 +46,27 @@ int CJoyStickEV::Open()
 {
     string dirpath(D_DEV_DIR_PATH);
     string nameparts(D_DEV_NAME_PARTS_EV);
-    string devName(D_DEV_NAME);
     string devPath;
     /**
      * get device file
      */
-    int rfd = deviceOpen(dirpath, nameparts, devName, devPath);
+    printf("Open Device Name is %s\n", m_devName.c_str());
+    int rfd = deviceOpen(dirpath, nameparts, m_devName, devPath);
     if (0 > rfd) {
+        printf("Can't open device.\n");
         return rfd;
     }
     m_nJoyStickID = rfd;
     /**
      * set grab
      */
+    printf("Check Grab is %s(%d)\n", m_devName.c_str(), rfd);
     if (false == deviceGrab(rfd)) {
+        printf("Can't get grab.\n");
         Close();
         return -1;
     }
 
-    if (0 > ioctl(rfd, EVIOCGABS(ABS_X), &m_absInf[E_ABSX])) {
-        cerr << "ioctl(EVIOCGABS(ABS_X)) get error" << endl;
-        m_absInf[E_ABSX].minimum = 0;
-        m_absInf[E_ABSX].maximum = 1023;
-    }
-    if (0 > ioctl(rfd, EVIOCGABS(ABS_Y), &m_absInf[E_ABSY])) {
-        cerr << "ioctl(EVIOCGABS(ABS_Y)) get error" << endl;
-        m_absInf[E_ABSY].minimum = 0;
-        m_absInf[E_ABSY].maximum = 255;
-    }
-    if (0 > ioctl(rfd, EVIOCGABS(ABS_HAT0X), &m_absInf[E_ABSHAT0X])) {
-        cerr << "ioctl(EVIOCGABS(ABS_HAT0X)) get error" << endl;
-        m_absInf[E_ABSHAT0X].minimum = -1;
-        m_absInf[E_ABSHAT0X].maximum = 1;
-    }
-    if (0 > ioctl(rfd, EVIOCGABS(ABS_HAT0Y), &m_absInf[E_ABSHAT0Y])) {
-        cerr << "ioctl(EVIOCGABS(ABS_HAT0Y)) get error" << endl;
-        m_absInf[E_ABSHAT0Y].minimum = -1;
-        m_absInf[E_ABSHAT0Y].maximum = 1;
-    }
     fds.fd = m_nJoyStickID;
     return m_nJoyStickID;
 }
@@ -185,12 +169,17 @@ int CJoyStickEV::ReadData()
 int CJoyStickEV::getJS_EVENT_BUTTON(int& num, int& val,
                                     const struct input_event& s)
 {
+/*
     if ((BTN_JOYSTICK <= s.code) && (s.code <= BTN_GEAR_UP)) {
         num = s.code - BTN_JOYSTICK;
         val = s.value;
         return JS_EVENT_BUTTON;
     }
     return -1;
+*/
+    num = s.code;
+    val = s.value;
+    return JS_EVENT_BUTTON;
 }
 
 /**
@@ -204,22 +193,32 @@ int CJoyStickEV::getJS_EVENT_AXIS(int& num, int& val,
     case ABS_X:
         r = JS_EVENT_AXIS;
         num = 0;
-        val = calc1pm32767((int)s.value, m_absInf[E_ABSX]);
+        val = calc2pm32767((int)s.value, m_absInf[E_ABSX]);
         break;
     case ABS_Y:
         r = JS_EVENT_AXIS;
         num = 1;
-        val = calc1pm32767((int)s.value, m_absInf[E_ABSY]);
+        val = calc2pm32767((int)s.value, m_absInf[E_ABSY]);
         break;
-    case ABS_HAT0X:
+    case ABS_Z:
         r = JS_EVENT_AXIS;
         num = 2;
-        val = calc2pm32767((int)s.value, m_absInf[E_ABSHAT0X]);
+        val = calc2pm32767((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]);
+        break;
+    case ABS_HAT0X:
+        r = JS_EVENT_AXIS;
+        num = 16;
+        val = (int)s.value;
         break;
     case ABS_HAT0Y:
         r = JS_EVENT_AXIS;
-        num = 3;
-        val = calc2pm32767((int)s.value, m_absInf[E_ABSHAT0Y]);
+        num = 17;
+        val = (int)s.value;
         break;
     defaulr:
         break;
index aeddb79..4688545 100644 (file)
@@ -21,6 +21,8 @@
 #include <string.h>
 #include <poll.h>
 
+#include "CJoyStick.h"
+
 #define D_DEV_NAME_PARTS_EV "event"
 
 class CJoyStickEV : public CJoyStick
@@ -43,13 +45,16 @@ class CJoyStickEV : public CJoyStick
     enum {
         E_ABSX = 0, /* ABS_X */
         E_ABSY,     /* ABS_Y */
+        E_ABSZ,
+        E_ABSRZ,
         E_ABSHAT0X, /* ABS_HAT0X */
         E_ABSHAT0Y, /* ABS_HAT0Y */
         E_ABSMAX    /* */
     };
-  private:
     struct input_absinfo m_absInf[E_ABSMAX];
     bool m_grab;
+    std::string m_devName;
+  private:
 };
 
 #endif /* CJOYSTICKEV_H_ */
diff --git a/src/CJoyStickG25.cpp b/src/CJoyStickG25.cpp
new file mode 100644 (file)
index 0000000..8caff56
--- /dev/null
@@ -0,0 +1,45 @@
+#include <iostream>
+
+#include "CJoyStickG25.h"
+
+CJoyStickG25::CJoyStickG25() : CJoyStickEV() {
+}
+
+CJoyStickG25::~CJoyStickG25() {
+}
+
+int CJoyStickG25::Open() {
+    m_devName = std::string(D_DEV_NAME_G25);
+    int rfd = CJoyStickEV::Open();
+    if (rfd < 0) {
+        return rfd;
+    }
+
+    if (0 > ioctl(rfd, EVIOCGABS(ABS_X), &m_absInf[E_ABSX])) {
+        std::cerr << "ioctl(EVIOCGABS(ABS_X)) get error" << std::endl;
+        m_absInf[E_ABSX].minimum = 0;
+        m_absInf[E_ABSX].maximum = 16384;
+    }
+    if (0 > ioctl(rfd, EVIOCGABS(ABS_Y), &m_absInf[E_ABSY])) {
+        std::cerr << "ioctl(EVIOCGABS(ABS_Y)) get error" << std::endl;
+        m_absInf[E_ABSY].minimum = 0;
+        m_absInf[E_ABSY].maximum = 255;
+    }
+    if (0 > ioctl(rfd, EVIOCGABS(ABS_Z), &m_absInf[E_ABSZ])) {
+        std::cerr << "ioctl(EVIOCGABS(ABS_Z)) get error" << std::endl;
+        m_absInf[E_ABSZ].minimum = 0;
+        m_absInf[E_ABSZ].maximum = 255;
+    }
+    if (0 > ioctl(rfd, EVIOCGABS(ABS_HAT0X), &m_absInf[E_ABSHAT0X])) {
+        std::cerr << "ioctl(EVIOCGABS(ABS_HAT0X)) get error" << std::endl;
+        m_absInf[E_ABSHAT0X].minimum = -1;
+        m_absInf[E_ABSHAT0X].maximum = 1;
+    }
+    if (0 > ioctl(rfd, EVIOCGABS(ABS_HAT0Y), &m_absInf[E_ABSHAT0Y])) {
+        std::cerr << "ioctl(EVIOCGABS(ABS_HAT0Y)) get error" << std::endl;
+        m_absInf[E_ABSHAT0Y].minimum = -1;
+        m_absInf[E_ABSHAT0Y].maximum = 1;
+    }
+    return rfd;
+}
+
diff --git a/src/CJoyStickG25.h b/src/CJoyStickG25.h
new file mode 100644 (file)
index 0000000..c8ac040
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef CJOYSTICKG25_H_
+#define CJOYSTICKG25_H_
+#include "CJoyStickEV.h"
+
+class CJoyStickG25 : public CJoyStickEV
+{
+public:
+    CJoyStickG25();
+    ~CJoyStickG25();
+
+    virtual int Open();
+};
+
+#endif /* CJOYSTICKG25_H_ */
diff --git a/src/CJoyStickG27.cpp b/src/CJoyStickG27.cpp
new file mode 100644 (file)
index 0000000..817adc4
--- /dev/null
@@ -0,0 +1,50 @@
+#include <iostream>
+
+#include "CJoyStickG27.h"
+
+CJoyStickG27::CJoyStickG27() : CJoyStickEV() {
+}
+
+CJoyStickG27::~CJoyStickG27() {
+}
+
+int CJoyStickG27::Open() {
+    m_devName = std::string(D_DEV_NAME_G27);
+    int rfd = CJoyStickEV::Open();
+    if (rfd < 0) {
+        return rfd;
+    }
+
+    if (0 > ioctl(rfd, EVIOCGABS(ABS_X), &m_absInf[E_ABSX])) {
+        std::cerr << "ioctl(EVIOCGABS(ABS_X)) get error" << std::endl;
+        m_absInf[E_ABSX].minimum = 0;
+        m_absInf[E_ABSX].maximum = 16384;
+    }
+    if (0 > ioctl(rfd, EVIOCGABS(ABS_Y), &m_absInf[E_ABSY])) {
+        std::cerr << "ioctl(EVIOCGABS(ABS_Y)) get error" << std::endl;
+        m_absInf[E_ABSY].minimum = 0;
+        m_absInf[E_ABSY].maximum = 255;
+    }
+    if (0 > ioctl(rfd, EVIOCGABS(ABS_Z), &m_absInf[E_ABSZ])) {
+        std::cerr << "ioctl(EVIOCGABS(ABS_Z)) get error" << std::endl;
+        m_absInf[E_ABSZ].minimum = 0;
+        m_absInf[E_ABSZ].maximum = 255;
+    }
+    if (0 > ioctl(rfd, EVIOCGABS(ABS_RZ), &m_absInf[E_ABSRZ])) {
+        std::cerr << "ioctl(EVIOCGABS(ABS_RZ)) get error" << std::endl;
+        m_absInf[E_ABSRZ].minimum = 0;
+        m_absInf[E_ABSRZ].maximum = 255;
+    }
+    if (0 > ioctl(rfd, EVIOCGABS(ABS_HAT0X), &m_absInf[E_ABSHAT0X])) {
+        std::cerr << "ioctl(EVIOCGABS(ABS_HAT0X)) get error" << std::endl;
+        m_absInf[E_ABSHAT0X].minimum = -1;
+        m_absInf[E_ABSHAT0X].maximum = 1;
+    }
+    if (0 > ioctl(rfd, EVIOCGABS(ABS_HAT0Y), &m_absInf[E_ABSHAT0Y])) {
+        std::cerr << "ioctl(EVIOCGABS(ABS_HAT0Y)) get error" << std::endl;
+        m_absInf[E_ABSHAT0Y].minimum = -1;
+        m_absInf[E_ABSHAT0Y].maximum = 1;
+    }
+    return rfd;
+}
+
diff --git a/src/CJoyStickG27.h b/src/CJoyStickG27.h
new file mode 100644 (file)
index 0000000..66b3189
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef CJOYSTICKG27_H_
+#define CJOYSTICKG27_H_
+#include "CJoyStickEV.h"
+
+class CJoyStickG27 : public CJoyStickEV
+{
+public:
+    CJoyStickG27();
+    ~CJoyStickG27();
+
+    virtual int Open();
+};
+
+#endif /* CJOYSTICKG27_H_ */
index 06fdcd4..9a68789 100644 (file)
@@ -1,3 +1,5 @@
+[DEVICE]
+NAME=Driving Force GT
 [HAZARDLAMP]
 TYPE=1
 NUMBER=3
@@ -22,7 +24,10 @@ NUMBER=2
 [STEERING]
 TYPE=2
 NUMBER=0
-[ACCEL_BRAKE]
+[ACCEL]
+TYPE=2
+NUMBER=1
+[BRAKE]
 TYPE=2
 NUMBER=1
 
index 5c98052..ba22cb8 100644 (file)
@@ -1,6 +1,6 @@
 bin_PROGRAMS = carsim
 
-carsim_SOURCES = AmbpiComm.h AmbpiComm.cpp CJoyStick.h CJoyStick.cpp CJoyStickEV.h CJoyStickEV.cpp CConf.h CConf.cpp CGtCtrl.h CGtCtrl.cpp CCalc.h CCalc.cpp CAvgCar.h CAvgCar.cpp CarSim_Daemon.cpp
+carsim_SOURCES = AmbpiComm.h AmbpiComm.cpp CJoyStick.h CJoyStick.cpp CJoyStickEV.h CJoyStickEV.cpp CJoyStickG25.h CJoyStickG25.cpp CJoyStickG27.h CJoyStickG27.cpp CConf.h CConf.cpp CGtCtrl.h CGtCtrl.cpp CCalc.h CCalc.cpp CAvgCar.h CAvgCar.cpp CarSim_Daemon.cpp
 carsim_LDADD = -lpthread -ljson-glib-1.0 -lgobject-2.0 -lglib-2.0 -lrt -lico-util-com
 carsim_CPPFLAGS = -I/usr/include/glib-2.0 -I/usr/include/json-glib-1.0 -I/usr/lib/glib-2.0/include -std=c++0x
 carsim_LDFLAGS =