@@ -39,6 +39,71 @@ nsapi_error_t QUECTEL_BG96_CellularStack::socket_accept(void *server, void **soc
39
39
return NSAPI_ERROR_UNSUPPORTED;
40
40
}
41
41
42
+ nsapi_error_t QUECTEL_BG96_CellularStack::socket_connect (nsapi_socket_t handle, const SocketAddress &address)
43
+ {
44
+ CellularSocket *socket = (CellularSocket *)handle;
45
+
46
+ int modem_connect_id = -1 ;
47
+ int request_connect_id = socket->id ;
48
+ int err = -1 ;
49
+
50
+ _at.lock ();
51
+ if (socket->proto == NSAPI_TCP) {
52
+ _at.cmd_start (" AT+QIOPEN=" );
53
+ _at.write_int (_cid);
54
+ _at.write_int (request_connect_id);
55
+ _at.write_string (" TCP" );
56
+ _at.write_string (address.get_ip_address ());
57
+ _at.write_int (address.get_port ());
58
+ _at.write_int (socket->localAddress .get_port ());
59
+ _at.write_int (0 );
60
+ _at.cmd_stop ();
61
+
62
+ handle_open_socket_response (modem_connect_id, err);
63
+
64
+ if ((_at.get_last_error () == NSAPI_ERROR_OK) && err) {
65
+ _at.cmd_start (" AT+QICLOSE=" );
66
+ _at.write_int (modem_connect_id);
67
+ _at.cmd_stop ();
68
+ _at.resp_start ();
69
+ _at.resp_stop ();
70
+
71
+ _at.cmd_start (" AT+QIOPEN=" );
72
+ _at.write_int (_cid);
73
+ _at.write_int (request_connect_id);
74
+ _at.write_string (" TCP" );
75
+ _at.write_string (address.get_ip_address ());
76
+ _at.write_int (address.get_port ());
77
+ _at.write_int (socket->localAddress .get_port ());
78
+ _at.write_int (0 );
79
+ _at.cmd_stop ();
80
+
81
+ handle_open_socket_response (modem_connect_id, err);
82
+ }
83
+ }
84
+
85
+ // If opened successfully BUT not requested one, close it
86
+ if (!err && (modem_connect_id != request_connect_id)) {
87
+ _at.cmd_start (" AT+QICLOSE=" );
88
+ _at.write_int (modem_connect_id);
89
+ _at.cmd_stop ();
90
+ _at.resp_start ();
91
+ _at.resp_stop ();
92
+ }
93
+
94
+ nsapi_error_t ret_val = _at.get_last_error ();
95
+ _at.unlock ();
96
+
97
+ if ((ret_val == NSAPI_ERROR_OK) && (modem_connect_id == request_connect_id)) {
98
+ socket->created = true ;
99
+ socket->remoteAddress = address;
100
+ socket->connected = true ;
101
+ return NSAPI_ERROR_OK;
102
+ }
103
+
104
+ return NSAPI_ERROR_NO_CONNECTION;
105
+ }
106
+
42
107
void QUECTEL_BG96_CellularStack::urc_qiurc ()
43
108
{
44
109
int sock_id = 0 ;
@@ -66,16 +131,18 @@ int QUECTEL_BG96_CellularStack::get_max_socket_count()
66
131
67
132
bool QUECTEL_BG96_CellularStack::is_protocol_supported (nsapi_protocol_t protocol)
68
133
{
69
- return (protocol == NSAPI_UDP);
134
+ return (protocol == NSAPI_UDP || protocol == NSAPI_TCP );
70
135
}
71
136
72
137
nsapi_error_t QUECTEL_BG96_CellularStack::socket_close_impl (int sock_id)
73
138
{
139
+ _at.set_at_timeout (BG96_CLOSE_SOCKET_TIMEOUT);
74
140
_at.cmd_start (" AT+QICLOSE=" );
75
141
_at.write_int (sock_id);
76
142
_at.cmd_stop ();
77
143
_at.resp_start ();
78
144
_at.resp_stop ();
145
+ _at.restore_at_timeout ();
79
146
80
147
return _at.get_last_error ();
81
148
}
@@ -198,8 +265,10 @@ nsapi_size_or_error_t QUECTEL_BG96_CellularStack::socket_sendto_impl(CellularSoc
198
265
_at.cmd_start (" AT+QISEND=" );
199
266
_at.write_int (socket->id );
200
267
_at.write_int (size);
201
- _at.write_string (address.get_ip_address ());
202
- _at.write_int (address.get_port ());
268
+ if (socket->proto == NSAPI_UDP) {
269
+ _at.write_string (address.get_ip_address ());
270
+ _at.write_int (address.get_port ());
271
+ }
203
272
_at.cmd_stop ();
204
273
205
274
_at.resp_start (" >" );
0 commit comments