LinkBase.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. #ifndef LINKBASE_H
  2. #define LINKBASE_H
  3. #ifdef __cplusplus
  4. using namespace std;
  5. #include <string>
  6. #include <list>
  7. typedef enum
  8. {
  9. Carplay,
  10. Android_Auto,
  11. Carlife,
  12. HiCar,
  13. ECLink,
  14. Mirror,
  15. Airplay,
  16. }LinkType;
  17. typedef enum
  18. {
  19. Wired,
  20. Wireless,
  21. Auto,
  22. }LinkMode;
  23. //dbus mode carlink send
  24. typedef enum
  25. {
  26. DBUS_DEVICE_ATTACHED, //usb insert
  27. DBUS_DEVICE_DEATTACHED, //usb removed
  28. DBUS_CONNECTTING, //carlink connectting
  29. DBUS_CONNECTED, //carlink connected
  30. DBUS_FOREGROUND, //carlink foreground
  31. DBUS_BACKGROUND, //carlink background
  32. DBUS_FAILED, //carlink failed
  33. DBUS_DISCONNECTED, //carlink disconnected
  34. DBUS_APP_EXIT, //phone's app exited
  35. DBUS_INTERRUPTED_BY_APP, //start connecting by interrupted (kill phone's app or connecting removed)
  36. DBUS_MUSIC_STARTED, //music start
  37. DBUS_MUSIC_STOPPED, //music stop
  38. DBUS_NAVI_STARTED, //navigation start
  39. DBUS_NAVI_STOPPED, //navigation stop
  40. DBUS_VR_STARTED, //voices start
  41. DBUS_VR_STOPPED, //voices stop
  42. DBUS_RECOGNITION_STARTED, //voices recognition start(record start)
  43. DBUS_RECOGNITION_STOPPED, //voices recognition stop(record stop)
  44. DBUS_PHONE_STARTED, //phone call start
  45. DBUS_PHONE_STOPPED, //phone call stop
  46. DBUS_NAVI_SOUND_STARTED, //navigation sound start
  47. DBUS_NAVI_SOUND_STOPPED, //navigation sound stop
  48. DBUS_VOICE_DUCK, //navigation sound start(carplay)
  49. DBUS_VOICE_UNDUCK, //navigation sound stop(carplay)
  50. DBUS_ALERT_STARTED, //ring sound start (carplay)
  51. DBUS_ALERT_STOPPED, //ring sound stop (carplay)
  52. DBUS_VIDEO_START,
  53. DBUS_VIDEO_STOP,
  54. }DbusSend;
  55. //carlink receive or user's request
  56. typedef enum
  57. {
  58. DBUS_REQUEST_CONNECT,
  59. DBUS_REQUEST_FOREGROUND,
  60. DBUS_REQUEST_BACKGROUND,
  61. DBUS_REQUEST_EXITED,
  62. DBUS_REQUEST_GET_AUDIO_FOCUS,
  63. DBUS_REQUEST_RELEASE_AUDIO_FOCUS,
  64. DBUS_REQUEST_VIDEO_STOP,
  65. DBUS_REQUEST_VIDEO_START,
  66. DBUS_REQUEST_VIDEO_RESTART,
  67. DBUS_REQUEST_QUIT_PORECESS,
  68. }DbusReceive;
  69. #if 0
  70. LIBUSB_CLASS_PER_INTERFACE = 0x00,
  71. /** Audio class */
  72. LIBUSB_CLASS_AUDIO = 0x01,
  73. /** Communications class */
  74. LIBUSB_CLASS_COMM = 0x02,
  75. /** Human Interface Device class */
  76. LIBUSB_CLASS_HID = 0x03,
  77. /** Physical */
  78. LIBUSB_CLASS_PHYSICAL = 0x05,
  79. /** Image class */
  80. LIBUSB_CLASS_IMAGE = 0x06,
  81. LIBUSB_CLASS_PTP = 0x06, /* legacy name from libusb-0.1 usb.h */
  82. /** Printer class */
  83. LIBUSB_CLASS_PRINTER = 0x07,
  84. /** Mass storage class */
  85. LIBUSB_CLASS_MASS_STORAGE = 0x08,
  86. /** Hub class */
  87. LIBUSB_CLASS_HUB = 0x09,
  88. /** Data class */
  89. LIBUSB_CLASS_DATA = 0x0a,
  90. /** Smart Card */
  91. LIBUSB_CLASS_SMART_CARD = 0x0b,
  92. /** Content Security */
  93. LIBUSB_CLASS_CONTENT_SECURITY = 0x0d,
  94. /** Video */
  95. LIBUSB_CLASS_VIDEO = 0x0e,
  96. /** Personal Healthcare */
  97. LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f,
  98. /** Diagnostic Device */
  99. LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
  100. /** Wireless class */
  101. LIBUSB_CLASS_WIRELESS = 0xe0,
  102. /** Miscellaneous class */
  103. LIBUSB_CLASS_MISCELLANEOUS = 0xef,
  104. /** Application class */
  105. LIBUSB_CLASS_APPLICATION = 0xfe,
  106. /** Class is vendor-specific */
  107. LIBUSB_CLASS_VENDOR_SPEC = 0xff
  108. */
  109. #endif
  110. typedef enum
  111. {
  112. UnKnown,
  113. Phone_Android,
  114. Phone_IOS,
  115. }PhoneType;
  116. typedef enum
  117. {
  118. APP_NOT_RUNNING, //phone app not open
  119. APP_FOREGROUND, //carlink foreground
  120. APP_BACKGROUND, //carlink background
  121. APP_SCREENLOCKED, //phone screen locked
  122. APP_UNSCREENLOCKED, //phone screen unlocked
  123. APP_MUSIC_STARTED, //music start
  124. APP_MUSIC_STOPPED, //music stop
  125. APP_NAVI_STARTED, //navigation start
  126. APP_NAVI_STOPPED, //navigation stop
  127. APP_VR_STARTED, //voices start
  128. APP_VR_STOPPED, //voices stop
  129. APP_RECOGNITION_STARTED, //voices recognition start(record start)
  130. APP_RECOGNITION_STOPPED, //voices recognition stop(record stop)
  131. APP_PHONE_STARTED, //phone call start
  132. APP_PHONE_STOPPED, //phone call stop
  133. APP_ALERT_STARTED, //ring sound start
  134. APP_ALERT_STOPPED, //ring sound stop
  135. APP_NAVI_SOUND_STARTED, //navigation sound start
  136. APP_NAVI_SOUND_STOPPED, //navigation sound stop
  137. LAUNCH_PHONE_APP, //notify open phone's app
  138. APP_QRCODE, //qr code 's information
  139. APP_LICENSE, //license information
  140. APP_INPUTINFO, //keyboard input information
  141. APP_INPUTPOS, //keyboard input pos information
  142. APP_VRTEXT, //voices information
  143. APP_VOICE_CMD, //voices controls information
  144. APP_VERSION, //version
  145. APP_VOICE_DUCK, //duck
  146. APP_VOICE_UNDUCK, //unduck
  147. APP_PINCODE, //wireless pin code(hicar)
  148. APP_BT_CMD, //bt at cmd
  149. APP_BT_DISCONNECTED, //bt disconnect
  150. APP_CARLINK_INIT_DONE, //carlink done
  151. APP_LINK_TIMEOUT, //link timeout(carlife usbmuxd)
  152. APP_GOTO_DESKTOP, //car's carlife goto background
  153. APP_PHONE_BT_INFO, //phone bt info about address
  154. APP_MIRROR_STOP,
  155. APP_MIRROR_START,
  156. APP_STATE_MSG, //state message
  157. APP_RESERVED, //reserved
  158. }AppStatusMessage;
  159. //亿连id
  160. struct License{
  161. bool activate;
  162. int code;
  163. string msg;
  164. string ver;
  165. };
  166. struct InputInfo
  167. {
  168. int32_t inputType;
  169. int32_t imeOptions;
  170. string rawText;
  171. uint32_t minLines;
  172. uint32_t maxLines;
  173. uint32_t maxLength;
  174. };
  175. struct InputPos{
  176. int start;
  177. int stop;
  178. };
  179. enum VRTextType
  180. {
  181. VR_TEXT_FROM_UNKNOWN = 0,
  182. VR_TEXT_FROM_VR,
  183. VR_TEXT_FROM_SPEAK
  184. };
  185. struct VRTextInfo
  186. {
  187. VRTextType type;
  188. int32_t sequence;
  189. string plainText;
  190. string htmlText;
  191. };
  192. typedef enum
  193. {
  194. APP_PAGE_NAVIGATION,
  195. APP_PAGE_MUSIC,
  196. APP_PAGE_VR,
  197. APP_PAGE_NAVI_HOME,
  198. APP_PAGE_NAVI_WORK,
  199. APP_PAGE_MAIN,
  200. APP_PAGE_NAVI_GAS_STATION,
  201. APP_PAGE_CAR_PARK,
  202. APP_PAGE_4S_SHOP,
  203. }AppPage;
  204. enum CallType
  205. {
  206. CALL_TYPE_DAIL = 0, ///< ring up
  207. CALL_TYPE_HANG_UP, ///< ring off
  208. CALL_TYPE_MAX, ///< reserve
  209. };
  210. enum ConnectedStatus
  211. {
  212. CONNECT_STATUS_DEVICE_ATTACHED,
  213. CONNECT_STATUS_DEVICE_DEATTACHED,
  214. CONNECT_STATUS_CONNECTING,
  215. CONNECT_STATUS_CONNECT_FAILED,
  216. CONNECT_STATUS_CONNECT_SUCCEED,
  217. CONNECT_STATUS_DISCONNECTED,
  218. CONNECT_STATUS_APP_EXIT,
  219. CONNECT_STATUS_INTERRUPTED_BY_APP,
  220. };
  221. enum RequestAppStatus
  222. {
  223. QUERYTIME,
  224. QUERYGPS,
  225. QUERYBTSTATUS,
  226. QUERYQRCODE,
  227. QUERYINPUT,
  228. };
  229. enum AudioType
  230. {
  231. AUDIO_TYPE_MUSIC = 0x00, ///< Music audio
  232. AUDIO_TYPE_CALL = 0x01, ///< phone call audio
  233. AUDIO_TYPE_VR = 0x02, ///< VR audio
  234. AUDIO_TYPE_TTS = 0x03, ///< TTS audio
  235. AUDIO_TYPE_Rec = 0x04, ///< rec audio
  236. AUDIO_TYPE_Alert = 0x05, ///< alert audio
  237. };
  238. struct AudioInfo
  239. {
  240. uint32_t sampleRate; ///< sample rate
  241. uint32_t channel; ///< channel type
  242. uint32_t format; ///< audio format type
  243. };
  244. enum WheelCode
  245. {
  246. Wheel_Previous = -1,
  247. Wheel_Keep = 0,
  248. Wheel_Next = 1,
  249. Wheel_Enter = 2,
  250. Wheel_Left = 3,
  251. Wheel_Right = 4,
  252. Wheel_Up = 5,
  253. Wheel_Down = 6,
  254. };
  255. enum TouchCode
  256. {
  257. Touch_Up = 0,
  258. Touch_Press = 1,
  259. Touch_Move = 2,
  260. };
  261. struct WifiInfo{
  262. string ssid;
  263. string passphrase;
  264. string channel_id;
  265. };
  266. struct BlueToothInfo{
  267. string name;
  268. string addr;
  269. string pin;
  270. };
  271. struct BT_CMD{
  272. string cmd;
  273. int len;
  274. };
  275. struct DuckInfo{
  276. double inDurationSecs;
  277. double volume;
  278. };
  279. struct PhoneBlueToothInfo{
  280. string phoneBTAddr;
  281. int pairMethod;
  282. };
  283. struct MSGInfo
  284. {
  285. string msg;
  286. int msg_len;
  287. };
  288. enum WifiStateAction
  289. {
  290. WIFI_STATE_CHANGED_ACTION = 0, ///<AP, STATION
  291. WIFI_P2P_STATE_CHANGED_ACTION = 1, ///< P2P
  292. };
  293. enum WifiState
  294. {
  295. WIFI_STATE_UNKNOWN = 0,
  296. WIFI_STATE_ENABLE, ///< The network is available
  297. WIFI_STATE_DISABLE, ///< Network unavailable
  298. WIFI_STATE_CONNECTED, ///< Network connected
  299. WIFI_STATE_DISCONNECTED, ///< Network disconnection
  300. };
  301. struct NetWorkInfo
  302. {
  303. int32_t state; ///<see ECWifiState
  304. string phoneIp; ///<phone ip
  305. string carIp; ///<car ip
  306. };
  307. enum KeyCode
  308. {
  309. // for driving mode
  310. KEY_HOME = 1,
  311. KEY_PHONE = 2,
  312. KEY_TALKIE = 3, ///< start talkie
  313. KEY_NAVIGATION = 4, ///< start navigation
  314. KEY_VOICE_ASSISTANT = 5, ///< start voice assistant
  315. KEY_MUSIC_PLAY = 6, ///< play music
  316. KEY_MUSIC_NEXT = 7, ///< play next music
  317. KEY_MUSIC_PREVIOUS = 8, ///< play previous music
  318. KEY_MUSIC_PAUSE = 9, ///< music pause
  319. KEY_MUSIC_STOP = 10, ///< music stop
  320. KEY_MUSIC_PLAY_PAUSE = 11, ///< music switch between pause and stop
  321. KEY_VOLUME_UP = 12, ///< increase the volume of phone
  322. KEY_VOLUME_DOWN = 13, ///< decrease the volume of phone
  323. KEY_TOPLEFT = 14, ///< click top left button
  324. KEY_TOPRIGHT = 15, ///< click top right button
  325. KEY_BOTTOMLEFT = 16, ///< click bottom left button
  326. KEY_BOTTOMRIGHT = 17, ///< click bottom right button
  327. KEY_LIGHTMODE = 18, ///< click night mode button
  328. KEY_NIGHTMODE = 19, ///light mode
  329. KEY_APP_FRONT = 20, ///< make the app of android phone switch to the foreground
  330. KEY_APP_BACK = 21, ///< it works like the function of the back button to the app of the connected phone.
  331. KEY_CAR_FOREGROUND = 22, ///it carlinks 's ui foreground
  332. KEY_CAR_BACKGROUND = 23, ///it carlinks 's ui background
  333. KEY_ENFORCE_LANDSCAPE = 24, ///< make the android phone enforce landscape.
  334. KEY_CANCEL_LANDSCAPE = 25, ///< make the android phone cancel landscape.
  335. KEY_ENFORCE_OR_CANCEL_LANDSCAPE = 26, ///< make the android phone enforce or cancel landscape.
  336. KEY_SYSTEM_HOME = 27, ///< The Android phone's HOME key
  337. KEY_SYSTEM_BACK = 28, ///< The Android phone's BACK key
  338. KEY_PICKUP_PHONE = 29, /// pick up phone
  339. KEY_HANGUP_PHONE = 30, ///hang up phone
  340. KEY_CAR_OK = 31, ///make car links 'ui enter comfirm
  341. KEY_CAR_BACK = 32, ///make car links 'ui back page
  342. KEY_LEFT = 33, ///< click left button
  343. KEY_RIGHT = 34, ///< click right button
  344. KEY_TOP = 35, ///< click top button
  345. KEY_BOTTOM = 36, ///< click bottom button
  346. KEY_MUSIC = 37, ///< start music screen
  347. KEY_MUSIC_PLAYING = 38, /// show playing screen
  348. KEY_PHONE_NUMBER = 39, ///show phone number
  349. KEY_PICKUP_HANGUP_PHONE = 40, ///pick up or hang up phone
  350. KEY_MAX, ///< reserve
  351. };
  352. struct LinkConfig
  353. {
  354. int offset_x;
  355. int offset_y;
  356. int screen_width;
  357. int screen_height;
  358. bool diy_screen;
  359. bool autostart;
  360. bool encryption;
  361. bool usb_index;
  362. LinkType linkType;
  363. string version;
  364. string manufacturer;
  365. string phone_bt_mac;
  366. string car_bt_mac;
  367. string phone_wifi_mac;
  368. string car_wifi_ssid;
  369. string car_wifi_passphrase;
  370. string car_wifi_channel;
  371. };
  372. struct CarlifeConfig
  373. {
  374. int ios_link_mode;
  375. int android_link_mode;
  376. bool mic_record;
  377. };
  378. struct CarplayConfig
  379. {
  380. int screen_physical_width;
  381. int screen_physical_height;
  382. int aec_delay;
  383. int fps;
  384. int i2c_addr;
  385. int i2c_number;
  386. int device_current;
  387. bool audio_plugin;
  388. bool switch_usb_mode;
  389. string vehicle_name;
  390. string vehicle_icon_label;
  391. string vehicle_icon_path;
  392. list<string> parameter_name;
  393. list<string> parameter_id;
  394. };
  395. class CarBack;
  396. class LinkBase
  397. {
  398. public:
  399. LinkBase(){}
  400. virtual ~LinkBase(){}
  401. protected:
  402. virtual bool init(LinkMode linkMode) = 0;
  403. virtual bool start() = 0;
  404. virtual bool stop() = 0;
  405. virtual bool release() = 0;
  406. virtual bool start_mirror() = 0;
  407. virtual bool stop_mirror() = 0;
  408. virtual bool set_background() = 0;
  409. virtual bool set_foreground() = 0;
  410. virtual bool get_audio_focus() = 0;
  411. virtual bool release_audio_focus() = 0;
  412. virtual void set_inserted(bool inserted, PhoneType phoneType) = 0;
  413. virtual void send_screen_size(int width, int height) = 0;
  414. virtual void record_audio_callback(unsigned char *data, int len) = 0;
  415. virtual void send_car_bluetooth(const string& name, const string& address, const string& pin) = 0;
  416. virtual void send_phone_bluetooth(const string& address) = 0;
  417. virtual void send_car_wifi(WifiInfo& info) = 0;
  418. virtual void send_touch(int x, int y, TouchCode touchCode) = 0;
  419. virtual void send_multi_touch(int x1, int y1, TouchCode touchCode1, int x2, int y2, TouchCode touchCode2) = 0;
  420. virtual bool send_key(KeyCode keyCode) = 0;
  421. virtual bool send_wheel(WheelCode wheel, bool foucs) = 0;
  422. virtual bool send_night_mode(bool night) = 0;
  423. virtual bool send_right_hand_driver(bool right) = 0;
  424. virtual bool send_disable_car_audio(bool disable) = 0;
  425. virtual bool open_page(AppPage appPage) = 0;
  426. virtual void request_status(RequestAppStatus requestAppStatus, void *reserved = nullptr) = 0;
  427. virtual void send_license(const string& license) = 0;
  428. virtual void send_input_text(const string& text) = 0;
  429. virtual void send_input_selection(const int start, const int stop) = 0;
  430. virtual void send_input_action(const int acionId, const int keyCode) = 0;
  431. virtual void send_bluetooth_cmd(const string& cmd ) = 0;
  432. virtual void send_broadcast(bool enable) = 0;
  433. virtual void send_delay_record(int millisecond) = 0;
  434. virtual void send_wifi_state_changed(WifiStateAction action, WifiState state, const string& phoneIp, const string& carIp) = 0;
  435. virtual void carback(CarBack *pCarback) = 0;
  436. };
  437. #endif
  438. #endif // LINKBASE_H