diff options
Diffstat (limited to 'lib/usbhost/USB_Host_Shield_2.0/parsetools.cpp')
-rw-r--r-- | lib/usbhost/USB_Host_Shield_2.0/parsetools.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/usbhost/USB_Host_Shield_2.0/parsetools.cpp b/lib/usbhost/USB_Host_Shield_2.0/parsetools.cpp new file mode 100644 index 000000000..74a861059 --- /dev/null +++ b/lib/usbhost/USB_Host_Shield_2.0/parsetools.cpp | |||
@@ -0,0 +1,67 @@ | |||
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 | } | ||