takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers UBLOX_AT_CellularStack.h Source File

UBLOX_AT_CellularStack.h

00001 /*
00002  * Copyright (c) 2018, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 #ifndef UBLOX_AT_CELLULARSTACK_H_
00018 #define UBLOX_AT_CELLULARSTACK_H_
00019 
00020 #include "AT_CellularStack.h"
00021 #include "CellularUtil.h"
00022 #include "mbed_wait_api.h"
00023 #include "drivers/Timer.h"
00024 
00025 
00026 namespace mbed
00027 {
00028 
00029 class UBLOX_AT_CellularStack : public AT_CellularStack
00030 {
00031 public:
00032     UBLOX_AT_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type);
00033     virtual ~UBLOX_AT_CellularStack();
00034 
00035     virtual const char *get_ip_address();
00036 
00037     virtual nsapi_error_t gethostbyname(const char *host,
00038                                         SocketAddress *address, nsapi_version_t version = NSAPI_UNSPEC );
00039 
00040 protected:
00041     virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog);
00042 
00043     virtual nsapi_error_t socket_accept(nsapi_socket_t server,
00044                                         nsapi_socket_t *handle, SocketAddress *address=0);
00045 
00046 protected: // AT_CellularStack
00047 
00048     /** The profile to use (on board the modem).
00049      */
00050 #define PROFILE "0"
00051 
00052     /** Socket "unused" value.
00053      */
00054     static const int SOCKET_UNUSED = -1;
00055 
00056     /** Socket timeout value in milliseconds.
00057      * Note: the sockets layer above will retry the
00058      * call to the functions here when they return NSAPI_ERROR_WOULD_BLOCK
00059      * and the user has set a larger timeout or full blocking.
00060      */
00061     static const int SOCKET_TIMEOUT = 1000;
00062 
00063     /** Maximum allowed sockets.
00064      */
00065     static const int UBLOX_MAX_SOCKET = 7;
00066 
00067     /** The maximum number of bytes in a packet that can be write/read from
00068      * the AT interface in one go.
00069      */
00070     static const int UBLOX_MAX_PACKET_SIZE = 1024;
00071 
00072     virtual int get_max_socket_count();
00073 
00074     virtual bool is_protocol_supported(nsapi_protocol_t protocol);
00075 
00076     virtual nsapi_error_t create_socket_impl(CellularSocket *socket);
00077 
00078     virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address);
00079 
00080     virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
00081             const void *data, nsapi_size_t size);
00082 
00083     virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
00084             void *buffer, nsapi_size_t size);
00085 
00086     virtual nsapi_error_t socket_close_impl(int sock_id);
00087 
00088 private:
00089     // URC handlers
00090     void UUSORD_URC();
00091     void UUSORF_URC();
00092     void UUSOCL_URC();
00093     void UUPSDD_URC();
00094 
00095     /** Find a socket from the list.
00096      *
00097      * @param id       Socket ID.
00098      * @return         Socket if True, otherwise NULL.
00099      */
00100     CellularSocket * find_socket(int id = SOCKET_UNUSED);
00101 
00102     /** Clear out the storage for a socket.
00103      *
00104      * @param id       Cellular Socket.
00105      * @return         None
00106      */
00107     void clear_socket(CellularSocket * socket);
00108 };
00109 } // namespace mbed
00110 #endif /* UBLOX_AT_CELLULARSTACK_H_ */