STA5 SmartLink command guidance
Agenda
Designer
Purpose
SmartLink, an IPC application on STA5 platform, it's a middle-ware between applications
such as UI, AndroidAuto, Apple CarPlay, Bluetooth,... .
Main function includes:
- Windows focus switching(by software, hardware button)
- Audio manager(by rotary button)
- Wi-Fi manager
- Device manager
- Resource manager
Requirement
- Platform: STA5
- The version unmber can be found in sml_def.h, please follow the latest version.
- Rule is (SML_MAJOR_VERSION).(SML_MINOR_VERSION).(SML_MAIN_VERSION)
- (SML_MAJOR_VERSION): +1 if there are big modifications on SmartLink main function.
- (SML_MINOR_VERSION): +1 if the change will impact the communication with other APP.
- (SML_MAIN_VERSION): +1 if the change only impact a small portion of SmartLink function.
- Please import below files to your project, they’re under SmartLink build folder:
export
├── include
│ ├── libunixsocket.h
│ ├── sml_def.h
│ └── sml_data_format.h
└── libsocket.so
Main Flow Chart
graph TD
A[START] -->|Multi-thread| B(Socket Accepter thread)
B --> C(create_unix_server_socket)
C --> D(accept_unix_stream_socket)
D -->|Multi-thread| E(listener thread)
E --> F(Receive E_REQ_SUBSCRIBE command)
F --> G(Switch case by APP_TYPE)
G --> H{case MAIN_UI}
H --> I[Main UI message handler]
H --> J{case AA}
J --> K[Android Auto message handler]
J --> L{case CP}
L --> M[Apple CarPlay message handler]
L --> N{case BT_SRV}
N --> O[BT SRV message handler]
N --> P{case Others}
P --> Q[Others message handler]
P --> G
D -->|Multi-thread| R(listener thread)
R --> S(...)
D -->|Multi-thread| T(...)
A -->|Multi-thread| U(Key button thread)
U --> V(Detect /dev/input/event0)
A -->|Multi-thread| W(Rotary button thread)
W --> X(Detect /dev/input/event1)
APIs
ret = sfd = create_unix_stream_socket(TMP_SOCKET_SML, 0);
if (ret < 0) {
perror(0);
exit(1);
}
ret = write(sfd, &send_data, sizeof(send_data));
if (ret < 0) {
perror(0);
goto ERR_EXIT;
}
ret = bytes = read(sfd, buf, MAX_MESSAGE_READ);
if (ret < 0) {
perror(0);
exit(1);
}
SmartLink data format
Data member |
Data type |
Data length |
Description |
version |
unsigned char |
1 byte |
Set to SML_MAJOR_VERSION. |
mode |
unsigned char |
1 byte |
Refer to type REQ_MODE. |
AppType |
unsigned char |
1 byte |
Refer to type APP_TYPE. |
state |
unsigned char |
1 byte |
Refer to type SML_STATE_CODE. |
AppClientID |
unsigned int |
4 bytes |
Client ID. |
srcAppName |
unsigned char[128] |
128 bytes |
Source application name in string. |
dstAppName |
unsigned char[128] |
128 bytes |
Destination application name in string. |
cmd |
unsigned int |
4 bytes |
Refer to type SML_COMMAND. |
len |
unsigned int |
4 bytes |
Total length of message in bytes. |
SmartLink data base structure
Data member |
Data type |
Data length |
Description |
index |
int |
4 bytes |
|
DeviceName[32] |
char |
32 bytes |
Phone Name. |
usbSerialNumber[32] |
char |
32 bytes |
USB serial number. |
btMacAddress[32] |
char |
32 bytes |
Bluetooth MAC address. |
SupportedAPP |
int |
4 bytess |
Refer to APP_TYPE. |
Common Command
Subscribe
- From APPs - Client
- To subscribe the service from SmartLink. Send below message to SmartLink.
- Supported types: E_MAIN_UI, E_PHONE_CONNECTIVITY_AA, E_PHONE_CONNECTIVITY_CP, E_BT_SRV, E_OTHER_TYPE.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
Source application name in string. |
dstAppName |
"SML" |
cmd |
E_REQ_SUBSCRIBE |
len |
Total length of message in bytes(288). |
- From SmartLink: No return message.
Get WiFi status
- From APPs - Client
- To get the Wi-Fi AP status from SmartLink. Send below message to SmartLink.
- Supported types: E_MAIN_UI, E_PHONE_CONNECTIVITY_AA, E_PHONE_CONNECTIVITY_CP, E_BT_SRV, E_OTHER_TYPE.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
Source application name in string. |
dstAppName |
"SML" |
cmd |
E_REQ_GET_WIFI_STATUS |
len |
Total length of message in bytes(288). |
- From SmartLink: Returned message, refer next section(Return WiFi status).
Return WiFi status
- From SmartLink - Server
- Wi-Fi AP status returned from SmartLink:
- E_RETURN_WIFI_STATUS_ON means Wi-Fi AP is on and ready.
- E_RETURN_WIFI_STATUS_OFF means Wi-Fi AP is off and not ready.
- Supported types: E_MAIN_UI, E_PHONE_CONNECTIVITY_AA, E_PHONE_CONNECTIVITY_CP, E_BT_SRV, E_OTHER_TYPE.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
"SML" |
dstAppName |
Received Application name. |
cmd |
E_RETURN_WIFI_STATUS_ON/E_RETURN_WIFI_STATUS_OFF |
len |
Total length of message in bytes(288). |
Windows Focus switch command
On Top Notification
- From APPs - Client
- Notify SmartLink when APP is on Projection mode. Send below message to SmartLink.
- Supported types: E_MAIN_UI, E_PHONE_CONNECTIVITY_CP, E_OTHER_TYPE.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
Source application name in string. |
dstAppName |
"SML" |
cmd |
E_REQ_I_AM_TOP |
len |
Total length of message in bytes(288). |
- From SmartLink: No return message.
On Top Notification for Android Auto
- From AA - Client
- Notify SmartLink when APP is on Projection mode. Send below message to SmartLink.
- Supported types: E_PHONE_CONNECTIVITY_AA.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
"AA" |
dstAppName |
"SML" |
cmd |
E_REQ_I_AM_TOP |
len |
Total length of message in bytes(288+64). |
---Outside of 288 bytes--- |
|
UsbSerialNumber[32] |
32 bytes, the USB serial number of MD. |
BtMacAddress[32] |
32 bytes, the BT MAC address of MD. |
- From SmartLink: No return message.
Get Up
- From SmartLink - Server
- Notify APP to enter Projection mode.
- Supported types: E_MAIN_UI, E_PHONE_CONNECTIVITY_AA, E_PHONE_CONNECTIVITY_CP, E_OTHER_TYPE.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
"SML" |
dstAppName |
Received Application name. |
cmd |
E_GET_UP |
len |
Total length of message in bytes(288). |
Get Down
- From SmartLink - Server
- Notify APP to hide to background.
- Supported types: E_MAIN_UI, E_PHONE_CONNECTIVITY_AA, E_PHONE_CONNECTIVITY_CP, E_OTHER_TYPE.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
"SML" |
dstAppName |
Received Application name. |
cmd |
E_GET_DOWN |
len |
Total length of message in bytes(288). |
Device Manager Command
Get device information
- From APPs - Client
- To get the device info from SmartLink. Send below message to SmartLink.
- Supported types: E_MAIN_UI, E_PHONE_CONNECTIVITY_AA, E_BT_SRV, E_OTHER_TYPE.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
Source application name in string. |
dstAppName |
"SML" |
cmd |
E_REQ_GET_DEVICE_INFO |
len |
Total length of message in bytes(288+6). |
---Outside of 288 bytes--- |
|
BtMacAddress[6] |
6 bytes, the BT MAC address of MD. |
- From SmartLink: Returned message, refer next page(Return device information).
Return device information
- From SmartLink - Server
- The device info returned from SmartLink.
- Supported types: E_MAIN_UI, E_PHONE_CONNECTIVITY_AA, E_BT_SRV, E_OTHER_TYPE.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
"SML" |
dstAppName |
Received Application name |
cmd |
E_RETURN_DEVICE_INFO |
len |
Total length of message in bytes(288+10). |
---Outside of 288 bytes--- |
|
BtMacAddress[6] |
6 bytes, the BT MAC address from E_REQ_GET_DEVICE_INFO command. |
SupportedAPP |
4 bytes, refer to APP_TYPE. |
Device Phone Link ON
- From SmartLink - Server
- The device Phone Link status is ON.
- Supported types: E_MAIN_UI.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
"SML" |
dstAppName |
Received Application name |
cmd |
E_DEVICE_PHONE_LINK_ON |
len |
Total length of message in bytes(288+10). |
---Outside of 288 bytes--- |
|
BtMacAddress[6] |
6 bytes, the BT MAC address of MD. |
SupportedAPP |
4 bytes, refer to APP_TYPE. |
Device Phone Link OFF
- From SmartLink - Server
- The device Phone Link status is OFF.
- Supported types: E_MAIN_UI.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
"SML" |
dstAppName |
Received Application name |
cmd |
E_DEVICE_PHONE_LINK_OFF |
len |
Total length of message in bytes(288+10). |
---Outside of 288 bytes--- |
|
BtMacAddress[6] |
6 bytes, the BT MAC address of MD. |
SupportedAPP |
4 bytes, refer to APP_TYPE. |
UI Phone Link software button
- From UI - Client
- The Phone Link software button pressed, need to notify SmartLink.
- Supported types: E_MAIN_UI.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
Source application name in string. |
dstAppName |
"SML" |
cmd |
E_UI_PHONE_LINK_BTN |
len |
Total length of message in bytes(288+6). |
---Outside of 288 bytes--- |
|
BtMacAddress[6] |
6 bytes, the BT MAC address of MD. |
- From SmartLink: No return message.
iAP2 connected
- From BTSRV - Client
- When iAP2 connected, need to notify SmartLink.
- Supported types: E_BT_SRV.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
Source application name in string. |
dstAppName |
"SML" |
cmd |
E_BT_IAP2_CONNECTED |
len |
Total length of message in bytes(288+10). |
---Outside of 288 bytes--- |
|
BtMacAddress[6] |
6 bytes, the BT MAC address of MD. |
iAP2SessionHandle |
4 bytes int. Represents a handle of iAP2 Session over bluetooth. |
- From SmartLink: No return message.
iAP2 disconnected
- From BTSRV - Client
- When iAP2 disconnected, need to notify SmartLink.
- Supported types: E_BT_SRV.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
Source application name in string. |
dstAppName |
"SML" |
cmd |
E_BT_IAP2_DISCONNECTED |
len |
Total length of message in bytes(288+10). |
---Outside of 288 bytes--- |
|
BtMacAddress[6] |
6 bytes, the BT MAC address of MD. |
iAP2SessionHandle |
4 bytes int. Represents a handle of iAP2 Session over bluetooth. |
- From SmartLink: No return message.
Pop a window for Phone Link
- From SmartLink - Server
- Call UI to pop a window for user confirm if Phone Link connection is allowed or not.
- Supported types: E_MAIN_UI.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
"SML" |
dstAppName |
Received Application name |
cmd |
E_UI_POP_WINDOW_PHONE_LINK_CONN |
len |
Total length of message in bytes(288+10). |
---Outside of 288 bytes--- |
|
BtMacAddress[6] |
6 bytes, the BT MAC address of MD. |
SupportedAPP |
4 bytes, refer to APP_TYPE. |
Pop up window return
- From UI - Client
- To return the result of pop up window to SmartLink.
- Supported types: E_MAIN_UI.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
Source application name in string. |
dstAppName |
"SML" |
cmd |
E_UI_WINDOW_MSG_BTN_YES/E_UI_WINDOW_MSG_BTN_NO/E_UI_WINDOW_MSG_BTN_CANCEL |
len |
Total length of message in bytes(288). |
Disconnect BT connection with iPhone
- From SmartLink - Server
- Call BTSRV to disconnect BT connection with iPhone.
- Supported types: E_BT_SRV.
Data member |
Value |
version |
SML_MAJOR_VERSION |
mode |
E_DELEGATE |
AppType |
Refer to type APP_TYPE. |
state |
E_STATE_OK |
AppClientID |
Client ID. |
srcAppName |
"SML" |
dstAppName |
Received Application name |
cmd |
E_DISCONNECT_IPHONE_BT |
len |
Total length of message in bytes(288+6). |
---Outside of 288 bytes--- |
|
BtMacAddress[6] |
6 bytes, the BT MAC address of MD. |
Resource Manager VIP Socket
Android Auto VIP Socket
- Purpose: For Android Auto resource manager data transfer between Android Auto and SmartLink.
- The Data type and Data are defined in header file: aa_rsc_mgr.h.
Object |
Description |
Socket Path(defined in sml_def.h) |
#define TMP_SOCKET_AA_VIP "/tmp/socket_aa_vip" |
Message format(From SmartLink) |
“Ez”+(Total Length of Message)+(Data type)+(Data)+”RCM” |
- Total length of message: 16 bit.
- Data type: 8 bit.
CarPlay VIP Socket
- Purpose: For CarPlay resource manager data transfer between CarPlay and SmartLink.
- The ResourceID and Data are defined in header file: cp_rsc_mgr.h.
Object |
Description |
Socket Path(defined in sml_def.h) |
#define TMP_SOCKET_CP_VIP "/tmp/socket_cp_vip" |
Message format(From SmartLink) |
(ResourceID)+(Length of Data)+(Data) |
- ResourceID: 32 bit.
- Length of data: 32 bit.
- Data: Length of data.