Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

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 "rtos/ThisThread.h"
00023 #include "drivers/Timer.h"
00024 
00025 
00026 namespace mbed {
00027 
00028 class UBLOX_AT_CellularStack : public AT_CellularStack {
00029 public:
00030     UBLOX_AT_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type, AT_CellularDevice &device);
00031     virtual ~UBLOX_AT_CellularStack();
00032 
00033     virtual const char *get_ip_address();
00034 
00035     virtual nsapi_error_t gethostbyname(const char *host,
00036                                         SocketAddress *address, nsapi_version_t version = NSAPI_UNSPEC , const char *interface_name = NULL);
00037 
00038 protected:
00039     virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog);
00040 
00041     virtual nsapi_error_t socket_accept(nsapi_socket_t server,
00042                                         nsapi_socket_t *handle, SocketAddress *address = 0);
00043 
00044 protected: // AT_CellularStack
00045 
00046     /** The profile to use (on board the modem).
00047      */
00048 #define PROFILE 0
00049 
00050     /** Socket "unused" value.
00051      */
00052     static const int SOCKET_UNUSED = -1;
00053 
00054     /** Socket timeout value in milliseconds.
00055      * Note: the sockets layer above will retry the
00056      * call to the functions here when they return NSAPI_ERROR_WOULD_BLOCK
00057      * and the user has set a larger timeout or full blocking.
00058      */
00059     static const int SOCKET_TIMEOUT = 1000;
00060 
00061     /** Maximum allowed sockets.
00062      */
00063     static const int UBLOX_MAX_SOCKET = 7;
00064 
00065     /** The maximum number of bytes in a packet that can be write/read from
00066      * the AT interface in one go.
00067      */
00068     static const int UBLOX_MAX_PACKET_SIZE = 1024;
00069 
00070     virtual int get_max_socket_count();
00071 
00072     virtual bool is_protocol_supported(nsapi_protocol_t protocol);
00073 
00074     virtual nsapi_error_t create_socket_impl(CellularSocket *socket);
00075 
00076     virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address);
00077 
00078     virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
00079                                                      const void *data, nsapi_size_t size);
00080 
00081     virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
00082                                                        void *buffer, nsapi_size_t size);
00083 
00084     virtual nsapi_error_t socket_close_impl(int sock_id);
00085 
00086 private:
00087     // URC handlers
00088     void UUSORD_URC();
00089     void UUSORF_URC();
00090     void UUSOCL_URC();
00091     void UUPSDD_URC();
00092 
00093     /** Find a socket from the list.
00094      *
00095      * @param id       Socket ID.
00096      * @return         Socket if True, otherwise NULL.
00097      */
00098     CellularSocket *find_socket(int id = SOCKET_UNUSED);
00099 
00100     /** Clear out the storage for a socket.
00101      *
00102      * @param id       Cellular Socket.
00103      * @return         None
00104      */
00105     void clear_socket(CellularSocket *socket);
00106 };
00107 } // namespace mbed
00108 #endif /* UBLOX_AT_CELLULARSTACK_H_ */