--- /dev/null
+[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
+
+
--- /dev/null
+[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
+
+
--- /dev/null
+#
+# 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
+
+
+* 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.
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
# 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
%files
%defattr(-,root,root,-)
%{_bindir}/*
-%{carsim_conf}/CarSim_Daemon.conf
+/etc/carsim/*
+/usr/lib/systemd/system/carsim.service
+#%{carsim_conf}/CarSim_Daemon.conf
CAvgGear::CAvgGear()
{
m_transmission = E_SHIFT_PARKING;
+ m_transmissionOLD = m_transmission;
m_transmissionValue = D_SHIFT_VALUE_PARKING;
}
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;
{
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;
{
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
******************************************/
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;
}
}
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();
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;
};
*/
inline void CAvgGear::chgGear(E_AT_GEAR tm)
{
+ m_transmissionOLD = m_transmission;
m_transmission = tm;
}
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
******************************************/
// 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);
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);
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,
static void GetModulePath(char *buf, int bufsize);
- void LoadConfig();
+ void LoadConfig(const char*filePath);
int m_nHazard;
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;
};
int nClient = 0;
int nDelayedCallback = 0;
-
int ReadPriv = 0;
int WritePriv = 0;
CGtCtrl::CGtCtrl()
{
+ m_strConfPath = "/usr/bin/CarSimDaemon.conf";
// TODO Auto-generated constructor stub
signal(SIGINT, CGtCtrl::signal_handler);
signal(SIGQUIT, CGtCtrl::signal_handler);
m_bUseGps = false;
myJS = NULL;
- if (true == gbDevJs) {
- myJS = new CJoyStick;
- }
- else {
- myJS = new CJoyStickEV;
- }
}
CGtCtrl::~CGtCtrl()
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();
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]);
{
bool b = true;
- myJS->Close();
+ if (myJS != NULL) {
+ myJS->Close();
+ }
return b;
}
}
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();
+ }
}
}
/**
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);
return false;
}
- g_type_init();
+ //g_type_init();
printf("conf=%s\nvehicleinfo conf=%s\n", fname, confpath);
parser = json_parser_new();
JsonReader *rd = NULL;
memset(jsonfname, 0x00, size);
- g_type_init();
+ //g_type_init();
ps = json_parser_new();
GError *error = NULL;
#include "CConf.h"
#include "CJoyStick.h"
#include "CJoyStickEV.h"
+#include "CJoyStickG25.h"
+#include "CJoyStickG27.h"
#include <pthread.h>
#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
bool m_bFirstOpen;
+ std::string m_strConfPath;
+
VehicleInfo m_stVehicleInfo;
int m_ambpicomm_port[4];
#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
{
// 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()
{
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;
}
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;
}
/**
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;
#include <string.h>
#include <poll.h>
+#include "CJoyStick.h"
+
#define D_DEV_NAME_PARTS_EV "event"
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_ */
--- /dev/null
+#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;
+}
+
--- /dev/null
+#ifndef CJOYSTICKG25_H_
+#define CJOYSTICKG25_H_
+#include "CJoyStickEV.h"
+
+class CJoyStickG25 : public CJoyStickEV
+{
+public:
+ CJoyStickG25();
+ ~CJoyStickG25();
+
+ virtual int Open();
+};
+
+#endif /* CJOYSTICKG25_H_ */
--- /dev/null
+#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;
+}
+
--- /dev/null
+#ifndef CJOYSTICKG27_H_
+#define CJOYSTICKG27_H_
+#include "CJoyStickEV.h"
+
+class CJoyStickG27 : public CJoyStickEV
+{
+public:
+ CJoyStickG27();
+ ~CJoyStickG27();
+
+ virtual int Open();
+};
+
+#endif /* CJOYSTICKG27_H_ */
+[DEVICE]
+NAME=Driving Force GT
[HAZARDLAMP]
TYPE=1
NUMBER=3
[STEERING]
TYPE=2
NUMBER=0
-[ACCEL_BRAKE]
+[ACCEL]
+TYPE=2
+NUMBER=1
+[BRAKE]
TYPE=2
NUMBER=1
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 =