From b98fa03dd0a7902dd9131b03f17dcfbded1431f0 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 15 Jun 2020 14:44:32 +0200 Subject: [PATCH] Added valueGet_P option --- lib/LibTeleinfo/src/LibTeleinfo.cpp | 38 +++++++++++++++++++++++++++++ lib/LibTeleinfo/src/LibTeleinfo.h | 1 + 2 files changed, 39 insertions(+) diff --git a/lib/LibTeleinfo/src/LibTeleinfo.cpp b/lib/LibTeleinfo/src/LibTeleinfo.cpp index bb7b7119f..588555831 100644 --- a/lib/LibTeleinfo/src/LibTeleinfo.cpp +++ b/lib/LibTeleinfo/src/LibTeleinfo.cpp @@ -436,6 +436,44 @@ char * TInfo::valueGet(char * name, char * value) return ( NULL); } +/* ====================================================================== +Function: valueGet_P +Purpose : get value of one element +Input : Pointer to the label name + pointer to the value where we fill data +Output : pointer to the value where we filled data NULL is not found +====================================================================== */ +char * TInfo::valueGet_P(const char * name, char * value) +{ + // Get our linked list + ValueList * me = &_valueslist; + uint8_t lgname = strlen_P(name); + + // Got one and all seems good ? + if (me && lgname) { + + // Loop thru the node + while (me->next) { + + // go to next node + me = me->next; + + // Check if we match this LABEL + if (lgname==strlen(me->name) && strncmp_P(me->name, name, lgname)==0) { + // this one has a value ? + if (me->value) { + // copy to dest buffer + uint8_t lgvalue = strlen(me->value); + strlcpy(value, me->value , lgvalue + 1 ); + return ( value ); + } + } + } + } + // not found + return ( NULL); +} + /* ====================================================================== Function: getTopList Purpose : return a pointer on the top of the linked list diff --git a/lib/LibTeleinfo/src/LibTeleinfo.h b/lib/LibTeleinfo/src/LibTeleinfo.h index a9725b26a..5b43523c7 100755 --- a/lib/LibTeleinfo/src/LibTeleinfo.h +++ b/lib/LibTeleinfo/src/LibTeleinfo.h @@ -117,6 +117,7 @@ class TInfo ValueList * getList(void); uint8_t valuesDump(void); char * valueGet(char * name, char * value); + char * valueGet_P(const char * name, char * value); boolean listDelete(); unsigned char calcChecksum(char *etiquette, char *valeur) ;