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 "Usb.h"
18 
19 bool MultiByteValueParser::Parse(uint8_t **pp, uint16_t *pcntdn) {
20  if (!pBuf) {
21  Notify(PSTR("Buffer pointer is NULL!\r\n"), 0x80);
22  return false;
23  }
24  for (; countDown && (*pcntdn); countDown--, (*pcntdn)--, (*pp)++)
25  pBuf[valueSize - countDown] = (**pp);
26 
27  if (countDown)
28  return false;
29 
30  countDown = valueSize;
31  return true;
32 }
33 
34 bool PTPListParser::Parse(uint8_t **pp, uint16_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me) {
35  switch (nStage) {
36  case 0:
37  pBuf->valueSize = lenSize;
38  theParser.Initialize(pBuf);
39  nStage = 1;
40 
41  case 1:
42  if (!theParser.Parse(pp, pcntdn))
43  return false;
44 
45  arLen = 0;
46  arLen = (pBuf->valueSize >= 4) ? *((uint32_t*)pBuf->pValue) : (uint32_t)(*((uint16_t*)pBuf->pValue));
47  arLenCntdn = arLen;
48  nStage = 2;
49 
50  case 2:
51  pBuf->valueSize = valSize;
52  theParser.Initialize(pBuf);
53  nStage = 3;
54 
55  case 3:
56  for (; arLenCntdn; arLenCntdn--) {
57  if (!theParser.Parse(pp, pcntdn))
58  return false;
59 
60  if (pf)
61  pf(pBuf, (arLen - arLenCntdn), me);
62  }
63 
64  nStage = 0;
65  }
66  return true;
67 }
void(* PTP_ARRAY_EL_FUNC)(const MultiValueBuffer *const p, uint32_t count, const void *me)
Definition: parsetools.h:81
#define Notify(...)
Definition: message.h:44
bool Parse(uint8_t **pp, uint16_t *pcntdn)
Definition: parsetools.cpp:19
uint8_t valueSize
Definition: parsetools.h:24
void Initialize(MultiValueBuffer *const pbuf)
Definition: parsetools.h:42
bool Parse(uint8_t **pp, uint16_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me=NULL)
Definition: parsetools.cpp:34