mbed Connector Interface simplification API on top of mbed-client
Fork of mbedConnectorInterfaceV3 by
NOTE:
This repo has been replaced with https://github.com/ARMmbed/mbedConnectorInterface. No further updates will occur with this repo. Please use the github repo instead. Thanks!
Diff: source/ConnectorEndpoint.cpp
- Revision:
- 10:3f79b5e67c22
- Parent:
- 8:f950fb1b78c0
- Child:
- 13:9edad7677211
--- a/source/ConnectorEndpoint.cpp Wed Feb 24 14:50:03 2016 +0000 +++ b/source/ConnectorEndpoint.cpp Fri Mar 04 19:16:57 2016 +0000 @@ -124,17 +124,39 @@ // mbed-client: create our interface void Endpoint::create_interface() { + // get the CoAP listening port + uint16_t listening_port = (uint16_t)this->m_options->getConnectorPort(); + + // randomize the port if we are using certificates... + if (this->m_options->getServerCertificateSize() > 0) { // Randomizing listening port for Certificate mode connectivity srand(time(NULL)); - uint16_t port = rand() % 65535 + 12345; - this->m_interface = M2MInterfaceFactory::create_interface(*this, - (char *)this->m_options->getEndpointNodename().c_str(), - (char *)this->m_options->getEndpointType().c_str(), - (int32_t)this->m_options->getLifetime(), - port, - (char *)this->m_options->getDomain().c_str(), - M2MInterface::UDP, - M2MInterface::LwIP_IPv4); + listening_port = rand() % 65535 + 12345; + } + + // Binding Mode - TCP or UDP + M2MInterface::BindingMode network_protocol = M2MInterface::UDP; + if (this->m_options->getCoAPConnectionType() == COAP_TCP) network_protocol = M2MInterface::TCP; + + // Network Type IPv4 or IPv6 + M2MInterface::NetworkStack ip_address_type = M2MInterface::LwIP_IPv4; + if (this->m_options->getIPAddressType() == IP_ADDRESS_TYPE_IPV6) ip_address_type = M2MInterface::LwIP_IPv6; + + // DEBUG + if (network_protocol == M2MInterface::TCP) this->logger()->log("Endpoint: Underlying Protocol: TCP"); + if (network_protocol == M2MInterface::UDP) this->logger()->log("Endpoint: Underlying Protocol: UDP"); + if (ip_address_type == M2MInterface::LwIP_IPv4) this->logger()->log("Endpoint: IP Address Type: IPv4"); + if (ip_address_type == M2MInterface::LwIP_IPv6) this->logger()->log("Endpoint: IP Address Type: IPv6"); + + // Create the M2M Interface instance + this->m_interface = M2MInterfaceFactory::create_interface(*this, + (char *)this->m_options->getEndpointNodename().c_str(), + (char *)this->m_options->getEndpointType().c_str(), + (int32_t)this->m_options->getLifetime(), + listening_port, // listening port + (char *)this->m_options->getDomain().c_str(), + network_protocol, // CoAP over UDP or TCP... + ip_address_type); // IPv4 addressing or IPv6 addressing } // mbed-client: create_server_instance()