diff options
| author | WangHuachen <[email protected]> | 2020-11-08 19:30:50 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-11-08 19:30:50 +0800 |
| commit | 9756c77f0447f9ce4f00a37600298a1f1fd90cda (patch) | |
| tree | 093247a1719c087dba33783be3a4ee44c1026b2d /components/net/at | |
| parent | 9545529b33cbaae137f1e389dd0e3a5233d516da (diff) | |
| parent | 4b2b9a87c6f0a87b125e5c5a18bcfcf663de9fbb (diff) | |
Merge pull request #1 from RT-Thread/master
同步原有仓库
Diffstat (limited to 'components/net/at')
| -rw-r--r-- | components/net/at/Kconfig | 2 | ||||
| -rw-r--r-- | components/net/at/at_socket/at_socket.c | 42 | ||||
| -rw-r--r-- | components/net/at/at_socket/at_socket.h | 2 | ||||
| -rw-r--r-- | components/net/at/include/at.h | 2 | ||||
| -rw-r--r-- | components/net/at/src/at_client.c | 5 |
5 files changed, 32 insertions, 21 deletions
diff --git a/components/net/at/Kconfig b/components/net/at/Kconfig index 92818331af..4aedbb888b 100644 --- a/components/net/at/Kconfig +++ b/components/net/at/Kconfig @@ -82,7 +82,7 @@ if RT_USING_AT config AT_SW_VERSION_NUM hex - default 0x10300 + default 0x10301 help software module version number diff --git a/components/net/at/at_socket/at_socket.c b/components/net/at/at_socket/at_socket.c index 11be4e23c0..666b0f509e 100644 --- a/components/net/at/at_socket/at_socket.c +++ b/components/net/at/at_socket/at_socket.c @@ -302,7 +302,7 @@ static int alloc_empty_socket(rt_slist_t *l) return idx; } -static struct at_socket *alloc_socket_by_device(struct at_device *device) +static struct at_socket *alloc_socket_by_device(struct at_device *device, enum at_socket_type type) { static rt_mutex_t at_slock = RT_NULL; struct at_socket *sock = RT_NULL; @@ -323,14 +323,21 @@ static struct at_socket *alloc_socket_by_device(struct at_device *device) rt_mutex_take(at_slock, RT_WAITING_FOREVER); /* find an empty at socket entry */ - for (idx = 0; idx < device->class->socket_num && device->sockets[idx].magic; idx++); + if (device->class->socket_ops->at_socket != RT_NULL) + { + idx = device->class->socket_ops->at_socket(device, type); + } + else + { + for (idx = 0; idx < device->class->socket_num && device->sockets[idx].magic; idx++); + } /* can't find an empty protocol family entry */ - if (idx == device->class->socket_num) + if (idx < 0 || idx >= device->class->socket_num) { goto __err; } - + sock = &(device->sockets[idx]); /* the socket descriptor is the number of sockte lists */ sock->socket = alloc_empty_socket(&(sock->list)); @@ -374,7 +381,7 @@ __err: return RT_NULL; } -static struct at_socket *alloc_socket(void) +static struct at_socket *alloc_socket(enum at_socket_type type) { extern struct netdev *netdev_default; struct netdev *netdev = RT_NULL; @@ -401,9 +408,12 @@ static struct at_socket *alloc_socket(void) return RT_NULL; } - return alloc_socket_by_device(device); + return alloc_socket_by_device(device, type); } +static void at_recv_notice_cb(struct at_socket *sock, at_socket_evt_t event, const char *buff, size_t bfsz); +static void at_closed_notice_cb(struct at_socket *sock, at_socket_evt_t event, const char *buff, size_t bfsz); + int at_socket(int domain, int type, int protocol) { struct at_socket *sock = RT_NULL; @@ -430,7 +440,7 @@ int at_socket(int domain, int type, int protocol) } /* allocate and initialize a new AT socket */ - sock = alloc_socket(); + sock = alloc_socket(socket_type); if (sock == RT_NULL) { return -1; @@ -438,6 +448,10 @@ int at_socket(int domain, int type, int protocol) sock->type = socket_type; sock->state = AT_SOCKET_OPEN; + /* set AT socket receive data callback function */ + sock->ops->at_set_event_cb(AT_SOCKET_EVT_RECV, at_recv_notice_cb); + sock->ops->at_set_event_cb(AT_SOCKET_EVT_CLOSED, at_closed_notice_cb); + return sock->socket; } @@ -608,7 +622,7 @@ int at_bind(int socket, const struct sockaddr *name, socklen_t namelen) } /* allocate new socket */ - new_sock = alloc_socket_by_device(new_device); + new_sock = alloc_socket_by_device(new_device, type); if (new_sock == RT_NULL) { return -1; @@ -703,10 +717,6 @@ int at_connect(int socket, const struct sockaddr *name, socklen_t namelen) sock->state = AT_SOCKET_CONNECT; - /* set AT socket receive data callback function */ - sock->ops->at_set_event_cb(AT_SOCKET_EVT_RECV, at_recv_notice_cb); - sock->ops->at_set_event_cb(AT_SOCKET_EVT_CLOSED, at_closed_notice_cb); - __exit: if (result < 0) @@ -744,7 +754,7 @@ int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *f goto __exit; } - /* if the socket type is UDP, nead to connect socket first */ + /* if the socket type is UDP, need to connect socket first */ if (from && sock->type == AT_SOCKET_UDP && sock->state == AT_SOCKET_OPEN) { ip_addr_t remote_addr; @@ -760,9 +770,6 @@ int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *f goto __exit; } sock->state = AT_SOCKET_CONNECT; - /* set AT socket receive data callback function */ - sock->ops->at_set_event_cb(AT_SOCKET_EVT_RECV, at_recv_notice_cb); - sock->ops->at_set_event_cb(AT_SOCKET_EVT_CLOSED, at_closed_notice_cb); } /* receive packet list last transmission of remaining data */ @@ -924,9 +931,6 @@ int at_sendto(int socket, const void *data, size_t size, int flags, const struct goto __exit; } sock->state = AT_SOCKET_CONNECT; - /* set AT socket receive data callback function */ - sock->ops->at_set_event_cb(AT_SOCKET_EVT_RECV, at_recv_notice_cb); - sock->ops->at_set_event_cb(AT_SOCKET_EVT_CLOSED, at_closed_notice_cb); } if ((len = sock->ops->at_send(sock, (char *) data, size, sock->type)) < 0) diff --git a/components/net/at/at_socket/at_socket.h b/components/net/at/at_socket/at_socket.h index d98fa05f24..3317579f05 100644 --- a/components/net/at/at_socket/at_socket.h +++ b/components/net/at/at_socket/at_socket.h @@ -56,6 +56,7 @@ typedef enum } at_socket_evt_t; struct at_socket; +struct at_device; typedef void (*at_evt_cb_t)(struct at_socket *socket, at_socket_evt_t event, const char *buff, size_t bfsz); @@ -70,6 +71,7 @@ struct at_socket_ops int (*at_send)(struct at_socket *socket, const char *buff, size_t bfsz, enum at_socket_type type); int (*at_domain_resolve)(const char *name, char ip[16]); void (*at_set_event_cb)(at_socket_evt_t event, at_evt_cb_t cb); + int (*at_socket)(struct at_device *device, enum at_socket_type type); }; /* AT receive package list structure */ diff --git a/components/net/at/include/at.h b/components/net/at/include/at.h index a7a6aeca7a..2d0e270f6a 100644 --- a/components/net/at/include/at.h +++ b/components/net/at/include/at.h @@ -18,7 +18,7 @@ extern "C" { #endif -#define AT_SW_VERSION "1.3.0" +#define AT_SW_VERSION "1.3.1" #define AT_CMD_NAME_LEN 16 #define AT_END_MARK_LEN 4 diff --git a/components/net/at/src/at_client.c b/components/net/at/src/at_client.c index ba4009738d..788549392d 100644 --- a/components/net/at/src/at_client.c +++ b/components/net/at/src/at_client.c @@ -917,6 +917,11 @@ int at_client_init(const char *dev_name, rt_size_t recv_bufsz) RT_ASSERT(dev_name); RT_ASSERT(recv_bufsz > 0); + if (at_client_get(dev_name) != RT_NULL) + { + return result; + } + for (idx = 0; idx < AT_CLIENT_NUM_MAX && at_client_table[idx].device; idx++); if (idx >= AT_CLIENT_NUM_MAX) |
