📄 ag_parse.c
字号:
/*
Warning - this file was autogenerated by genparse
DO NOT EDIT - any changes will be lost
*/
#include "ag_parse.h"
#include <ctype.h>
#include <panic.h>
#include <stdlib.h>
#include <string.h>
#ifdef TEST_HARNESS
#include <stdio.h>
#endif
typedef const uint8 *ptr;
static ptr skip1(ptr s, ptr e)
{
if(s)
while(s != e && (*s == ' ' || *s == '\t' || *s == ',' || *s == ';'))
++s;
return s;
}
static ptr matchChar(ptr s, ptr e, uint8 c)
{ return s && s != e && toupper(*s) == (int) c ? s+1 : 0; }
static ptr match1(ptr s, ptr e)
{ return s && s != e && (*s == '=' || *s == ':') ? s+1 : 0; }
static ptr getNumber(ptr p, ptr e, uint16 *num)
{
if(p)
{
ptr s = p;
uint16 r = 0;
while(p != e && isdigit(*p)) r = r * 10 + (*p++ - '0');
*num = r;
return p != s ? p : 0;
}
return 0;
}
static ptr match2(ptr s, ptr e)
{ return s && s != e && (*s == '\r' || *s == '\n') ? s+1 : 0; }
static ptr skipQuote(ptr p, ptr e)
{ return p && p != e && *p == '"' ? p+1 : p; }
static ptr getString(ptr p, ptr e, struct sequence *res)
{
p = skipQuote(p, e);
if(p)
{
ptr s = p;
while(p != e && (isalnum(*p) || *p==' ' || *p=='+' || *p=='*' || *p=='^' || *p=='-' || *p=='_' || *p=='#')) ++p;
if(p != s)
{
res->data = s;
res->length = p - s;
return skipQuote(p, e);
}
}
res->data = 0;
res->length = 0;
return 0;
}
#ifdef TEST_HARNESS
static void printString(const char *name, const struct sequence *s)
{
uint16 i;
printf(" %s='", name);
for(i = 0; i < s->length; ++i) putchar(s->data[i]);
printf("'");
}
#endif
static ptr skip2(ptr s, ptr e)
{
if(s)
while(s != e && (*s == '?'))
++s;
return s;
}
static ptr findEndOfPacket(ptr s, ptr e)
{
/*
Returns
0 if the buffer holds an incomplete packet
s+1 if the buffer holds an invalid packet
end of the first packet otherwise
*/
if(s == e) return 0;
if(*s == '\r')
{
/* expecting <cr> <lf> ... <cr> <lf> */
if(e-s >= 4)
{
if(s[1] == '\n')
{
ptr p = s+2;
while(p != e && *p != '\r') ++p;
return p == e || p + 1 == e ? 0 /* no terminator yet */
: p[1] == '\n' ? p+2 /* valid */
: s+1 ; /* invalid terminator */
}
else
{
return s+1;
}
}
else
{
/* Can't tell yet */
return 0;
}
}
else if(*s == '\n')
{
/*
Probably confused. Don't leave this around. We could end up
incorrectly swallowing a <cr> which is likely to be the start of
a <cr><lf>...<cr><lf> and then we'll never get back in sync.
*/
return s+1;
}
else
{
/* expecting ... <cr> */
ptr p = s;
while(p != e && *p != '\r') ++p;
return p == e ? 0 : p+1;
}
}
ptr parseData(ptr s, ptr e, const BD_ADDR_T *addr)
{
ptr p;
#ifdef TEST_HARNESS
addr = addr;
#endif
for(; (p = findEndOfPacket(s, e)) != 0; s = p)
{
if(p == s+1)
{
/* Silently discard one character; no packets are that short */
continue;
}
else
{
union {
struct MicrophoneGain MicrophoneGain;
struct SpeakerGain SpeakerGain;
struct ButtonPress ButtonPress;
struct CustomButtonPress CustomButtonPress;
struct IndicatorReportActivation IndicatorReportActivation;
struct RemoteNumberDial RemoteNumberDial;
struct RemoteMemoryDial RemoteMemoryDial;
struct CallWaitingEnable CallWaitingEnable;
struct CallHoldRequest CallHoldRequest;
struct CallerIdActivation CallerIdActivation;
struct EchoCancellingDisable EchoCancellingDisable;
struct VoiceRecognitionEnable VoiceRecognitionEnable;
struct SpecificDataRequest SpecificDataRequest;
struct DTMFGeneration DTMFGeneration;
} u, *uu = &u;
if(match2(skip1(getNumber(skip1(match1(skip1(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'V'), e, 'G'), e, 'M'), e), e), e), e, &uu->MicrophoneGain.gain), e), e))
{
#ifndef TEST_HARNESS
handleMicrophoneGain(addr, &uu->MicrophoneGain);
#endif
#ifdef TEST_HARNESS
printf("Called handleMicrophoneGain");
printf(" gain=%d", uu->MicrophoneGain.gain);
putchar('\n');
#endif
continue;
}
if(match2(skip1(getNumber(skip1(match1(skip1(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'V'), e, 'G'), e, 'S'), e), e), e), e, &uu->SpeakerGain.gain), e), e))
{
#ifndef TEST_HARNESS
handleSpeakerGain(addr, &uu->SpeakerGain);
#endif
#ifdef TEST_HARNESS
printf("Called handleSpeakerGain");
printf(" gain=%d", uu->SpeakerGain.gain);
putchar('\n');
#endif
continue;
}
if(match2(skip1(getNumber(skip1(match1(skip1(matchChar(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'C'), e, 'K'), e, 'P'), e, 'D'), e), e), e), e, &uu->ButtonPress.button), e), e))
{
#ifndef TEST_HARNESS
handleButtonPress(addr, &uu->ButtonPress);
#endif
#ifdef TEST_HARNESS
printf("Called handleButtonPress");
printf(" button=%d", uu->ButtonPress.button);
putchar('\n');
#endif
continue;
}
if(match2(skip1(getString(skip1(match1(skip1(matchChar(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'C'), e, 'K'), e, 'P'), e, 'D'), e), e), e), e, &uu->CustomButtonPress.button), e), e))
{
#ifndef TEST_HARNESS
handleCustomButtonPress(addr, &uu->CustomButtonPress);
#endif
#ifdef TEST_HARNESS
printf("Called handleCustomButtonPress");
printString("button", &uu->CustomButtonPress.button);
putchar('\n');
#endif
continue;
}
if(match2(skip1(skip2(skip1(match1(skip1(matchChar(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'C'), e, 'I'), e, 'N'), e, 'D'), e), e), e), e), e), e))
{
#ifndef TEST_HARNESS
handleIndicatorDescriptionRequest(addr);
#endif
#ifdef TEST_HARNESS
printf("Called handleIndicatorDescriptionRequest");
putchar('\n');
#endif
continue;
}
if(match2(skip1(skip2(skip1(matchChar(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'C'), e, 'I'), e, 'N'), e, 'D'), e), e), e), e))
{
#ifndef TEST_HARNESS
handleIndicatorStatusRequest(addr);
#endif
#ifdef TEST_HARNESS
printf("Called handleIndicatorStatusRequest");
putchar('\n');
#endif
continue;
}
if(match2(skip1(getNumber(skip1(getNumber(skip1(getNumber(skip1(getNumber(skip1(match1(skip1(matchChar(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'C'), e, 'M'), e, 'E'), e, 'R'), e), e), e), e, &uu->IndicatorReportActivation.mode), e), e, &uu->IndicatorReportActivation.keyp), e), e, &uu->IndicatorReportActivation.disp), e), e, &uu->IndicatorReportActivation.ind), e), e))
{
#ifndef TEST_HARNESS
handleIndicatorReportActivation(addr, &uu->IndicatorReportActivation);
#endif
#ifdef TEST_HARNESS
printf("Called handleIndicatorReportActivation");
printf(" mode=%d", uu->IndicatorReportActivation.mode);
printf(" keyp=%d", uu->IndicatorReportActivation.keyp);
printf(" disp=%d", uu->IndicatorReportActivation.disp);
printf(" ind=%d", uu->IndicatorReportActivation.ind);
putchar('\n');
#endif
continue;
}
if(match2(skip1(matchChar(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e, 'A'), e), e))
{
#ifndef TEST_HARNESS
handleCallAnswer(addr);
#endif
#ifdef TEST_HARNESS
printf("Called handleCallAnswer");
putchar('\n');
#endif
continue;
}
if(match2(skip1(matchChar(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'C'), e, 'H'), e, 'U'), e, 'P'), e), e))
{
#ifndef TEST_HARNESS
handleCallHangUp(addr);
#endif
#ifdef TEST_HARNESS
printf("Called handleCallHangUp");
putchar('\n');
#endif
continue;
}
if(match2(skip1(getString(skip1(matchChar(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e, 'D'), e), e, &uu->RemoteNumberDial.number), e), e))
{
#ifndef TEST_HARNESS
handleRemoteNumberDial(addr, &uu->RemoteNumberDial);
#endif
#ifdef TEST_HARNESS
printf("Called handleRemoteNumberDial");
printString("number", &uu->RemoteNumberDial.number);
putchar('\n');
#endif
continue;
}
if(match2(skip1(getString(skip1(matchChar(skip1(matchChar(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e, 'D'), e), e, '>'), e), e, &uu->RemoteMemoryDial.memory), e), e))
{
#ifndef TEST_HARNESS
handleRemoteMemoryDial(addr, &uu->RemoteMemoryDial);
#endif
#ifdef TEST_HARNESS
printf("Called handleRemoteMemoryDial");
printString("memory", &uu->RemoteMemoryDial.memory);
putchar('\n');
#endif
continue;
}
if(match2(skip1(matchChar(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'B'), e, 'L'), e, 'D'), e, 'N'), e), e))
{
#ifndef TEST_HARNESS
handleLastNumberRedial(addr);
#endif
#ifdef TEST_HARNESS
printf("Called handleLastNumberRedial");
putchar('\n');
#endif
continue;
}
if(match2(skip1(getNumber(skip1(match1(skip1(matchChar(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'C'), e, 'C'), e, 'W'), e, 'A'), e), e), e), e, &uu->CallWaitingEnable.status), e), e))
{
#ifndef TEST_HARNESS
handleCallWaitingEnable(addr, &uu->CallWaitingEnable);
#endif
#ifdef TEST_HARNESS
printf("Called handleCallWaitingEnable");
printf(" status=%d", uu->CallWaitingEnable.status);
putchar('\n');
#endif
continue;
}
if(match2(skip1(getNumber(skip1(match1(skip1(matchChar(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'C'), e, 'H'), e, 'L'), e, 'D'), e), e), e), e, &uu->CallHoldRequest.hold), e), e))
{
#ifndef TEST_HARNESS
handleCallHoldRequest(addr, &uu->CallHoldRequest);
#endif
#ifdef TEST_HARNESS
printf("Called handleCallHoldRequest");
printf(" hold=%d", uu->CallHoldRequest.hold);
putchar('\n');
#endif
continue;
}
if(match2(skip1(skip2(skip1(match1(skip1(matchChar(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'C'), e, 'H'), e, 'L'), e, 'D'), e), e), e), e), e), e))
{
#ifndef TEST_HARNESS
handleCallHoldTestCmd(addr);
#endif
#ifdef TEST_HARNESS
printf("Called handleCallHoldTestCmd");
putchar('\n');
#endif
continue;
}
if(match2(skip1(getNumber(skip1(match1(skip1(matchChar(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'C'), e, 'L'), e, 'I'), e, 'P'), e), e), e), e, &uu->CallerIdActivation.enable), e), e))
{
#ifndef TEST_HARNESS
handleCallerIdActivation(addr, &uu->CallerIdActivation);
#endif
#ifdef TEST_HARNESS
printf("Called handleCallerIdActivation");
printf(" enable=%d", uu->CallerIdActivation.enable);
putchar('\n');
#endif
continue;
}
if(match2(skip1(getNumber(skip1(match1(skip1(matchChar(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'N'), e, 'R'), e, 'E'), e, 'C'), e), e), e), e, &uu->EchoCancellingDisable.enable), e), e))
{
#ifndef TEST_HARNESS
handleEchoCancellingDisable(addr, &uu->EchoCancellingDisable);
#endif
#ifdef TEST_HARNESS
printf("Called handleEchoCancellingDisable");
printf(" enable=%d", uu->EchoCancellingDisable.enable);
putchar('\n');
#endif
continue;
}
if(match2(skip1(getNumber(skip1(match1(skip1(matchChar(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'B'), e, 'V'), e, 'R'), e, 'A'), e), e), e), e, &uu->VoiceRecognitionEnable.enable), e), e))
{
#ifndef TEST_HARNESS
handleVoiceRecognitionEnable(addr, &uu->VoiceRecognitionEnable);
#endif
#ifdef TEST_HARNESS
printf("Called handleVoiceRecognitionEnable");
printf(" enable=%d", uu->VoiceRecognitionEnable.enable);
putchar('\n');
#endif
continue;
}
if(match2(skip1(getNumber(skip1(match1(skip1(matchChar(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'B'), e, 'I'), e, 'N'), e, 'P'), e), e), e), e, &uu->SpecificDataRequest.request), e), e))
{
#ifndef TEST_HARNESS
handleSpecificDataRequest(addr, &uu->SpecificDataRequest);
#endif
#ifdef TEST_HARNESS
printf("Called handleSpecificDataRequest");
printf(" request=%d", uu->SpecificDataRequest.request);
putchar('\n');
#endif
continue;
}
if(match2(skip1(getString(skip1(match1(skip1(matchChar(matchChar(matchChar(skip1(matchChar(skip1(matchChar(matchChar(skip1(s, e), e, 'A'), e, 'T'), e), e, '+'), e), e, 'V'), e, 'T'), e, 'S'), e), e), e), e, &uu->DTMFGeneration.code), e), e))
{
#ifndef TEST_HARNESS
handleDTMFGeneration(addr, &uu->DTMFGeneration);
#endif
#ifdef TEST_HARNESS
printf("Called handleDTMFGeneration");
printString("code", &uu->DTMFGeneration.code);
putchar('\n');
#endif
continue;
}
if(match2(skip1(match2(skip1(matchChar(matchChar(skip1(match2(skip1(match2(skip1(s, e), e), e), e), e), e, 'O'), e, 'K'), e), e), e), e))
{
#ifndef TEST_HARNESS
handleOK(addr);
#endif
#ifdef TEST_HARNESS
printf("Called handleOK");
putchar('\n');
#endif
continue;
}
if(match2(skip1(match2(skip1(matchChar(matchChar(matchChar(matchChar(matchChar(skip1(match2(skip1(match2(skip1(s, e), e), e), e), e), e, 'E'), e, 'R'), e, 'R'), e, 'O'), e, 'R'), e), e), e), e))
{
#ifndef TEST_HARNESS
handleError(addr);
#endif
#ifdef TEST_HARNESS
printf("Called handleError");
putchar('\n');
#endif
continue;
}
if(match2(skip1(match2(skip1(matchChar(matchChar(matchChar(matchChar(skip1(match2(skip1(match2(skip1(s, e), e), e), e), e), e, 'R'), e, 'I'), e, 'N'), e, 'G'), e), e), e), e))
{
#ifndef TEST_HARNESS
handleRing(addr);
#endif
#ifdef TEST_HARNESS
printf("Called handleRing");
putchar('\n');
#endif
continue;
}
if(match2(skip1(match2(skip1(getNumber(skip1(match1(skip1(matchChar(matchChar(matchChar(skip1(matchChar(skip1(match2(skip1(match2(skip1(s, e), e), e), e), e), e, '+'), e), e, 'V'), e, 'G'), e, 'M'), e), e), e), e, &uu->MicrophoneGain.gain), e), e), e), e))
{
#ifndef TEST_HARNESS
handleMicrophoneGain(addr, &uu->MicrophoneGain);
#endif
#ifdef TEST_HARNESS
printf("Called handleMicrophoneGain");
printf(" gain=%d", uu->MicrophoneGain.gain);
putchar('\n');
#endif
continue;
}
if(match2(skip1(match2(skip1(getNumber(skip1(match1(skip1(matchChar(matchChar(matchChar(skip1(matchChar(skip1(match2(skip1(match2(skip1(s, e), e), e), e), e), e, '+'), e), e, 'V'), e, 'G'), e, 'S'), e), e), e), e, &uu->SpeakerGain.gain), e), e), e), e))
{
#ifndef TEST_HARNESS
handleSpeakerGain(addr, &uu->SpeakerGain);
#endif
#ifdef TEST_HARNESS
printf("Called handleSpeakerGain");
printf(" gain=%d", uu->SpeakerGain.gain);
putchar('\n');
#endif
continue;
}
/*
The message does not contain a recognised AT command or response.
Pass the data on to the application to have a go at
*/
#ifndef TEST_HARNESS
handleUnrecognised(s, p-s, addr);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -