USB Host Shield 2.0
Loading...
Searching...
No Matches
parsetools.cpp
Go to the documentation of this file.
1/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License as published by
5the Free Software Foundation; either version 2 of the License, or
6(at your option) any later version.
7
8This program is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License
14along with this program; if not, write to the Free Software
15Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17Contact information
18-------------------
19
20Circuits At Home, LTD
21Web : http://www.circuitsathome.com
22e-mail : support@circuitsathome.com
23 */
24#include "Usb.h"
25
27 if(!pBuf) {
28 Notify(PSTR("Buffer pointer is NULL!\r\n"), 0x80);
29 return false;
30 }
31 for(; countDown && (*pcntdn); countDown--, (*pcntdn)--, (*pp)++)
32 pBuf[valueSize - countDown] = (**pp);
33
34 if(countDown)
35 return false;
36
37 countDown = valueSize;
38 return true;
39}
40
42 switch(nStage) {
43 case 0:
44 pBuf->valueSize = lenSize;
45 theParser.Initialize(pBuf);
46 nStage = 1;
47 // fall through
48
49 case 1:
50 if(!theParser.Parse(pp, pcntdn))
51 return false;
52
53 arLen = 0;
54 arLen = (pBuf->valueSize >= 4) ? *((uint32_t*)pBuf->pValue) : (uint32_t)(*((uint16_t*)pBuf->pValue));
55 arLenCntdn = arLen;
56 nStage = 2;
57 // fall through
58
59 case 2:
60 pBuf->valueSize = valSize;
61 theParser.Initialize(pBuf);
62 nStage = 3;
63 // fall through
64
65 case 3:
66 for(; arLenCntdn; arLenCntdn--) {
67 if(!theParser.Parse(pp, pcntdn))
68 return false;
69
70 if(pf)
71 pf(pBuf, (arLen - arLenCntdn), me);
72 }
73
74 nStage = 0;
75 }
76 return true;
77}
void Initialize(MultiValueBuffer *const pbuf)
Definition parsetools.h:54
bool Parse(uint8_t **pp, uint16_t *pcntdn)
bool Parse(uint8_t **pp, uint16_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me=NULL)
#define Notify(...)
Definition message.h:51
void(* PTP_ARRAY_EL_FUNC)(const MultiValueBuffer *const p, uint32_t count, const void *me)
Definition parsetools.h:94
uint8_t valueSize
Definition parsetools.h:31
#define PSTR(str)