Andrew Reed
/
CITY1082-i2c_master_wifi_mqtt
CITY3032-wifi-mqtt
src/MQTTSNNetworkUDP.h@5:f62a9e4a499a, 2021-11-13 (annotated)
- Committer:
- reedas
- Date:
- Sat Nov 13 12:02:49 2021 +0000
- Revision:
- 5:f62a9e4a499a
- Parent:
- 3:62825c5f3cd7
trying to include mbed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
reedas | 3:62825c5f3cd7 | 1 | /* |
reedas | 3:62825c5f3cd7 | 2 | * Copyright (c) 2019, ARM Limited, All Rights Reserved |
reedas | 3:62825c5f3cd7 | 3 | * SPDX-License-Identifier: Apache-2.0 |
reedas | 3:62825c5f3cd7 | 4 | * |
reedas | 3:62825c5f3cd7 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
reedas | 3:62825c5f3cd7 | 6 | * not use this file except in compliance with the License. |
reedas | 3:62825c5f3cd7 | 7 | * You may obtain a copy of the License at |
reedas | 3:62825c5f3cd7 | 8 | * |
reedas | 3:62825c5f3cd7 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
reedas | 3:62825c5f3cd7 | 10 | * |
reedas | 3:62825c5f3cd7 | 11 | * Unless required by applicable law or agreed to in writing, software |
reedas | 3:62825c5f3cd7 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
reedas | 3:62825c5f3cd7 | 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
reedas | 3:62825c5f3cd7 | 14 | * See the License for the specific language governing permissions and |
reedas | 3:62825c5f3cd7 | 15 | * limitations under the License. |
reedas | 3:62825c5f3cd7 | 16 | */ |
reedas | 3:62825c5f3cd7 | 17 | |
reedas | 3:62825c5f3cd7 | 18 | #ifndef _MQTTNETWORKUDP_H_ |
reedas | 3:62825c5f3cd7 | 19 | #define _MQTTNETWORKUDP_H_ |
reedas | 3:62825c5f3cd7 | 20 | |
reedas | 3:62825c5f3cd7 | 21 | #include "UDPSocket.h" |
reedas | 3:62825c5f3cd7 | 22 | |
reedas | 3:62825c5f3cd7 | 23 | class MQTTSNNetworkUDP { |
reedas | 3:62825c5f3cd7 | 24 | public: |
reedas | 3:62825c5f3cd7 | 25 | MQTTSNNetworkUDP(NetworkInterface *net) : |
reedas | 3:62825c5f3cd7 | 26 | network(net) |
reedas | 3:62825c5f3cd7 | 27 | { |
reedas | 3:62825c5f3cd7 | 28 | socket = new UDPSocket(); |
reedas | 3:62825c5f3cd7 | 29 | } |
reedas | 3:62825c5f3cd7 | 30 | |
reedas | 3:62825c5f3cd7 | 31 | ~MQTTSNNetworkUDP() |
reedas | 3:62825c5f3cd7 | 32 | { |
reedas | 3:62825c5f3cd7 | 33 | delete socket; |
reedas | 3:62825c5f3cd7 | 34 | } |
reedas | 3:62825c5f3cd7 | 35 | |
reedas | 3:62825c5f3cd7 | 36 | int read(unsigned char *buffer, int len, int timeout) |
reedas | 3:62825c5f3cd7 | 37 | { |
reedas | 3:62825c5f3cd7 | 38 | return socket->recv(buffer, len); |
reedas | 3:62825c5f3cd7 | 39 | } |
reedas | 3:62825c5f3cd7 | 40 | |
reedas | 3:62825c5f3cd7 | 41 | int write(unsigned char *buffer, int len, int timeout) |
reedas | 3:62825c5f3cd7 | 42 | { |
reedas | 3:62825c5f3cd7 | 43 | return socket->send(buffer, len); |
reedas | 3:62825c5f3cd7 | 44 | } |
reedas | 3:62825c5f3cd7 | 45 | |
reedas | 3:62825c5f3cd7 | 46 | int connect(const char *hostname, int port) |
reedas | 3:62825c5f3cd7 | 47 | { |
reedas | 3:62825c5f3cd7 | 48 | socket->open(network); |
reedas | 3:62825c5f3cd7 | 49 | SocketAddress addr(hostname, port); |
reedas | 3:62825c5f3cd7 | 50 | return socket->connect(addr); |
reedas | 3:62825c5f3cd7 | 51 | } |
reedas | 3:62825c5f3cd7 | 52 | |
reedas | 3:62825c5f3cd7 | 53 | int disconnect(void) |
reedas | 3:62825c5f3cd7 | 54 | { |
reedas | 3:62825c5f3cd7 | 55 | return 0; |
reedas | 3:62825c5f3cd7 | 56 | } |
reedas | 3:62825c5f3cd7 | 57 | |
reedas | 3:62825c5f3cd7 | 58 | private: |
reedas | 3:62825c5f3cd7 | 59 | NetworkInterface *network; |
reedas | 3:62825c5f3cd7 | 60 | UDPSocket *socket; |
reedas | 3:62825c5f3cd7 | 61 | }; |
reedas | 3:62825c5f3cd7 | 62 | |
reedas | 3:62825c5f3cd7 | 63 | #endif // _MQTTNETWORKUDP_H_ |