Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions class/a9g/at_socket_a9g.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,9 @@ static const struct at_socket_ops a9g_socket_ops =
a9g_socket_send,
a9g_domain_resolve,
a9g_socket_set_event_cb,
#if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
RT_NULL,
#endif
};

int a9g_socket_init(struct at_device *device)
Expand Down
15 changes: 9 additions & 6 deletions class/air720/at_socket_air720.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,15 @@ static const struct at_urc urc_table[] =
};

static const struct at_socket_ops air720_socket_ops =
{
air720_socket_connect,
air720_socket_close,
air720_socket_send,
air720_domain_resolve,
air720_socket_set_event_cb,
{
air720_socket_connect,
air720_socket_close,
air720_socket_send,
air720_domain_resolve,
air720_socket_set_event_cb,
#if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
RT_NULL,
#endif
};

int air720_socket_init(struct at_device *device)
Expand Down
3 changes: 3 additions & 0 deletions class/bc26/at_socket_bc26.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,9 @@ static const struct at_socket_ops bc26_socket_ops =
bc26_socket_send,
bc26_domain_resolve,
bc26_socket_set_event_cb,
#if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
RT_NULL,
#endif
};

int bc26_socket_init(struct at_device *device)
Expand Down
15 changes: 15 additions & 0 deletions class/bc28/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# BC28

## 注意事项

### 申请 socket

- BC28 最多支持 7 个 socket,编号 0-6;
- 如果 BC28 使用支持 MQTT 或 CoAP 协议的固件,则相关服务会占用部分 socket,因此最小可用的 socket 并不一定是 0;
- 可以创建 1 个 UDP socket,多个 TCP socket;
- 另外,执行 DNS 域名解析时也会占用 socket;

### 连接 socket

- R02 的基线版本固件才支持 `AT+QTCPIND` 查询 TCP 连接情况,因此目前采用保守的 30 秒延时来确保连接状态;

5 changes: 4 additions & 1 deletion class/bc28/at_device_bc28.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@

#include <stdio.h>
#include <string.h>

#include <at_device_bc28.h>

#if !defined(AT_SW_VERSION_NUM) || AT_SW_VERSION_NUM < 0x10301
#error "This AT Client version is older, please check and update latest AT Client!"
#endif

#define LOG_TAG "at.dev.bc28"
#include <at_log.h>

Expand Down
53 changes: 17 additions & 36 deletions class/bc28/at_socket_bc28.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@
* Change Logs:
* Date Author Notes
* 2020-02-13 luhuadong first version
* 2020-07-19 luhuadong support alloc socket
*/

#include <stdio.h>
#include <string.h>

#include <at_device_bc28.h>

#if !defined(AT_SW_VERSION_NUM) || AT_SW_VERSION_NUM < 0x10301
#error "This AT Client version is older, please check and update latest AT Client!"
#endif

#define LOG_TAG "at.skt.bc28"
#include <at_log.h>

Expand Down Expand Up @@ -194,7 +198,7 @@ static int bc28_socket_close(struct at_socket *socket)
{
int result = RT_EOK;
at_response_t resp = RT_NULL;
int device_socket = (int) socket->user_data + AT_DEVICE_BC28_MIN_SOCKET;
int device_socket = (int) socket->user_data;
struct at_device *device = (struct at_device *) socket->device;

resp = at_create_resp(64, 0, rt_tick_from_millisecond(3000));
Expand Down Expand Up @@ -223,16 +227,16 @@ static int bc28_socket_close(struct at_socket *socket)
* create socket by AT commands.
*
* @param type connect socket type(tcp, udp)
* @param port listen port (range: 0-65535), if 0 means get a random port
*
* @return >=0: create socket success, return the socket id (0-6)
* -1: send or exec AT commands error
* -5: no memory
*/
static int bc28_socket_create(struct at_device *device, enum at_socket_type type, uint32_t port)
static int bc28_socket_create(struct at_device *device, enum at_socket_type type)
{
const char *type_str = RT_NULL;
uint32_t protocol = 0;
uint32_t port = 0; /* range: 0-65535, if 0 means get a random port */
at_response_t resp = RT_NULL;
int socket = -1, result = 0;

Expand Down Expand Up @@ -309,7 +313,7 @@ static int bc28_socket_connect(struct at_socket *socket, char *ip, int32_t port,
uint32_t event = 0;
at_response_t resp = RT_NULL;
int result = 0, event_result = 0;
int device_socket = (int) socket->user_data + AT_DEVICE_BC28_MIN_SOCKET;
int device_socket = (int) socket->user_data;
int return_socket = -1;
struct at_device *device = (struct at_device *) socket->device;

Expand All @@ -328,32 +332,6 @@ static int bc28_socket_connect(struct at_socket *socket, char *ip, int32_t port,
return -RT_ENOMEM;
}

return_socket = bc28_socket_create(device, type, 0);

if (return_socket != device_socket)
{
LOG_E("socket not match (request %d, return %d).", device_socket, return_socket);

result = at_obj_exec_cmd(device->client, resp, "AT+NSOCL=%d", return_socket);
if (result < 0)
{
LOG_E("%s device close socket(%d) failed [%d].", device->name, return_socket, result);
}
else
{
LOG_D("%s device close socket(%d).", device->name, return_socket);

/* notice the socket is disconnect by remote */
if (at_evt_cb_set[AT_SOCKET_EVT_CLOSED])
{
at_evt_cb_set[AT_SOCKET_EVT_CLOSED](socket, AT_SOCKET_EVT_CLOSED, NULL, 0);
}
}

result = -RT_ERROR;
goto __exit;
}

/* if the protocol is not tcp, no need connect to server */
if (type != AT_SOCKET_TCP)
{
Expand Down Expand Up @@ -439,7 +417,7 @@ static int bc28_socket_send(struct at_socket *socket, const char *buff,
int result = 0, event_result = 0;
size_t cur_pkt_size = 0, sent_size = 0;
at_response_t resp = RT_NULL;
int device_socket = (int) socket->user_data + AT_DEVICE_BC28_MIN_SOCKET;
int device_socket = (int) socket->user_data;
struct at_device *device = (struct at_device *) socket->device;
struct at_device_bc28 *bc28 = (struct at_device_bc28 *) device->user_data;
rt_mutex_t lock = device->client->lock;
Expand Down Expand Up @@ -748,10 +726,10 @@ static void urc_close_func(struct at_client *client, const char *data, rt_size_t

bc28_socket_event_send(device, SET_EVENT(device_socket, BC28_EVENT_CONN_FAIL));

if (device_socket - AT_DEVICE_BC28_MIN_SOCKET >= 0)
if (device_socket >= 0)
{
/* get at socket object by device socket descriptor */
socket = &(device->sockets[device_socket - AT_DEVICE_BC28_MIN_SOCKET]);
socket = &(device->sockets[device_socket]);

/* notice the socket is disconnect by remote */
if (at_evt_cb_set[AT_SOCKET_EVT_CLOSED])
Expand Down Expand Up @@ -828,7 +806,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
rt_free(hex_buf);

/* get at socket object by device socket descriptor */
socket = &(device->sockets[device_socket - AT_DEVICE_BC28_MIN_SOCKET]);
socket = &(device->sockets[device_socket]);

/* notice the receive buffer and buffer size */
if (at_evt_cb_set[AT_SOCKET_EVT_RECV])
Expand Down Expand Up @@ -900,6 +878,9 @@ static const struct at_socket_ops bc28_socket_ops =
bc28_socket_send,
bc28_domain_resolve,
bc28_socket_set_event_cb,
#if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
bc28_socket_create,
#endif
};

int bc28_socket_init(struct at_device *device)
Expand All @@ -916,7 +897,7 @@ int bc28_socket_class_register(struct at_device_class *class)
{
RT_ASSERT(class);

class->socket_num = AT_DEVICE_BC28_SOCKETS_NUM - AT_DEVICE_BC28_MIN_SOCKET;
class->socket_num = AT_DEVICE_BC28_SOCKETS_NUM;
class->socket_ops = &bc28_socket_ops;

return RT_EOK;
Expand Down
3 changes: 3 additions & 0 deletions class/ec20/at_socket_ec20.c
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,9 @@ static const struct at_socket_ops ec20_socket_ops =
ec20_socket_send,
ec20_domain_resolve,
ec20_socket_set_event_cb,
#if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
RT_NULL,
#endif
};

int ec20_socket_init(struct at_device *device)
Expand Down
3 changes: 3 additions & 0 deletions class/ec200x/at_socket_ec200x.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,9 @@ static const struct at_socket_ops ec200x_socket_ops =
ec200x_socket_send,
ec200x_domain_resolve,
ec200x_socket_set_event_cb,
#if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
RT_NULL,
#endif
};

int ec200x_socket_init(struct at_device *device)
Expand Down
3 changes: 3 additions & 0 deletions class/esp32/at_socket_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ static const struct at_socket_ops esp32_socket_ops =
esp32_socket_send,
esp32_domain_resolve,
esp32_socket_set_event_cb,
#if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
RT_NULL,
#endif
};

static void urc_send_func(struct at_client *client, const char *data, rt_size_t size)
Expand Down
3 changes: 3 additions & 0 deletions class/esp8266/at_socket_esp8266.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ static const struct at_socket_ops esp8266_socket_ops =
esp8266_socket_send,
esp8266_domain_resolve,
esp8266_socket_set_event_cb,
#if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
RT_NULL,
#endif
};

static void urc_send_func(struct at_client *client, const char *data, rt_size_t size)
Expand Down
3 changes: 3 additions & 0 deletions class/m26/at_socket_m26.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,9 @@ static const struct at_socket_ops m26_socket_ops =
m26_socket_send,
m26_domain_resolve,
m26_socket_set_event_cb,
#if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
RT_NULL,
#endif
};

int m26_socket_init(struct at_device *device)
Expand Down
3 changes: 3 additions & 0 deletions class/m5311/at_socket_m5311.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,9 @@ static const struct at_socket_ops m5311_socket_ops =
m5311_socket_send,
m5311_domain_resolve,
m5311_socket_set_event_cb,
#if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
RT_NULL,
#endif
};

int m5311_socket_init(struct at_device *device)
Expand Down
3 changes: 3 additions & 0 deletions class/m6315/at_socket_m6315.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,9 @@ static const struct at_socket_ops m6315_socket_ops =
m6315_socket_send,
m6315_domain_resolve,
m6315_socket_set_event_cb,
#if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
RT_NULL,
#endif
};

int m6315_socket_init(struct at_device *device)
Expand Down
3 changes: 3 additions & 0 deletions class/me3616/at_socket_me3616.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@ static const struct at_socket_ops me3616_socket_ops =
me3616_socket_send,
me3616_domain_resolve,
me3616_socket_set_event_cb,
#if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
RT_NULL,
#endif
};

int me3616_socket_init(struct at_device *device)
Expand Down
3 changes: 3 additions & 0 deletions class/mw31/at_socket_mw31.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ static const struct at_socket_ops mw31_socket_ops =
mw31_socket_send,
mw31_domain_resolve,
mw31_socket_set_event_cb,
#if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
RT_NULL,
#endif
};

static void urc_recv_func(struct at_client *client, const char *data, rt_size_t size)
Expand Down
34 changes: 18 additions & 16 deletions class/n21/at_socket_n21.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,25 +617,27 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t

/* n21 device URC table for the socket data */
static const struct at_urc urc_table[] =
{
{"+TCPSETUP:", "\r\n", urc_connect_func},
{"+UDPSETUP:", "\r\n", urc_connect_func},
{"+TCPSEND:", "\r\n", urc_send_func},
{"+UDPSEND:", "\r\n", urc_send_func},
{"+TCPCLOSE:", "\r\n", urc_close_func},
{"+UDPCLOSE:", "\r\n", urc_close_func},
{"+TCPRECV:", "\r\n", urc_recv_func},
{"+UDPRECV:", "\r\n", urc_recv_func},

{
{"+TCPSETUP:", "\r\n", urc_connect_func},
{"+UDPSETUP:", "\r\n", urc_connect_func},
{"+TCPSEND:", "\r\n", urc_send_func},
{"+UDPSEND:", "\r\n", urc_send_func},
{"+TCPCLOSE:", "\r\n", urc_close_func},
{"+UDPCLOSE:", "\r\n", urc_close_func},
{"+TCPRECV:", "\r\n", urc_recv_func},
{"+UDPRECV:", "\r\n", urc_recv_func},
};

static const struct at_socket_ops n21_socket_ops =
{
n21_socket_connect,
n21_socket_close,
n21_socket_send,
n21_domain_resolve,
n21_socket_set_event_cb,
{
n21_socket_connect,
n21_socket_close,
n21_socket_send,
n21_domain_resolve,
n21_socket_set_event_cb,
#if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
RT_NULL,
#endif
};

int n21_socket_init(struct at_device *device)
Expand Down
35 changes: 18 additions & 17 deletions class/n58/at_socket_n58.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,26 +624,27 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t

/* n58 device URC table for the socket data */
static const struct at_urc urc_table[] =
{

{"+TCPSETUP:", "\r\n", urc_connect_func},
{"+UDPSETUP:", "\r\n", urc_connect_func},
{"+TCPSEND:", "\r\n", urc_send_func},
{"+UDPSEND:", "\r\n", urc_send_func},
{"+TCPCLOSE:", "\r\n", urc_close_func},
{"+UDPCLOSE:", "\r\n", urc_close_func},
{"+TCPRECV:", "\r\n", urc_recv_func},
{"+UDPRECV:", "\r\n", urc_recv_func},

{
{"+TCPSETUP:", "\r\n", urc_connect_func},
{"+UDPSETUP:", "\r\n", urc_connect_func},
{"+TCPSEND:", "\r\n", urc_send_func},
{"+UDPSEND:", "\r\n", urc_send_func},
{"+TCPCLOSE:", "\r\n", urc_close_func},
{"+UDPCLOSE:", "\r\n", urc_close_func},
{"+TCPRECV:", "\r\n", urc_recv_func},
{"+UDPRECV:", "\r\n", urc_recv_func},
};

static const struct at_socket_ops n58_socket_ops =
{
n58_socket_connect,
n58_socket_close,
n58_socket_send,
n58_domain_resolve,
n58_socket_set_event_cb,
{
n58_socket_connect,
n58_socket_close,
n58_socket_send,
n58_domain_resolve,
n58_socket_set_event_cb,
#if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
RT_NULL,
#endif
};

int n58_socket_init(struct at_device *device)
Expand Down
3 changes: 3 additions & 0 deletions class/rw007/at_socket_rw007.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ static const struct at_socket_ops rw007_socket_ops =
rw007_socket_send,
rw007_domain_resolve,
rw007_socket_set_event_cb,
#if defined(AT_SW_VERSION_NUM) && AT_SW_VERSION_NUM > 0x10300
RT_NULL,
#endif
};

static void urc_send_func(struct at_client *client, const char *data, rt_size_t size)
Expand Down
Loading