AWS IoT demonstration using the Avnet Shield (AT&T LTE) and the FRDM-K64F target board.
Dependencies: K64F_FATFileSystem
Fork of mbed-os-example-tls-tls-client by
WNCEndpoint.cpp
00001 /* ===================================================================== 00002 Copyright © 2016, Avnet (R) 00003 00004 Contributors: 00005 * James M Flynn, www.em.avnet.com 00006 00007 Licensed under the Apache License, Version 2.0 (the "License"); 00008 you may not use this file except in compliance with the License. 00009 You may obtain a copy of the License at 00010 00011 http://www.apache.org/licenses/LICENSE-2.0 00012 00013 Unless required by applicable law or agreed to in writing, 00014 software distributed under the License is distributed on an 00015 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 00016 either express or implied. See the License for the specific 00017 language governing permissions and limitations under the License. 00018 00019 @file WNCInterface.cpp 00020 @version 1.0 00021 @date Sept 2016 00022 00023 ======================================================================== */ 00024 00025 #include "../WNCInterface.h" 00026 #include "WNCSocket.h" 00027 #include "WNCEndpoint.h" 00028 00029 WNCEndpoint::WNCEndpoint() { 00030 reset_address(); 00031 } 00032 00033 WNCEndpoint::~WNCEndpoint() {} 00034 00035 void WNCEndpoint::reset_address(void) { 00036 std::memset(&_epAddr, 0, sizeof(struct EndPointAddr)); 00037 } 00038 00039 // 00040 // It is possible to call set_address with either a URL or 00041 // an IP address. So try each in-turn and set the end point 00042 // address. 00043 // 00044 00045 int WNCEndpoint::set_address(const char* host, const int port) { 00046 // IP Address 00047 char address[5]; 00048 int rslt; 00049 00050 CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), fail); 00051 00052 reset_address(); 00053 _epAddr.port = port; //go ahead and save the port 00054 00055 // Dot-decimal notation? 00056 rslt = std::sscanf(host, "%3u.%3u.%3u.%3u", 00057 (unsigned int*)&address[0], (unsigned int*)&address[1], 00058 (unsigned int*)&address[2], (unsigned int*)&address[3]); 00059 00060 M_LOCK; 00061 if (rslt != 4) // No, need to resolve address with DNS 00062 WNCInterface::_pwnc->resolveUrl(0,host); 00063 else 00064 WNCInterface::_pwnc->setIpAddr(0,host); 00065 00066 rslt = WNCInterface::_pwnc->getIpAddr(0,_epAddr.IP); 00067 M_ULOCK; 00068 return rslt; 00069 } 00070 00071 char* WNCEndpoint::get_address() { 00072 return _epAddr.IP; 00073 } 00074 00075 int WNCEndpoint::get_port() { 00076 return _epAddr.port; 00077 } 00078 00079
Generated on Wed Jul 13 2022 00:34:50 by 1.7.2