Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mbed-client/m2mresourceinstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ friend class M2MResource;
* \brief Converts a value to integer and returns it. Note: Conversion
* errors are not detected.
*/
int get_value_int();
int64_t get_value_int() const;

/**
* Get the value as a string object. No encoding/charset conversions
Expand Down
3 changes: 2 additions & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"license": "Apache-2.0",
"dependencies": {
"mbed-client-c": "^5.0.0",
"mbed-trace": ">=0.2.0,<2.0.0"
"mbed-trace": ">=0.2.0,<2.0.0",
"nanostack-libservice": "^3.0.0"
},
"targetDependencies": {
"arm": {
Expand Down
3 changes: 2 additions & 1 deletion run_unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ find ./build -name '*.xml' | xargs cp -t ./results/
find ./build/x86-linux-native-coverage/test -name '*.gcno' | xargs cp -t ./coverage/
find ./build/x86-linux-native-coverage/test -name '*.gcda' | xargs cp -t ./coverage/
touch coverage/*.gcda
exclude_files="${PWD}/test/"
exclude_files="${PWD}/test/|${PWD}/yotta_modules*"
#exclude_files2="${PWD}/yotta_modules*"
gcovr -r ./ --gcov-filter='.*source*.' --exclude-unreachable-branches --exclude $exclude_files --object-directory ./coverage -x -o ./results/gcovr.xml
echo
echo "Create coverage document"
Expand Down
2 changes: 2 additions & 0 deletions source/include/m2mtlvserializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,6 @@ private :
static void serialize_id(uint16_t id, uint32_t &size, uint8_t *id_ptr);

static void serialize_length(uint32_t length, uint32_t &size, uint8_t *length_ptr);

static bool serialize_TLV_binary_int(const M2MResourceInstance *resource, uint8_t type, uint16_t id, uint8_t *&data, uint32_t &size);
};
17 changes: 6 additions & 11 deletions source/m2mresourceinstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,12 @@ void M2MResourceInstance::get_value(uint8_t *&value, uint32_t &value_length)
}
}

int M2MResourceInstance::get_value_int()
{
int value_int = 0;
// Get the value and convert it into integer. This is not the most
// efficient way, as it takes pointless heap copy to get the zero termination.
uint8_t* buffer = NULL;
uint32_t length;
get_value(buffer,length);
if(buffer) {
value_int = atoi((const char*)buffer);
free(buffer);
int64_t M2MResourceInstance::get_value_int() const
{
int64_t value_int = 0;

if(_value) {
value_int = atoll((const char*)_value);
}
return value_int;
}
Expand Down
46 changes: 44 additions & 2 deletions source/m2mtlvserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "include/nsdllinker.h"
#include "mbed-client/m2mconstants.h"
#include <stdlib.h>
#include "common_functions.h"

#define TRACE_GROUP "mClt"

Expand Down Expand Up @@ -126,8 +127,15 @@ bool M2MTLVSerializer::serialize_resource(const M2MResource *resource, uint8_t *
{
bool success = false;
if(resource->name_id() != -1) {
success = serialize_TILV(TYPE_RESOURCE, resource->name_id(),
if ( (resource->resource_instance_type() == M2MResourceInstance::INTEGER) ||
(resource->resource_instance_type() == M2MResourceInstance::BOOLEAN) ||
(resource->resource_instance_type() == M2MResourceInstance::TIME) ) {
success = serialize_TLV_binary_int(resource, TYPE_RESOURCE, resource->name_id(), data, size);
}
else {
success = serialize_TILV(TYPE_RESOURCE, resource->name_id(),
resource->value(), resource->value_length(), data, size);
}
}
return success;
}
Expand Down Expand Up @@ -166,9 +174,43 @@ bool M2MTLVSerializer::serialize_multiple_resource(const M2MResource *resource,

bool M2MTLVSerializer::serialize_resource_instance(uint16_t id, const M2MResourceInstance *resource, uint8_t *&data, uint32_t &size)
{
return serialize_TILV(TYPE_RESOURCE_INSTANCE, id, resource->value(), resource->value_length(), data, size);
bool success;

if ( (resource->resource_instance_type() == M2MResourceInstance::INTEGER) ||
(resource->resource_instance_type() == M2MResourceInstance::BOOLEAN) ||
(resource->resource_instance_type() == M2MResourceInstance::TIME) ) {
success=serialize_TLV_binary_int(resource, TYPE_RESOURCE_INSTANCE, id, data, size);
}
else {
success=serialize_TILV(TYPE_RESOURCE_INSTANCE, id, resource->value(), resource->value_length(), data, size);
}

return success;
}

/* See, OMA-TS-LightweightM2M-V1_0-20170208-A, Appendix C,
* Data Types, Integer, Boolean and TY
* Yime, TLV Format */
bool M2MTLVSerializer::serialize_TLV_binary_int(const M2MResourceInstance *resource, uint8_t type, uint16_t id, uint8_t *&data, uint32_t &size)
{
int64_t valueInt = resource->get_value_int();
uint32_t buffer_size;
/* max len 8 bytes */
uint8_t buffer[8];

if (resource->resource_instance_type() == M2MResourceInstance::BOOLEAN) {
buffer_size = 1;
buffer[0] = valueInt;
}
else {
buffer_size = 8;
common_write_64_bit(valueInt, buffer);
}

return serialize_TILV(type, id, buffer, buffer_size, data, size);
}


bool M2MTLVSerializer::serialize_TILV(uint8_t type, uint16_t id, uint8_t *value, uint32_t value_length, uint8_t *&data, uint32_t &size)
{
uint8_t *tlv = 0;
Expand Down
1 change: 1 addition & 0 deletions test/mbedclient/utest/m2mtlvdeserializer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_executable(m2mtlv
target_link_libraries(m2mtlv
CppUTest
CppUTestExt
nanostack-libservice
)
set_target_properties(m2mtlv
PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS}"
Expand Down
10 changes: 3 additions & 7 deletions test/mbedclient/utest/stub/m2mresourceinstance_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,16 @@ void M2MResourceInstance::get_value(uint8_t *&value, uint32_t &value_length)
}
}

int M2MResourceInstance::get_value_int()
int64_t M2MResourceInstance::get_value_int() const
{
// Note: this is a copy-paste from the original version, as the tests
// set only m2mresourceinstance_stub::value.

int value_int = 0;
// Get the value and convert it into integer. This is not the most
// efficient way, as it takes pointless heap copy to get the zero termination.
uint8_t* buffer = NULL;
uint32_t length;
get_value(buffer,length);
uint8_t* buffer = m2mresourceinstance_stub::value;

if(buffer) {
value_int = atoi((const char*)buffer);
free(buffer);
}
return value_int;
}
Expand Down