@@ -41,6 +41,36 @@ nsapi_error_t QUECTEL_BC95_CellularStack::socket_accept(void *server, void **soc
41
41
return NSAPI_ERROR_UNSUPPORTED;
42
42
}
43
43
44
+ nsapi_error_t QUECTEL_BC95_CellularStack::socket_connect (nsapi_socket_t handle, const SocketAddress &address)
45
+ {
46
+ CellularSocket *socket = (CellularSocket *)handle;
47
+
48
+ _at.lock ();
49
+ if (!socket->created ) {
50
+ const nsapi_error_t error_create = create_socket_impl (socket);
51
+ if (error_create != NSAPI_ERROR_OK) {
52
+ return error_create;
53
+ }
54
+ }
55
+
56
+ _at.cmd_start (" AT+NSOCO=" );
57
+ _at.write_int (socket->id );
58
+ _at.write_string (address.get_ip_address (), false );
59
+ _at.write_int (address.get_port ());
60
+ _at.cmd_stop ();
61
+ _at.resp_start ();
62
+ _at.resp_stop ();
63
+ _at.unlock ();
64
+
65
+ if (_at.get_last_error () == NSAPI_ERROR_OK) {
66
+ socket->remoteAddress = address;
67
+ socket->connected = true ;
68
+ return NSAPI_ERROR_OK;
69
+ }
70
+
71
+ return NSAPI_ERROR_NO_CONNECTION;
72
+ }
73
+
44
74
void QUECTEL_BC95_CellularStack::urc_nsonmi ()
45
75
{
46
76
int sock_id = _at.read_int ();
@@ -63,7 +93,7 @@ int QUECTEL_BC95_CellularStack::get_max_socket_count()
63
93
64
94
bool QUECTEL_BC95_CellularStack::is_protocol_supported (nsapi_protocol_t protocol)
65
95
{
66
- return (protocol == NSAPI_UDP);
96
+ return (protocol == NSAPI_UDP || protocol == NSAPI_TCP );
67
97
}
68
98
69
99
nsapi_error_t QUECTEL_BC95_CellularStack::socket_close_impl (int sock_id)
@@ -85,8 +115,32 @@ nsapi_error_t QUECTEL_BC95_CellularStack::create_socket_impl(CellularSocket *soc
85
115
bool socketOpenWorking = false ;
86
116
87
117
if (socket->proto == NSAPI_UDP) {
88
-
89
118
_at.cmd_start (" AT+NSOCR=DGRAM,17," );
119
+ } else if (socket->proto == NSAPI_TCP) {
120
+ _at.cmd_start (" AT+NSOCR=STREAM,6," );
121
+ } else {
122
+ return NSAPI_ERROR_PARAMETER;
123
+ }
124
+ _at.write_int (socket->localAddress .get_port ());
125
+ _at.write_int (1 );
126
+ _at.cmd_stop ();
127
+ _at.resp_start ();
128
+ sock_id = _at.read_int ();
129
+ _at.resp_stop ();
130
+
131
+ socketOpenWorking = (_at.get_last_error () == NSAPI_ERROR_OK);
132
+
133
+ if (!socketOpenWorking) {
134
+ _at.cmd_start (" AT+NSOCL=0" );
135
+ _at.cmd_stop ();
136
+ _at.resp_start ();
137
+ _at.resp_stop ();
138
+
139
+ if (socket->proto == NSAPI_UDP) {
140
+ _at.cmd_start (" AT+NSOCR=DGRAM,17," );
141
+ } else if (socket->proto == NSAPI_TCP) {
142
+ _at.cmd_start (" AT+NSOCR=STREAM,6," );
143
+ }
90
144
_at.write_int (socket->localAddress .get_port ());
91
145
_at.write_int (1 );
92
146
_at.cmd_stop ();
@@ -95,23 +149,6 @@ nsapi_error_t QUECTEL_BC95_CellularStack::create_socket_impl(CellularSocket *soc
95
149
_at.resp_stop ();
96
150
97
151
socketOpenWorking = (_at.get_last_error () == NSAPI_ERROR_OK);
98
-
99
- if (!socketOpenWorking) {
100
- _at.cmd_start (" AT+NSOCL=0" );
101
- _at.cmd_stop ();
102
- _at.resp_start ();
103
- _at.resp_stop ();
104
-
105
- _at.cmd_start (" AT+NSOCR=DGRAM,17," );
106
- _at.write_int (socket->localAddress .get_port ());
107
- _at.write_int (1 );
108
- _at.cmd_stop ();
109
- _at.resp_start ();
110
- sock_id = _at.read_int ();
111
- _at.resp_stop ();
112
-
113
- socketOpenWorking = (_at.get_last_error () == NSAPI_ERROR_OK);
114
- }
115
152
}
116
153
117
154
if (!socketOpenWorking || (sock_id == -1 )) {
@@ -145,11 +182,22 @@ nsapi_size_or_error_t QUECTEL_BC95_CellularStack::socket_sendto_impl(CellularSoc
145
182
int hexlen = char_str_to_hex_str ((const char *)data, size, hexstr);
146
183
// NULL terminated for write_string
147
184
hexstr[hexlen] = 0 ;
148
- _at.cmd_start (" AT+NSOST=" );
149
- _at.write_int (socket->id );
150
- _at.write_string (address.get_ip_address (), false );
151
- _at.write_int (address.get_port ());
152
- _at.write_int (size);
185
+
186
+ if (socket->proto == NSAPI_UDP) {
187
+ _at.cmd_start (" AT+NSOST=" );
188
+ _at.write_int (socket->id );
189
+ _at.write_string (address.get_ip_address (), false );
190
+ _at.write_int (address.get_port ());
191
+ _at.write_int (size);
192
+ } else if (socket->proto == NSAPI_TCP) {
193
+ _at.cmd_start (" AT+NSOSD=" );
194
+ _at.write_int (socket->id );
195
+ _at.write_int (size);
196
+ } else {
197
+ delete hexstr;
198
+ return NSAPI_ERROR_PARAMETER;
199
+ }
200
+
153
201
_at.write_string (hexstr, false );
154
202
_at.cmd_stop ();
155
203
_at.resp_start ();
0 commit comments