24
24
25
25
#include " hu_uti.h"
26
26
27
+ #define HMI_BUS_ADDRESS " unix:path=/tmp/dbus_hmi_socket"
27
28
#define SERVICE_BUS_ADDRESS " unix:path=/tmp/dbus_service_socket"
28
29
29
30
std::string IP_ADDRESS;
@@ -81,10 +82,80 @@ int handleWifiInfoRequestResponse(int fd, uint8_t *buffer, uint16_t length) {
81
82
return msg.status ();
82
83
}
83
84
85
+ // uint32 15
86
+ // uint32 3
87
+ // uint32 1
88
+ // uint32 100
89
+ // struct {
90
+ // array of bytes [
91
+ // 2f 64 65 76 2f 70 74 73 2f 30 00 00 00 00 00 00 00 00 00 00 00
92
+ // ]
93
+
94
+
95
+ void handle_connect (char *pty){
96
+ char buf[100 ];
97
+ logd (" \t PTY: %s\n " , pty);
98
+ int fd = open (pty, O_RDWR | O_NOCTTY | O_SYNC);
99
+ HU::WifiInfoRequest request;
100
+ request.set_ip_address (IP_ADDRESS.c_str ());
101
+ request.set_port (30515 );
102
+
103
+ sendMessage (fd, request, 1 );
104
+
105
+ logd (" PTY opened\n " );
106
+ ssize_t len = 0 ;
107
+ int loop = 1 ;
108
+ while (loop) {
109
+ ssize_t i = read (fd, buf, 4 );
110
+ len += i;
111
+ if (len >= 4 ) {
112
+ uint16_t size = be16toh (*(uint16_t *) buf);
113
+ uint16_t type = be16toh (*(uint16_t * )(buf + 2 ));
114
+ logd (" Size: %u, MessageID: %u, left: %u\n " , size, type);
115
+ if (len >= size + 4 ) {
116
+ uint8_t *buffer = (uint8_t *) malloc (size);
117
+ i = 0 ;
118
+ while (i < size) {
119
+ i += read (fd, buffer, size);
120
+ }
121
+ switch (type) {
122
+ case 1 :
123
+ handleWifiInfoRequest (fd, buffer, size);
124
+ break ;
125
+ case 2 :
126
+ handleWifiSecurityRequest (fd, buffer, size);
127
+ break ;
128
+ case 7 :
129
+ if (handleWifiInfoRequestResponse (fd, buffer, size) == 0 ) {
130
+ loop = 0 ;
131
+ }
132
+ break ;
133
+ default :
134
+ break ;
135
+ }
136
+ }
137
+ }
138
+ }
139
+ }
140
+
141
+ void BCAClient::ConnectionStatusResp (
142
+ const uint32_t &serviceId,
143
+ const uint32_t &connStatus,
144
+ const uint32_t &btDeviceId,
145
+ const uint32_t &status,
146
+ const ::DBus::Struct <std::vector<uint8_t >> &terminalPath) {
147
+ if (serviceId == 15 && connStatus == 3 ) {
148
+ char *pty = (char *) malloc (terminalPath._1 .size ());
149
+ std::copy (terminalPath._1 .begin (), terminalPath._1 .end (), pty);
150
+ logd (" \t PTY: %s\n " , pty);
151
+ handle_connect (pty);
152
+ free (pty);
153
+ }
154
+ }
155
+
84
156
void BDSClient::SignalConnected_cb (const uint32_t &type, const ::DBus::Struct <std::vector<uint8_t >> &data) {
85
157
char mac[18 ];
86
158
char pty[100 ];
87
- char buf[100 ];
88
159
logd (" Signal Connected:\n " );
89
160
logd (" \t Type: %u\n " , type);
90
161
std::copy (data._1 .begin () + 14 , data._1 .begin () + 32 , mac);
@@ -94,47 +165,7 @@ void BDSClient::SignalConnected_cb(const uint32_t &type, const ::DBus::Struct <s
94
165
if (data._1 [36 ] == 15 ) {
95
166
std::strncpy (pty, (char *) &data._1 [48 ], 100 );
96
167
logd (" \t PTY: %s\n " , pty);
97
- int fd = open (pty, O_RDWR | O_NOCTTY | O_SYNC);
98
- HU::WifiInfoRequest request;
99
- request.set_ip_address (IP_ADDRESS.c_str ());
100
- request.set_port (30515 );
101
-
102
- sendMessage (fd, request, 1 );
103
-
104
- logd (" PTY opened\n " );
105
- ssize_t len = 0 ;
106
- int loop = 1 ;
107
- while (loop) {
108
- ssize_t i = read (fd, buf, 4 );
109
- len += i;
110
- if (len >= 4 ) {
111
- uint16_t size = be16toh (*(uint16_t *) buf);
112
- uint16_t type = be16toh (*(uint16_t * )(buf + 2 ));
113
- logd (" Size: %u, MessageID: %u, left: %u\n " , size, type);
114
- if (len >= size + 4 ) {
115
- uint8_t *buffer = (uint8_t *) malloc (size);
116
- i = 0 ;
117
- while (i < size) {
118
- i += read (fd, buffer, size);
119
- }
120
- switch (type) {
121
- case 1 :
122
- handleWifiInfoRequest (fd, buffer, size);
123
- break ;
124
- case 2 :
125
- handleWifiSecurityRequest (fd, buffer, size);
126
- break ;
127
- case 7 :
128
- if (handleWifiInfoRequestResponse (fd, buffer, size) == 0 ) {
129
- loop = 0 ;
130
- }
131
- break ;
132
- default :
133
- break ;
134
- }
135
- }
136
- }
137
- }
168
+ handle_connect (pty);
138
169
}
139
170
}
140
171
@@ -174,15 +205,20 @@ void wireless_stop(){
174
205
void wireless_thread () {
175
206
static BDSClient *bds_client = NULL ;
176
207
static NMSClient *nms_client = NULL ;
208
+ static BCAClient *bca_client = NULL ;
177
209
DBus::default_dispatcher = &wireless_dispatcher;
178
210
179
211
logd (" DBus::Glib::BusDispatcher attached\n " );
180
212
181
213
try {
214
+ DBus::Connection hmi_bus (HMI_BUS_ADDRESS, false );
215
+ hmi_bus.register_bus ();
182
216
DBus::Connection service_bus (SERVICE_BUS_ADDRESS, false );
183
217
service_bus.register_bus ();
184
218
bds_client = new BDSClient (service_bus, " /com/jci/bds" , " com.jci.bds" );
185
219
nms_client = new NMSClient (service_bus, " /com/jci/nms" , " com.jci.nms" );
220
+ bca_client = new BCAClient (hmi_bus, " /com/jci/bca" , " com.jci.bca" );
221
+
186
222
187
223
::DBus::Struct <std::vector<int32_t >> interface_list;
188
224
int32_t rvalue;
@@ -198,6 +234,8 @@ void wireless_thread() {
198
234
}
199
235
}
200
236
237
+ bca_client->StartAdd (15 );
238
+
201
239
202
240
wireless_dispatcher.enter ();
203
241
logd (" Exiting" );
0 commit comments