cellular unittests ported to googletest framework

pull/7944/head
Antti Kauppila 2018-08-30 13:29:42 +03:00
parent 0cd43157d1
commit 9f9aa4a210
85 changed files with 8140 additions and 374 deletions

View File

@ -90,17 +90,35 @@ endif(COVERAGE)
set(unittest-includes-base
"${PROJECT_SOURCE_DIR}/target_h"
"${PROJECT_SOURCE_DIR}/target_h/events"
"${PROJECT_SOURCE_DIR}/target_h/events/equeue"
"${PROJECT_SOURCE_DIR}/target_h/platform"
"${PROJECT_SOURCE_DIR}/stubs"
"${PROJECT_SOURCE_DIR}/.."
"${PROJECT_SOURCE_DIR}/../features"
"${PROJECT_SOURCE_DIR}/../features/netsocket"
"${PROJECT_SOURCE_DIR}/../platform"
"${PROJECT_SOURCE_DIR}/../drivers"
"${PROJECT_SOURCE_DIR}/../hal"
"${PROJECT_SOURCE_DIR}/../events"
"${PROJECT_SOURCE_DIR}/../events/equeue"
"${PROJECT_SOURCE_DIR}/../rtos"
"${PROJECT_SOURCE_DIR}/../rtos/TARGET_CORTEX"
"${PROJECT_SOURCE_DIR}/../rtos/TARGET_CORTEX/rtx5/Include"
"${PROJECT_SOURCE_DIR}/../cmsis"
"${PROJECT_SOURCE_DIR}/../features/frameworks/nanostack-libservice/mbed-client-libservice/"
"${PROJECT_SOURCE_DIR}/../features/frameworks"
"${PROJECT_SOURCE_DIR}/../features/frameworks/mbed-trace"
"${PROJECT_SOURCE_DIR}/../features/frameworks/nanostack-libservice"
"${PROJECT_SOURCE_DIR}/../features/frameworks/nanostack-libservice/mbed-client-libservice"
"${PROJECT_SOURCE_DIR}/../features/filesystem/fat"
"${PROJECT_SOURCE_DIR}/../features/filesystem/fat/ChaN"
"${PROJECT_SOURCE_DIR}/../features/filesystem/bd"
"${PROJECT_SOURCE_DIR}/../features/filesystem/"
"${PROJECT_SOURCE_DIR}/../features/filesystem/littlefs"
"${PROJECT_SOURCE_DIR}/../features/filesystem/littlefs/littlefs"
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/API"
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/AT"
"${PROJECT_SOURCE_DIR}/../features/cellular/framework"
"${PROJECT_SOURCE_DIR}/../features/cellular/framework/common"
)
# Create a list for test suites.
@ -168,3 +186,4 @@ foreach(testfile ${unittest-file-list})
message(WARNING "No test source files found for ${TEST_SUITE_NAME}.\n")
endif(unittest-test-sources)
endforeach(testfile)

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "test_at_cellularbase.h"
#include "AT_CellularBase.h"
class TestAT_CellularBase : public testing::Test {
protected:
Test_AT_CellularBase *unit;
virtual void SetUp()
{
unit = new Test_AT_CellularBase();
}
virtual void TearDown()
{
delete unit;
}
};
TEST_F(TestAT_CellularBase, Create)
{
EXPECT_TRUE(unit);
}
TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_at_handler)
{
unit->test_AT_CellularBase_get_at_handler();
}
TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_device_error)
{
unit->test_AT_CellularBase_get_device_error();
}

View File

@ -1,59 +0,0 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "test_at_cellularbase.h"
#include "EventQueue.h"
#include "AT_CellularBase.h"
#include "ATHandler_stub.h"
#include "FileHandle_stub.h"
#include <string.h>
using namespace mbed;
using namespace events;
Test_AT_CellularBase::Test_AT_CellularBase()
{
}
Test_AT_CellularBase::~Test_AT_CellularBase()
{
}
void Test_AT_CellularBase::test_AT_CellularBase_get_at_handler()
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 100, ",");
AT_CellularBase at(ah);
EXPECT_EQ(&ah, &at.get_at_handler());
}
void Test_AT_CellularBase::test_AT_CellularBase_get_device_error()
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 0, ",");
AT_CellularBase at(ah);
ATHandler_stub::device_err_value.errCode = 8;
EXPECT_EQ(8, at.get_device_error().errCode);
ATHandler_stub::device_err_value.errCode = 0;
}

View File

@ -0,0 +1,137 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "AT_CellularBase.h"
#include "EventQueue.h"
#include "AT_CellularBase.h"
#include "ATHandler_stub.h"
#include "FileHandle_stub.h"
#include <string.h>
using namespace mbed;
using namespace events;
class my_base : public AT_CellularBase {
public:
my_base(ATHandler &at) : AT_CellularBase(at)
{
}
bool check_not_supported()
{
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE,
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
};
set_unsupported_features(unsupported_features);
return is_supported(AT_CGSN_WITH_TYPE);
}
bool check_supported()
{
set_unsupported_features(NULL);
return is_supported(AT_CGSN_WITH_TYPE);
}
bool check_supported_not_found()
{
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE,
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
};
set_unsupported_features(unsupported_features);
return is_supported(SUPPORTED_FEATURE_END_MARK);
}
};
// AStyle ignored as the definition is not clear due to preprocessor usage
// *INDENT-OFF*
class TestAT_CellularBase : public testing::Test {
protected:
void SetUp()
{
}
void TearDown()
{
}
};
// *INDENT-ON*
TEST_F(TestAT_CellularBase, Create)
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 100, ",");
AT_CellularBase *unit = new AT_CellularBase(ah);
EXPECT_TRUE(unit != NULL);
delete unit;
}
TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_at_handler)
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 100, ",");
AT_CellularBase at(ah);
EXPECT_TRUE(&ah == &at.get_at_handler());
}
TEST_F(TestAT_CellularBase, test_AT_CellularBase_get_device_error)
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 0, ",");
AT_CellularBase at(ah);
ATHandler_stub::device_err_value.errCode = 8;
EXPECT_EQ(8, at.get_device_error().errCode);
ATHandler_stub::device_err_value.errCode = 0;
}
TEST_F(TestAT_CellularBase, test_AT_CellularBase_set_unsupported_features)
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 0, ",");
AT_CellularBase at(ah);
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
AT_CellularBase::AT_CGSN_WITH_TYPE,
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
};
at.set_unsupported_features(unsupported_features);
}
TEST_F(TestAT_CellularBase, test_AT_CellularBase_is_supported)
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 0, ",");
my_base my_at(ah);
EXPECT_TRUE(true == my_at.check_supported());
EXPECT_TRUE(true == my_at.check_supported_not_found());
EXPECT_TRUE(false == my_at.check_not_supported());
}

View File

@ -23,10 +23,9 @@ set(unittest-sources
# Test files
set(unittest-test-sources
features/cellular/framework/AT/at_cellularbase/at_cellularbasetest.cpp
stubs/mbed_assert_stub.c
stubs/ATHandler_stub.cpp
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
features/cellular/framework/AT/AT_CellularBase/test_at_cellularbase.cpp
features/cellular/framework/AT/AT_CellularBase/at_cellularbasetest.cpp
)

View File

@ -0,0 +1,261 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "AT_CellularDevice.h"
#include "ATHandler_stub.h"
#include "AT_CellularBase_stub.h"
#include <string.h>
using namespace mbed;
using namespace events;
class TestAT_CellularDevice : public testing::Test {
protected:
void SetUp() {
}
void TearDown() {
}
};
TEST_F(TestAT_CellularDevice, Create)
{
EventQueue que;
AT_CellularDevice dev(que);
CellularDevice *dev2 = new AT_CellularDevice(que);
EXPECT_TRUE(dev2 != NULL);
delete dev2;
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
FileHandle_stub fh2;
FileHandle_stub fh3;
EXPECT_TRUE(dev.open_network(&fh1));
EXPECT_TRUE(dev.open_sms(&fh2));
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
EXPECT_TRUE(dev.open_sim(&fh3));
ATHandler_stub::fh_value = &fh1;
EXPECT_TRUE(dev.open_power(&fh1));
ATHandler_stub::fh_value = NULL;
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_network)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
EXPECT_TRUE(!dev.open_network(NULL));
EXPECT_TRUE(dev.open_network(&fh1));
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sms)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
EXPECT_TRUE(!dev.open_sms(NULL));
EXPECT_TRUE(dev.open_sms(&fh1));
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_power)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
EXPECT_TRUE(!dev.open_power(NULL));
EXPECT_TRUE(dev.open_power(&fh1));
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sim)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
EXPECT_TRUE(! dev.open_sim(NULL));
EXPECT_TRUE(dev.open_sim(&fh1));
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
EXPECT_TRUE(!dev.open_information(NULL));
EXPECT_TRUE(dev.open_information(&fh1));
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_network)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
ATHandler_stub::ref_count = 0;
EXPECT_TRUE(dev.open_network(&fh1));
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
dev.close_network();
EXPECT_TRUE(ATHandler_stub::ref_count == 0);
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sms)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
ATHandler_stub::ref_count = 0;
EXPECT_TRUE(dev.open_sms(&fh1));
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
dev.close_sms();
EXPECT_TRUE(ATHandler_stub::ref_count == 0);
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
ATHandler_stub::ref_count = 0;
EXPECT_TRUE(dev.open_power(&fh1));
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
dev.close_power();
EXPECT_TRUE(ATHandler_stub::ref_count == 0);
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sim)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
ATHandler_stub::ref_count = 0;
EXPECT_TRUE(dev.open_sim(&fh1));
dev.close_sms(); // this should not affect to refcount as it's not opened
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
dev.close_sim();
EXPECT_TRUE(ATHandler_stub::ref_count == 0);
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
ATHandler_stub::int_value = 0;
EXPECT_TRUE(dev.open_information(&fh1));
ATHandler_stub::fh_value = NULL;
AT_CellularBase_stub::handler_value = NULL;
dev.close_information();
ATHandler_stub::fh_value = &fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularBase_stub::handler_value = &at;
EXPECT_TRUE(dev.open_information(&fh1));
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
dev.close_information();
ATHandler_stub::fh_value = NULL;
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
ATHandler_stub::timeout = 0;
ATHandler_stub::default_timeout = false;
// no interfaces open so settings timeout should not change anything
dev.set_timeout(5000);
EXPECT_TRUE(ATHandler_stub::timeout == 0);
EXPECT_TRUE(ATHandler_stub::default_timeout == false);
EXPECT_TRUE(dev.open_sim(&fh1));
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
dev.set_timeout(5000);
EXPECT_TRUE(ATHandler_stub::timeout == 5000);
EXPECT_TRUE(ATHandler_stub::default_timeout == true);
dev.close_sim();
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
ATHandler_stub::debug_on = false;
// no interfaces open so debug toggling should not affect
dev.modem_debug_on(true);
EXPECT_TRUE(ATHandler_stub::debug_on == false);
EXPECT_TRUE(dev.open_sim(&fh1));
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
dev.modem_debug_on(true);
EXPECT_TRUE(ATHandler_stub::debug_on == true);
dev.close_sim();
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_stack)
{
EventQueue que;
AT_CellularDevice dev(que);
FileHandle_stub fh1;
NetworkStack *stack = dev.get_stack();
EXPECT_TRUE(stack == NULL);
EXPECT_TRUE(dev.open_network(&fh1));
stack = dev.get_stack();
EXPECT_TRUE(stack == NULL); // Not in PPP so also null but this is got from the network class
}
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay)
{
EventQueue que;
AT_CellularDevice dev(que);
EXPECT_TRUE(0 == dev.get_send_delay());
}

View File

@ -0,0 +1,38 @@
####################
# UNIT TESTS
####################
# Unit test suite name
set(TEST_SUITE_NAME "at_cellular_device_unit")
# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
../features/cellular/framework/common
../features/cellular/framework/AT
../features/frameworks/mbed-client-randlib/mbed-client-randlib
)
# Source files
set(unittest-sources
stubs/randLIB_stub.c
../features/cellular/framework/AT/AT_CellularDevice.cpp
)
# Test files
set(unittest-test-sources
features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp
stubs/AT_CellularNetwork_stub.cpp
stubs/ATHandler_stub.cpp
stubs/AT_CellularSMS_stub.cpp
stubs/AT_CellularSIM_stub.cpp
stubs/AT_CellularPower_stub.cpp
stubs/AT_CellularInformation_stub.cpp
stubs/CellularUtil_stub.cpp
stubs/AT_CellularBase_stub.cpp
stubs/NetworkInterface_stub.cpp
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/mbed_assert_stub.cpp
)

View File

@ -0,0 +1,155 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include <string.h>
#include "ATHandler_stub.h"
#include "EventQueue.h"
#include "FileHandle_stub.h"
#include "AT_CellularBase_stub.h"
#include "ATHandler.h"
#include "AT_CellularInformation.h"
#include "AT_CellularBase.h"
using namespace mbed;
using namespace events;
// AStyle ignored as the definition is not clear due to preprocessor usage
// *INDENT-OFF*
class TestAT_CellularInformation : public testing::Test {
protected:
void SetUp()
{
}
void TearDown()
{
}
};
// *INDENT-ON*
TEST_F(TestAT_CellularInformation, Create)
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 0, ",");
AT_CellularInformation *unit = new AT_CellularInformation(ah);
EXPECT_TRUE(unit != NULL);
delete unit;
}
TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_manufacturer)
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 0, ",");
AT_CellularInformation aci(ah);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
ATHandler_stub::read_string_value = "some";
ATHandler_stub::ssize_value = 4;
char buf[8];
EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_manufacturer(buf, 8));
EXPECT_TRUE(strcmp("some", buf) == 0);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
ATHandler_stub::ssize_value = -1;
buf[0] = 0;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci.get_manufacturer(buf, 8));
EXPECT_TRUE(strlen(buf) == 0);
}
TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_model)
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 0, ",");
AT_CellularInformation aci(ah);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
ATHandler_stub::read_string_value = "model";
ATHandler_stub::ssize_value = 5;
char buf[8];
EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_model(buf, 8));
EXPECT_TRUE(strcmp("model", buf) == 0);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
ATHandler_stub::ssize_value = -1;
buf[0] = 0;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci.get_model(buf, 8));
EXPECT_TRUE(strlen(buf) == 0);
}
TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_revision)
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 0, ",");
//Used heap var here to visit heap constructor
AT_CellularInformation *aci = new AT_CellularInformation(ah);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
ATHandler_stub::read_string_value = "revision";
ATHandler_stub::ssize_value = 8;
char buf[9];
EXPECT_TRUE(NSAPI_ERROR_OK == aci->get_revision(buf, 9));
EXPECT_TRUE(strcmp("revision", buf) == 0);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
ATHandler_stub::ssize_value = -1;
buf[0] = 0;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci->get_revision(buf, 8));
EXPECT_TRUE(strlen(buf) == 0);
delete aci;
}
TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_serial_number)
{
EventQueue eq;
FileHandle_stub fh;
ATHandler ah(&fh, eq, 0, ",");
AT_CellularInformation aci(ah);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
ATHandler_stub::read_string_value = "1234567";
ATHandler_stub::ssize_value = 7;
char buf[8];
EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::SN));
EXPECT_TRUE(strcmp("1234567", buf) == 0);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
ATHandler_stub::ssize_value = -1;
buf[0] = 0;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci.get_serial_number(buf, 8, CellularInformation::SN));
EXPECT_TRUE(strlen(buf) == 0);
AT_CellularBase_stub::supported_bool = false;
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == aci.get_serial_number(buf, 8, CellularInformation::IMEI));
EXPECT_TRUE(strlen(buf) == 0);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
ATHandler_stub::read_string_value = "1234567";
ATHandler_stub::ssize_value = 7;
AT_CellularBase_stub::supported_bool = true;
EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::IMEI));
EXPECT_TRUE(strcmp("1234567", buf) == 0);
}

View File

@ -0,0 +1,31 @@
####################
# UNIT TESTS
####################
# Unit test suite name
set(TEST_SUITE_NAME "at_cellular_information_unit")
# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
../features/cellular/framework/common
../features/cellular/framework/AT
../features/frameworks/mbed-client-randlib/mbed-client-randlib
)
# Source files
set(unittest-sources
stubs/randLIB_stub.c
../features/cellular/framework/AT/AT_CellularInformation.cpp
)
# Test files
set(unittest-test-sources
features/cellular/framework/AT//at_cellularinformation/at_cellularinformationtest.cpp
stubs/ATHandler_stub.cpp
stubs/AT_CellularBase_stub.cpp
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/mbed_assert_stub.cpp
)

View File

@ -0,0 +1,37 @@
####################
# UNIT TESTS
####################
# Unit test suite name
set(TEST_SUITE_NAME "at_cellular_network_unit")
# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
../features/cellular/framework/common
../features/cellular/framework/AT
../features/frameworks/mbed-client-randlib/mbed-client-randlib
)
# Source files
set(unittest-sources
../features/cellular/framework/AT/AT_CellularNetwork.cpp
../features/cellular/framework/AT/AT_CellularStack.cpp
../features/cellular/framework/common/CellularUtil.cpp
)
# Test files
set(unittest-test-sources
features/cellular/framework/AT/at_cellularnetwork/at_cellularnetworktest.cpp
stubs/ATHandler_stub.cpp
stubs/AT_CellularBase_stub.cpp
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/NetworkInterface_stub.cpp
stubs/NetworkStack_stub.cpp
stubs/us_ticker_stub.cpp
stubs/mbed_assert_stub.cpp
stubs/SocketAddress_stub.cpp
stubs/randLIB_stub.cpp
)

View File

@ -0,0 +1,201 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include <string.h>
#include "AT_CellularNetwork.h"
#include "EventQueue.h"
#include "ATHandler.h"
#include "AT_CellularPower.h"
#include "FileHandle_stub.h"
#include "ATHandler_stub.h"
using namespace mbed;
using namespace events;
// AStyle ignored as the definition is not clear due to preprocessor usage
// *INDENT-OFF*
class TestAT_CellularPower : public testing::Test {
protected:
void SetUp() {
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
}
void TearDown() {
}
};
// *INDENT-ON*
static void device_ready_cb()
{
}
TEST_F(TestAT_CellularPower, Create)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower *pow = new AT_CellularPower(at);
EXPECT_TRUE(pow != NULL);
delete pow;
}
TEST_F(TestAT_CellularPower, test_AT_CellularPower_on)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.on());
}
TEST_F(TestAT_CellularPower, test_AT_CellularPower_off)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.off());
}
TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_at_mode)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_at_mode());
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.set_at_mode());
}
TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_power_level)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_power_level(6));
EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_power_level(1, 1));
EXPECT_TRUE(NSAPI_ERROR_OK == pow.set_power_level(1, 0));
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.set_power_level(6));
}
TEST_F(TestAT_CellularPower, test_AT_CellularPower_reset)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
EXPECT_TRUE(NSAPI_ERROR_OK == pow.reset());
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.reset());
}
TEST_F(TestAT_CellularPower, test_AT_CellularPower_opt_power_save_mode)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(0, 0));
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(10, 0));
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(912, 0));
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(1834, 1834));
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(18345, 18345));
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(101234, 101234));
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(1012345, 1012345));
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_power_save_mode(39612345, 39612345));
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.opt_power_save_mode(0, 0));
}
TEST_F(TestAT_CellularPower, test_AT_CellularPower_opt_receive_period)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
EXPECT_TRUE(NSAPI_ERROR_OK == pow.opt_receive_period(1, CellularPower::EDRXUTRAN_Iu_mode, 3));
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == pow.opt_receive_period(1, CellularPower::EDRXUTRAN_Iu_mode, 3));
}
TEST_F(TestAT_CellularPower, test_AT_CellularPower_is_device_ready)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == pow.is_device_ready());
}
TEST_F(TestAT_CellularPower, test_AT_CellularPower_set_device_ready_urc_cb)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb));
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(NULL));
}
TEST_F(TestAT_CellularPower, test_AT_CellularPower_remove_device_ready_urc_cb)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularPower pow(at);
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == pow.set_device_ready_urc_cb(&device_ready_cb));
pow.remove_device_ready_urc_cb(NULL);
pow.remove_device_ready_urc_cb(&device_ready_cb);
}

View File

@ -0,0 +1,31 @@
####################
# UNIT TESTS
####################
# Unit test suite name
set(TEST_SUITE_NAME "at_cellular_power_unit")
# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
../features/cellular/framework/common
../features/cellular/framework/AT
../features/frameworks/mbed-client-randlib/mbed-client-randlib
)
# Source files
set(unittest-sources
../features/cellular/framework/AT/AT_CellularPower.cpp
)
# Test files
set(unittest-test-sources
features/cellular/framework/AT/at_cellularpower/at_cellularpowertest.cpp
stubs/ATHandler_stub.cpp
stubs/AT_CellularBase_stub.cpp
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/CellularUtil_stub.cpp
stubs/mbed_assert_stub.cpp
)

View File

@ -0,0 +1,204 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "ATHandler_stub.h"
#include <string.h>
#include "AT_CellularNetwork.h"
#include "EventQueue.h"
#include "ATHandler.h"
#include "AT_CellularSIM.h"
#include "FileHandle_stub.h"
#include "CellularLog.h"
#include "ATHandler_stub.h"
using namespace mbed;
using namespace events;
// AStyle ignored as the definition is not clear due to preprocessor usage
// *INDENT-OFF*
class TestAT_CellularSIM : public testing::Test {
protected:
void SetUp()
{
ATHandler_stub::read_string_index = kRead_string_table_size;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
ATHandler_stub::read_string_value = NULL;
ATHandler_stub::ssize_value = 0;
}
void TearDown()
{
}
};
// *INDENT-ON*
TEST_F(TestAT_CellularSIM, Create)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSIM *sim = new AT_CellularSIM(at);
EXPECT_TRUE(sim != NULL);
delete sim;
}
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_set_pin)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSIM sim(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin("12"));
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin("12"));
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
ATHandler_stub::read_string_value = "READY";
ATHandler_stub::ssize_value = 5;
EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin("12"));
EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin(NULL));
}
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_change_pin)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSIM sim(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin("12", "34"));
EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin(NULL, "34"));
EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin("12", NULL));
EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin(NULL, NULL));
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.change_pin("12", "34"));
}
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_set_pin_query)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSIM sim(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query("12", true));
EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query(NULL, true));
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query("12", false));
EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query(NULL, false));
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin_query("12", false));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin_query("12", true));
}
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_sim_state)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSIM sim(at);
CellularSIM::SimState state;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
ATHandler_stub::ssize_value = -1;
ATHandler_stub::read_string_value = NULL;
EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state));
EXPECT_TRUE(CellularSIM::SimStateUnknown == state);
ATHandler_stub::read_string_value = "READY";
ATHandler_stub::ssize_value = 5;
EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state));
EXPECT_TRUE(CellularSIM::SimStateReady == state);
ATHandler_stub::read_string_value = "SIM PIN";
ATHandler_stub::ssize_value = 7;
EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state));
EXPECT_TRUE(CellularSIM::SimStatePinNeeded == state);
ATHandler_stub::read_string_value = "SIM PUK";
ATHandler_stub::ssize_value = 7;
EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state));
EXPECT_TRUE(CellularSIM::SimStatePukNeeded == state);
ATHandler_stub::read_string_value = "SOME CRAP";
ATHandler_stub::ssize_value = 9;
EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state));
EXPECT_TRUE(CellularSIM::SimStateUnknown == state);
}
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_imsi)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
char imsi[16];
AT_CellularSIM sim(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
ATHandler_stub::read_string_value = "123456789012345";
ATHandler_stub::ssize_value = 15;
EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_imsi(imsi));
EXPECT_TRUE(strcmp(ATHandler_stub::read_string_value, imsi) == 0);
ATHandler_stub::read_string_value = NULL;
ATHandler_stub::ssize_value = -1;
ATHandler_stub::read_string_index = -1;
imsi[0] = 0;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.get_imsi(imsi));
EXPECT_TRUE(strlen(imsi) == 0);
EXPECT_TRUE(NSAPI_ERROR_PARAMETER == sim.get_imsi(NULL));
// this would fail as get_imsi should take another param which is the size of the buffer which we could use for validation.
// Now we have improved documentation that that the given imsi buffer size must be over 15.
//char imsi2[5];
//EXPECT_TRUE(NSAPI_ERROR_PARAMETER == sim.get_imsi(imsi2));
}
TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_iccid)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
char buf[16];
AT_CellularSIM sim(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
ATHandler_stub::read_string_value = "123456789012345";
ATHandler_stub::ssize_value = 15;
EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_iccid(buf, 16));
EXPECT_TRUE(strcmp(ATHandler_stub::read_string_value, buf) == 0);
buf[0] = 0;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
ATHandler_stub::read_string_value = NULL;
ATHandler_stub::ssize_value = -1;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.get_iccid(buf, 16));
EXPECT_TRUE(strlen(buf) == 0);
}

View File

@ -0,0 +1,32 @@
####################
# UNIT TESTS
####################
# Unit test suite name
set(TEST_SUITE_NAME "at_cellular_sim_unit")
# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
../features/cellular/framework/common
../features/cellular/framework/AT
../features/frameworks/mbed-client-randlib/mbed-client-randlib
)
# Source files
set(unittest-sources
../features/cellular/framework/AT/AT_CellularSIM.cpp
)
# Test files
set(unittest-test-sources
features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp
stubs/ATHandler_stub.cpp
stubs/AT_CellularBase_stub.cpp
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/CellularUtil_stub.cpp
stubs/us_ticker_stub.cpp
stubs/mbed_assert_stub.cpp
)

View File

@ -0,0 +1,203 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include <string.h>
#include "AT_CellularNetwork.h"
#include "EventQueue.h"
#include "ATHandler.h"
#include "ATHandler_stub.h"
#include "AT_CellularSMS.h"
#include "FileHandle_stub.h"
#include "CellularLog.h"
using namespace mbed;
using namespace events;
// AStyle ignored as the definition is not clear due to preprocessor usage
// *INDENT-OFF*
class TestAT_CellularSMS : public testing::Test {
protected:
void SetUp()
{
ATHandler_stub::return_given_size = false;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
}
void TearDown()
{
}
};
// *INDENT-ON*
TEST_F(TestAT_CellularSMS, Create)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS *sms = new AT_CellularSMS(at);
EXPECT_TRUE(sms != NULL);
delete sms;
}
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_initialize)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
EXPECT_TRUE(NSAPI_ERROR_NO_MEMORY == sms.initialize(CellularSMS::CellularSMSMmodeText));
}
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_send_sms)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
EXPECT_EQ(NSAPI_ERROR_PARAMETER, sms.send_sms(NULL, "2", 1));
sms.initialize(CellularSMS::CellularSMSMmodeText);
ATHandler_stub::size_value = 1;
EXPECT_EQ(1, sms.send_sms("1", "22", 2));
ATHandler_stub::size_value = 2;
EXPECT_EQ(2, sms.send_sms("1", "22", 2));
ATHandler_stub::return_given_size = true; // PDU mode write is much longer than than msg len
sms.initialize(CellularSMS::CellularSMSMmodePDU);
EXPECT_EQ(2, sms.send_sms("1", "23", 2));;
ATHandler_stub::nsapi_error_ok_counter = 1;
ATHandler_stub::size_value = 32;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
EXPECT_EQ(NSAPI_ERROR_AUTH_FAILURE, sms.send_sms("1", "23232323", 8));
ATHandler_stub::nsapi_error_ok_counter = 2;
ATHandler_stub::size_value = 32;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
EXPECT_EQ(NSAPI_ERROR_AUTH_FAILURE, sms.send_sms("1", "23232323", 8));
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
char table[] = "232323232323232323232323232323232323232323232323232323\
232323232323232323232323232323232323232323232323232323\
232323232323232323232323232323232323232323232323232323\
23232323232323232323232323232323232323\0";
EXPECT_EQ(strlen(table), sms.send_sms("1", table, strlen(table)));
EXPECT_EQ(strlen(table), sms.send_sms("12", table, strlen(table)));
}
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_get_sms)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
char buf[16];
char phone[21];
char stamp[21];
int size;
EXPECT_TRUE(NSAPI_ERROR_PARAMETER == sms.get_sms(NULL, 16, phone, 21, stamp, 21, &size));
ATHandler_stub::resp_info_true_counter = 1;
ATHandler_stub::int_value = 0;
EXPECT_TRUE(-1 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
ATHandler_stub::resp_info_true_counter = 2;
ATHandler_stub::int_value = 11;
EXPECT_TRUE(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
//TODO: Should make add_info to happen, before calling get_sms!
ATHandler_stub::resp_info_true_counter = 2;
ATHandler_stub::int_value = 11;
sms.initialize(CellularSMS::CellularSMSMmodePDU);
EXPECT_TRUE(0 == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.get_sms(buf, 16, phone, 21, stamp, 21, &size));
}
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_sms_callback)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
sms.set_sms_callback(NULL);
}
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_cpms)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.set_cpms("2", "3", "4"));
}
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_csca)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.set_csca("2", 1));
}
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_cscs)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.set_cscs("2"));
}
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_delete_all_messages)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_AUTH_FAILURE;
EXPECT_TRUE(NSAPI_ERROR_AUTH_FAILURE == sms.delete_all_messages());
}
TEST_F(TestAT_CellularSMS, test_AT_CellularSMS_set_extra_sim_wait_time)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
AT_CellularSMS sms(at);
sms.set_extra_sim_wait_time(56);
}

View File

@ -0,0 +1,33 @@
####################
# UNIT TESTS
####################
# Unit test suite name
set(TEST_SUITE_NAME "at_cellular_sms_unit")
# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
../features/cellular/framework/common
../features/cellular/framework/AT
../features/frameworks/mbed-client-randlib/mbed-client-randlib
)
# Source files
set(unittest-sources
../features/cellular/framework/AT/AT_CellularSMS.cpp
)
# Test files
set(unittest-test-sources
features/cellular/framework/AT/at_cellularsms/at_cellularsmstest.cpp
stubs/ATHandler_stub.cpp
stubs/AT_CellularBase_stub.cpp
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/CellularUtil_stub.cpp
stubs/us_ticker_stub.cpp
stubs/mbed_assert_stub.cpp
stubs/mbed_wait_api_stub.cpp
)

View File

@ -0,0 +1,377 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "AT_CellularStack.h"
#include <string.h>
#include "AT_CellularNetwork.h"
#include "EventQueue.h"
#include "ATHandler.h"
#include "AT_CellularStack.h"
#include "FileHandle_stub.h"
#include "CellularLog.h"
#include "ATHandler_stub.h"
#include "SocketAddress.h"
using namespace mbed;
using namespace events;
class MyStack : public AT_CellularStack {
public:
bool bool_value;
bool max_sock_value;
nsapi_error_t create_error;
CellularSocket socket;
MyStack(ATHandler &atr, int cid, nsapi_ip_stack_t typ) : AT_CellularStack(atr, cid, typ)
{
bool_value = false;
max_sock_value = 0;
create_error = NSAPI_ERROR_OK;
}
virtual int get_max_socket_count()
{
return max_sock_value;
}
virtual bool is_protocol_supported(nsapi_protocol_t protocol)
{
return bool_value;
}
virtual nsapi_error_t socket_close_impl(int sock_id)
{
return NSAPI_ERROR_OK;
}
virtual nsapi_error_t create_socket_impl(CellularSocket *socket)
{
return create_error;
}
virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
const void *data, nsapi_size_t size)
{
return NSAPI_ERROR_OK;
}
virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
void *buffer, nsapi_size_t size)
{
return NSAPI_ERROR_OK;
}
virtual nsapi_error_t socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
{
return AT_CellularStack::socket_open(handle, proto);
}
virtual nsapi_error_t socket_close(nsapi_socket_t handle)
{
return AT_CellularStack::socket_close(handle);
}
virtual nsapi_error_t socket_bind(nsapi_socket_t handle, const SocketAddress &address)
{
return AT_CellularStack::socket_bind(handle, address);
}
virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog)
{
return AT_CellularStack::socket_listen(handle, backlog);
}
virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address)
{
return AT_CellularStack::socket_connect(handle, address);
}
virtual nsapi_error_t socket_accept(nsapi_socket_t server,
nsapi_socket_t *handle, SocketAddress *address = 0)
{
return AT_CellularStack::socket_accept(server, handle, address);
}
virtual nsapi_size_or_error_t socket_send(nsapi_socket_t handle,
const void *data, nsapi_size_t size)
{
return AT_CellularStack::socket_send(handle, data, size);
}
virtual nsapi_size_or_error_t socket_recv(nsapi_socket_t handle,
void *data, nsapi_size_t size)
{
return AT_CellularStack::socket_recv(handle, data, size);
}
virtual nsapi_size_or_error_t socket_sendto(nsapi_socket_t handle, const SocketAddress &address,
const void *data, nsapi_size_t size)
{
return AT_CellularStack::socket_sendto(handle, address, data, size);
}
virtual nsapi_size_or_error_t socket_recvfrom(nsapi_socket_t handle, SocketAddress *address,
void *buffer, nsapi_size_t size)
{
return AT_CellularStack::socket_recvfrom(handle, address, buffer, size);
}
virtual void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data)
{
return AT_CellularStack::socket_attach(handle, callback, data);
}
};
// AStyle ignored as the definition is not clear due to preprocessor usage
// *INDENT-OFF*
class TestAT_CellularStack : public testing::Test {
protected:
void SetUp()
{
ATHandler_stub::return_given_size = false;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK;
ATHandler_stub::ssize_value = 0;
ATHandler_stub::bool_value = false;
ATHandler_stub::read_string_value = NULL;
}
void TearDown()
{
}
};
// *INDENT-ON*
TEST_F(TestAT_CellularStack, Create)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack *st = new MyStack(at, 0, IPV4_STACK);
EXPECT_TRUE(st != NULL);
delete st;
}
TEST_F(TestAT_CellularStack, test_AT_CellularStack_get_ip_address)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
EXPECT_TRUE(0 == strlen(st.get_ip_address()));
char table[] = "1.2.3.4.5.65.7.8.9.10.11\0";
ATHandler_stub::ssize_value = -1;
ATHandler_stub::bool_value = true;
ATHandler_stub::read_string_value = table;
EXPECT_TRUE(NULL == st.get_ip_address());
ATHandler_stub::ssize_value = strlen(table);
ATHandler_stub::bool_value = true;
ATHandler_stub::read_string_value = table;
EXPECT_TRUE(st.get_ip_address());
}
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_open)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
st.bool_value = false;
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == st.socket_open(NULL, NSAPI_TCP));
st.bool_value = true;
st.max_sock_value = 0;
nsapi_socket_t sock = &st.socket;
EXPECT_TRUE(NSAPI_ERROR_NO_SOCKET == st.socket_open(&sock, NSAPI_TCP));
MyStack st2(at, 0, IPV6_STACK);
st2.bool_value = true;
st2.max_sock_value = 1;
sock = &st2.socket;
EXPECT_TRUE(NSAPI_ERROR_OK == st2.socket_open(&sock, NSAPI_TCP));
}
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_close)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_close(&st.socket));
nsapi_socket_t sock = &st.socket;
st.bool_value = true;
st.max_sock_value = 1;
EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_open(&sock, NSAPI_TCP));
st.max_sock_value = 0;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_close(sock));
MyStack st2(at, 0, IPV6_STACK);
st2.max_sock_value = 1;
st2.bool_value = true;
sock = &st2.socket;
EXPECT_TRUE(NSAPI_ERROR_OK == st2.socket_open(&sock, NSAPI_TCP));
EXPECT_TRUE(NSAPI_ERROR_OK == st2.socket_close(sock));
}
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_bind)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
SocketAddress addr;
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_ALREADY;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_bind(NULL, addr));
EXPECT_TRUE(NSAPI_ERROR_ALREADY == st.socket_bind(&st.socket, addr));
}
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_listen)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == st.socket_listen(&st.socket, 4));
}
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_connect)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
SocketAddress addr;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_connect(NULL, addr));
EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_connect(&st.socket, addr));
}
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_accept)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
nsapi_socket_t sock = &st.socket;
EXPECT_TRUE(NSAPI_ERROR_UNSUPPORTED == st.socket_accept(NULL, &sock));
}
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_send)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(NULL, "addr", 4));
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_send(&st.socket, "addr", 4));
SocketAddress addr;
st.max_sock_value = 1;
st.bool_value = true;
nsapi_socket_t sock = &st.socket;
st.socket_open(&sock, NSAPI_TCP);
st.socket_connect(sock, addr);
EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_send(sock, "addr", 4));
}
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_sendto)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
SocketAddress addr;
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_sendto(NULL, addr, "addr", 4));
st.max_sock_value = 1;
st.bool_value = true;
nsapi_socket_t sock = &st.socket;
st.socket_open(&sock, NSAPI_TCP);
st.socket_connect(sock, addr);
st.create_error = NSAPI_ERROR_CONNECTION_LOST;
EXPECT_TRUE(NSAPI_ERROR_CONNECTION_LOST == st.socket_sendto(sock, addr, "addr", 4));
st.create_error = NSAPI_ERROR_OK;
EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_sendto(sock, addr, "addr", 4));
}
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_recv)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
char table[4];
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_recv(NULL, table, 4));
}
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_recvfrom)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
char table[4];
EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == st.socket_recvfrom(NULL, NULL, table, 4));
SocketAddress addr;
st.max_sock_value = 1;
st.bool_value = true;
nsapi_socket_t sock = &st.socket;
st.socket_open(&sock, NSAPI_TCP);
st.socket_connect(sock, addr);
st.create_error = NSAPI_ERROR_CONNECTION_LOST;
EXPECT_TRUE(NSAPI_ERROR_CONNECTION_LOST == st.socket_recvfrom(sock, &addr, table, 4));
st.create_error = NSAPI_ERROR_OK;
EXPECT_TRUE(NSAPI_ERROR_OK == st.socket_recvfrom(sock, &addr, table, 4));
}
TEST_F(TestAT_CellularStack, test_AT_CellularStack_socket_attach)
{
EventQueue que;
FileHandle_stub fh1;
ATHandler at(&fh1, que, 0, ",");
MyStack st(at, 0, IPV6_STACK);
st.socket_attach(NULL, NULL, NULL);
st.max_sock_value = 1;
st.bool_value = true;
nsapi_socket_t sock = &st.socket;
st.socket_open(&sock, NSAPI_TCP);
st.socket_attach(sock, NULL, NULL);
}

View File

@ -0,0 +1,34 @@
####################
# UNIT TESTS
####################
# Unit test suite name
set(TEST_SUITE_NAME "at_cellular_stack_unit")
# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
../features/cellular/framework/common
../features/cellular/framework/AT
../features/frameworks/mbed-client-randlib/mbed-client-randlib
)
# Source files
set(unittest-sources
../features/cellular/framework/AT/AT_CellularStack.cpp
)
# Test files
set(unittest-test-sources
features/cellular/framework/AT/at_cellularstack/at_cellularstacktest.cpp
stubs/ATHandler_stub.cpp
stubs/AT_CellularBase_stub.cpp
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/CellularUtil_stub.cpp
stubs/us_ticker_stub.cpp
stubs/NetworkStack_stub.cpp
stubs/SocketAddress_stub.cpp
stubs/mbed_assert_stub.cpp
)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,41 @@
####################
# UNIT TESTS
####################
# Unit test suite name
set(TEST_SUITE_NAME "at_handler_unit")
# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
../features/cellular/framework/common
../features/cellular/framework/AT
../features/frameworks/mbed-client-randlib/mbed-client-randlib
)
# Source files
set(unittest-sources
../features/cellular/framework/AT/ATHandler.cpp
../features/cellular/framework/common/CellularUtil.cpp
)
# Test files
set(unittest-test-sources
features/cellular/framework/AT/athandler/athandlertest.cpp
stubs/AT_CellularBase_stub.cpp
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/us_ticker_stub.cpp
stubs/mbed_wait_api_stub.cpp
stubs/mbed_assert_stub.cpp
stubs/mbed_poll_stub.cpp
stubs/Timer_stub.cpp
stubs/equeue_stub.c
stubs/Kernel_stub.cpp
stubs/Thread_stub.cpp
stubs/randLIB_stub.cpp
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_CELLULAR_DEBUG_AT=true -DOS_STACK_SIZE=2048")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_CELLULAR_DEBUG_AT=true -DOS_STACK_SIZE=2048")

View File

@ -1,179 +0,0 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "test_util.h"
#include <string.h>
#include "CellularUtil.h"
#include <iostream>
using namespace mbed_cellular_util;
Test_util::Test_util()
{
}
Test_util::~Test_util()
{
}
void Test_util::test_util_uint_to_binary_string()
{
char str[33];
uint_to_binary_str(15, str, 33, 32);
str[32] = '\0';
// 15 is "1111" in binary but we ask all 32 bits so it should return "00000000000000000000000000001111"
EXPECT_STREQ("00000000000000000000000000001111", str);
// test NULL pointer
uint_to_binary_str(15, NULL, 0, 32);
// test give too small buffer
char too_small[5];
uint_to_binary_str(15, too_small, 5, 6);
}
void Test_util::test_util_char_str_to_hex()
{
// basic conversion test, happy days
char hex_buf[50];
uint16_t number_of_hex_chars = char_str_to_hex_str("1234", 4, hex_buf);
hex_buf[number_of_hex_chars] = '\0';
EXPECT_STREQ("31323334", hex_buf);
EXPECT_EQ(8, number_of_hex_chars);
number_of_hex_chars = char_str_to_hex_str("wuhuu", 5, hex_buf);
hex_buf[number_of_hex_chars] = '\0';
EXPECT_STREQ("7775687575", hex_buf);
EXPECT_EQ(10, number_of_hex_chars);
// First don't omit the leading zero and then omit and check that leading zero is missing
number_of_hex_chars = char_str_to_hex_str("\nwuhuu", 6, hex_buf);
hex_buf[number_of_hex_chars] = '\0';
EXPECT_STREQ("0A7775687575", hex_buf);
EXPECT_EQ(12, number_of_hex_chars);
number_of_hex_chars = char_str_to_hex_str("\nwuhuu", 6, hex_buf, true);
hex_buf[number_of_hex_chars] = '\0';
EXPECT_STREQ("A7775687575", hex_buf);
EXPECT_EQ(11, number_of_hex_chars);
// test giving a null pointer
number_of_hex_chars = char_str_to_hex_str(NULL, 4, hex_buf);
EXPECT_EQ(0, number_of_hex_chars);
number_of_hex_chars = char_str_to_hex_str("1234", 4, NULL);
EXPECT_EQ(0, number_of_hex_chars);
}
void Test_util::test_util_convert_ipv6()
{
// leading zeros omitted
char ipv6[64];
strncpy(ipv6, "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1", 64);
convert_ipv6(ipv6);
EXPECT_STREQ("101:101:101:101:101:101:101:101", ipv6);
EXPECT_EQ(31, strlen(ipv6));
// some omitted and some not so much
strncpy(ipv6, "255.1.120.2.244.12.55.45.201.110.11.2.233.154.85.96", 64);
convert_ipv6(ipv6);
EXPECT_STREQ("FF01:7802:F40C:372D:C96E:B02:E99A:5560", ipv6);
EXPECT_EQ(38, strlen(ipv6));
// test giving a null pointer
convert_ipv6(NULL);
}
void Test_util::test_util_prefer_ipv6()
{
char tt[20] = "62.241.198.246";
char temp[64] = "2001:14B8:1000:000:000:000:000:002";
// not enough space to swap, arrays should stay the same
prefer_ipv6(tt, sizeof(tt), temp, sizeof(temp));
EXPECT_STREQ("62.241.198.246", tt);
EXPECT_STREQ("2001:14B8:1000:000:000:000:000:002", temp);
// should swap as first one was ip4 and later was ipv6 and enough space
char tt2[64] = "62.241.198.246";
prefer_ipv6(tt2, sizeof(tt2), temp, sizeof(temp));
EXPECT_STREQ("62.241.198.246", temp);
EXPECT_STREQ("2001:14B8:1000:000:000:000:000:002", tt2);
}
void Test_util::test_util_separate_ip_addresses()
{
char *s = (char *)calloc(128, 1);
char ip[64] = {0};
char subnet[64] = {0};
strncpy(s, "32.1.20.187.1.112.139.245.251.136.232.110.123.51.230.138.0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15", 94);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
EXPECT_STREQ("2001:14BB:170:8BF5:FB88:E86E:7B33:E68A", ip);
EXPECT_STREQ("001:203:405:607:809:A0B:C0D:E0F", subnet);
strncpy(s, "32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138 0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", 94);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", ip);
EXPECT_STREQ("0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "1.2.3.4\0", 8);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
EXPECT_STREQ("1.2.3.4", ip);
EXPECT_STREQ("", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "1.2.3.4.5.6.7.8\0", 16);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
EXPECT_STREQ("1.2.3.4", ip);
EXPECT_STREQ("5.6.7.8", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16\0", 39);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
EXPECT_STREQ("102:304:506:708:90A:B0C:D0E:F10", ip);
EXPECT_STREQ("", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0", 57);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", ip);
EXPECT_STREQ("", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "1.2.3.4 32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0", 65);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
EXPECT_STREQ("1.2.3.4", ip);
EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20\0", 51);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
EXPECT_STREQ("1.2.3.4", ip);
EXPECT_STREQ("506:708:90A:B0C:D0E:F10:1112:1314", subnet);
EXPECT_STREQ("1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20", s);
free(s);
}

View File

@ -20,7 +20,6 @@ set(unittest-sources
# Test files
set(unittest-test-sources
stubs/randLIB_stub.c
features/cellular/framework/common/util/test_util.cpp
features/cellular/framework/common/util/utiltest.cpp
stubs/randLIB_stub.cpp
)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -15,49 +15,167 @@
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "test_util.h"
#include <string.h>
#include "CellularUtil.h"
class TestUtil : public testing::Test {
using namespace mbed_cellular_util;
// AStyle ignored as the definition is not clear due to preprocessor usage
// *INDENT-OFF*
class Testutil : public testing::Test {
protected:
Test_util *unit;
virtual void SetUp()
void SetUp()
{
unit = new Test_util();
}
virtual void TearDown()
void TearDown()
{
delete unit;
}
};
// *INDENT-ON*
TEST_F(TestUtil, Create)
TEST_F(Testutil, test_util_uint_to_binary_string)
{
EXPECT_TRUE(unit);
char str[33];
uint_to_binary_str(15, str, 33, 32);
str[32] = '\0';
// 15 is "1111" in binary but we ask all 32 bits so it should return "00000000000000000000000000001111"
EXPECT_STREQ("00000000000000000000000000001111", str);
// test NULL pointer
uint_to_binary_str(15, NULL, 0, 32);
// test give too small buffer
char too_small[5];
uint_to_binary_str(15, too_small, 5, 6);
}
TEST_F(TestUtil, test_util_uint_to_binary_string)
TEST_F(Testutil, char_str_to_hex)
{
unit->test_util_uint_to_binary_string();
// basic conversion test, happy days
char hex_buf[50];
uint16_t number_of_hex_chars = char_str_to_hex_str("1234", 4, hex_buf);
hex_buf[number_of_hex_chars] = '\0';
EXPECT_STREQ("31323334", hex_buf);
EXPECT_EQ(8, number_of_hex_chars);
number_of_hex_chars = char_str_to_hex_str("wuhuu", 5, hex_buf);
hex_buf[number_of_hex_chars] = '\0';
EXPECT_STREQ("7775687575", hex_buf);
EXPECT_EQ(10, number_of_hex_chars);
// First don't omit the leading zero and then omit and check that leading zero is missing
number_of_hex_chars = char_str_to_hex_str("\nwuhuu", 6, hex_buf);
hex_buf[number_of_hex_chars] = '\0';
EXPECT_STREQ("0A7775687575", hex_buf);
EXPECT_EQ(12, number_of_hex_chars);
number_of_hex_chars = char_str_to_hex_str("\nwuhuu", 6, hex_buf, true);
hex_buf[number_of_hex_chars] = '\0';
EXPECT_STREQ("A7775687575", hex_buf);
EXPECT_EQ(11, number_of_hex_chars);
// test giving a null pointer
number_of_hex_chars = char_str_to_hex_str(NULL, 4, hex_buf);
EXPECT_EQ(0, number_of_hex_chars);
number_of_hex_chars = char_str_to_hex_str("1234", 4, NULL);
EXPECT_EQ(0, number_of_hex_chars);
}
TEST_F(TestUtil, char_str_to_hex)
TEST_F(Testutil, convert_ipv6)
{
unit->test_util_char_str_to_hex();
// leading zeros omitted
char ipv6[64];
strncpy(ipv6, "1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1", 64);
convert_ipv6(ipv6);
EXPECT_STREQ("101:101:101:101:101:101:101:101", ipv6);
EXPECT_EQ(31, strlen(ipv6));
// some omitted and some not so much
strncpy(ipv6, "255.1.120.2.244.12.55.45.201.110.11.2.233.154.85.96", 64);
convert_ipv6(ipv6);
EXPECT_STREQ("FF01:7802:F40C:372D:C96E:B02:E99A:5560", ipv6);
EXPECT_EQ(38, strlen(ipv6));
// test giving a null pointer
convert_ipv6(NULL);
}
TEST_F(TestUtil, convert_ipv6)
TEST_F(Testutil, prefer_ipv6)
{
unit->test_util_convert_ipv6();
char tt[20] = "62.241.198.246";
char temp[64] = "2001:14B8:1000:000:000:000:000:002";
// not enough space to swap, arrays should stay the same
prefer_ipv6(tt, sizeof(tt), temp, sizeof(temp));
EXPECT_STREQ("62.241.198.246", tt);
EXPECT_STREQ("2001:14B8:1000:000:000:000:000:002", temp);
// should swap as first one was ip4 and later was ipv6 and enough space
char tt2[64] = "62.241.198.246";
prefer_ipv6(tt2, sizeof(tt2), temp, sizeof(temp));
EXPECT_STREQ("62.241.198.246", temp);
EXPECT_STREQ("2001:14B8:1000:000:000:000:000:002", tt2);
}
TEST_F(TestUtil, prefer_ipv6)
TEST_F(Testutil, separate_ip_addresses)
{
unit->test_util_prefer_ipv6();
}
char *s = (char *)malloc(128);
TEST_F(TestUtil, separate_ip_addresses)
{
unit->test_util_separate_ip_addresses();
char ip[64] = {0};
char subnet[64] = {0};
strncpy(s, "32.1.20.187.1.112.139.245.251.136.232.110.123.51.230.138.0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15", 94);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
EXPECT_STREQ("2001:14BB:170:8BF5:FB88:E86E:7B33:E68A", ip);
EXPECT_STREQ("001:203:405:607:809:A0B:C0D:E0F", subnet);
strncpy(s, "32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138 0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", 94);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", ip);
EXPECT_STREQ("0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "1.2.3.4\0", 8);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
EXPECT_STREQ("1.2.3.4", ip);
EXPECT_STREQ("", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "1.2.3.4.5.6.7.8\0", 16);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
EXPECT_STREQ("1.2.3.4", ip);
EXPECT_STREQ("5.6.7.8", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16\0", 39);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
EXPECT_STREQ("102:304:506:708:90A:B0C:D0E:F10", ip);
EXPECT_STREQ("", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0", 57);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", ip);
EXPECT_STREQ("", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "1.2.3.4 32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0", 65);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
EXPECT_STREQ("1.2.3.4", ip);
EXPECT_STREQ("32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138", subnet);
ip[0] = '\0';
subnet[0] = '\0';
strncpy(s, "1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20\0", 51);
separate_ip_addresses(s, ip, sizeof(ip), subnet, sizeof(subnet));
EXPECT_STREQ("1.2.3.4", ip);
EXPECT_STREQ("506:708:90A:B0C:D0E:F10:1112:1314", subnet);
EXPECT_STREQ("1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20", s);
}

View File

@ -0,0 +1,420 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ATCmdParser.h"
#include "mbed_poll.h"
#include "mbed_debug.h"
#ifdef LF
#undef LF
#define LF 10
#else
#define LF 10
#endif
#ifdef CR
#undef CR
#define CR 13
#else
#define CR 13
#endif
// getc/putc handling with timeouts
int ATCmdParser::putc(char c)
{
pollfh fhs;
fhs.fh = _fh;
fhs.events = POLLOUT;
int count = poll(&fhs, 1, _timeout);
if (count > 0 && (fhs.revents & POLLOUT)) {
return _fh->write(&c, 1) == 1 ? 0 : -1;
} else {
return -1;
}
}
int ATCmdParser::getc()
{
pollfh fhs;
fhs.fh = _fh;
fhs.events = POLLIN;
int count = poll(&fhs, 1, _timeout);
if (count > 0 && (fhs.revents & POLLIN)) {
unsigned char ch;
return _fh->read(&ch, 1) == 1 ? ch : -1;
} else {
return -1;
}
}
void ATCmdParser::flush()
{
while (_fh->readable()) {
unsigned char ch;
_fh->read(&ch, 1);
}
}
// read/write handling with timeouts
int ATCmdParser::write(const char *data, int size)
{
int i = 0;
for (; i < size; i++) {
if (putc(data[i]) < 0) {
return -1;
}
}
return i;
}
int ATCmdParser::read(char *data, int size)
{
int i = 0;
for (; i < size; i++) {
int c = getc();
if (c < 0) {
return -1;
}
data[i] = c;
}
return i;
}
// printf/scanf handling
int ATCmdParser::vprintf(const char *format, va_list args)
{
if (vsprintf(_buffer, format, args) < 0) {
return false;
}
int i = 0;
for (; _buffer[i]; i++) {
if (putc(_buffer[i]) < 0) {
return -1;
}
}
return i;
}
int ATCmdParser::vscanf(const char *format, va_list args)
{
// Since format is const, we need to copy it into our buffer to
// add the line's null terminator and clobber value-matches with asterisks.
//
// We just use the beginning of the buffer to avoid unnecessary allocations.
int i = 0;
int offset = 0;
while (format[i]) {
if (format[i] == '%' && format[i + 1] != '%' && format[i + 1] != '*') {
_buffer[offset++] = '%';
_buffer[offset++] = '*';
i++;
} else {
_buffer[offset++] = format[i++];
}
}
// Scanf has very poor support for catching errors
// fortunately, we can abuse the %n specifier to determine
// if the entire string was matched.
_buffer[offset++] = '%';
_buffer[offset++] = 'n';
_buffer[offset++] = 0;
// To workaround scanf's lack of error reporting, we actually
// make two passes. One checks the validity with the modified
// format string that only stores the matched characters (%n).
// The other reads in the actual matched values.
//
// We keep trying the match until we succeed or some other error
// derails us.
int j = 0;
while (true) {
// Ran out of space
if (j + 1 >= _buffer_size - offset) {
return false;
}
// Recieve next character
int c = getc();
if (c < 0) {
return -1;
}
_buffer[offset + j++] = c;
_buffer[offset + j] = 0;
// Check for match
int count = -1;
sscanf(_buffer + offset, _buffer, &count);
// We only succeed if all characters in the response are matched
if (count == j) {
// Store the found results
vsscanf(_buffer + offset, format, args);
return j;
}
}
}
// Command parsing with line handling
bool ATCmdParser::vsend(const char *command, va_list args)
{
// Create and send command
if (vsprintf(_buffer, command, args) < 0) {
return false;
}
for (int i = 0; _buffer[i]; i++) {
if (putc(_buffer[i]) < 0) {
return false;
}
}
// Finish with newline
for (size_t i = 0; _output_delimiter[i]; i++) {
if (putc(_output_delimiter[i]) < 0) {
return false;
}
}
debug_if(_dbg_on, "AT> %s\n", _buffer);
return true;
}
bool ATCmdParser::vrecv(const char *response, va_list args)
{
restart:
_aborted = false;
// Iterate through each line in the expected response
while (response[0]) {
// Since response is const, we need to copy it into our buffer to
// add the line's null terminator and clobber value-matches with asterisks.
//
// We just use the beginning of the buffer to avoid unnecessary allocations.
int i = 0;
int offset = 0;
bool whole_line_wanted = false;
while (response[i]) {
if (response[i] == '%' && response[i + 1] != '%' && response[i + 1] != '*') {
_buffer[offset++] = '%';
_buffer[offset++] = '*';
i++;
} else {
_buffer[offset++] = response[i++];
// Find linebreaks, taking care not to be fooled if they're in a %[^\n] conversion specification
if (response[i - 1] == '\n' && !(i >= 3 && response[i - 3] == '[' && response[i - 2] == '^')) {
whole_line_wanted = true;
break;
}
}
}
// Scanf has very poor support for catching errors
// fortunately, we can abuse the %n specifier to determine
// if the entire string was matched.
_buffer[offset++] = '%';
_buffer[offset++] = 'n';
_buffer[offset++] = 0;
debug_if(_dbg_on, "AT? %s\n", _buffer);
// To workaround scanf's lack of error reporting, we actually
// make two passes. One checks the validity with the modified
// format string that only stores the matched characters (%n).
// The other reads in the actual matched values.
//
// We keep trying the match until we succeed or some other error
// derails us.
int j = 0;
while (true) {
// Receive next character
int c = getc();
if (c < 0) {
debug_if(_dbg_on, "AT(Timeout)\n");
return false;
}
// Simplify newlines (borrowed from retarget.cpp)
if ((c == CR && _in_prev != LF) ||
(c == LF && _in_prev != CR)) {
_in_prev = c;
c = '\n';
} else if ((c == CR && _in_prev == LF) ||
(c == LF && _in_prev == CR)) {
_in_prev = c;
// onto next character
continue;
} else {
_in_prev = c;
}
_buffer[offset + j++] = c;
_buffer[offset + j] = 0;
// Check for oob data
for (struct oob *oob = _oobs; oob; oob = oob->next) {
if ((unsigned)j == oob->len && memcmp(
oob->prefix, _buffer + offset, oob->len) == 0) {
debug_if(_dbg_on, "AT! %s\n", oob->prefix);
oob->cb();
if (_aborted) {
debug_if(_dbg_on, "AT(Aborted)\n");
return false;
}
// oob may have corrupted non-reentrant buffer,
// so we need to set it up again
goto restart;
}
}
// Check for match
int count = -1;
if (whole_line_wanted && c != '\n') {
// Don't attempt scanning until we get delimiter if they included it in format
// This allows recv("Foo: %s\n") to work, and not match with just the first character of a string
// (scanf does not itself match whitespace in its format string, so \n is not significant to it)
} else {
sscanf(_buffer + offset, _buffer, &count);
}
// We only succeed if all characters in the response are matched
if (count == j) {
debug_if(_dbg_on, "AT= %s\n", _buffer + offset);
// Reuse the front end of the buffer
memcpy(_buffer, response, i);
_buffer[i] = 0;
// Store the found results
vsscanf(_buffer + offset, _buffer, args);
// Jump to next line and continue parsing
response += i;
break;
}
// Clear the buffer when we hit a newline or ran out of space
// running out of space usually means we ran into binary data
if (c == '\n' || j + 1 >= _buffer_size - offset) {
debug_if(_dbg_on, "AT< %s", _buffer + offset);
j = 0;
}
}
}
return true;
}
// Mapping to vararg functions
int ATCmdParser::printf(const char *format, ...)
{
va_list args;
va_start(args, format);
int res = vprintf(format, args);
va_end(args);
return res;
}
int ATCmdParser::scanf(const char *format, ...)
{
va_list args;
va_start(args, format);
int res = vscanf(format, args);
va_end(args);
return res;
}
bool ATCmdParser::send(const char *command, ...)
{
va_list args;
va_start(args, command);
bool res = vsend(command, args);
va_end(args);
return res;
}
bool ATCmdParser::recv(const char *response, ...)
{
va_list args;
va_start(args, response);
bool res = vrecv(response, args);
va_end(args);
return res;
}
// oob registration
void ATCmdParser::oob(const char *prefix, Callback<void()> cb)
{
struct oob *oob = new struct oob;
oob->len = strlen(prefix);
oob->prefix = prefix;
oob->cb = cb;
oob->next = _oobs;
_oobs = oob;
}
void ATCmdParser::abort()
{
_aborted = true;
}
bool ATCmdParser::process_oob()
{
if (!_fh->readable()) {
return false;
}
int i = 0;
while (true) {
// Receive next character
int c = getc();
if (c < 0) {
return false;
}
_buffer[i++] = c;
_buffer[i] = 0;
// Check for oob data
struct oob *oob = _oobs;
while (oob) {
if (i == (int)oob->len && memcmp(
oob->prefix, _buffer, oob->len) == 0) {
debug_if(_dbg_on, "AT! %s\r\n", oob->prefix);
oob->cb();
return true;
}
oob = oob->next;
}
// Clear the buffer when we hit a newline or ran out of space
// running out of space usually means we ran into binary data
if (i + 1 >= _buffer_size ||
strcmp(&_buffer[i - _output_delim_size], _output_delimiter) == 0) {
debug_if(_dbg_on, "AT< %s", _buffer);
i = 0;
}
}
}

View File

@ -31,6 +31,10 @@ const int DEFAULT_AT_TIMEOUT = 1000; // at default timeout in milliseconds
nsapi_error_t ATHandler_stub::nsapi_error_value = 0;
uint8_t ATHandler_stub::nsapi_error_ok_counter = 0;
int ATHandler_stub::int_value = -1;
int ATHandler_stub::ref_count = 0;
int ATHandler_stub::timeout = 0;
bool ATHandler_stub::default_timeout = 0;
bool ATHandler_stub::debug_on = 0;
ssize_t ATHandler_stub::ssize_value = 0;
char *ATHandler_stub::read_string_value = NULL;
size_t ATHandler_stub::size_value = 0;
@ -41,28 +45,45 @@ FileHandle_stub *ATHandler_stub::fh_value = NULL;
device_err_t ATHandler_stub::device_err_value;
Callback<void()> ATHandler_stub::callback = NULL;
uint8_t ATHandler_stub::resp_info_true_counter = false;
uint8_t ATHandler_stub::info_elem_true_counter = false;
int ATHandler_stub::int_valid_count_table[kRead_int_table_size];
int ATHandler_stub::int_count = kRead_int_table_size;
ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char *output_delimiter, uint16_t send_delay) : _nextATHandler(0),
int ATHandler_stub::read_string_index = kRead_string_table_size;
char *ATHandler_stub::read_string_table[kRead_string_table_size];
int ATHandler_stub::resp_stop_success_count = kResp_stop_count_default;
ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, int timeout, const char *output_delimiter, uint16_t send_delay) :
_nextATHandler(0),
_fileHandle(fh),
_queue(queue)
{
ATHandler_stub::ref_count = 1;
}
void ATHandler::set_debug(bool debug_on)
{
ATHandler_stub::debug_on = debug_on;
}
ATHandler::~ATHandler()
{
ATHandler_stub::ref_count = -909;
}
void ATHandler::inc_ref_count()
{
ATHandler_stub::ref_count++;
}
void ATHandler::dec_ref_count()
{
ATHandler_stub::ref_count--;
}
int ATHandler::get_ref_count()
{
return ATHandler_stub::int_value;
return ATHandler_stub::ref_count;
}
FileHandle *ATHandler::get_file_handle()
@ -77,7 +98,7 @@ void ATHandler::set_file_handle(FileHandle *fh)
nsapi_error_t ATHandler::set_urc_handler(const char *urc, mbed::Callback<void()> cb)
{
ATHandler_stub::callback = cb;
return NSAPI_ERROR_OK;
return ATHandler_stub::nsapi_error_value;
}
void ATHandler::remove_urc_handler(const char *prefix, mbed::Callback<void()> callback)
@ -108,6 +129,8 @@ nsapi_error_t ATHandler::unlock_return_error()
void ATHandler::set_at_timeout(uint32_t timeout_milliseconds, bool default_timeout)
{
ATHandler_stub::timeout = timeout_milliseconds;
ATHandler_stub::default_timeout = default_timeout;
}
void ATHandler::restore_at_timeout()
@ -120,10 +143,12 @@ void ATHandler::process_oob()
void ATHandler::clear_error()
{
ATHandler_stub::nsapi_error_ok_counter++;
}
void ATHandler::skip_param(uint32_t count)
{
}
void ATHandler::skip_param(ssize_t len, uint32_t count)
@ -137,15 +162,44 @@ ssize_t ATHandler::read_bytes(uint8_t *buf, size_t len)
ssize_t ATHandler::read_string(char *buf, size_t size, bool read_even_stop_tag)
{
if (ATHandler_stub::read_string_value && ATHandler_stub::ssize_value >= 0) {
memcpy(buf, ATHandler_stub::read_string_value, ATHandler_stub::ssize_value);
if (ATHandler_stub::read_string_index == kRead_string_table_size) {
if (ATHandler_stub::read_string_value && ATHandler_stub::ssize_value >= 0) {
memcpy(buf, ATHandler_stub::read_string_value, ATHandler_stub::ssize_value + 1);
}
return ATHandler_stub::ssize_value;
}
return ATHandler_stub::ssize_value;
ATHandler_stub::read_string_index--;
if (ATHandler_stub::read_string_index >= 0) {
char *tmp = ATHandler_stub::read_string_table[ATHandler_stub::read_string_index];
ssize_t len = strlen(tmp);
memcpy(buf, tmp, len + 1);
return len;
}
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
return -1;
}
int ATHandler::read_int()
int32_t ATHandler::read_int()
{
return ATHandler_stub::int_value;
if (ATHandler_stub::nsapi_error_value != NSAPI_ERROR_OK) {
return -1;
}
if (ATHandler_stub::int_count == kRead_int_table_size) {
return ATHandler_stub::int_value;
}
//printf("ATHandler_stub::int_count: %d", ATHandler_stub::int_count);
ATHandler_stub::int_count--;
if (ATHandler_stub::int_count < kRead_int_table_size && ATHandler_stub::int_count >= 0) {
return ATHandler_stub::int_valid_count_table[ATHandler_stub::int_count];
}
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
return -1;
}
void ATHandler::set_delimiter(char delimiter)
@ -180,6 +234,10 @@ bool ATHandler::info_resp()
bool ATHandler::info_elem(char start_tag)
{
if (ATHandler_stub::info_elem_true_counter) {
ATHandler_stub::info_elem_true_counter--;
return true;
}
return ATHandler_stub::bool_value;
}
@ -190,13 +248,18 @@ bool ATHandler::consume_to_stop_tag()
void ATHandler::resp_stop()
{
if (ATHandler_stub::resp_stop_success_count > 0) {
ATHandler_stub::resp_stop_success_count--;
return;
}
ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR;
}
void ATHandler::cmd_start(const char *cmd)
{
}
void ATHandler::write_int(int param)
void ATHandler::write_int(int32_t param)
{
}
@ -223,4 +286,5 @@ device_err_t ATHandler::get_last_device_error() const
void ATHandler::flush()
{
}

View File

@ -23,21 +23,37 @@
#include "FileHandle_stub.h"
#include "Callback.h"
namespace ATHandler_stub
{
#ifndef __AT_HANDLER_STUB_H__
#define __AT_HANDLER_STUB_H__
static const int kRead_string_table_size = 100;
static const int kRead_int_table_size = 100;
static const int kResp_stop_count_default = 100;
namespace ATHandler_stub {
extern nsapi_error_t nsapi_error_value;
extern uint8_t nsapi_error_ok_counter;
extern int int_value;
extern int ref_count;
extern int timeout;
extern bool default_timeout;
extern bool debug_on;
extern ssize_t ssize_value;
extern char *read_string_value;
extern size_t size_value;
extern size_t return_given_size;
extern bool bool_value;
extern uint8_t resp_info_true_counter;
extern uint8_t info_elem_true_counter;
extern uint8_t uint8_value;
extern mbed::FileHandle_stub *fh_value;
extern mbed::device_err_t device_err_value;
extern mbed::Callback<void()> callback;
extern char *read_string_table[kRead_string_table_size];
extern int read_string_index;
extern int int_valid_count_table[kRead_int_table_size];
extern int int_count;
extern int resp_stop_success_count;
}
} // namespace ATHandler_stub
#endif

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "nsapi_types.h"
#include "AT_CellularBase.h"
#include "AT_CellularBase_stub.h"
using namespace mbed;
ATHandler *AT_CellularBase_stub::handler_value = NULL;
ATHandler *AT_CellularBase_stub::handler_at_constructor_value = NULL;
device_err_t AT_CellularBase_stub::device_err_value;
bool AT_CellularBase_stub::supported_bool = true;
AT_CellularBase::AT_CellularBase(ATHandler &at) : _at(at)
{
AT_CellularBase_stub::handler_at_constructor_value = &_at;
}
ATHandler &AT_CellularBase::get_at_handler()
{
return *AT_CellularBase_stub::handler_value;
}
device_err_t AT_CellularBase::get_device_error() const
{
return AT_CellularBase_stub::device_err_value;
}
bool AT_CellularBase::is_supported(SupportedFeature feature)
{
return AT_CellularBase_stub::supported_bool;
}

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ATHandler.h"
namespace AT_CellularBase_stub {
extern mbed::ATHandler *handler_value;
extern mbed::ATHandler *handler_at_constructor_value;
extern mbed::device_err_t device_err_value;
extern bool supported_bool;
}

View File

@ -0,0 +1,91 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "AT_CellularDevice.h"
AT_CellularDevice::AT_CellularDevice(EventQueue &queue) :
_atHandlers(0), _network(0), _sms(0), _sim(0), _power(0), _multiplexer(0), _information(0), _queue(queue)
{
}
AT_CellularDevice::~AT_CellularDevice()
{
}
ATHandler *AT_CellularDevice::get_at_handler(FileHandle *fileHandle)
{
return NULL;
}
void AT_CellularDevice::release_at_handler(ATHandler *at_handler)
{
}
CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh)
{
return NULL;
}
CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh)
{
return NULL;
}
CellularSIM *AT_CellularDevice::open_sim(FileHandle *fh)
{
return NULL;
}
CellularPower *AT_CellularDevice::open_power(FileHandle *fh)
{
return NULL;
}
CellularMultiplexer *AT_CellularDevice::open_multiplexer(FileHandle *fh)
{
return NULL;
}
CellularInformation *AT_CellularDevice::open_information(FileHandle *fh)
{
return NULL;
}
void AT_CellularDevice::close_network()
{
}
void AT_CellularDevice::close_sms()
{
}
void AT_CellularDevice::close_power()
{
}
void AT_CellularDevice::close_sim()
{
}
void AT_CellularDevice::close_multiplexer()
{
}
void AT_CellularDevice::close_information()
{
}

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "AT_CellularInformation.h"
#include "nsapi_types.h"
using namespace mbed;
AT_CellularInformation::AT_CellularInformation(ATHandler &at) : AT_CellularBase(at)
{
}
AT_CellularInformation::~AT_CellularInformation()
{
}
nsapi_error_t AT_CellularInformation::get_manufacturer(char *buf, size_t buf_size)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularInformation::get_model(char *buf, size_t buf_size)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularInformation::get_revision(char *buf, size_t buf_size)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_size, SerialNumberType type)
{
return NSAPI_ERROR_OK;
}

View File

@ -0,0 +1,35 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "AT_CellularMultiplexer.h"
#include "CellularLog.h"
#include "nsapi_types.h"
using namespace mbed;
AT_CellularMultiplexer::AT_CellularMultiplexer(ATHandler &at) : AT_CellularBase(at)
{
}
AT_CellularMultiplexer::~AT_CellularMultiplexer()
{
}
nsapi_error_t AT_CellularMultiplexer::multiplexer_mode_start()
{
return 0;
}

View File

@ -0,0 +1,256 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "AT_CellularNetwork.h"
#include "CellularNetwork.h"
#include "CellularUtil.h"
#include "CellularLog.h"
#include "FileHandle.h"
#include "nsapi_types.h"
using namespace mbed;
using namespace mbed_cellular_util;
AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(atHandler)
{
}
AT_CellularNetwork::~AT_CellularNetwork()
{
}
nsapi_error_t AT_CellularNetwork::init()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::set_credentials(const char *apn,
const char *username, const char *password)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::set_credentials(const char *apn,
AuthenticationType type, const char *username, const char *password)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::connect(const char *apn,
const char *username, const char *password)
{
return connect();
}
nsapi_error_t AT_CellularNetwork::connect()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::activate_context()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::open_data_channel()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::disconnect()
{
return NSAPI_ERROR_OK;
}
void AT_CellularNetwork::attach(Callback<void(nsapi_event_t, intptr_t)> status_cb)
{
}
nsapi_connection_status_t AT_CellularNetwork::get_connection_status() const
{
return NSAPI_STATUS_LOCAL_UP;
}
nsapi_error_t AT_CellularNetwork::set_blocking(bool blocking)
{
return NSAPI_ERROR_OK;;
}
nsapi_ip_stack_t AT_CellularNetwork::string_to_stack_type(const char *pdp_type)
{
return IPV4_STACK;
}
nsapi_error_t AT_CellularNetwork::set_registration_urc(RegistrationType type, bool urc_on)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_network_registering_mode(NWRegisteringMode &mode)
{
mode = NWModeAutomatic;
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::set_registration(const char *plmn)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_registration_status(RegistrationType type, RegistrationStatus &status)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_cell_id(int &cell_id)
{
return NSAPI_ERROR_OK;
}
AT_CellularNetwork::RegistrationMode AT_CellularNetwork::has_registration(RegistrationType reg_type)
{
return RegistrationModeDisable;
}
nsapi_error_t AT_CellularNetwork::set_attach(int timeout)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_attach(AttachStatus &status)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::detach()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_apn_backoff_timer(int &backoffTime)
{
return NSAPI_ERROR_OK;
}
NetworkStack *AT_CellularNetwork::get_stack()
{
return NULL;
}
const char *AT_CellularNetwork::get_ip_address()
{
return NULL;
}
nsapi_error_t AT_CellularNetwork::set_stack_type(nsapi_ip_stack_t stack_type)
{
return NSAPI_ERROR_OK;
}
nsapi_ip_stack_t AT_CellularNetwork::get_stack_type()
{
return IPV4_STACK;
}
bool AT_CellularNetwork::get_modem_stack_type(nsapi_ip_stack_t requested_stack)
{
return false;
}
void AT_CellularNetwork::urc_no_carrier()
{
}
nsapi_error_t AT_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opsAct)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::set_access_technology(RadioAccessTechnology opAct)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_access_technology(RadioAccessTechnology &rat)
{
rat = RAT_CATM1;
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::scan_plmn(operList_t &operators, int &opsCount)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::set_ciot_optimization_config(Supported_UE_Opt supported_opt,
Preferred_UE_Opt preferred_opt)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_ciot_optimization_config(Supported_UE_Opt &supported_opt,
Preferred_UE_Opt &preferred_opt)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_rate_control(
CellularNetwork::RateControlExceptionReports &reports,
CellularNetwork::RateControlUplinkTimeUnit &timeUnit, int &uplinkRate)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_pdpcontext_params(pdpContextList_t &params_list)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_extended_signal_quality(int &rxlev, int &ber, int &rscp, int &ecno, int &rsrq, int &rsrp)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_signal_quality(int &rssi, int &ber)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::get_operator_params(int &format, operator_t &operator_params)
{
return NSAPI_ERROR_OK;
}
int AT_CellularNetwork::get_3gpp_error()
{
return 0;
}
nsapi_error_t AT_CellularNetwork::get_operator_names(operator_names_list &op_names)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularNetwork::do_user_authentication()
{
return NSAPI_ERROR_OK;
}

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "AT_CellularPower.h"
#include "CellularUtil.h"
#include "CellularLog.h"
using namespace mbed_cellular_util;
using namespace mbed;
AT_CellularPower::AT_CellularPower(ATHandler &at) : AT_CellularBase(at)
{
}
AT_CellularPower::~AT_CellularPower()
{
}
nsapi_error_t AT_CellularPower::on()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularPower::off()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularPower::set_at_mode()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularPower::set_power_level(int func_level, int do_reset)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularPower::reset()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularPower::opt_power_save_mode(int periodic_time, int active_time)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularPower::opt_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularPower::set_device_ready_urc_cb(mbed::Callback<void()> callback)
{
return NSAPI_ERROR_OK;
}
void AT_CellularPower::remove_device_ready_urc_cb(mbed::Callback<void()> callback)
{
}
nsapi_error_t AT_CellularPower::is_device_ready()
{
return NSAPI_ERROR_OK;
}

View File

@ -0,0 +1,59 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "AT_CellularSIM.h"
#include "CellularLog.h"
using namespace mbed;
AT_CellularSIM::AT_CellularSIM(ATHandler &at) : AT_CellularBase(at)
{
}
AT_CellularSIM::~AT_CellularSIM()
{
}
nsapi_error_t AT_CellularSIM::get_sim_state(SimState &state)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSIM::set_pin(const char *sim_pin)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSIM::change_pin(const char *sim_pin, const char *new_pin)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSIM::set_pin_query(const char *sim_pin, bool query_pin)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSIM::get_imsi(char *imsi)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSIM::get_iccid(char *buf, size_t buf_size)
{
return NSAPI_ERROR_OK;
}

View File

@ -0,0 +1,190 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <time.h>
#include "AT_CellularSMS.h"
#include "CellularLog.h"
using namespace mbed;
#define CTRL_Z "\x1a"
#define ESC "\x1b"
const int SMS_STATUS_SIZE = 12 + 1;
const int FIRST_OCTET_DELIVER_SUBMIT = 17;
const int TP_VALIDITY_PERIOD_24_HOURS = 167;
const int TP_PROTOCOL_IDENTIFIER = 0;
const int SMS_DATA_CODING_SCHEME = 0;
const uint16_t SMS_MAX_8BIT_CONCATENATED_SINGLE_SMS_SIZE = 134;
const uint16_t SMS_MAX_GSM7_CONCATENATED_SINGLE_SMS_SIZE = 153;
AT_CellularSMS::AT_CellularSMS(ATHandler &at) : AT_CellularBase(at), _cb(0), _mode(CellularSMSMmodeText),
_use_8bit_encoding(false), _sim_wait_time(0), _sms_message_ref_number(1), _sms_info(NULL)
{
}
AT_CellularSMS::~AT_CellularSMS()
{
}
void AT_CellularSMS::cmt_urc()
{
}
void AT_CellularSMS::cmti_urc()
{
}
nsapi_error_t AT_CellularSMS::set_cnmi()
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSMS::set_cmgf(int msg_format)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSMS::set_csmp(int fo, int vp, int pid, int dcs)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSMS::set_csdh(int show_header)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode)
{
return NSAPI_ERROR_OK;
}
void AT_CellularSMS::set_extra_sim_wait_time(int sim_wait_time)
{
}
char *AT_CellularSMS::create_pdu(const char *phone_number, const char *message, uint8_t message_length, uint8_t msg_parts,
uint8_t msg_part_number, uint8_t &header_size)
{
return NULL;
}
nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const char *message, int msg_len)
{
return NSAPI_ERROR_OK;
}
void AT_CellularSMS::set_sms_callback(Callback<void()> func)
{
}
nsapi_error_t AT_CellularSMS::set_cpms(const char *memr, const char *memw, const char *mems)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSMS::set_csca(const char *sca, int type)
{
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t AT_CellularSMS::set_cscs(const char *chr_set)
{
return NSAPI_ERROR_OK;
}
//nsapi_error_t AT_CellularSMS::set_csms(int msg_service)
//{
// return NSAPI_ERROR_OK;
//}
nsapi_error_t AT_CellularSMS::delete_sms(sms_info_t *sms)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSMS::delete_all_messages()
{
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t AT_CellularSMS::read_sms_from_index(int msg_index, char *buf, uint16_t len, char *phone_num, char *time_stamp)
{
return NSAPI_ERROR_OK;
}
// read msg in PDU mode
nsapi_size_or_error_t AT_CellularSMS::read_sms(sms_info_t *sms, char *buf, char *phone_num, char *time_stamp)
{
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t AT_CellularSMS::get_sms(char *buf, uint16_t len, char *phone_num, uint16_t phone_len,
char *time_stamp, uint16_t time_len, int *buf_size)
{
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t AT_CellularSMS::get_data_from_pdu(const char *pdu, sms_info_t *info, int *part_number, char *phone_number, char *msg)
{
return NSAPI_ERROR_OK;
}
// read params from User DEfined Header
int AT_CellularSMS::read_udh_from_pdu(const char *pdu, sms_info_t *info, int &part_number, int &padding_bits)
{
return 0;
}
nsapi_size_or_error_t AT_CellularSMS::read_pdu_payload(const char *pdu, int msg_len, int scheme, char *msg, int padding_bits)
{
return NSAPI_ERROR_OK;
}
void AT_CellularSMS::free_linked_list()
{
}
void AT_CellularSMS::add_info(sms_info_t *info, int index, int part_number)
{
}
// reads all the messages to the linked list AT_CellularSMS::_sms_info
nsapi_error_t AT_CellularSMS::list_messages()
{
return NSAPI_ERROR_OK;
}
AT_CellularSMS::sms_info_t *AT_CellularSMS::get_oldest_sms_index()
{
return NULL;
}
// if time_string_1 is greater (more fresh date) then return 1, same 0, smaller -1. Error -2
int AT_CellularSMS::compare_time_strings(const char *time_string_1, const char *time_string_2)
{
return 0;
}
bool AT_CellularSMS::create_time(const char *time_string, time_t *time)
{
return 0;
}

View File

@ -0,0 +1,90 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "AT_CellularStack.h"
#include "CellularUtil.h"
#include "CellularLog.h"
using namespace mbed_cellular_util;
AT_CellularStack::AT_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type) : _at(atHandler), _socket(NULL), _cid(cid), _stack_type(stack_type)
{
}
AT_CellularStack::~AT_CellularStack()
{
}
const char *AT_CellularStack::get_ip_address()
{
return NULL;
}
nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularStack::socket_close(nsapi_socket_t handle)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularStack::socket_bind(nsapi_socket_t handle, const SocketAddress &addr)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularStack::socket_listen(nsapi_socket_t handle, int backlog)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularStack::socket_connect(nsapi_socket_t handle, const SocketAddress &addr)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularStack::socket_accept(void *server, void **socket, SocketAddress *addr)
{
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t AT_CellularStack::socket_send(nsapi_socket_t handle, const void *data, unsigned size)
{
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t AT_CellularStack::socket_sendto(nsapi_socket_t handle, const SocketAddress &addr, const void *data, unsigned size)
{
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t AT_CellularStack::socket_recv(nsapi_socket_t handle, void *data, unsigned size)
{
return NSAPI_ERROR_OK;
}
nsapi_size_or_error_t AT_CellularStack::socket_recvfrom(nsapi_socket_t handle, SocketAddress *addr, void *buffer, unsigned size)
{
return NSAPI_ERROR_OK;
}
void AT_CellularStack::socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data)
{
}

View File

@ -0,0 +1,104 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "BufferedBlockDevice.h"
#include "mbed_assert.h"
#include "mbed_critical.h"
#include <algorithm>
#include <string.h>
static inline uint32_t align_down(bd_size_t val, bd_size_t size)
{
return 0;
}
BufferedBlockDevice::BufferedBlockDevice(BlockDevice *bd)
{
}
BufferedBlockDevice::~BufferedBlockDevice()
{
}
int BufferedBlockDevice::init()
{
return 0;
}
int BufferedBlockDevice::deinit()
{
return 0;
}
int BufferedBlockDevice::flush()
{
return 0;
}
int BufferedBlockDevice::sync()
{
return 0;
}
int BufferedBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int BufferedBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int BufferedBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
return 0;
}
int BufferedBlockDevice::trim(bd_addr_t addr, bd_size_t size)
{
return 0;
}
bd_size_t BufferedBlockDevice::get_read_size() const
{
return 1;
}
bd_size_t BufferedBlockDevice::get_program_size() const
{
return 1;
}
bd_size_t BufferedBlockDevice::get_erase_size() const
{
return 0;
}
bd_size_t BufferedBlockDevice::get_erase_size(bd_addr_t addr) const
{
return 0;
}
int BufferedBlockDevice::get_erase_value() const
{
return 0;
}
bd_size_t BufferedBlockDevice::size() const
{
return 0;
}

View File

@ -0,0 +1,113 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "CellularUtil.h"
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
namespace mbed_cellular_util {
#define MAX_STRING_LEN 200
void str_copy_skip_char(char *dest, uint16_t dest_size, const char *src, char c)
{
}
void str_remove_char(char *src, char c)
{
}
void uint_to_binary_str(uint32_t num, char *str, uint8_t str_size, uint8_t bit_cnt)
{
}
// converts the given str to hex string to buf
uint16_t char_str_to_hex(const char *str, uint16_t len, char *buf, bool omit_leading_zero)
{
return 0;
}
void convert_ipv6(char *ip)
{
}
char *find_dot_number(char *str, int dot_number)
{
return NULL;
}
void separate_ip4like_addresses(char *orig, char *ip, size_t ip_size, char *ip2, size_t ip2_size)
{
}
void separate_ip_addresses(char *orig, char *ip, size_t ip_size, char *ip2, size_t ip2_size)
{
}
void prefer_ipv6(char *ip, size_t ip_size, char *ip2, size_t ip2_size)
{
}
void int_to_hex_str(uint8_t num, char *buf)
{
buf[0] = '0';
buf[1] = '2';
}
int hex_str_to_int(const char *hex_string, int hex_string_length)
{
return 0;
}
int hex_str_to_char_str(const char *str, uint16_t len, char *buf)
{
return 0;
}
void uint_to_binary_str(uint32_t num, char *str, int str_size, int bit_cnt)
{
}
int char_str_to_hex_str(const char *str, uint16_t len, char *buf, bool omit_leading_zero)
{
//The code is dependent on this, so this is easiest just to put here
if (!str || !buf) {
return 0;
}
char *ptr = buf;
int i = 0;
while (i < len) {
if (omit_leading_zero == true && i == 0 && !(str[i] >> 4 & 0x0F)) {
*ptr++ = hex_values[(str[i]) & 0x0F];
} else {
*ptr++ = hex_values[((str[i]) >> 4) & 0x0F];
*ptr++ = hex_values[(str[i]) & 0x0F];
}
i++;
}
return ptr - buf;
}
uint16_t get_dynamic_ip_port()
{
return 0;
}
} // namespace mbed_cellular_util

View File

@ -0,0 +1,88 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ChainingBlockDevice.h"
#include "mbed_critical.h"
ChainingBlockDevice::ChainingBlockDevice(BlockDevice **bds, size_t bd_count)
{
}
static bool is_aligned(uint64_t x, uint64_t alignment)
{
return true;
}
int ChainingBlockDevice::init()
{
return 0;
}
int ChainingBlockDevice::deinit()
{
return 0;
}
int ChainingBlockDevice::sync()
{
return 0;
}
int ChainingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int ChainingBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int ChainingBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
return 0;
}
bd_size_t ChainingBlockDevice::get_read_size() const
{
return 0;
}
bd_size_t ChainingBlockDevice::get_program_size() const
{
return 0;
}
bd_size_t ChainingBlockDevice::get_erase_size() const
{
return 0;
}
bd_size_t ChainingBlockDevice::get_erase_size(bd_addr_t addr) const
{
return 0;
}
int ChainingBlockDevice::get_erase_value() const
{
return 0;
}
bd_size_t ChainingBlockDevice::size() const
{
return 0;
}

View File

@ -15,6 +15,7 @@
* limitations under the License.
*/
#include <cstddef>
#include "rtos/EventFlags.h"
rtos::EventFlags::EventFlags() {}

View File

@ -0,0 +1,88 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ExhaustibleBlockDevice.h"
#include "mbed.h"
#include "mbed_critical.h"
ExhaustibleBlockDevice::ExhaustibleBlockDevice(BlockDevice *bd, uint32_t erase_cycles)
{
}
ExhaustibleBlockDevice::~ExhaustibleBlockDevice()
{
}
int ExhaustibleBlockDevice::init()
{
return 0;
}
int ExhaustibleBlockDevice::deinit()
{
return 0;
}
int ExhaustibleBlockDevice::sync()
{
return 0;
}
int ExhaustibleBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int ExhaustibleBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int ExhaustibleBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
return 0;
}
bd_size_t ExhaustibleBlockDevice::get_read_size() const
{
return 0;
}
bd_size_t ExhaustibleBlockDevice::get_program_size() const
{
return 0;
}
bd_size_t ExhaustibleBlockDevice::get_erase_size() const
{
return 0;
}
bd_size_t ExhaustibleBlockDevice::get_erase_size(bd_addr_t addr) const
{
return 0;
}
int ExhaustibleBlockDevice::get_erase_value() const
{
return 0;
}
bd_size_t ExhaustibleBlockDevice::size() const
{
return 0;
}

View File

@ -0,0 +1,97 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "FlashSimBlockDevice.h"
#include "mbed_assert.h"
#include "mbed_critical.h"
#include <algorithm>
#include <stdlib.h>
#include <string.h>
static const bd_size_t min_blank_buf_size = 32;
static inline uint32_t align_up(bd_size_t val, bd_size_t size)
{
return (((val - 1) / size) + 1) * size;
}
FlashSimBlockDevice::FlashSimBlockDevice(BlockDevice *bd, uint8_t erase_value)
{
}
FlashSimBlockDevice::~FlashSimBlockDevice()
{
}
int FlashSimBlockDevice::init()
{
return 0;
}
int FlashSimBlockDevice::deinit()
{
return 0;
}
int FlashSimBlockDevice::sync()
{
return 0;
}
bd_size_t FlashSimBlockDevice::get_read_size() const
{
return 0;
}
bd_size_t FlashSimBlockDevice::get_program_size() const
{
return 0;
}
bd_size_t FlashSimBlockDevice::get_erase_size() const
{
return 0;
}
bd_size_t FlashSimBlockDevice::get_erase_size(bd_addr_t addr) const
{
return 0;
}
bd_size_t FlashSimBlockDevice::size() const
{
return 0;
}
int FlashSimBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int FlashSimBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int FlashSimBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
return 0;
}
int FlashSimBlockDevice::get_erase_value() const
{
return 0;
}

View File

@ -0,0 +1,82 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "HeapBlockDevice.h"
#include "mbed_critical.h"
HeapBlockDevice::HeapBlockDevice(bd_size_t size, bd_size_t block)
{
}
HeapBlockDevice::HeapBlockDevice(bd_size_t size, bd_size_t read, bd_size_t program, bd_size_t erase)
{
}
HeapBlockDevice::~HeapBlockDevice()
{
}
int HeapBlockDevice::init()
{
return 0;
}
int HeapBlockDevice::deinit()
{
return 0;
}
bd_size_t HeapBlockDevice::get_read_size() const
{
return 0;
}
bd_size_t HeapBlockDevice::get_program_size() const
{
return 0;
}
bd_size_t HeapBlockDevice::get_erase_size() const
{
return 0;
}
bd_size_t HeapBlockDevice::get_erase_size(bd_addr_t addr) const
{
return 0;
}
bd_size_t HeapBlockDevice::size() const
{
return 0;
}
int HeapBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int HeapBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int HeapBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
return 0;
}

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "Kernel.h"
namespace rtos {
uint64_t Kernel::get_ms_count()
{
return 20;
}
}

View File

@ -0,0 +1,156 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "MBRBlockDevice.h"
#include "mbed_critical.h"
#include <algorithm>
// On disk structures, all entries are little endian
MBED_PACKED(struct) mbr_entry {
uint8_t status;
uint8_t chs_start[3];
uint8_t type;
uint8_t chs_stop[3];
uint32_t lba_offset;
uint32_t lba_size;
};
MBED_PACKED(struct) mbr_table {
struct mbr_entry entries[4];
uint8_t signature[2];
};
// Little-endian conversion, should compile to noop
// if system is little-endian
static inline uint32_t tole32(uint32_t a)
{
return 0;
}
static inline uint32_t fromle32(uint32_t a)
{
return 0;
}
static void tochs(uint32_t lba, uint8_t chs[3])
{
}
// Partition after address are turned into absolute
// addresses, assumes bd is initialized
static int partition_absolute(
BlockDevice *bd, int part, uint8_t type,
bd_size_t offset, bd_size_t size)
{
return 0;
}
int MBRBlockDevice::partition(BlockDevice *bd, int part, uint8_t type, bd_addr_t start)
{
return 0;
}
int MBRBlockDevice::partition(BlockDevice *bd, int part, uint8_t type,
bd_addr_t start, bd_addr_t stop)
{
return 0;
}
MBRBlockDevice::MBRBlockDevice(BlockDevice *bd, int part)
{
}
int MBRBlockDevice::init()
{
return 0;
}
int MBRBlockDevice::deinit()
{
return 0;
}
int MBRBlockDevice::sync()
{
return 0;
}
int MBRBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int MBRBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int MBRBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
return 0;
}
bd_size_t MBRBlockDevice::get_read_size() const
{
return 0;
}
bd_size_t MBRBlockDevice::get_program_size() const
{
return 0;
}
bd_size_t MBRBlockDevice::get_erase_size() const
{
return 0;
}
bd_size_t MBRBlockDevice::get_erase_size(bd_addr_t addr) const
{
return 0;
}
int MBRBlockDevice::get_erase_value() const
{
return 0;
}
bd_size_t MBRBlockDevice::size() const
{
return 0;
}
bd_size_t MBRBlockDevice::get_partition_start() const
{
return 0;
}
bd_size_t MBRBlockDevice::get_partition_stop() const
{
return 0;
}
uint8_t MBRBlockDevice::get_partition_type() const
{
return 0;
}
int MBRBlockDevice::get_partition_number() const
{
return 0;
}

View File

@ -0,0 +1,89 @@
/*
* Copyright (c) 2015, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "netsocket/NetworkInterface.h"
#include "netsocket/NetworkStack.h"
#include <string.h>
// Default network-interface state
const char *NetworkInterface::get_mac_address()
{
return 0;
}
const char *NetworkInterface::get_ip_address()
{
return 0;
}
const char *NetworkInterface::get_netmask()
{
return 0;
}
const char *NetworkInterface::get_gateway()
{
return 0;
}
nsapi_error_t NetworkInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkInterface::set_dhcp(bool dhcp)
{
return NSAPI_ERROR_UNSUPPORTED;
}
// DNS operations go through the underlying stack by default
nsapi_error_t NetworkInterface::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkInterface::add_dns_server(const SocketAddress &address)
{
return NSAPI_ERROR_UNSUPPORTED;
}
void NetworkInterface::attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb)
{
}
nsapi_connection_status_t NetworkInterface::get_connection_status() const
{
return NSAPI_STATUS_LOCAL_UP;
}
nsapi_error_t NetworkInterface::set_blocking(bool blocking)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_value_or_error_t NetworkInterface::gethostbyname_async(char const *, mbed::Callback<void (int, SocketAddress *)>, nsapi_version)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkInterface::gethostbyname_async_cancel(int id)
{
return NSAPI_ERROR_UNSUPPORTED;
}

View File

@ -0,0 +1,95 @@
/*
* Copyright (c) 2015, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "NetworkStack.h"
#include "nsapi_dns.h"
#include "mbed.h"
#include "stddef.h"
#include <new>
// Default NetworkStack operations
nsapi_error_t NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t NetworkStack::add_dns_server(const SocketAddress &address)
{
return NSAPI_ERROR_OK;
}
nsapi_error_t NetworkStack::get_dns_server(int index, SocketAddress *address)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkStack::setstackopt(int level, int optname, const void *optval, unsigned optlen)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkStack::getstackopt(int level, int optname, void *optval, unsigned *optlen)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkStack::setsockopt(void *handle, int level, int optname, const void *optval, unsigned optlen)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkStack::getsockopt(void *handle, int level, int optname, void *optval, unsigned *optlen)
{
return NSAPI_ERROR_UNSUPPORTED;
}
// Conversion function for network stacks
NetworkStack *nsapi_create_stack(nsapi_stack_t *stack)
{
return NULL;
}
NetworkStack *nsapi_create_stack(NetworkStack *stack)
{
return NULL;
}
nsapi_value_or_error_t NetworkStack::gethostbyname_async(const char *host, hostbyname_cb_t callback,
nsapi_version_t version)
{
return NSAPI_ERROR_UNSUPPORTED;
}
nsapi_error_t NetworkStack::gethostbyname_async_cancel(int id)
{
return NSAPI_ERROR_UNSUPPORTED;
}
call_in_callback_cb_t NetworkStack::get_call_in_callback()
{
return NULL;
}
nsapi_error_t NetworkStack::call_in(int delay, mbed::Callback<void()> func)
{
return NSAPI_ERROR_UNSUPPORTED;
}
const char *NetworkStack::get_ip_address()
{
return NULL;
}

View File

@ -0,0 +1,100 @@
/* mbed Microcontroller Library
* Copyright (c) 2017-2017 ARM Limited
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "ObservingBlockDevice.h"
#include "ReadOnlyBlockDevice.h"
#include "mbed.h"
ObservingBlockDevice::ObservingBlockDevice(BlockDevice *bd)
{
// Does nothing
}
ObservingBlockDevice::~ObservingBlockDevice()
{
// Does nothing
}
void ObservingBlockDevice::attach(Callback<void(BlockDevice *)> cb)
{
}
int ObservingBlockDevice::init()
{
return 0;
}
int ObservingBlockDevice::deinit()
{
return 0;
}
int ObservingBlockDevice::sync()
{
return 0;
}
int ObservingBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int ObservingBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int ObservingBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
return 0;
}
bd_size_t ObservingBlockDevice::get_read_size() const
{
return 0;
}
bd_size_t ObservingBlockDevice::get_program_size() const
{
return 0;
}
bd_size_t ObservingBlockDevice::get_erase_size() const
{
return 0;
}
bd_size_t ObservingBlockDevice::get_erase_size(bd_addr_t addr) const
{
return 0;
}
int ObservingBlockDevice::get_erase_value() const
{
return 0;
}
bd_size_t ObservingBlockDevice::size() const
{
return 0;
}

View File

@ -0,0 +1,101 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ProfilingBlockDevice.h"
ProfilingBlockDevice::ProfilingBlockDevice(BlockDevice *bd)
{
}
int ProfilingBlockDevice::init()
{
return 0;
}
int ProfilingBlockDevice::deinit()
{
return 0;
}
int ProfilingBlockDevice::sync()
{
return 0;
}
int ProfilingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int ProfilingBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int ProfilingBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
return 0;
}
bd_size_t ProfilingBlockDevice::get_read_size() const
{
return 0;
}
bd_size_t ProfilingBlockDevice::get_program_size() const
{
return 0;
}
bd_size_t ProfilingBlockDevice::get_erase_size() const
{
return 0;
}
bd_size_t ProfilingBlockDevice::get_erase_size(bd_addr_t addr) const
{
return 0;
}
int ProfilingBlockDevice::get_erase_value() const
{
return 0;
}
bd_size_t ProfilingBlockDevice::size() const
{
return 0;
}
void ProfilingBlockDevice::reset()
{
}
bd_size_t ProfilingBlockDevice::get_read_count() const
{
return 0;
}
bd_size_t ProfilingBlockDevice::get_program_count() const
{
return 0;
}
bd_size_t ProfilingBlockDevice::get_erase_count() const
{
return 0;
}

View File

@ -0,0 +1,95 @@
/* mbed Microcontroller Library
* Copyright (c) 2017-2017 ARM Limited
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "ReadOnlyBlockDevice.h"
#include "mbed_error.h"
ReadOnlyBlockDevice::ReadOnlyBlockDevice(BlockDevice *bd)
{
// Does nothing
}
ReadOnlyBlockDevice::~ReadOnlyBlockDevice()
{
// Does nothing
}
int ReadOnlyBlockDevice::init()
{
return 0;
}
int ReadOnlyBlockDevice::deinit()
{
return 0;
}
int ReadOnlyBlockDevice::sync()
{
return 0;
}
int ReadOnlyBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int ReadOnlyBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int ReadOnlyBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
return 0;
}
bd_size_t ReadOnlyBlockDevice::get_read_size() const
{
return 0;
}
bd_size_t ReadOnlyBlockDevice::get_program_size() const
{
return 0;
}
bd_size_t ReadOnlyBlockDevice::get_erase_size() const
{
return 0;
}
bd_size_t ReadOnlyBlockDevice::get_erase_size(bd_addr_t addr) const
{
return 0;
}
int ReadOnlyBlockDevice::get_erase_value() const
{
return 0;
}
bd_size_t ReadOnlyBlockDevice::size() const
{
return 0;
}

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "Semaphore.h"
namespace rtos {
Semaphore::Semaphore(int32_t count)
{
}
Semaphore::Semaphore(int32_t count, uint16_t max_count)
{
}
void Semaphore::constructor(int32_t count, uint16_t max_count)
{
}
int32_t Semaphore::wait(uint32_t millisec)
{
return 0;
}
int32_t Semaphore::wait_until(uint64_t millisec)
{
return 0;
}
osStatus Semaphore::release(void)
{
return 0;
}
Semaphore::~Semaphore()
{
}
}

View File

@ -0,0 +1,83 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "SlicingBlockDevice.h"
SlicingBlockDevice::SlicingBlockDevice(BlockDevice *bd, bd_addr_t start, bd_addr_t stop)
{
}
int SlicingBlockDevice::init()
{
return 0;
}
int SlicingBlockDevice::deinit()
{
return 0;
}
int SlicingBlockDevice::sync()
{
return 0;
}
int SlicingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int SlicingBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
{
return 0;
}
int SlicingBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
return 0;
}
bd_size_t SlicingBlockDevice::get_read_size() const
{
return 0;
}
bd_size_t SlicingBlockDevice::get_program_size() const
{
return 0;
}
bd_size_t SlicingBlockDevice::get_erase_size() const
{
return 0;
}
bd_size_t SlicingBlockDevice::get_erase_size(bd_addr_t addr) const
{
return 0;
}
int SlicingBlockDevice::get_erase_value() const
{
return 0;
}
bd_size_t SlicingBlockDevice::size() const
{
return 0;
}

View File

@ -0,0 +1,145 @@
/*
* Copyright (c) 2015, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "SocketAddress.h"
#include "NetworkInterface.h"
#include "NetworkStack.h"
#include <string.h>
#include "mbed.h"
static bool ipv4_is_valid(const char *addr)
{
return false;
}
static bool ipv6_is_valid(const char *addr)
{
return false;
}
static void ipv4_from_address(uint8_t *bytes, const char *addr)
{
}
static int ipv6_scan_chunk(uint16_t *shorts, const char *chunk)
{
return 0;
}
static void ipv6_from_address(uint8_t *bytes, const char *addr)
{
}
static void ipv4_to_address(char *addr, const uint8_t *bytes)
{
}
static void ipv6_to_address(char *addr, const uint8_t *bytes)
{
}
SocketAddress::SocketAddress(nsapi_addr_t addr, uint16_t port)
{
}
SocketAddress::SocketAddress(const char *addr, uint16_t port)
{
}
SocketAddress::SocketAddress(const void *bytes, nsapi_version_t version, uint16_t port)
{
}
SocketAddress::SocketAddress(const SocketAddress &addr)
{
}
SocketAddress::~SocketAddress()
{
}
bool SocketAddress::set_ip_address(const char *addr)
{
return false;
}
void SocketAddress::set_ip_bytes(const void *bytes, nsapi_version_t version)
{
}
void SocketAddress::set_addr(nsapi_addr_t addr)
{
}
void SocketAddress::set_port(uint16_t port)
{
}
const char *SocketAddress::get_ip_address() const
{
return NULL;
}
const void *SocketAddress::get_ip_bytes() const
{
return NULL;
}
nsapi_version_t SocketAddress::get_ip_version() const
{
nsapi_version_t ver = NSAPI_IPv6;
return ver;
}
nsapi_addr_t SocketAddress::get_addr() const
{
nsapi_addr_t addr;
addr.version = NSAPI_IPv6;
return _addr;
}
uint16_t SocketAddress::get_port() const
{
return 0;
}
SocketAddress::operator bool() const
{
return false;
}
SocketAddress &SocketAddress::operator=(const SocketAddress &addr)
{
set_addr(addr.get_addr());
set_port(addr.get_port());
return *this;
}
bool operator==(const SocketAddress &a, const SocketAddress &b)
{
return false;
}
bool operator!=(const SocketAddress &a, const SocketAddress &b)
{
return false;
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "Thread.h"
namespace rtos {
osStatus Thread::wait_until(uint64_t millisec)
{
return 0;
}
}

View File

@ -0,0 +1,74 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "Timer.h"
#include "Timer_stub.h"
namespace mbed {
Timer::Timer()
{
}
Timer::Timer(const ticker_data_t *data)
{
}
Timer::~Timer()
{
}
void Timer::start()
{
}
void Timer::stop()
{
;
}
int Timer::read_us()
{
return 0;
}
float Timer::read()
{
return 0;
}
int Timer::read_ms()
{
timer_stub_value += timer_stub_step;
return timer_stub_value;
}
us_timestamp_t Timer::read_high_resolution_us()
{
return 0;
}
void Timer::reset()
{
}
Timer::operator float()
{
return 0;
}
} // namespace mbed

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TIMER_STUB_H
#define TIMER_STUB_H
static uint16_t timer_stub_value = 0;
static uint16_t timer_stub_step = 20;
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -15,25 +15,90 @@
* limitations under the License.
*/
#include "equeue/equeue.h"
#include "equeue.h"
void *equeue_alloc(equeue_t *q, size_t size)
{
}
int equeue_post(equeue_t *q, void (*cb)(void *), void *p)
int equeue_create(equeue_t *queue, size_t size)
{
return 0;
}
void equeue_event_delay(void *p, int ms)
int equeue_create_inplace(equeue_t *queue, size_t size, void *buffer)
{
return 0;
}
void equeue_event_period(void *p, int ms)
void equeue_destroy(equeue_t *queue)
{
}
void equeue_event_dtor(void *p, void (*dtor)(void *))
void equeue_dispatch(equeue_t *queue, int ms)
{
}
void equeue_break(equeue_t *queue)
{
}
int equeue_call(equeue_t *queue, void (*cb)(void *), void *data)
{
return 0;
}
int equeue_call_in(equeue_t *queue, int ms, void (*cb)(void *), void *data)
{
return 0;
}
int equeue_call_every(equeue_t *queue, int ms, void (*cb)(void *), void *data)
{
return 0;
}
void *equeue_alloc(equeue_t *queue, size_t size)
{
return NULL;
}
void equeue_dealloc(equeue_t *queue, void *event)
{
}
void equeue_event_delay(void *event, int ms)
{
}
void equeue_event_period(void *event, int ms)
{
}
void equeue_event_dtor(void *event, void (*dtor)(void *))
{
}
int equeue_post(equeue_t *queue, void (*cb)(void *), void *event)
{
return 0;
}
void equeue_cancel(equeue_t *queue, int id)
{
}
void equeue_background(equeue_t *queue,
void (*update)(void *timer, int ms), void *timer)
{
}
void equeue_chain(equeue_t *queue, equeue_t *target)
{
}

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed_assert.h"
void mbed_assert_internal(const char *expr, const char *file, int line)
{
}

View File

@ -0,0 +1,115 @@
/*
* Copyright (c) 2015-2016, ARM Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Declare __STDC_LIMIT_MACROS so stdint.h defines UINT32_MAX when using C++ */
#define __STDC_LIMIT_MACROS
#include "hal/critical_section_api.h"
#include "cmsis.h"
#include "platform/mbed_assert.h"
#include "platform/mbed_critical.h"
#include "platform/mbed_toolchain.h"
static volatile uint32_t critical_section_reentrancy_counter = 0;
bool core_util_are_interrupts_enabled(void)
{
return false;
}
bool core_util_is_isr_active(void)
{
return false;
}
bool core_util_in_critical_section(void)
{
return false;
}
void core_util_critical_section_enter(void)
{
}
void core_util_critical_section_exit(void)
{
}
bool core_util_atomic_cas_u8(volatile uint8_t *ptr, uint8_t *expectedCurrentValue, uint8_t desiredValue)
{
return false;
}
bool core_util_atomic_cas_u16(volatile uint16_t *ptr, uint16_t *expectedCurrentValue, uint16_t desiredValue)
{
return false;
}
bool core_util_atomic_cas_u32(volatile uint32_t *ptr, uint32_t *expectedCurrentValue, uint32_t desiredValue)
{
return false;
}
uint8_t core_util_atomic_incr_u8(volatile uint8_t *valuePtr, uint8_t delta)
{
return 0;
}
uint16_t core_util_atomic_incr_u16(volatile uint16_t *valuePtr, uint16_t delta)
{
return 0;
}
uint32_t core_util_atomic_incr_u32(volatile uint32_t *valuePtr, uint32_t delta)
{
return 0;
}
uint8_t core_util_atomic_decr_u8(volatile uint8_t *valuePtr, uint8_t delta)
{
return 0;
}
uint16_t core_util_atomic_decr_u16(volatile uint16_t *valuePtr, uint16_t delta)
{
return 0;
}
uint32_t core_util_atomic_decr_u32(volatile uint32_t *valuePtr, uint32_t delta)
{
return 0;
}
bool core_util_atomic_cas_ptr(void *volatile *ptr, void **expectedCurrentValue, void *desiredValue)
{
return false;
}
void *core_util_atomic_incr_ptr(void *volatile *valuePtr, ptrdiff_t delta)
{
return NULL;
}
void *core_util_atomic_decr_ptr(void *volatile *valuePtr, ptrdiff_t delta)
{
return NULL;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -14,18 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_AT_CELLULARBASE_H
#define TEST_AT_CELLULARBASE_H
class Test_AT_CellularBase {
public:
Test_AT_CellularBase();
#include "mbed_poll.h"
#include "mbed_poll_stub.h"
virtual ~Test_AT_CellularBase();
int mbed_poll_stub::revents_value = POLLOUT;
int mbed_poll_stub::int_value = 0;
void test_AT_CellularBase_get_at_handler();
namespace mbed {
void test_AT_CellularBase_get_device_error();
};
int poll(pollfh fhs[], unsigned nfhs, int timeout)
{
fhs->revents = mbed_poll_stub::revents_value;
return mbed_poll_stub::int_value;
}
#endif // TEST_AT_CELLULARBASE_H
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MBED_POLL_STUB_H__
#define __MBED_POLL_STUB_H__
#include <stdint.h>
namespace mbed_poll_stub {
extern int revents_value;
extern int int_value;
}
#endif

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed_wait_api.h"
void wait(float s)
{
}
void wait_ms(int ms)
{
}
void wait_us(int us)
{
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "randLIB.h"
void randLIB_seed_random(void)
{
}
uint16_t randLIB_get_random_in_range(uint16_t min, uint16_t max)
{
return min;
}

View File

@ -0,0 +1,54 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "stdlib.h"
#include "us_ticker_api.h"
const ticker_data_t *get_us_ticker_data(void)
{
return NULL;
}
void us_ticker_irq_handler(void)
{
}
void us_ticker_init(void)
{
}
uint32_t us_ticker_read(void)
{
return 0;
}
void us_ticker_set_interrupt(timestamp_t timestamp)
{
}
void us_ticker_disable_interrupt(void)
{
}
void us_ticker_clear_interrupt(void)
{
}
void us_ticker_fire_interrupt(void)
{
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __AT_CMD_PARSER_H__
#define __AT_CMD_PARSER_H__
#include "mbed.h"
#include <cstdarg>
#include "FileHandle.h"
class ATCmdParser {
public:
ATCmdParser(mbed::FileHandle *fh, const char *output_delimiter = "\r",
int buffer_size = 256, int timeout = 8000, bool debug = false) {}
~ATCmdParser() {}
};
#endif //__AT_CMD_PARSER_H__

View File

@ -0,0 +1,16 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

View File

@ -0,0 +1,16 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

View File

@ -0,0 +1,16 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Arm Limited and affiliates.
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -14,24 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_UTIL_H
#define TEST_UTIL_H
class Test_util {
public:
Test_util();
#ifndef CMSIS_OS_H_
#define CMSIS_OS_H_
virtual ~Test_util();
#include "cmsis_os2.h"
void test_util_uint_to_binary_string();
#define osPriority osPriority_t
void test_util_char_str_to_hex();
#define osThreadId osThreadId_t
void test_util_convert_ipv6();
typedef struct {
} osEvent;
void test_util_prefer_ipv6();
void test_util_separate_ip_addresses();
};
#endif // TEST_UTIL_H
#endif

View File

@ -0,0 +1,78 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __CMSIS_OS2_H__
#define __CMSIS_OS2_H__
#include <inttypes.h>
//If conflicts, then remove these, copied from cmsis_os.h
typedef int32_t osStatus;
#define osOK 0
//These are from cmsis_os2.h
typedef void *osSemaphoreId_t;
typedef struct {
const char *name; ///< name of the semaphore
uint32_t attr_bits; ///< attribute bits
void *cb_mem; ///< memory for control block
uint32_t cb_size; ///< size of provided memory for control block
} osSemaphoreAttr_t;
//Thread
typedef enum {
osPriorityNormal = 24 ///< Priority: normal
} osPriority_t;
typedef void *osThreadId_t;
typedef void *osEventFlagsId_t;
/// Attributes structure for thread.
typedef struct {
} osThreadAttr_t;
#define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value.
// Flags options (\ref osThreadFlagsWait and \ref osEventFlagsWait).
#define osFlagsWaitAny 0x00000000U ///< Wait for any flag (default).
#define osFlagsWaitAll 0x00000001U ///< Wait for all flags.
#define osFlagsNoClear 0x00000002U ///< Do not clear flags which have been specified to wait for.
// Flags errors (returned by osThreadFlagsXxxx and osEventFlagsXxxx).
#define osFlagsError 0x80000000U ///< Error indicator.
#define osFlagsErrorUnknown 0xFFFFFFFFU ///< osError (-1).
#define osFlagsErrorTimeout 0xFFFFFFFEU ///< osErrorTimeout (-2).
#define osFlagsErrorResource 0xFFFFFFFDU ///< osErrorResource (-3).
#define osFlagsErrorParameter 0xFFFFFFFCU ///< osErrorParameter (-4).
#define osFlagsErrorISR 0xFFFFFFFAU ///< osErrorISR (-6).
// Thread attributes (attr_bits in \ref osThreadAttr_t).
#define osThreadDetached 0x00000000U ///< Thread created in detached mode (default)
#define osThreadJoinable 0x00000001U ///< Thread created in joinable mode
// Mutex attributes (attr_bits in \ref osMutexAttr_t).
#define osMutexRecursive 0x00000001U ///< Recursive mutex.
#define osMutexPrioInherit 0x00000002U ///< Priority inherit protocol.
#define osMutexRobust 0x00000008U ///< Robust mutex.
#endif

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* Copyright (c) 2018, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -22,6 +22,7 @@
#include <cstring>
#include "events/mbed_events.h"
#include "events/mbed_shared_queues.h"
namespace mbed {
#include "platform/Callback.h"

View File

@ -18,6 +18,7 @@
#ifndef MBED_RTOS1_TYPES_H
#define MBED_RTOS1_TYPES_H
#include "cmsis_os.h"
#include "mbed_rtos_storage.h"
#endif // MBED_RTOS1_TYPES_H

View File

@ -23,17 +23,13 @@ extern "C" {
#endif
#include "cmsis_os2.h"
#include "rtx_os.h"
#include "rtx_lib.h"
#include "mbed_rtx_conf.h"
typedef osMutexId_t mbed_rtos_storage_mutex_t;
typedef osSemaphoreId_t mbed_rtos_storage_semaphore_t;
typedef osThreadId_t mbed_rtos_storage_thread_t;
typedef osThreadId_t osThreadId;
typedef osMemoryPoolId_t mbed_rtos_storage_mem_pool_t;
typedef osMessageQueueId_t mbed_rtos_storage_msg_queue_t;
typedef osEventFlagsId_t mbed_rtos_storage_event_flags_t;
typedef void *mbed_rtos_storage_message_t;
typedef osTimerId_t mbed_rtos_storage_timer_t;
typedef osStatus_t osStatus;
typedef os_semaphore_t mbed_rtos_storage_semaphore_t;
typedef os_thread_t mbed_rtos_storage_thread_t;
typedef osRtxEventFlags_t mbed_rtos_storage_event_flags_t;
#ifdef __cplusplus
}

View File

@ -0,0 +1,16 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OS_STACK_SIZE
#define OS_STACK_SIZE 0
#endif

View File

@ -0,0 +1,16 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

View File

@ -0,0 +1,17 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

View File

@ -18,7 +18,15 @@
#ifndef RETARGET_H
#define RETARGET_H
#include <inttypes.h>
#include <sys/types.h>
#include <stdio.h>
#include <time.h>
namespace mbed {
#define NAME_MAX 255
#undef EPERM
#define EPERM 1 /* Operation not permitted */
@ -283,4 +291,75 @@
#undef ENOTRECOVERABLE
#define ENOTRECOVERABLE 131 /* State not recoverable */
#define _IFMT 0170000 //< type of file
#define _IFSOCK 0140000 //< socket
#define _IFLNK 0120000 //< symbolic link
#define _IFREG 0100000 //< regular
#define _IFBLK 0060000 //< block special
#define _IFDIR 0040000 //< directory
#define _IFCHR 0020000 //< character special
#define _IFIFO 0010000 //< fifo special
#define O_RDONLY 0 ///< Open for reading
#define O_WRONLY 1 ///< Open for writing
#define O_RDWR 2 ///< Open for reading and writing
#define O_NONBLOCK 0x0004 ///< Non-blocking mode
#define O_APPEND 0x0008 ///< Set file offset to end of file prior to each write
#define O_CREAT 0x0200 ///< Create file if it does not exist
#define O_TRUNC 0x0400 ///< Truncate file to zero length
#define O_EXCL 0x0800 ///< Fail if file exists
#define O_BINARY 0x8000 ///< Open file in binary mode
#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
#define NAME_MAX 255 ///< Maximum size of a name in a file path
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
struct statvfs {
unsigned long f_bsize; ///< Filesystem block size
unsigned long f_frsize; ///< Fragment size (block size)
fsblkcnt_t f_blocks; ///< Number of blocks
fsblkcnt_t f_bfree; ///< Number of free blocks
fsblkcnt_t f_bavail; ///< Number of free blocks for unprivileged users
unsigned long f_fsid; ///< Filesystem ID
unsigned long f_namemax; ///< Maximum filename length
};
struct dirent {
char d_name[NAME_MAX + 1]; ///< Name of file
uint8_t d_type; ///< Type of file
};
enum {
DT_UNKNOWN, ///< The file type could not be determined.
DT_FIFO, ///< This is a named pipe (FIFO).
DT_CHR, ///< This is a character device.
DT_DIR, ///< This is a directory.
DT_BLK, ///< This is a block device.
DT_REG, ///< This is a regular file.
DT_LNK, ///< This is a symbolic link.
DT_SOCK, ///< This is a UNIX domain socket.
};
/* fcntl.h defines */
#define F_GETFL 3
#define F_SETFL 4
struct pollfd {
int fd;
short events;
short revents;
};
}
#endif //RETARGET_H

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2017, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FEATURES_CELLULAR_UNITTESTS_TARGET_H_RANDLIB_H_
#define FEATURES_CELLULAR_UNITTESTS_TARGET_H_RANDLIB_H_
#include <stdint.h>
extern void randLIB_seed_random(void);
uint16_t randLIB_get_random_in_range(uint16_t min, uint16_t max);
#endif /* FEATURES_CELLULAR_UNITTESTS_TARGET_H_RANDLIB_H_ */

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __MUTEX_H__
#define __MUTEX_H__
#include <inttypes.h>
#include "cmsis_os2.h"
namespace rtos {
class Mutex {
public:
Mutex();
Mutex(const char *name);
osStatus lock(uint32_t millisec=osWaitForever);
bool trylock();
bool trylock_for(uint32_t millisec);
bool trylock_until(uint64_t millisec);
osStatus unlock();
osThreadId_t get_owner();
~Mutex();
};
}
#endif

View File

@ -0,0 +1,18 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
typedef void *Semaphore;

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __RTX_LIB_H__
#define __RTX_LIB_H__
#include "rtx_os.h"
#define os_semaphore_t osRtxSemaphore_t
#define os_thread_t osRtxThread_t
#endif

View File

@ -0,0 +1,70 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __RTX_OS__
#define __RTX_OS__
#include "inttypes.h"
typedef struct osRtxSemaphore_s {
uint8_t id; ///< Object Identifier
uint8_t state; ///< Object State
uint8_t flags; ///< Object Flags
uint8_t reserved;
const char *name; ///< Object Name
uint16_t tokens; ///< Current number of tokens
uint16_t max_tokens; ///< Maximum number of tokens
} osRtxSemaphore_t;
typedef struct osRtxThread_s {
uint8_t id; ///< Object Identifier
uint8_t state; ///< Object State
uint8_t flags; ///< Object Flags
uint8_t attr; ///< Object Attributes
const char *name; ///< Object Name
struct osRtxThread_s *thread_next; ///< Link pointer to next Thread in Object list
struct osRtxThread_s *thread_prev; ///< Link pointer to previous Thread in Object list
struct osRtxThread_s *delay_next; ///< Link pointer to next Thread in Delay list
struct osRtxThread_s *delay_prev; ///< Link pointer to previous Thread in Delay list
struct osRtxThread_s *thread_join; ///< Thread waiting to Join
uint32_t delay; ///< Delay Time
int8_t priority; ///< Thread Priority
int8_t priority_base; ///< Base Priority
uint8_t stack_frame; ///< Stack Frame (EXC_RETURN[7..0])
uint8_t flags_options; ///< Thread/Event Flags Options
uint32_t wait_flags; ///< Waiting Thread/Event Flags
uint32_t thread_flags; ///< Thread Flags
struct osRtxMutex_s *mutex_list; ///< Link pointer to list of owned Mutexes
void *stack_mem; ///< Stack Memory
uint32_t stack_size; ///< Stack Size
uint32_t sp; ///< Current Stack Pointer
uint32_t thread_addr; ///< Thread entry address
uint32_t tz_memory; ///< TrustZone Memory Identifier
void *context; ///< Context for OsEventObserver objects
} osRtxThread_t;
typedef struct {
uint8_t id; ///< Object Identifier
uint8_t state; ///< Object State
uint8_t flags; ///< Object Flags
uint8_t reserved;
const char *name; ///< Object Name
osRtxThread_t *thread_list; ///< Waiting Threads List
uint32_t event_flags; ///< Event Flags
} osRtxEventFlags_t;
#endif

View File

@ -0,0 +1,17 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define NAME_MAX 255