Skip to content

Commit 621c848

Browse files
author
Maksymilian Wojczuk
committed
Wakaama
Changed object files and fixed memory tracing
1 parent 4f84db7 commit 621c848

File tree

6 files changed

+50
-34
lines changed

6 files changed

+50
-34
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ WAKAAMA_INC = \
208208

209209
WAKAAMA_SYMBOL = -DLWM2M_LITTLE_ENDIAN
210210
WAKAAMA_SYMBOL += -DLWM2M_CLIENT_MODE
211+
WAKAAMA_SYMBOL += -DLWM2M_MEMORY_TRACE
211212
#WAKAAMA_SYMBOL += -DCOAPLOG # download logs
212213
#WAKAAMA_SYMBOL += -DLWM2M_WITH_LOGS # LOGS
213214

Middlewares/Third_Party/wakaama/client/client_config.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44

55
#define DEVICE_NAME "Remote Programmer"
66

7-
#define SERVER_URI "coap://192.168.1.21:5683"
7+
#define SERVER_URI "coap://192.168.1.13:5683"
88
#define LWM2M_PORT 5683
99
#define MAX_PACKET_SIZE 1024
1010

11+
#define WAKAAMA_SHORT_ID 100 // 0 is forbidden
12+
#define WAKAAMA_BINDING 'U'
13+
#define WAKAAMA_COMPANY 'AGH'
14+
#define WAKAAMA_MODEL_NUMBER DEVICE_NAME
15+
1116
#endif

Middlewares/Third_Party/wakaama/client/objects/object_device.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,9 @@
6464
#include <stdlib.h>
6565
#include <string.h>
6666
#include <ctype.h>
67+
#include "client_config.h"
6768

6869

69-
#define PRV_MANUFACTURER "Open Mobile Alliance"
70-
#define PRV_MODEL_NUMBER "Lightweight M2M Client"
71-
#define PRV_BINDING_MODE "U"
72-
7370
// Resource Id's:
7471
#define RES_O_MANUFACTURER 0
7572
#define RES_O_MODEL_NUMBER 1
@@ -101,18 +98,18 @@ static uint8_t prv_set_value(lwm2m_data_t * dataP)
10198
switch (dataP->id)
10299
{
103100
case RES_O_MANUFACTURER:
104-
lwm2m_data_encode_string(PRV_MANUFACTURER, dataP);
101+
lwm2m_data_encode_string(WAKAAMA_COMPANY, dataP);
105102
return COAP_205_CONTENT;
106103

107104
case RES_O_MODEL_NUMBER:
108-
lwm2m_data_encode_string(PRV_MODEL_NUMBER, dataP);
105+
lwm2m_data_encode_string(WAKAAMA_MODEL_NUMBER, dataP);
109106
return COAP_205_CONTENT;
110107

111108
case RES_M_REBOOT:
112109
return COAP_405_METHOD_NOT_ALLOWED;
113110

114111
case RES_M_BINDING_MODES:
115-
lwm2m_data_encode_string(PRV_BINDING_MODE, dataP);
112+
lwm2m_data_encode_string(WAKAAMA_BINDING, dataP);
116113
return COAP_205_CONTENT;
117114

118115

@@ -249,10 +246,12 @@ lwm2m_object_t * get_object_device()
249246
*/
250247
lwm2m_object_t * deviceObj;
251248

249+
printf("ALLOC\n\r");
252250
deviceObj = (lwm2m_object_t *)lwm2m_malloc(sizeof(lwm2m_object_t));
253-
251+
printf("Alloced!\n\r");
254252
if (NULL != deviceObj)
255253
{
254+
printf("NULL\n\r");
256255
memset(deviceObj, 0, sizeof(lwm2m_object_t));
257256

258257
/*
@@ -286,6 +285,7 @@ lwm2m_object_t * get_object_device()
286285
deviceObj->discoverFunc = prv_device_discover;
287286

288287
}
288+
printf("GO on!\n\r");
289289

290290
return deviceObj;
291291
}

Middlewares/Third_Party/wakaama/client/objects/objects.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
#define __OBJECTS_H
33

44
lwm2m_object_t * get_security_object();
5-
lwm2m_object_t * get_server_object();
5+
lwm2m_object_t * get_server_object(int serverId,
6+
const char* binding,
7+
int lifetime,
8+
bool storing);
69
lwm2m_object_t * get_object_device();
710
lwm2m_object_t * get_test_object();
811

Middlewares/Third_Party/wakaama/platform/platform.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,42 @@
1414
// it with FreeRTOS is bad idea (as far as heared).
1515

1616
// Allocate a block of size bytes of memory, returning a pointer to the beginning of the block.
17-
void * lwm2m_malloc(size_t s
1817
#ifdef LWM2M_MEMORY_TRACE
19-
, const char * file, const char * function, int lineno
20-
) {
18+
void * lwm2m_trace_malloc(size_t s, const char * file, const char * function, int lineno) {
2119
printf("lwm2m_malloc: \"%s\" : \"%s\" : %d \n", file, function, lineno);
22-
#else
23-
) {
24-
#endif
2520
return pvPortMalloc(s);
2621
}
22+
#else
23+
void * lwm2m_malloc(size_t s){
24+
return pvPortMalloc(s);
25+
}
26+
#endif
27+
2728
// Deallocate a block of memory previously allocated by lwm2m_malloc() or lwm2m_strdup()
28-
void lwm2m_free(void * p
2929
#ifdef LWM2M_MEMORY_TRACE
30-
, const char * file, const char * function, int lineno
31-
) {
32-
printf("lwm2m_malloc: \"%s\" : \"%s\" : %d \n", file, function, lineno);
33-
#else
34-
) {
35-
#endif
30+
void lwm2m_trace_free(void * p, const char * file, const char * function, int lineno) {
31+
printf("lwm2m_free: \"%s\" : \"%s\" : %d \n", file, function, lineno);
3632
return vPortFree(p);
3733
}
38-
34+
#else
35+
void lwm2m_free(void * p) {
36+
return vPortFree(p);
37+
}
38+
#endif
3939

4040
// Allocate a memory block, duplicate the string str in it and return a pointer to this new block.
41-
char * lwm2m_strdup(const char * str
4241
#ifdef LWM2M_MEMORY_TRACE
43-
, const char * file, const char * function, int lineno
44-
) {
45-
printf("lwm2m_malloc: \"%s\" : \"%s\" : %d \n", file, function, lineno);
42+
char * lwm2m_trace_strdup(const char * str, const char * file, const char * function, int lineno) {
43+
printf("lwm2m_strdup: \"%s\" : \"%s\" : %d \n", file, function, lineno);
44+
char *dup = pvPortMalloc(strlen(str) + 1);
45+
return dup ? strcpy(dup, str) : dup;
46+
}
4647
#else
47-
) {
48-
#endif
48+
char * lwm2m_strdup(const char * str) {
4949
char *dup = pvPortMalloc(strlen(str) + 1);
5050
return dup ? strcpy(dup, str) : dup;
5151
}
52+
#endif
5253

5354
// Compare at most the n first bytes of s1 and s2, return 0 if they match
5455
int lwm2m_strncmp(const char * s1, const char * s2, size_t n) {

Src/main.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,17 +383,19 @@ static void taskWakaama(void *socket) {
383383
printf("SecurityObject Created\n");
384384

385385
if(objArray[1] == NULL) {
386-
objArray[1] = get_server_object();
386+
objArray[1] = get_server_object(WAKAAMA_SHORT_ID, WAKAAMA_BINDING, 300, false);
387387
}
388388

389389
if (NULL == objArray[1]) {
390390
printf("Failed to create server object\r\n");
391391
result = -2;
392392
continue;
393393
}
394-
printf("ServerObject Created\n");
394+
printf("ServerObject Created\n\r");
395+
printf("NEXT printf\n\r");
395396

396397
if(objArray[2] == NULL) {
398+
printf("Getting object device\n\r");
397399
objArray[2] = get_object_device();
398400
}
399401
if (NULL == objArray[2]) {
@@ -639,12 +641,16 @@ void StartDefaultTask(void const * argument)
639641
MX_FATFS_Init();
640642

641643
/* USER CODE BEGIN 5 */
644+
printf("\n\n\n-----------------------START-------------------------\n\n");
642645

643646
// Initialize Wakaama LWM2M Client
644647
int socket = getUDPSocket(LWM2M_PORT, AF_INET);
645648
if(socket != -1){
646-
int res = xTaskCreate(taskWakaama, "wakaama", 700, (void *) socket, 2, NULL);
647-
printf("\r\ntaskWakaama xTaskCreate returned %d\n", res);
649+
int res = xTaskCreate(taskWakaama, "wakaama", 10000, (void *) socket, 2, NULL);
650+
if (res != pdPASS) {
651+
printf("\r\ntaskWakaama xTaskCreate returned %d\n", res);
652+
}
653+
648654
}
649655

650656

0 commit comments

Comments
 (0)