terence zhang / Mbed OS mbed-os-example-wakaama

Dependencies:   C12832 LM75B

Committer:
terencez
Date:
Sun May 07 03:00:16 2017 +0000
Revision:
15:d0f20339c1ad
Parent:
3:a280069151ac
Child:
16:31c387e94b6d
Fix the "Get" operation fail issue, tested get information from device.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
terencez 0:f9d13e09cf11 1 /*******************************************************************************
terencez 0:f9d13e09cf11 2 *
terencez 0:f9d13e09cf11 3 * Copyright (c) 2013 Intel Corporation and others.
terencez 0:f9d13e09cf11 4 * All rights reserved. This program and the accompanying materials
terencez 0:f9d13e09cf11 5 * are made available under the terms of the Eclipse Public License v1.0
terencez 0:f9d13e09cf11 6 * and Eclipse Distribution License v1.0 which accompany this distribution.
terencez 0:f9d13e09cf11 7 *
terencez 0:f9d13e09cf11 8 * The Eclipse Public License is available at
terencez 0:f9d13e09cf11 9 * http://www.eclipse.org/legal/epl-v10.html
terencez 0:f9d13e09cf11 10 * The Eclipse Distribution License is available at
terencez 0:f9d13e09cf11 11 * http://www.eclipse.org/org/documents/edl-v10.php.
terencez 0:f9d13e09cf11 12 *
terencez 0:f9d13e09cf11 13 * Contributors:
terencez 0:f9d13e09cf11 14 * David Navarro, Intel Corporation - initial API and implementation
terencez 0:f9d13e09cf11 15 *
terencez 0:f9d13e09cf11 16 *******************************************************************************/
terencez 0:f9d13e09cf11 17
terencez 0:f9d13e09cf11 18 #include "internals.h"
terencez 0:f9d13e09cf11 19
terencez 0:f9d13e09cf11 20
terencez 0:f9d13e09cf11 21 lwm2m_list_t * lwm2m_list_add(lwm2m_list_t * head,
terencez 0:f9d13e09cf11 22 lwm2m_list_t * node)
terencez 0:f9d13e09cf11 23 {
terencez 0:f9d13e09cf11 24 lwm2m_list_t * target;
terencez 0:f9d13e09cf11 25
terencez 0:f9d13e09cf11 26 if (NULL == head) return node;
terencez 0:f9d13e09cf11 27
terencez 0:f9d13e09cf11 28 if (head->id > node->id)
terencez 0:f9d13e09cf11 29 {
terencez 0:f9d13e09cf11 30 node->next = head;
terencez 0:f9d13e09cf11 31 return node;
terencez 0:f9d13e09cf11 32 }
terencez 0:f9d13e09cf11 33
terencez 0:f9d13e09cf11 34 target = head;
terencez 0:f9d13e09cf11 35 while (NULL != target->next && target->next->id < node->id)
terencez 0:f9d13e09cf11 36 {
terencez 0:f9d13e09cf11 37 target = target->next;
terencez 0:f9d13e09cf11 38 }
terencez 0:f9d13e09cf11 39
terencez 0:f9d13e09cf11 40 node->next = target->next;
terencez 0:f9d13e09cf11 41 target->next = node;
terencez 0:f9d13e09cf11 42
terencez 0:f9d13e09cf11 43 return head;
terencez 0:f9d13e09cf11 44 }
terencez 0:f9d13e09cf11 45
terencez 0:f9d13e09cf11 46
terencez 0:f9d13e09cf11 47 lwm2m_list_t * lwm2m_list_find(lwm2m_list_t * head,
terencez 0:f9d13e09cf11 48 uint16_t id)
terencez 0:f9d13e09cf11 49 {
terencez 15:d0f20339c1ad 50 printf(" ## %d, %d\n",id, head->id);
terencez 15:d0f20339c1ad 51
terencez 0:f9d13e09cf11 52 while (NULL != head && head->id < id)
terencez 0:f9d13e09cf11 53 {
terencez 15:d0f20339c1ad 54 printf(" ##-- %d, %d\n",id, head->id);
terencez 0:f9d13e09cf11 55 head = head->next;
terencez 0:f9d13e09cf11 56 }
terencez 15:d0f20339c1ad 57 printf(" ## %d, %d\n",id, head->id);
terencez 15:d0f20339c1ad 58
terencez 0:f9d13e09cf11 59 if (NULL != head && head->id == id) return head;
terencez 0:f9d13e09cf11 60
terencez 0:f9d13e09cf11 61 return NULL;
terencez 0:f9d13e09cf11 62 }
terencez 0:f9d13e09cf11 63
terencez 0:f9d13e09cf11 64
terencez 0:f9d13e09cf11 65 lwm2m_list_t * lwm2m_list_remove(lwm2m_list_t * head,
terencez 0:f9d13e09cf11 66 uint16_t id,
terencez 0:f9d13e09cf11 67 lwm2m_list_t ** nodeP)
terencez 0:f9d13e09cf11 68 {
terencez 0:f9d13e09cf11 69 lwm2m_list_t * target;
terencez 0:f9d13e09cf11 70
terencez 0:f9d13e09cf11 71 if (head == NULL)
terencez 0:f9d13e09cf11 72 {
terencez 0:f9d13e09cf11 73 if (nodeP) *nodeP = NULL;
terencez 0:f9d13e09cf11 74 return NULL;
terencez 0:f9d13e09cf11 75 }
terencez 0:f9d13e09cf11 76
terencez 0:f9d13e09cf11 77 if (head->id == id)
terencez 0:f9d13e09cf11 78 {
terencez 0:f9d13e09cf11 79 if (nodeP) *nodeP = head;
terencez 0:f9d13e09cf11 80 return head->next;
terencez 0:f9d13e09cf11 81 }
terencez 0:f9d13e09cf11 82
terencez 0:f9d13e09cf11 83 target = head;
terencez 0:f9d13e09cf11 84 while (NULL != target->next && target->next->id < id)
terencez 0:f9d13e09cf11 85 {
terencez 0:f9d13e09cf11 86 target = target->next;
terencez 0:f9d13e09cf11 87 }
terencez 0:f9d13e09cf11 88
terencez 0:f9d13e09cf11 89 if (NULL != target->next && target->next->id == id)
terencez 0:f9d13e09cf11 90 {
terencez 0:f9d13e09cf11 91 if (nodeP) *nodeP = target->next;
terencez 0:f9d13e09cf11 92 target->next = target->next->next;
terencez 0:f9d13e09cf11 93 }
terencez 0:f9d13e09cf11 94 else
terencez 0:f9d13e09cf11 95 {
terencez 0:f9d13e09cf11 96 if (nodeP) *nodeP = NULL;
terencez 0:f9d13e09cf11 97 }
terencez 0:f9d13e09cf11 98
terencez 0:f9d13e09cf11 99 return head;
terencez 0:f9d13e09cf11 100 }
terencez 0:f9d13e09cf11 101
terencez 0:f9d13e09cf11 102 uint16_t lwm2m_list_newId(lwm2m_list_t * head)
terencez 0:f9d13e09cf11 103 {
terencez 0:f9d13e09cf11 104 uint16_t id;
terencez 0:f9d13e09cf11 105 lwm2m_list_t * target;
terencez 0:f9d13e09cf11 106
terencez 0:f9d13e09cf11 107 id = 0;
terencez 0:f9d13e09cf11 108 target = head;
terencez 0:f9d13e09cf11 109
terencez 0:f9d13e09cf11 110 while (target != NULL && id == target->id)
terencez 0:f9d13e09cf11 111 {
terencez 0:f9d13e09cf11 112 id = target->id + 1;
terencez 0:f9d13e09cf11 113 target = target->next;
terencez 0:f9d13e09cf11 114 }
terencez 0:f9d13e09cf11 115
terencez 0:f9d13e09cf11 116 return id;
terencez 0:f9d13e09cf11 117 }
terence zhang 3:a280069151ac 118
terence zhang 3:a280069151ac 119 void lwm2m_list_free(lwm2m_list_t * head)
terence zhang 3:a280069151ac 120 {
terence zhang 3:a280069151ac 121 if (head != NULL)
terence zhang 3:a280069151ac 122 {
terence zhang 3:a280069151ac 123 lwm2m_list_t * nextP;
terence zhang 3:a280069151ac 124
terence zhang 3:a280069151ac 125 nextP = head->next;
terence zhang 3:a280069151ac 126 lwm2m_free(head);
terence zhang 3:a280069151ac 127 lwm2m_list_free(nextP);
terence zhang 3:a280069151ac 128 }
terence zhang 3:a280069151ac 129 }