+* 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.
+- Bug fix : Compilation errors that occur when updating version of Tizen.
+
* Thu Jun 06 2013 Shibata Makoto <shibata@mac.tec.toyota.co.jp> submit/2.0alpha-wayland/20130426.192225@29e931f
- 0.1.3 release
- Organize unnecessary files.
Name: ico-vic-carsimulator
Summary: CarSimulator
-Version: 0.1.3
-Release: 1
+Version: 0.1.4
+Release: 2
Group: System Environment/Daemons
License: Apache 2.0
Source0: %{name}-%{version}.tar.bz2
Requires(postun): /sbin/ldconfig
Requires: glib2
Requires: ico-vic-amb-plugin
+Requires: ico-uxf-utilities
BuildRequires: make
BuildRequires: automake
BuildRequires: boost-devel
-BuildRequires: libwebsockets-devel
+#BuildRequires: libwebsockets-devel
BuildRequires: glib2-devel
BuildRequires: json-glib-devel
+#BuildRequires: ico-uxf-utilities
+BuildRequires: ico-uxf-utilities-devel
%description
CarSimulator is simulated driving software
--- /dev/null
+/*
+ * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
+ *
+ * This program is licensed under the terms and conditions of the
+ * Apache License, version 2.0. The full text of the Apache License is at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ */
+/**
+ * @brief AMB plug-inn Communication I/F
+ *
+ */
+
+#include <string.h>
+#include <iostream>
+#include <vector>
+#include <unistd.h>
+#include "AmbpiComm.h"
+using namespace std;
+
+static vector<AmbpiCommIF*> _commList;
+
+bool _addAmbCommIFList(AmbpiCommIF* comm);
+void _eraseAmbCommIFList(const AmbpiCommIF* comm);
+static void _icoUwsCallback(const struct ico_uws_context *context,
+ const ico_uws_evt_e event, const void *id,
+ const ico_uws_detail *detail, void *user_data);
+
+
+AmbpiCommRecvQueue::AmbpiCommRecvQueue()
+: msize(0), maxqueuesize(10)
+{
+ init();
+}
+
+AmbpiCommRecvQueue::AmbpiCommRecvQueue(int queuesize)
+: msize(0)
+{
+ maxqueuesize = queuesize;
+ init();
+}
+
+AmbpiCommRecvQueue::~AmbpiCommRecvQueue()
+{
+ delete[] mdata;
+ delete[] mdatasize;
+}
+
+bool AmbpiCommRecvQueue::push(char *data, int datasize)
+{
+ if (datasize > maxdatasize || (msize + 1) > maxqueuesize) {
+ return false;
+ }
+ memset(mdata[msize], 0, maxdatasize);
+ memcpy(mdata[msize], data, datasize);
+ mdatasize[msize] = datasize;
+ msize++;
+ return true;
+}
+
+bool AmbpiCommRecvQueue::front(char *buf) const
+{
+ if (msize == 0) {
+ return false;
+ }
+ memcpy(buf, mdata[0], mdatasize[0]);
+ return true;
+}
+
+bool AmbpiCommRecvQueue::empty() const
+{
+ return (msize == 0);
+}
+
+void AmbpiCommRecvQueue::pop()
+{
+ if (msize > 0) {
+ msize--;
+ for (int i = 0; i < msize; i++) {
+ memset(mdata[i], 0, maxdatasize);
+ memcpy(mdata[i], mdata[i + 1], mdatasize[i + 1]);
+ mdatasize[i] = mdatasize[i + 1];
+ }
+ memset(mdata[msize], 0, maxdatasize);
+ mdatasize[msize] = 0;
+ }
+}
+
+int AmbpiCommRecvQueue::size() const
+{
+ return msize;
+}
+
+void AmbpiCommRecvQueue::init()
+{
+ mdata = new char[maxqueuesize][maxdatasize];
+ memset((void *) mdata, 0, maxqueuesize * maxdatasize);
+
+ mdatasize = new int[maxqueuesize];
+
+ memset(mdatasize, 0, maxqueuesize);
+}
+
+AmbpiCommIF::AmbpiCommIF()
+{
+ isready = false;
+ m_threadid = 0;
+ m_mutex = PTHREAD_MUTEX_INITIALIZER;
+ m_cond = PTHREAD_COND_INITIALIZER;
+ m_id = NULL;
+ m_context = NULL;
+ reset_ercode();
+}
+
+AmbpiCommIF::AmbpiCommIF(const char* uri, const char* protocolName)
+{
+ isready = false;
+ m_threadid = 0;
+ m_mutex = PTHREAD_MUTEX_INITIALIZER;
+ m_cond = PTHREAD_COND_INITIALIZER;
+ m_id = NULL;
+ m_context = NULL;
+ reset_ercode();
+ start(uri, protocolName);
+}
+
+AmbpiCommIF::~AmbpiCommIF()
+{
+ if (isready) {
+ int ret;
+ if (m_threadid != 0) {
+ ret = pthread_cancel(m_threadid);
+ if (ret != 0) {
+ cerr << m_pNm << ":Failed to pthread_cancel" << endl;
+ }
+ }
+ ret = pthread_join(m_threadid, NULL);
+ if (ret != 0) {
+ cerr << m_pNm << ":Failed to pthread_join" << endl;
+ }
+ if (m_context != NULL) {
+ ico_uws_close(m_context);
+ m_context = NULL;
+ }
+ _eraseAmbCommIFList(this);
+ }
+}
+
+bool AmbpiCommIF::start(const char* uri, const char* protocolName)
+{
+ if (isready) {
+ return isready;
+ }
+ isready = init(uri, protocolName);
+ return isready;
+}
+
+bool AmbpiCommIF::send(const char *msg, const int size)
+{
+ if (!isready) {
+ return isready;
+ }
+ reset_ercode();
+ ico_uws_send(m_context, m_id, (unsigned char*)msg, (size_t)size);
+ if ((ICO_UWS_ERR_UNKNOWN != m_ercode) && (ICO_UWS_ERR_NONE != m_ercode)) {
+ return false;
+ }
+ return true;
+}
+
+bool AmbpiCommIF::recv(char *msg, bool fblocking)
+{
+ if (!isready) {
+ return isready;
+ }
+
+ if (fblocking) {
+ if (m_queue.empty()) {
+ if (pthread_cond_wait(&m_cond, &m_mutex) != 0) {
+ cerr << m_pNm << ":Failed to wait signal" << endl;
+ }
+ }
+ m_queue.front(msg);
+ m_queue.pop();
+ }
+ else {
+ if (m_queue.empty()) {
+ return false;
+ }
+ else {
+ m_queue.front(msg);
+ m_queue.pop();
+ }
+ }
+ return true;
+}
+
+bool AmbpiCommIF::poll()
+{
+ if (!isready) {
+ return isready;
+ }
+
+ while (true) {
+ ico_uws_service(m_context);
+ usleep(100000);
+ }
+}
+
+void *AmbpiCommIF::loop(void *arg)
+{
+ AmbpiCommIF *src = reinterpret_cast < AmbpiCommIF * >(arg);
+ return (void *) src->poll();
+}
+
+bool AmbpiCommIF::init(const char* uri, const char* protocolName)
+{
+ if (NULL == uri) {
+ cerr << "Failed create context param" << endl;
+ return false;
+ }
+ if (NULL == protocolName) {
+ cerr << "Failed create context param 2" << endl;
+ return false;
+ }
+ m_uri = uri;
+ m_pNm = protocolName;
+ m_context = ico_uws_create_context(uri, protocolName);
+ if (NULL == m_context) {
+ cerr << m_pNm << ":Failed to create context." << endl;
+ return false;
+ }
+ 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;
+ return false;
+ }
+ _addAmbCommIFList(this);
+ if (pthread_create(&m_threadid, NULL, AmbpiCommIF::loop,
+ (void *) this) != 0) {
+ cerr << m_pNm << ":Failed to create thread." << endl;
+ return false;
+ }
+ return true;
+}
+
+/**
+ * @brief event
+ * @param event ico_uws_evt_e event code
+ * @param id unique id
+ * @param detail infomation or data detail
+ * @param user_data added user data
+ */
+void AmbpiCommIF::event_cb(const ico_uws_evt_e event, const void *id,
+ const ico_uws_detail *d, void *user_data)
+{
+ switch (event) {
+ case ICO_UWS_EVT_RECEIVE:
+ {
+ if (NULL == d) {
+ cerr << m_pNm << ":Failed Receive event" << endl;
+ break;
+ }
+ if (0 != pthread_mutex_lock(&m_mutex)) {
+ cerr << m_pNm << ":Failed to lock mutex" << endl;
+ }
+ char buf[sizeof(KeyDataMsg_t) + MsgQueueMaxMsgSize];
+ memset(buf, 0, sizeof(buf));
+ memcpy(buf, reinterpret_cast<char*>(d->_ico_uws_message.recv_data),
+ d->_ico_uws_message.recv_len);
+ m_queue.push((&buf[0]), sizeof(buf));
+ pthread_cond_signal(&m_cond);
+ if (0 != pthread_mutex_unlock(&m_mutex)) {
+ cerr << m_pNm << ":Failed to unlock mutex" << endl;
+ }
+ break;
+ }
+ case ICO_UWS_EVT_OPEN:
+ {
+ m_id = (void*)id;
+ if (0 != pthread_mutex_lock(&m_mutex)) {
+ cerr << m_pNm << ":Failed to lock mutex" << endl;
+ }
+ if (0 != pthread_cond_signal(&m_cond)) {
+ cerr << m_pNm << ":Failed to issue cond_signal" << endl;
+ }
+ if (0 != pthread_mutex_unlock(&m_mutex)) {
+ cerr << m_pNm << ":Failed to unlock mutex" << endl;
+ }
+ break;
+ }
+ case ICO_UWS_EVT_ERROR:
+ {
+ if (NULL == d) {
+ cerr << m_pNm << ":Failed ERROR event" << endl;
+ break;
+ }
+ m_ercode = d->_ico_uws_error.code;
+ break;
+ }
+ default:
+ break;
+ }
+ return;
+}
+
+/**
+ * @brief _addAmbCommIFList
+ * @param comm entry item address
+ * @return true:succes false:fail
+ */
+bool _addAmbCommIFList(AmbpiCommIF* comm)
+{
+ if (NULL == comm) {
+ return false;
+ }
+ _commList.push_back(comm);
+ return true;
+}
+
+/**
+ * @brief _eraseAmbCommIFList
+ * @param comm erase target
+ */
+void _eraseAmbCommIFList(const AmbpiCommIF* comm)
+{
+ bool bMatch = false;
+ for (int i = 0; i < _commList.size(); i++) {
+ if (_commList[i] == comm) {
+ bMatch = true;
+ break; // break of for i
+ }
+ }
+ if (false == bMatch) {
+ return;
+ }
+ vector<AmbpiCommIF*> v_tmp(_commList);
+ _commList.clear();
+ for (int i = 0; i < v_tmp.size(); i++) {
+ if (v_tmp[i] != comm) {
+ _commList.push_back(v_tmp[i]);
+ }
+ }
+ return;
+}
+
+/**
+ * @brief _icoUwsCallback
+ * @param context identify connect
+ * @param event ico_uws_evt_e event code
+ * @param id unique id
+ * @param detail infomation or data detail
+ * @param user_data added user data
+ */
+static void _icoUwsCallback(const struct ico_uws_context *context,
+ const ico_uws_evt_e event, const void *id,
+ const ico_uws_detail *detail, void *user_data)
+{
+ for (int i = 0; i < _commList.size(); i++) {
+ AmbpiCommIF* comm = _commList[i];
+ if (NULL == comm) {
+ continue;
+ }
+ if (false == comm->isContextMatch(context)) {
+ continue;
+ }
+ comm->event_cb(event, id, detail, user_data);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
+ *
+ * This program is licensed under the terms and conditions of the
+ * Apache License, version 2.0. The full text of the Apache License is at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ */
+/**
+ * @brief AMB plug-in communication I/F
+ */
+
+#ifndef _ICO_VIC_AMBPICOMM_H_
+#define _ICO_VIC_AMBPICOMM_H_
+
+#include <sys/time.h>
+#include <string>
+#include "ico-util/ico_uws.h"
+
+const int MsgQueueMaxMsgSize = 128;
+
+struct KeyEventOptMsg_t
+{
+ char KeyEventType[64];
+ struct timeval recordtime;
+ struct KeyEventOpt
+ {
+ int common;
+ int sense;
+ int event_mask;
+ } eventopt;
+};
+
+struct KeyDataMsg_t
+{
+ char KeyEventType[64];
+ struct timeval recordtime;
+ struct KeyData
+ {
+ int common_status;
+ char status[];
+ } data;
+};
+
+class AmbpiCommRecvQueue
+{
+ public:
+ AmbpiCommRecvQueue();
+ AmbpiCommRecvQueue(int queuesize);
+ ~AmbpiCommRecvQueue();
+ bool push(char *data, int datasize);
+ bool front(char *buf) const;
+ bool empty() const;
+ void pop();
+ int size() const;
+
+ static const int maxdatasize = sizeof(KeyDataMsg_t) + MsgQueueMaxMsgSize;
+ private:
+ void init();
+
+ int maxqueuesize;
+ int msize;
+ char (*mdata)[maxdatasize];
+ int *mdatasize;
+};
+
+class AmbpiCommIF
+{
+ public:
+ AmbpiCommIF();
+ AmbpiCommIF(const char* uri, const char* protocolName);
+ ~AmbpiCommIF();
+ bool start(const char* uri, const char* protocolName);
+ bool send(const char *msg, const int size);
+ bool recv(char *msg, bool fbolcking);
+ bool poll();
+ static void *loop(void *arg);
+ bool isContextMatch(const ico_uws_context* context) const;
+ bool threadCondWait();
+ void event_cb(const ico_uws_evt_e event, const void *id,
+ const ico_uws_detail *detail, void *user_data);
+ void reset_ercode();
+ private:
+ bool init(const char* uri, const char* protocolName);
+
+ bool isready;
+ ico_uws_context* m_context;
+ pthread_t m_threadid;
+ pthread_mutex_t m_mutex;
+ pthread_cond_t m_cond;
+ char m_sendbuf[AmbpiCommRecvQueue::maxdatasize];
+ AmbpiCommRecvQueue m_queue;
+ std::string m_uri; // URI
+ std::string m_pNm; // protocol name
+ ico_uws_error_e m_ercode;
+ void* m_id;
+};
+
+/**
+ * @brief context compare
+ * @param context
+ * @return true:agree / false:not agree
+ */
+inline bool AmbpiCommIF::isContextMatch(const ico_uws_context* context) const
+{
+ if (context == m_context) {
+ return true;
+ }
+ return false;
+}
+
+/**
+ * @brief thread wait
+ * @return true:success / false:fail
+ */
+inline bool AmbpiCommIF::threadCondWait()
+{
+ if (0 != pthread_cond_wait(&m_cond, &m_mutex)) {
+ return false;
+ }
+ return true;
+}
+
+/**
+ * @brief reset error code
+ */
+inline void AmbpiCommIF::reset_ercode()
+{
+ m_ercode = ICO_UWS_ERR_UNKNOWN;
+}
+
+#endif //#ifndef _ICO_VIC_AMBPICOMM_H_
}
/**
- * @breif getPrevValue
+ * @brief getPrevValue
* @return prev sample value
*/
inline int iAverageMachine::getPrevValue() const
};
/**
- * @breif isOnBrake
+ * @brief isOnBrake
* @return true:on brake false:no brake
*/
inline bool CAvgBrake::isOnBrake() const
}
/**
- * @breif
+ * @brief
* @return
*/
inline int CAvgBrake::getBrakeAvg() const
};
/**
- * @breif getRPM
+ * @brief getRPM
* @return RPM
*/
inline double CAvgCar::getRPM() const
return (int)(x*100.0);
}
/**
- * @breif get Tripmeter
+ * @brief get Tripmeter
* @return trip meter value
*/
inline double CAvgCar::getTripmeter() const
return m_tripmeter;
}
/**
- * @breif tripmeterReset
+ * @brief tripmeterReset
* tripmeter reset
*/
inline void CAvgCar::tripmeterReset()
*
*/
+#include <unistd.h>
+
#include "CConf.h"
CConf::CConf()
std::queue < geoData > routeList;
std::string msgQueue;
int Daemon_MS;
-pthread_mutex_t m_websocket_mutex[] = {
- PTHREAD_MUTEX_INITIALIZER,
- PTHREAD_MUTEX_INITIALIZER,
- PTHREAD_MUTEX_INITIALIZER,
- PTHREAD_MUTEX_INITIALIZER
-};
-
-pthread_cond_t m_websocket_cond[] = {
- PTHREAD_COND_INITIALIZER,
- PTHREAD_COND_INITIALIZER,
- PTHREAD_COND_INITIALIZER,
- PTHREAD_COND_INITIALIZER
-};
-
-WebsocketRecvQueue m_websocket_queue[4];
int nClient = 0;
int nDelayedCallback = 0;
-int ViaSocket = -1;
int ReadPriv = 0;
int WritePriv = 0;
double g_GoalLongitude = 139.40504;
using namespace std;
-static int callback_data_def(libwebsocket_context *context,
- struct libwebsocket *wsi,
- enum libwebsocket_callback_reasons reason,
- void *user, void *in, size_t len);
-static int callback_ctrl_def(libwebsocket_context *context,
- struct libwebsocket *wsi,
- enum libwebsocket_callback_reasons reason,
- void *user, void *in, size_t len);
-static int callback_data_cust(libwebsocket_context *context,
- struct libwebsocket *wsi,
- enum libwebsocket_callback_reasons reason,
- void *user, void *in, size_t len);
-static int callback_ctrl_cust(libwebsocket_context *context,
- struct libwebsocket *wsi,
- enum libwebsocket_callback_reasons reason,
- void *user, void *in, size_t len);
-libwebsocket_protocols protocols[] = {
- {"standarddatamessage-only", callback_data_def, 0},
- {NULL, NULL, -1}
+#define _D_URI_FORM "ws://%s:%d"
+#define _D_HOST_STR "127.0.0.1"
+const int protocols_sz = 4;
+const char* protocolsName[protocols_sz] = {
+ "standarddatamessage-only",
+ "standardcontrolmessage-only",
+ "customdatamessage-only",
+ "customcontrolmessage-only"
};
-libwebsocket_protocols protocols2[] = {
- {"standardcontrolmessage-only", callback_ctrl_def, 0},
- {NULL, NULL, -1}
-};
-
-libwebsocket_protocols protocols3[] = {
- {"customdatamessage-only", callback_data_cust, 0},
- {NULL, NULL, -1}
-};
-
-libwebsocket_protocols protocols4[] = {
- {"customcontrolmessage-only", callback_ctrl_cust, 0},
- {NULL, NULL, -1}
-};
-
-/* Modify I/F MessageQueue -> Websocket End */
CGtCtrl::CGtCtrl()
{
return false;
}
- /* Modify I/F MessageQueue -> Websocket Start */
- if (!m_websocket_client[0].start(m_websocket_port[0], "lo",
- protocols,
- &m_websocket_mutex[0],
- &m_websocket_cond[0],
- &m_websocket_queue[0])) {
- return false;
- }
- if (pthread_cond_wait(&m_websocket_cond[0], &m_websocket_mutex[0]) != 0) {
- std::cerr << "Failed to wait signal" << std::endl;
- }
- if (!m_websocket_client[1].start(m_websocket_port[1], "lo",
- protocols2,
- &m_websocket_mutex[1],
- &m_websocket_cond[1],
- &m_websocket_queue[1])) {
- return false;
- }
- if (pthread_cond_wait(&m_websocket_cond[1], &m_websocket_mutex[1]) != 0) {
- std::cerr << "Failed to wait signal" << std::endl;
- }
- if (!m_websocket_client[2].start(m_websocket_port[2], "lo",
- protocols3,
- &m_websocket_mutex[2],
- &m_websocket_cond[2],
- &m_websocket_queue[2])) {
- return false;
- }
- if (pthread_cond_wait(&m_websocket_cond[2], &m_websocket_mutex[2]) != 0) {
- std::cerr << "Failed to wait signal" << std::endl;
- }
- if (!m_websocket_client[3].start(m_websocket_port[3], "lo",
- protocols4,
- &m_websocket_mutex[3],
- &m_websocket_cond[3],
- &m_websocket_queue[3])) {
- return false;
- }
- if (pthread_cond_wait(&m_websocket_cond[3], &m_websocket_mutex[3]) != 0) {
- std::cerr << "Failed to wait signal" << std::endl;
+ char uri[128];
+ for (int i = 0; i < protocols_sz; i++) {
+ sprintf(uri, _D_URI_FORM, _D_HOST_STR, m_ambpicomm_port[i]);
+ if (false == m_ambpicomm_client[i].start(uri, protocolsName[i])) {
+ return false; // connect fail
+ }
+ if (false == m_ambpicomm_client[i].threadCondWait()) {
+ std::cerr << "Failed to wait signal (" << i << ")" << std::endl;
+ }
}
const char *vi = "LOCATION";
#define sDIRECTION "DIRECTION"
#define sLOCATION "LOCATION"
#define sSHIFT "SHIFT"
+#define sLIGHTSTATUS "LIGHTSTATUS"
void CGtCtrl::Run()
{
g_bStopFlag = true;
shiftpos = pmCar.getValue();
}
}
-
+ /**
+ * TURN SIGNAL(WINKER) & LIGHTSTATUS
+ */
+ bool bTurnSignal = false;
if (number == myConf.m_nWinkR) {
if (value != 0) {
m_stVehicleInfo.bWinkR = !m_stVehicleInfo.bWinkR;
+ m_stVehicleInfo.bWinkL = false;
if (m_stVehicleInfo.bWinkR)
m_stVehicleInfo.nWinkerPos = WINKER_RIGHT;
else
int wpos =
m_stVehicleInfo.nWinkerPos == WINKER_RIGHT ? 1 : 0;
SendVehicleInfo(dataport_def, vi, wpos);
+ bTurnSignal = true;
}
}
if (number == myConf.m_nWinkL) {
if (value != 0) {
m_stVehicleInfo.bWinkL = !m_stVehicleInfo.bWinkL;
+ m_stVehicleInfo.bWinkR = false;
if (m_stVehicleInfo.bWinkL)
m_stVehicleInfo.nWinkerPos = WINKER_LEFT;
else
int wpos =
m_stVehicleInfo.nWinkerPos == WINKER_LEFT ? 2 : 0;
SendVehicleInfo(dataport_def, vi, wpos);
+ bTurnSignal = true;
}
}
+ if (true == bTurnSignal) {
+ const size_t LSsz = 8;
+ char data[LSsz];
+ memset(data, 0, sizeof(data));
+ if (WINKER_LEFT == m_stVehicleInfo.nWinkerPos) {
+ data[1] = 1;
+ }
+ else if (WINKER_RIGHT == m_stVehicleInfo.nWinkerPos) {
+ data[2] = 1;
+ }
+ SendVehicleInfo(dataport_def, sLIGHTSTATUS, &data[0], LSsz);
+ }
+
break;
}
pmCar.updateAvg();
SetMQKeyData(&mqMsg[0], sizeof(mqMsg), priority, key, adata,
sizeof(adata));
- if (!m_websocket_client[type].
+ if (!m_ambpicomm_client[type].
send(reinterpret_cast < char *>(mqMsg), sizeof(mqMsg)))
{
std::cerr << "Failed to send data(" << errno << ")." << std::endl;
subkey1, confreaderror->message);
return false;
}
- m_websocket_port[i * 2] = json_reader_get_int_value(reader);
+ m_ambpicomm_port[i * 2] = json_reader_get_int_value(reader);
json_reader_end_member(reader);
if (!json_reader_read_member(reader, subkey2)) {
subkey2, confreaderror->message);
return false;
}
- m_websocket_port[i * 2 + 1] =
+ m_ambpicomm_port[i * 2 + 1] =
json_reader_get_int_value(reader);
json_reader_end_member(reader);
json_reader_end_member(reader);
}
}
-/* Modify I/F MessageQueue -> Websocket Start */
-static int callback_data_def(libwebsocket_context * context,
- struct libwebsocket *wsi,
- enum libwebsocket_callback_reasons reason,
- void *user, void *in, size_t len)
-{
- switch (reason) {
- case LWS_CALLBACK_CLIENT_RECEIVE:{
- if (pthread_mutex_lock(&m_websocket_mutex[dataport_def]) != 0) {
- std::cerr << "Failed to lock mutex" << std::endl;
- }
- char recvDataMsgBuf[sizeof(KeyDataMsg_t) + MsgQueueMaxMsgSize];
- memset(&recvDataMsgBuf, 0, sizeof(recvDataMsgBuf));
- memcpy(&recvDataMsgBuf, reinterpret_cast < char *>(in), len);
- m_websocket_queue[dataport_def].push((&recvDataMsgBuf[0]),
- sizeof(recvDataMsgBuf));
- pthread_cond_signal(&m_websocket_cond[dataport_def]);
- if (pthread_mutex_unlock(&m_websocket_mutex[dataport_def]) != 0) {
- std::cerr << "Failed to unlock mutex" << std::endl;
- }
- break;
- }
- case LWS_CALLBACK_CLIENT_ESTABLISHED:
- if (pthread_mutex_lock(&m_websocket_mutex[dataport_def]) != 0) {
- std::cerr << "Failed to lock mutex" << std::endl;
- }
- if (pthread_cond_signal(&m_websocket_cond[dataport_def]) != 0) {
- std::cerr << "Failed to issue cond_signal" << std::endl;
- }
- if (pthread_mutex_unlock(&m_websocket_mutex[dataport_def]) != 0) {
- std::cerr << "Failed to unlock mutex" << std::endl;
- }
- break;
- default:
- break;
- }
- return 0;
-}
-
-static int callback_ctrl_def(libwebsocket_context * context,
- struct libwebsocket *wsi,
- enum libwebsocket_callback_reasons reason,
- void *user, void *in, size_t len)
-{
- switch (reason) {
- case LWS_CALLBACK_CLIENT_RECEIVE:{
- if (pthread_mutex_lock(&m_websocket_mutex[ctrlport_def]) != 0) {
- std::cerr << "Failed to lock mutex" << std::endl;
- }
- char recvDataMsgBuf[sizeof(KeyDataMsg_t) + MsgQueueMaxMsgSize];
- memset(&recvDataMsgBuf, 0, sizeof(recvDataMsgBuf));
- memcpy(&recvDataMsgBuf, reinterpret_cast < char *>(in), len);
- m_websocket_queue[ctrlport_def].push((&recvDataMsgBuf[0]),
- sizeof(recvDataMsgBuf));
- pthread_cond_signal(&m_websocket_cond[ctrlport_def]);
- if (pthread_mutex_unlock(&m_websocket_mutex[ctrlport_def]) != 0) {
- std::cerr << "Failed to unlock mutex" << std::endl;
- }
- break;
- }
- case LWS_CALLBACK_CLIENT_ESTABLISHED:
- if (pthread_mutex_lock(&m_websocket_mutex[ctrlport_def]) != 0) {
- std::cerr << "Failed to lock mutex" << std::endl;
- }
- if (pthread_cond_signal(&m_websocket_cond[ctrlport_def]) != 0) {
- std::cerr << "Failed to issue cond_signal" << std::endl;
- }
- if (pthread_mutex_unlock(&m_websocket_mutex[ctrlport_def]) != 0) {
- std::cerr << "Failed to unlock mutex" << std::endl;
- }
- break;
- default:
- break;
- }
- return 0;
-}
-
-static int callback_data_cust(libwebsocket_context * context,
- struct libwebsocket *wsi,
- enum libwebsocket_callback_reasons reason,
- void *user, void *in, size_t len)
-{
- switch (reason) {
- case LWS_CALLBACK_CLIENT_RECEIVE:{
- if (pthread_mutex_lock(&m_websocket_mutex[dataport_cust]) != 0) {
- std::cerr << "Failed to lock mutex" << std::endl;
- }
- char recvDataMsgBuf[sizeof(KeyDataMsg_t) + MsgQueueMaxMsgSize];
- memset(&recvDataMsgBuf, 0, sizeof(recvDataMsgBuf));
- memcpy(&recvDataMsgBuf, reinterpret_cast < char *>(in), len);
- m_websocket_queue[dataport_cust].push((&recvDataMsgBuf[0]),
- sizeof(recvDataMsgBuf));
- pthread_cond_signal(&m_websocket_cond[dataport_cust]);
- if (pthread_mutex_unlock(&m_websocket_mutex[dataport_cust]) != 0) {
- std::cerr << "Failed to unlock mutex" << std::endl;
- }
- break;
- }
- case LWS_CALLBACK_CLIENT_ESTABLISHED:
- if (pthread_mutex_lock(&m_websocket_mutex[dataport_cust]) != 0) {
- std::cerr << "Failed to lock mutex" << std::endl;
- }
- if (pthread_cond_signal(&m_websocket_cond[dataport_cust]) != 0) {
- std::cerr << "Failed to issue cond_signal" << std::endl;
- }
- if (pthread_mutex_unlock(&m_websocket_mutex[dataport_cust]) != 0) {
- std::cerr << "Failed to unlock mutex" << std::endl;
- }
- break;
- default:
- break;
- }
- return 0;
-}
-
-static int callback_ctrl_cust(libwebsocket_context * context,
- struct libwebsocket *wsi,
- enum libwebsocket_callback_reasons reason,
- void *user, void *in, size_t len)
-{
- switch (reason) {
- case LWS_CALLBACK_CLIENT_RECEIVE:{
- if (pthread_mutex_lock(&m_websocket_mutex[ctrlport_cust]) != 0) {
- std::cerr << "Failed to lock mutex" << std::endl;
- }
- char recvDataMsgBuf[sizeof(KeyDataMsg_t) + MsgQueueMaxMsgSize];
- memset(&recvDataMsgBuf, 0, sizeof(recvDataMsgBuf));
- memcpy(&recvDataMsgBuf, reinterpret_cast < char *>(in), len);
- m_websocket_queue[ctrlport_cust].push((&recvDataMsgBuf[0]),
- sizeof(recvDataMsgBuf));
- pthread_cond_signal(&m_websocket_cond[ctrlport_cust]);
- if (pthread_mutex_unlock(&m_websocket_mutex[ctrlport_cust]) != 0) {
- std::cerr << "Failed to unlock mutex" << std::endl;
- }
- break;
- }
- case LWS_CALLBACK_CLIENT_ESTABLISHED:
- if (pthread_mutex_lock(&m_websocket_mutex[ctrlport_cust]) != 0) {
- std::cerr << "Failed to lock mutex" << std::endl;
- }
- if (pthread_cond_signal(&m_websocket_cond[ctrlport_cust]) != 0) {
- std::cerr << "Failed to issue cond_signal" << std::endl;
- }
- if (pthread_mutex_unlock(&m_websocket_mutex[ctrlport_cust]) != 0) {
- std::cerr << "Failed to unlock mutex" << std::endl;
- }
- break;
- default:
- break;
- }
- return 0;
-}
-
-/* Modify I/F MessageQueue -> Websocket End */
-
/**
* End of File. (CGtCtrl.cpp)
*/
#include <glib-object.h>
#include <json-glib/json-glib.h>
-#include "Websocket.h"
+
+#include "AmbpiComm.h"
#if 1
#define MAX_SPEED 199
#else
void FullMakeFdSet(void);
void DaemonTerminate(int SigNo);
-void CloseAllSocket(void);
struct VehicleInfoNameList
VehicleInfo m_stVehicleInfo;
- int m_websocket_port[4];
- WebsocketIF m_websocket_client[4];
+ int m_ambpicomm_port[4];
+ AmbpiCommIF m_ambpicomm_client[4];
KeyEventOptMsg_t m_msgOpt;
KeyDataMsg_t m_msgDat;
using namespace std;
/**
- * @breif constructor
+ * @brief constructor
*/
CJoyStick::CJoyStick()
{
}
/**
- * @breif change input_event value to js_event value
+ * @brief change input_event value to js_event value
*/
int CJoyStickEV::getJS_EVENT_BUTTON(int& num, int& val,
const struct input_event& s)
}
/**
- * @breif change input_event value to js_event value
+ * @brief change input_event value to js_event value
*/
int CJoyStickEV::getJS_EVENT_AXIS(int& num, int& val,
const struct input_event& s)
return r;
}
/**
- * @breif calc value case 1
+ * @brief calc value case 1
*/
int CJoyStickEV::calc1pm32767(int val, const struct input_absinfo& ai)
{
return c;
}
/**
- * @breif calc value case 2
+ * @brief calc value case 2
*/
int CJoyStickEV::calc2pm32767(int val, const struct input_absinfo& ai)
{
}
/**
- * @breif device grab
+ * @brief device grab
*/
bool CJoyStickEV::deviceGrab(int fd)
{
}
/**
- * @breif device grab relese
+ * @brief device grab relese
*/
bool CJoyStickEV::deviceGrabRelese(int fd)
{
bUseGps = true;
break;
case 'c':
- printf("Using WebSocket\n");
+ printf("Using amb plug-in I/F\n");
comFlg = true;
break;
case 't':
bin_PROGRAMS = carsim
-carsim_SOURCES = Websocket.h Websocket.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_LDADD =
-carsim_CPPFLAGS = -I/usr/include/glib-2.0 -I/usr/include/json-glib-1.0 -I/usr/lib/glib-2.0/include
-carsim_LDFLAGS = -lpthread -ljson-glib-1.0 -lgobject-2.0 -lglib-2.0 -lwebsockets -lrt
+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_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 =
+++ /dev/null
-/*
- * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
- *
- * This program is licensed under the terms and conditions of the
- * Apache License, version 2.0. The full text of the Apache License is at
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- */
-/**
- * @brief websocket I/F
- *
- */
-
-#include <string.h>
-
-#include <iostream>
-
-#include "Websocket.h"
-
-WebsocketRecvQueue::WebsocketRecvQueue()
-: msize(0), maxqueuesize(10)
-{
- init();
-}
-
-WebsocketRecvQueue::WebsocketRecvQueue(int queuesize)
-: msize(0)
-{
- maxqueuesize = queuesize;
- init();
-}
-
-WebsocketRecvQueue::~WebsocketRecvQueue()
-{
- delete[] mdata;
- delete[] mdatasize;
-}
-
-bool WebsocketRecvQueue::push(char *data, int datasize)
-{
- if (datasize > maxdatasize || (msize + 1) > maxqueuesize) {
- return false;
- }
- memset(mdata[msize], 0, maxdatasize);
- memcpy(mdata[msize], data, datasize);
- mdatasize[msize] = datasize;
- msize++;
- return true;
-}
-
-bool WebsocketRecvQueue::front(char *buf) const
-{
- if (msize == 0) {
- return false;
- }
- memcpy(buf, mdata[0], mdatasize[0]);
- return true;
-}
-
-bool WebsocketRecvQueue::empty() const
-{
- return (msize == 0);
-}
-
-void WebsocketRecvQueue::pop()
-{
- if (msize > 0) {
- msize--;
- for (int i = 0; i < msize; i++) {
- memset(mdata[i], 0, maxdatasize);
- memcpy(mdata[i], mdata[i + 1], mdatasize[i + 1]);
- mdatasize[i] = mdatasize[i + 1];
- }
- memset(mdata[msize], 0, maxdatasize);
- mdatasize[msize] = 0;
- }
-}
-
-int WebsocketRecvQueue::size() const
-{
- return msize;
-}
-
-void WebsocketRecvQueue::init()
-{
- mdata = new char[maxqueuesize][maxdatasize];
- memset((void *) mdata, 0, maxqueuesize * maxdatasize);
-
- mdatasize = new int[maxqueuesize];
-
- memset(mdatasize, 0, maxqueuesize);
-}
-
-WebsocketIF::WebsocketIF()
-: isready(false), threadid(0)
-{
-}
-
-WebsocketIF::WebsocketIF(int port, char *interface,
- libwebsocket_protocols * protocols,
- pthread_mutex_t * mtx,
- pthread_cond_t * cnd, WebsocketRecvQueue * recvqueue)
-:threadid(0), mutex(mtx), cond(cnd), queue(recvqueue)
-{
- isready = init(port, interface, protocols, mtx, cnd, recvqueue);
-}
-
-WebsocketIF::~WebsocketIF()
-{
- if (isready) {
- int ret;
- if (threadid != 0) {
- ret = pthread_cancel(threadid);
- if (ret != 0) {
- std::cerr << "Failed to pthread_cancel" << std::endl;
- }
- }
- ret = pthread_join(threadid, NULL);
- if (ret != 0) {
- std::cerr << "Failed to pthread_join" << std::endl;
- }
- if (context != NULL) {
- libwebsocket_context_destroy(context);
- context = NULL;
- }
- }
-}
-
-bool WebsocketIF::start(int port, char *interface,
- libwebsocket_protocols * protocols,
- pthread_mutex_t * mtx,
- pthread_cond_t * cnd, WebsocketRecvQueue * recvqueue)
-{
- if (isready) {
- return isready;
- }
- mutex = mtx;
- cond = cnd;
- queue = recvqueue;
- isready = init(port, interface, protocols, mtx, cnd, recvqueue);
- return isready;
-}
-
-bool WebsocketIF::send(char *msg, int size)
-{
- if (!isready) {
- return isready;
- }
-
- char *buf;
- memset(sendbuf, 0, sizeof(sendbuf));
- buf = &sendbuf[LWS_SEND_BUFFER_PRE_PADDING];
- memcpy(buf, msg, size);
- int ret = libwebsocket_write(websocket,
- reinterpret_cast < unsigned char *>(buf),
- size, LWS_WRITE_BINARY);
- return (ret == 0);
-}
-
-bool WebsocketIF::recv(char *msg, bool fblocking)
-{
- if (!isready) {
- return isready;
- }
-
- if (fblocking) {
- if (queue->empty()) {
- if (pthread_cond_wait(cond, mutex) != 0) {
- std::cerr << "Failed to wait signal" << std::endl;
- }
- }
- queue->front(msg);
- queue->pop();
- }
- else {
- if (queue->empty()) {
- return false;
- }
- else {
- queue->front(msg);
- queue->pop();
- }
- }
- return true;
-}
-
-bool WebsocketIF::poll()
-{
- if (!isready) {
- return isready;
- }
-
- int ret = 0;
- while (true) {
- ret = libwebsocket_service(context, 100);
- }
-}
-
-void *WebsocketIF::loop(void *arg)
-{
- WebsocketIF *src = reinterpret_cast < WebsocketIF * >(arg);
- return (void *) src->poll();
-}
-
-bool WebsocketIF::init(int port, char *interface,
- libwebsocket_protocols * protocols,
- pthread_mutex_t * mtx,
- pthread_cond_t * cnd, WebsocketRecvQueue * recvqueue)
-{
- context = libwebsocket_create_context(CONTEXT_PORT_NO_LISTEN,
- interface, protocols,
- libwebsocket_internal_extensions,
- NULL, NULL, -1, -1, 0);
- if (context == NULL) {
- std::cerr << "Failed to create context." << std::endl;
- return false;
- }
- websocket = libwebsocket_client_connect(context, "127.0.0.1", port,
- 0, "/", "localhost", "websocket",
- protocols[0].name, -1);
- if (websocket == NULL) {
- std::cerr << "Failed to connect server." << std::endl;
- return false;
- }
- if (pthread_create(&threadid, NULL, WebsocketIF::loop,
- (void *) this) != 0) {
- std::cerr << "Failed to create thread." << std::endl;
- return false;
- }
- return true;
-}
+++ /dev/null
-/*
- * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
- *
- * This program is licensed under the terms and conditions of the
- * Apache License, version 2.0. The full text of the Apache License is at
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- */
-/**
- * @brief websocket I/F
- */
-
-#ifndef _ICO_VIC_WEBSOCKET_H_
-#define _ICO_VIC_WEBSOCKET_H_
-
-#include <sys/time.h>
-
-#include <libwebsockets.h>
-
-const int MsgQueueMaxMsgSize = 128;
-
-struct KeyEventOptMsg_t
-{
- char KeyEventType[64];
- struct timeval recordtime;
- struct KeyEventOpt
- {
- int common;
- int sense;
- int event_mask;
- } eventopt;
-};
-
-struct KeyDataMsg_t
-{
- char KeyEventType[64];
- struct timeval recordtime;
- struct KeyData
- {
- int common_status;
- char status[];
- } data;
-};
-
-class WebsocketRecvQueue
-{
- public:
- WebsocketRecvQueue();
- WebsocketRecvQueue(int queuesize);
- ~WebsocketRecvQueue();
- bool push(char *data, int datasize);
- bool front(char *buf) const;
- bool empty() const;
- void pop();
- int size() const;
-
- static const int maxdatasize = sizeof(KeyDataMsg_t) + MsgQueueMaxMsgSize;
- private:
- void init();
-
- int maxqueuesize;
- int msize;
- char (*mdata)[maxdatasize];
- int *mdatasize;
-};
-
-class WebsocketIF
-{
- public:
- WebsocketIF();
- WebsocketIF(int port, char *interface, libwebsocket_protocols *protocol,
- pthread_mutex_t *mtx, pthread_cond_t *cnd,
- WebsocketRecvQueue *recvqueue);
- ~WebsocketIF();
- bool start(int port, char *interface, libwebsocket_protocols *protocol,
- pthread_mutex_t *mtx, pthread_cond_t *cnd,
- WebsocketRecvQueue *recvqueue);
- bool send(char *msg, int size);
- bool recv(char *msg, bool fbolcking);
- bool poll();
- static void *loop(void *arg);
- private:
- bool init(int port, char *interface,
- libwebsocket_protocols *protocol, pthread_mutex_t *mtx,
- pthread_cond_t *cnd, WebsocketRecvQueue *recvqueue);
-
- bool isready;
- libwebsocket_context *context;
- libwebsocket *websocket;
- pthread_t threadid;
- pthread_mutex_t *mutex;
- pthread_cond_t *cond;
- char sendbuf[LWS_SEND_BUFFER_PRE_PADDING +
- WebsocketRecvQueue::maxdatasize +
- LWS_SEND_BUFFER_POST_PADDING];
- WebsocketRecvQueue *queue;
-};
-
-#endif //#ifndef _ICO_VIC_WEBSOCKET_H_