Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Parser.h"
- #include <string.h>
- void parseATResponse(const char *buffer, unsigned int size, unsigned int offset, char *response)
- {
- const char *twoPointsPointer = strchr(buffer, ':');
- unsigned int twoPointsIndex = (int)(twoPointsPointer - buffer);
- unsigned int valueStartIndex = twoPointsIndex + offset;
- for (unsigned int i = valueStartIndex; i < valueStartIndex + size; ++i)
- {
- response[i - valueStartIndex] = buffer[i];
- response[i - valueStartIndex + 1] = '\0';
- }
- }
- void parseJSONResponse(const char *buffer, unsigned int bufferSize, char *response)
- {
- unsigned int start_index = 0;
- unsigned int i = 0;
- while (i < bufferSize - 1 && start_index == 0)
- {
- char c = buffer[i];
- if ('{' == c)
- {
- start_index = i;
- }
- ++i;
- }
- unsigned int end_index = 0;
- int j = bufferSize - 1;
- while (j >= 0 && end_index == 0)
- {
- char c = buffer[j];
- if ('}' == c)
- {
- end_index = j;
- }
- --j;
- }
- for (int k = 0; k < (end_index - start_index) + 2; ++k)
- {
- response[k] = buffer[start_index + k];
- response[k + 1] = '\0';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement