-2

I am trying to send AT commands from my microcontroller and I am writing a my own implementation to check the responses from the remote module

At this point I want to send Strings with the command to the module in the following way:

    //File.h

    //where char const *message is my string from my file.c, LEN the lenght for my message and reply message from the remote module.

uint8_t CommandSenderCheckResponse(char const *message, uint16_t LEN, char const *reply);

    ---------------
    //File.c
    #include "File.h"
    #define Reply "OK"



    uint8_t CommandSenderCheckResponse(char const *message, uint16_t LEN, char const *reply);
    {       
    //something...
    }


    int main(void)
    {
    while(1)
    {
        CommandSenderCheckResponse("AT#TurnSomething=1", LEN, Reply);
    }
    }

how can I get the size for "AT#TurnSomething=1" ? for sure I am reinventing the wheel, what lib can you recommend to me to send generic AT commands a parse the responses from the module?

Regards

melpomene
  • 84,125
  • 8
  • 85
  • 148
jou
  • 1
  • 4
  • `File.c` sounds like C, not C++. – melpomene Aug 10 '18 at 22:19
  • that forum makes me.... if the people ask for things they are not able to do posts are considered off-topicc or spam, if they ask for some reference the same result.... – jou Aug 14 '18 at 01:40

2 Answers2

0

You do not need to use a library (more than the standard one) to get the length of a string.

int length = strlen(message);
Anders Lindén
  • 6,839
  • 11
  • 56
  • 109
0

Writing own implementation takes less than asking the question :)

size_t mystrlen(const char *p)
{
    size_t size = 0;
    for(;*p;p++,size++);
    return size;
}
0___________
  • 60,014
  • 4
  • 34
  • 74
  • You don't need to add/increment "size" if you just use pointer arithmetic :-) size_t mystrlen( const char *a) { char *b = a; while(*p++); return (t_size)(b-a);} – Micromuncher Aug 11 '18 at 00:37
  • @Micromuncher - you need to be save as the pointer arithmetic is signed and casting is unsafe. And the generated code is exactly the same - so what is better : safe or not safe : https://godbolt.org/g/jXK9BD. Always check your ideas before posting – 0___________ Aug 11 '18 at 01:05