USB_Host_Shield_2.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
parsetools.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
2 
3 This software may be distributed and modified under the terms of the GNU
4 General Public License version 2 (GPL2) as published by the Free Software
5 Foundation and appearing in the file GPL2.TXT included in the packaging of
6 this file. Please note that GPL2 Section 2[b] requires that all works based
7 on this software must also be made publicly available under the terms of
8 the GPL2 ("Copyleft").
9 
10 Contact information
11 -------------------
12 
13 Circuits At Home, LTD
14 Web : http://www.circuitsathome.com
15 e-mail : support@circuitsathome.com
16 */
17 #include "parsetools.h"
18 
19 bool MultiByteValueParser::Parse(uint8_t **pp, uint16_t *pcntdn)
20 {
21  if (!pBuf)
22  {
23  Notify(PSTR("Buffer pointer is NULL!\r\n"));
24  return false;
25  }
26  for (; countDown && (*pcntdn); countDown--, (*pcntdn)--, (*pp)++)
27  pBuf[valueSize-countDown] = (**pp);
28 
29  if (countDown)
30  return false;
31 
32  countDown = valueSize;
33  return true;
34 }
35 
36 bool PTPListParser::Parse(uint8_t **pp, uint16_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me)
37 {
38  switch (nStage)
39  {
40  case 0:
41  pBuf->valueSize = lenSize;
42  theParser.Initialize(pBuf);
43  nStage = 1;
44 
45  case 1:
46  if (!theParser.Parse(pp, pcntdn))
47  return false;
48 
49  arLen = 0;
50  arLen = (pBuf->valueSize >= 4) ? *((uint32_t*)pBuf->pValue) : (uint32_t)(*((uint16_t*)pBuf->pValue));
51  arLenCntdn = arLen;
52  nStage = 2;
53 
54  case 2:
55  pBuf->valueSize = valSize;
56  theParser.Initialize(pBuf);
57  nStage = 3;
58 
59  case 3:
60  for (; arLenCntdn; arLenCntdn--)
61  {
62  if (!theParser.Parse(pp, pcntdn))
63  return false;
64 
65  if (pf)
66  pf(pBuf, (arLen - arLenCntdn), me);
67  }
68 
69  nStage = 0;
70  }
71  return true;
72 }