USB Host Shield 2.0
parsetools.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
2 
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 
17 Contact information
18 -------------------
19 
20 Circuits At Home, LTD
21 Web : http://www.circuitsathome.com
22 e-mail : support@circuitsathome.com
23  */
24 #include "Usb.h"
25 
26 bool MultiByteValueParser::Parse(uint8_t **pp, uint16_t *pcntdn) {
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 
41 bool PTPListParser::Parse(uint8_t **pp, uint16_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me) {
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)
Definition: parsetools.cpp:26
bool Parse(uint8_t **pp, uint16_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me=NULL)
Definition: parsetools.cpp:41
#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)