|
17 | 17 | #include "include/nsdllinker.h"
|
18 | 18 | #include "mbed-client/m2mconstants.h"
|
19 | 19 | #include <stdlib.h>
|
| 20 | +#include "common_functions.h" |
20 | 21 |
|
21 | 22 | #define TRACE_GROUP "mClt"
|
22 | 23 |
|
@@ -126,8 +127,15 @@ bool M2MTLVSerializer::serialize_resource(const M2MResource *resource, uint8_t *
|
126 | 127 | {
|
127 | 128 | bool success = false;
|
128 | 129 | if(resource->name_id() != -1) {
|
129 |
| - success = serialize_TILV(TYPE_RESOURCE, resource->name_id(), |
| 130 | + if ( (resource->resource_instance_type() == M2MResourceInstance::INTEGER) || |
| 131 | + (resource->resource_instance_type() == M2MResourceInstance::BOOLEAN) || |
| 132 | + (resource->resource_instance_type() == M2MResourceInstance::TIME) ) { |
| 133 | + success = serialize_TLV_binary_int(resource, TYPE_RESOURCE, resource->name_id(), data, size); |
| 134 | + } |
| 135 | + else { |
| 136 | + success = serialize_TILV(TYPE_RESOURCE, resource->name_id(), |
130 | 137 | resource->value(), resource->value_length(), data, size);
|
| 138 | + } |
131 | 139 | }
|
132 | 140 | return success;
|
133 | 141 | }
|
@@ -166,9 +174,43 @@ bool M2MTLVSerializer::serialize_multiple_resource(const M2MResource *resource,
|
166 | 174 |
|
167 | 175 | bool M2MTLVSerializer::serialize_resource_instance(uint16_t id, const M2MResourceInstance *resource, uint8_t *&data, uint32_t &size)
|
168 | 176 | {
|
169 |
| - return serialize_TILV(TYPE_RESOURCE_INSTANCE, id, resource->value(), resource->value_length(), data, size); |
| 177 | + bool success; |
| 178 | + |
| 179 | + if ( (resource->resource_instance_type() == M2MResourceInstance::INTEGER) || |
| 180 | + (resource->resource_instance_type() == M2MResourceInstance::BOOLEAN) || |
| 181 | + (resource->resource_instance_type() == M2MResourceInstance::TIME) ) { |
| 182 | + success=serialize_TLV_binary_int(resource, TYPE_RESOURCE_INSTANCE, id, data, size); |
| 183 | + } |
| 184 | + else { |
| 185 | + success=serialize_TILV(TYPE_RESOURCE_INSTANCE, id, resource->value(), resource->value_length(), data, size); |
| 186 | + } |
| 187 | + |
| 188 | + return success; |
| 189 | +} |
| 190 | + |
| 191 | +/* See, OMA-TS-LightweightM2M-V1_0-20170208-A, Appendix C, |
| 192 | + * Data Types, Integer, Boolean and TY |
| 193 | + * Yime, TLV Format */ |
| 194 | +bool M2MTLVSerializer::serialize_TLV_binary_int(const M2MResourceInstance *resource, uint8_t type, uint16_t id, uint8_t *&data, uint32_t &size) |
| 195 | +{ |
| 196 | + int64_t valueInt = resource->get_value_int(); |
| 197 | + uint32_t buffer_size; |
| 198 | + /* max len 8 bytes */ |
| 199 | + uint8_t buffer[8]; |
| 200 | + |
| 201 | + if (resource->resource_instance_type() == M2MResourceInstance::BOOLEAN) { |
| 202 | + buffer_size = 1; |
| 203 | + buffer[0] = valueInt; |
| 204 | + } |
| 205 | + else { |
| 206 | + buffer_size = 8; |
| 207 | + common_write_64_bit(valueInt, buffer); |
| 208 | + } |
| 209 | + |
| 210 | + return serialize_TILV(type, id, buffer, buffer_size, data, size); |
170 | 211 | }
|
171 | 212 |
|
| 213 | + |
172 | 214 | bool M2MTLVSerializer::serialize_TILV(uint8_t type, uint16_t id, uint8_t *value, uint32_t value_length, uint8_t *&data, uint32_t &size)
|
173 | 215 | {
|
174 | 216 | uint8_t *tlv = 0;
|
|
0 commit comments