Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

parsetools.cpp 2.2KB

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