mainwindow.cpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <sys/ipc.h>
  4. #include <sys/msg.h>
  5. #define KEY 1234
  6. #define MESSAGEMAXSIZE 1024
  7. #define RECEIVETYPE 0
  8. struct msg
  9. {
  10. long int messageType;
  11. char message[MESSAGEMAXSIZE];
  12. };
  13. MainWindow::MainWindow(QWidget *parent) :
  14. QMainWindow(parent),
  15. ui(new Ui::MainWindow),mIsRunningBackGround(false),mDbusSend(DBUS_DISCONNECTED)
  16. {
  17. ui->setupUi(this);
  18. onUIInit();
  19. }
  20. MainWindow::~MainWindow()
  21. {
  22. delete ui;
  23. }
  24. void MainWindow::onUIInit()
  25. {
  26. int screen_width = 1920;
  27. int screen_height = 720;
  28. setGeometry(0, 0, screen_width, screen_height);
  29. setAttribute(Qt::WA_TranslucentBackground);
  30. QObject::connect(g_Link, SIGNAL(onLinkStatus(int,int,int)),
  31. this, SLOT(onLinkStatus(int,int,int)));
  32. QObject::connect(g_Link, SIGNAL(onCarLinkVersion(int,QString)),
  33. this, SLOT(onCarLinkVersion(int,QString)));
  34. QObject::connect(g_Link, SIGNAL(onPhoneType(int,int)),
  35. this, SLOT(onPhoneType(int,int)));
  36. QObject::connect(g_Link, SIGNAL(onDateTime(int,long long)),
  37. this, SLOT(onDateTime(int,long long)));
  38. m_CarplayWiredLink = new QPushButton(QString("Carplay Wired"), this);
  39. m_CarplayWiredLink->setGeometry(width() / 6 * 0, 0, width() / 6, height()/2);
  40. QObject::connect(m_CarplayWiredLink, SIGNAL(clicked()),
  41. this, SLOT(onClicked()));
  42. m_CarplayWirelessLink = new QPushButton(QString("Carplay Wireless"), this);
  43. m_CarplayWirelessLink->setGeometry(width() / 6 * 0, height()/2, width() / 6, height()/2);
  44. QObject::connect(m_CarplayWirelessLink, SIGNAL(clicked()),
  45. this, SLOT(onClicked()));
  46. m_AutoWiredLink = new QPushButton(QString("Auto Wired"), this);
  47. m_AutoWiredLink->setGeometry(width() / 6 * 1, 0, width() / 6, height()/2);
  48. QObject::connect(m_AutoWiredLink, SIGNAL(clicked()),
  49. this, SLOT(onClicked()));
  50. m_AutoWirelessLink = new QPushButton(QString("Auto Wireless"), this);
  51. m_AutoWirelessLink->setGeometry(width() / 6 * 1, height()/2, width() / 6, height()/2);
  52. QObject::connect(m_AutoWirelessLink, SIGNAL(clicked()),
  53. this, SLOT(onClicked()));
  54. m_CarlifeWiredLink = new QPushButton(QString("Carlife Wired"), this);
  55. m_CarlifeWiredLink->setGeometry(width() / 6 * 2, 0, width() / 6, height()/2);
  56. QObject::connect(m_CarlifeWiredLink, SIGNAL(clicked()),
  57. this, SLOT(onClicked()));
  58. m_CarlifeWirelessLink = new QPushButton(QString("Carlife Wireless"), this);
  59. m_CarlifeWirelessLink->setGeometry(width() / 6 * 2, height()/2, width() / 6, height()/2);
  60. QObject::connect(m_CarlifeWirelessLink, SIGNAL(clicked()),
  61. this, SLOT(onClicked()));
  62. m_HiCarWiredLink = new QPushButton(QString("HiCar Wired"), this);
  63. m_HiCarWiredLink->setGeometry(width() / 6 * 3, 0, width() / 6, height()/2);
  64. QObject::connect(m_HiCarWiredLink, SIGNAL(clicked()),
  65. this, SLOT(onClicked()));
  66. m_HiCarWirelessLink = new QPushButton(QString("HiCar Wireless"), this);
  67. m_HiCarWirelessLink->setGeometry(width() / 6 * 3, height()/2, width() / 6, height()/2);
  68. QObject::connect(m_HiCarWirelessLink, SIGNAL(clicked()),
  69. this, SLOT(onClicked()));
  70. m_MirrorWiredLink = new QPushButton(QString("Mirror Wired"), this);
  71. m_MirrorWiredLink->setGeometry(width() / 6 * 4, 0, width() / 6, height()/2);
  72. QObject::connect(m_MirrorWiredLink, SIGNAL(clicked()),
  73. this, SLOT(onClicked()));
  74. m_MirrorWirelessLink = new QPushButton(QString("Mirror Wireless"), this);
  75. m_MirrorWirelessLink->setGeometry(width() / 6 * 4, height()/2, width() / 6, height()/2);
  76. QObject::connect(m_MirrorWirelessLink, SIGNAL(clicked()),
  77. this, SLOT(onClicked()));
  78. m_EasyWiredConnectLink = new QPushButton(QString("ECLink Wired"), this);
  79. m_EasyWiredConnectLink->setGeometry(width() / 6 * 5, 0, width() / 6, height()/2);
  80. QObject::connect(m_EasyWiredConnectLink, SIGNAL(clicked()),
  81. this, SLOT(onClicked()));
  82. m_EasyWirelessConnectLink = new QPushButton(QString("ECLink Wireless"), this);
  83. m_EasyWirelessConnectLink->setGeometry(width() / 6 * 5, height()/2, width() / 6, height()/2);
  84. QObject::connect(m_EasyWirelessConnectLink, SIGNAL(clicked()),
  85. this, SLOT(onClicked()));
  86. }
  87. void MainWindow::onClicked()
  88. {
  89. const QPushButton* const ptr = static_cast<const QPushButton* const >(sender());
  90. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  91. printf("dbus recevier :%d\r\n ", mDbusSend);
  92. if(mDbusSend == DBUS_CONNECTED ){
  93. if(mIsRunningBackGround){
  94. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  95. printf("linktype = %d, linkmode = %d\r\n", (int)mLinkType, (int)mLinkMode);
  96. g_Link->requestLink(mLinkType, mLinkMode, DBUS_REQUEST_FOREGROUND);
  97. }
  98. }
  99. else if(mInserted == DBUS_DEVICE_ATTACHED){
  100. if (ptr == m_CarplayWiredLink) {
  101. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  102. g_Link->requestLink(Carplay, Wired, DBUS_REQUEST_CONNECT);
  103. }
  104. else if(ptr == m_AutoWiredLink) {
  105. g_Link->requestLink(Android_Auto, Wired, DBUS_REQUEST_CONNECT);
  106. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  107. }
  108. else if(ptr == m_CarlifeWiredLink) {
  109. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  110. g_Link->requestLink(Carlife, Wired, DBUS_REQUEST_CONNECT);
  111. }
  112. else if(ptr == m_HiCarWiredLink){
  113. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  114. g_Link->requestLink(HiCar, Wired, DBUS_REQUEST_CONNECT);
  115. }
  116. else if(ptr == m_MirrorWiredLink){
  117. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  118. g_Link->requestLink(Mirror, Wired, DBUS_REQUEST_CONNECT);
  119. } else if(ptr == m_EasyWiredConnectLink){
  120. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  121. g_Link->requestLink(ECLink, Wired, DBUS_REQUEST_CONNECT);
  122. }
  123. }
  124. else{
  125. if(ptr == m_CarplayWirelessLink){
  126. g_Link->requestWifi("ark1668e_devb_wifi", "12345678", "36");
  127. g_Link->requestCarBluetooth("carlink","00:11:22:33:44:55","0000");
  128. g_Link->requestLink(Carplay, Wireless, DBUS_REQUEST_CONNECT);
  129. }
  130. else if(ptr == m_AutoWirelessLink){
  131. g_Link->requestLink(Android_Auto, Wireless, DBUS_REQUEST_CONNECT);
  132. }
  133. else if(ptr == m_CarlifeWirelessLink){
  134. g_Link->requestLink(Carlife, Wireless, DBUS_REQUEST_CONNECT);
  135. }
  136. else if(ptr == m_HiCarWirelessLink){
  137. g_Link->requestLink(HiCar, Wireless, DBUS_REQUEST_CONNECT);
  138. }
  139. else if(ptr == m_MirrorWirelessLink){
  140. g_Link->requestLink(HiCar, Wireless, DBUS_REQUEST_CONNECT);
  141. }
  142. else if(ptr == m_EasyWirelessConnectLink){
  143. printf("%s:%s:%d\r\n",__FILE__,__func__,__LINE__);
  144. g_Link->requestLink(ECLink, Wireless, DBUS_REQUEST_CONNECT);
  145. }
  146. }
  147. }
  148. void MainWindow::onUIChanged(bool visible)
  149. {
  150. m_CarplayWiredLink->setVisible(visible);
  151. m_CarplayWirelessLink->setVisible(visible);
  152. m_AutoWiredLink->setVisible(visible);
  153. m_AutoWirelessLink->setVisible(visible);
  154. m_CarlifeWiredLink->setVisible(visible);
  155. m_CarlifeWirelessLink->setVisible(visible);
  156. m_HiCarWiredLink->setVisible(visible);
  157. m_HiCarWirelessLink->setVisible(visible);
  158. m_MirrorWiredLink->setVisible(visible);
  159. m_MirrorWirelessLink->setVisible(visible);
  160. m_EasyWiredConnectLink->setVisible(visible);
  161. m_EasyWirelessConnectLink->setVisible(visible);
  162. }
  163. void MainWindow::onLinkStatus(int type, int mode, int status)
  164. {
  165. if(status == DBUS_CONNECTED){
  166. onUIChanged(false);
  167. mDbusSend = (DbusSend)status;
  168. mLinkType = (LinkType)type;
  169. mLinkMode = (LinkMode)mode;
  170. }
  171. else if(status == DBUS_FOREGROUND){
  172. mIsRunningBackGround = false;
  173. onUIChanged(false);
  174. }
  175. else if(status == DBUS_BACKGROUND){
  176. mIsRunningBackGround = true;
  177. onUIChanged(true);
  178. }
  179. else if(status == DBUS_DISCONNECTED ||
  180. status == DBUS_FAILED ||
  181. status == DBUS_APP_EXIT ||
  182. status == DBUS_INTERRUPTED_BY_APP){
  183. onUIChanged(true);
  184. mDbusSend = (DbusSend)status;
  185. }
  186. printf("onLinkStatus :type = %d, mode =%d, status = %d\n", type, mode, status);
  187. }
  188. void MainWindow::onPhoneType(int type, int inserted)
  189. {
  190. if(inserted == 0)
  191. mInserted = DBUS_DEVICE_ATTACHED;
  192. else if(inserted == 1)
  193. mInserted = DBUS_DEVICE_DEATTACHED;
  194. }
  195. void MainWindow::onCarLinkVersion(const int type, const QString ver)
  196. {
  197. printf("onCarLinkVersion :type = %d, ver =%s\n", type, ver.toStdString().data());
  198. }
  199. void MainWindow::onDateTime(const int type, const long long time)
  200. {
  201. time_t t = time;
  202. char *ptime = ctime(&t);
  203. printf("onDateTime :type: %d, time:%s\n", type, ptime);
  204. }
  205. void MainWindow::mousePressEvent(QMouseEvent *event)
  206. {
  207. g_Link->requestTouch(event->pos().x(), event->pos().y(), Touch_Press);
  208. }
  209. void MainWindow::mouseReleaseEvent(QMouseEvent *event)
  210. {
  211. g_Link->requestTouch(event->pos().x(), event->pos().y(), Touch_Up);
  212. }
  213. void MainWindow::mouseMoveEvent(QMouseEvent *event)
  214. {
  215. printf("x:%d,y:%d\r\n",event->pos().x(),event->pos().y());
  216. g_Link->requestTouch(event->pos().x(), event->pos().y(), Touch_Move);
  217. }