evse_server.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2007-2011 Siemens AG
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published
  6. * by the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /*******************************************************************
  18. *
  19. * @author Sebastian.Kaebisch.EXT@siemens.com
  20. * @@version 0.5
  21. * @contact Joerg.Heuer@siemens.com
  22. *
  23. ********************************************************************/
  24. #include "evse_server.h"
  25. #include "v2g_service.h"
  26. #include "v2g_serviceDispatcher.h"
  27. #include "v2gtp.h"
  28. #define MAX_BYTE_SIZE 64
  29. #define MAX_STRING_SIZE 64
  30. #define MAX_STREAM_SIZE 100
  31. int testV2GService(uint8_t* inStream, uint16_t inStreamLength, uint8_t* outStream, uint16_t* outStreamLength)
  32. {
  33. static uint8_t byte_array[MAX_BYTE_SIZE]; /* define MAX_BYTE_SIZE before*/
  34. static uint32_t string_array[MAX_STRING_SIZE]; /* define MAX_STRING_SIZE before*/
  35. uint16_t exiMsgLength;
  36. struct EXIService service;
  37. /* BINARY memory setup */
  38. bytes_t bytes = { MAX_BYTE_SIZE, byte_array, 0 };
  39. /* STRING memory setup */
  40. string_ucs_t string = { MAX_STRING_SIZE, string_array, 0 };
  41. /**********************************************
  42. * Init V2G server and initialize array types *
  43. * for the EXI decoding as well as the offset *
  44. * for the transportation header *
  45. **********************************************/
  46. init_v2gservice(&service, bytes, string, V2GTP_HEADER_LENGTH);
  47. /* check, if the DoIP header is correct and determine payload */
  48. if(read_v2gtpHeader(inStream,inStreamLength, &exiMsgLength))
  49. {
  50. /* v2gtp header not correct */
  51. return -1;
  52. }
  53. /****************************************************************************
  54. * Pass the received EXI message stream (inStream + exiMsgLength) to the *
  55. * v2g message dispatcher. The outStream contains the response message *
  56. * stream. *
  57. ****************************************************************************/
  58. if(messageDispatcher(&service, inStream, exiMsgLength, outStream, MAX_STREAM_SIZE, outStreamLength))
  59. {
  60. /* an error occured */
  61. }
  62. else
  63. {
  64. /* write v2gtp header */
  65. write_v2gtpHeader(outStream, outStreamLength, V2GTP_EXI_TYPE);
  66. }
  67. return 0;
  68. }