Merge pull request #11200 from jarvte/move_string_to_pdp_type

Cellular: moved string_to_pdp_type from AT_CellularContext to Cellula…
pull/11178/head
Martin Kojtal 2019-08-14 12:53:20 +02:00 committed by GitHub
commit 0a73eda9d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 64 additions and 33 deletions

View File

@ -18,6 +18,7 @@
#include <string.h>
#include "CellularUtil.h"
using namespace mbed;
using namespace mbed_cellular_util;
// AStyle ignored as the definition is not clear due to preprocessor usage
@ -215,3 +216,21 @@ TEST_F(Testutil, int_to_hex_str)
EXPECT_TRUE(buf[1] == '4');
}
TEST_F(Testutil, string_to_pdp_type)
{
pdp_type_t type = string_to_pdp_type("IPV4V6");
ASSERT_EQ(type, IPV4V6_PDP_TYPE);
type = string_to_pdp_type("IPV6");
ASSERT_EQ(type, IPV6_PDP_TYPE);
type = string_to_pdp_type("IP");
ASSERT_EQ(type, IPV4_PDP_TYPE);
type = string_to_pdp_type("Non-IP");
ASSERT_EQ(type, NON_IP_PDP_TYPE);
type = string_to_pdp_type("diipadaapa");
ASSERT_EQ(type, DEFAULT_PDP_TYPE);
}

View File

@ -166,11 +166,6 @@ AT_CellularBase::CellularProperty AT_CellularContext::pdp_type_t_to_cellular_pro
return prop;
}
pdp_type_t AT_CellularContext::string_to_pdp_type(const char *pdp_type)
{
return IPV4V6_PDP_TYPE;
}
// PDP Context handling
nsapi_error_t AT_CellularContext::delete_current_context()
{

View File

@ -28,6 +28,7 @@ int CellularUtil_stub::char_pos = 0;
char *CellularUtil_stub::char_table[50] = {};
int CellularUtil_stub::table_idx = 0;
using namespace mbed;
namespace mbed_cellular_util {
#define MAX_STRING_LEN 200
@ -124,4 +125,9 @@ uint16_t get_dynamic_ip_port()
return CellularUtil_stub::uint16_value;
}
pdp_type_t string_to_pdp_type(const char *pdp_type)
{
return IPV4V6_PDP_TYPE;
}
} // namespace mbed_cellular_util

View File

@ -19,6 +19,7 @@
#include "CellularInterface.h"
#include "CellularDevice.h"
#include "CellularUtil.h"
#include "ControlPlane_netif.h"
#include "PinNames.h"
@ -29,14 +30,6 @@
namespace mbed {
typedef enum pdp_type {
DEFAULT_PDP_TYPE = DEFAULT_STACK,
IPV4_PDP_TYPE = IPV4_STACK,
IPV6_PDP_TYPE = IPV6_STACK,
IPV4V6_PDP_TYPE = IPV4V6_STACK,
NON_IP_PDP_TYPE
} pdp_type_t;
/**
* @addtogroup cellular
* @{

View File

@ -20,7 +20,6 @@
#include "AT_CellularStack.h"
#include "AT_CellularDevice.h"
#include "CellularLog.h"
#include "CellularUtil.h"
#if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
#include "UARTSerial.h"
#endif // #if DEVICE_SERIAL
@ -291,23 +290,6 @@ void AT_CellularContext::set_credentials(const char *apn, const char *uname, con
_pwd = pwd;
}
pdp_type_t AT_CellularContext::string_to_pdp_type(const char *pdp_type_str)
{
pdp_type_t pdp_type = DEFAULT_PDP_TYPE;
int len = strlen(pdp_type_str);
if (len == 6 && memcmp(pdp_type_str, "IPV4V6", len) == 0) {
pdp_type = IPV4V6_PDP_TYPE;
} else if (len == 4 && memcmp(pdp_type_str, "IPV6", len) == 0) {
pdp_type = IPV6_PDP_TYPE;
} else if (len == 2 && memcmp(pdp_type_str, "IP", len) == 0) {
pdp_type = IPV4_PDP_TYPE;
} else if (len == 6 && memcmp(pdp_type_str, "Non-IP", len) == 0) {
pdp_type = NON_IP_PDP_TYPE;
}
return pdp_type;
}
// PDP Context handling
nsapi_error_t AT_CellularContext::delete_current_context()
{

View File

@ -101,7 +101,6 @@ protected:
virtual void set_disconnect();
virtual void deactivate_context();
virtual bool get_context();
pdp_type_t string_to_pdp_type(const char *pdp_type);
AT_CellularBase::CellularProperty pdp_type_t_to_cellular_property(pdp_type_t pdp_type);
bool set_new_context(int cid);
private:

View File

@ -25,7 +25,7 @@
#define RANDOM_PORT_NUMBER_COUNT (RANDOM_PORT_NUMBER_END - RANDOM_PORT_NUMBER_START + 1)
#define RANDOM_PORT_NUMBER_MAX_STEP 100
using namespace mbed;
namespace mbed_cellular_util {
void convert_ipv6(char *ip)
@ -355,4 +355,21 @@ uint16_t get_dynamic_ip_port()
return (RANDOM_PORT_NUMBER_START + port_counter);
}
pdp_type_t string_to_pdp_type(const char *pdp_type_str)
{
pdp_type_t pdp_type = DEFAULT_PDP_TYPE;
int len = strlen(pdp_type_str);
if (len == 6 && memcmp(pdp_type_str, "IPV4V6", len) == 0) {
pdp_type = IPV4V6_PDP_TYPE;
} else if (len == 4 && memcmp(pdp_type_str, "IPV6", len) == 0) {
pdp_type = IPV6_PDP_TYPE;
} else if (len == 2 && memcmp(pdp_type_str, "IP", len) == 0) {
pdp_type = IPV4_PDP_TYPE;
} else if (len == 6 && memcmp(pdp_type_str, "Non-IP", len) == 0) {
pdp_type = NON_IP_PDP_TYPE;
}
return pdp_type;
}
} // namespace mbed_cellular_util

View File

@ -20,7 +20,18 @@
#include <stddef.h>
#include <inttypes.h>
#include "nsapi_types.h"
namespace mbed {
typedef enum pdp_type {
DEFAULT_PDP_TYPE = DEFAULT_STACK,
IPV4_PDP_TYPE = IPV4_STACK,
IPV6_PDP_TYPE = IPV6_STACK,
IPV4V6_PDP_TYPE = IPV4V6_STACK,
NON_IP_PDP_TYPE
} pdp_type_t;
}
namespace mbed_cellular_util {
// some helper macros
@ -120,6 +131,13 @@ uint32_t binary_str_to_uint(const char *binary_string, int binary_string_length)
*/
uint16_t get_dynamic_ip_port();
/** Converts the given pdp type in char format to enum pdp_type_t
*
* @param pdp_type pdp type in string format
* @return converted pdp_type_t enum
*/
mbed::pdp_type_t string_to_pdp_type(const char *pdp_type);
} // namespace mbed_cellular_util
#endif

View File

@ -19,6 +19,8 @@
#include "Semaphore.h"
using namespace mbed_cellular_util;
namespace mbed {
TELIT_ME910_CellularContext::TELIT_ME910_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req) :