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 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 
48  case 1:
49  if(!theParser.Parse(pp, pcntdn))
50  return false;
51 
52  arLen = 0;
53  arLen = (pBuf->valueSize >= 4) ? *((uint32_t*)pBuf->pValue) : (uint32_t)(*((uint16_t*)pBuf->pValue));
54  arLenCntdn = arLen;
55  nStage = 2;
56 
57  case 2:
58  pBuf->valueSize = valSize;
59  theParser.Initialize(pBuf);
60  nStage = 3;
61 
62  case 3:
63  for(; arLenCntdn; arLenCntdn--) {
64  if(!theParser.Parse(pp, pcntdn))
65  return false;
66 
67  if(pf)
68  pf(pBuf, (arLen - arLenCntdn), me);
69  }
70 
71  nStage = 0;
72  }
73  return true;
74 }
void(* PTP_ARRAY_EL_FUNC)(const MultiValueBuffer *const p, uint32_t count, const void *me)
Definition: parsetools.h:88
#define Notify(...)
Definition: message.h:51
bool Parse(uint8_t **pp, uint16_t *pcntdn)
Definition: parsetools.cpp:26
#define PSTR(str)
uint8_t valueSize
Definition: parsetools.h:31
void Initialize(MultiValueBuffer *const pbuf)
Definition: parsetools.h:49
bool Parse(uint8_t **pp, uint16_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me=NULL)
Definition: parsetools.cpp:41