main_databinder.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Copyright (C) 2007-2014 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 Daniel.Peintner.EXT@siemens.com
  20. * @version 0.9.2
  21. * @contact Joerg.Heuer@siemens.com
  22. *
  23. * <p>Code generated by EXIdizer</p>
  24. * <p>Schema: V2G_CI_MsgDef.xsd</p>
  25. *
  26. *
  27. ********************************************************************/
  28. /*******************************************************************
  29. *
  30. * <p>Sample program to illustrate how to read an EXI stream and
  31. * directly write it again to an output</p>
  32. *
  33. * <p>e.g., <executable> in.exi out.exi</p>
  34. ********************************************************************/
  35. #include <stdio.h>
  36. #include <stdarg.h>
  37. #include <stdlib.h>
  38. /* schema-dependent */
  39. #include "v2gEXIDatatypes.h"
  40. #include "v2gEXIDatatypesEncoder.h"
  41. #include "v2gEXIDatatypesDecoder.h"
  42. #include "ByteStream.h"
  43. /** EXI Debug mode */
  44. #define EXI_DEBUG 0
  45. #define BUFFER_SIZE 4096
  46. uint8_t bufferIn[BUFFER_SIZE];
  47. uint8_t bufferOut[BUFFER_SIZE];
  48. #if EXI_DEBUG == 1
  49. # define DEBUG_PRINTF(x) printf x
  50. #else
  51. # define DEBUG_PRINTF(x) do {} while (0)
  52. #endif
  53. int main_databinder(int argc, char *argv[]) {
  54. struct v2gEXIDocument exiDoc;
  55. int errn = 0;
  56. bitstream_t iStream, oStream;
  57. #if EXI_STREAM == BYTE_ARRAY
  58. uint16_t posDecode;
  59. uint16_t posEncode;
  60. #endif /* EXI_STREAM == BYTE_ARRAY */
  61. #if EXI_DEBUG == 1
  62. /* The Eclipse console has buffering problems on Windows e.g, Debug mode */
  63. setvbuf(stdout, NULL, _IONBF, 0);
  64. setvbuf(stderr, NULL, _IONBF, 0);
  65. #endif /*EXI_DEBUG*/
  66. if (argc != 3) {
  67. printf("Usage: %s exiInput exiOutput\n", argv[0]);
  68. return -1;
  69. }
  70. #if EXI_STREAM == BYTE_ARRAY
  71. /* input pos */
  72. posDecode = 0;
  73. /* parse EXI stream to internal byte structures */
  74. errn = readBytesFromFile(argv[1], bufferIn, BUFFER_SIZE, &posDecode);
  75. if (errn != 0) {
  76. printf("Problems while reading file into buffer, err==%d\n", errn);
  77. return errn;
  78. }
  79. posDecode = 0; /* reset position */
  80. #endif /* EXI_STREAM == BYTE_ARRAY */
  81. /* setup input stream */
  82. #if EXI_STREAM == BYTE_ARRAY
  83. iStream.size = BUFFER_SIZE;
  84. iStream.data = bufferIn;
  85. iStream.pos = &posDecode;
  86. #endif /* EXI_STREAM == BYTE_ARRAY */
  87. iStream.buffer = 0;
  88. iStream.capacity = 0;
  89. printf("Start decoding EXI stream to databinding layer \n");
  90. errn = decode_v2gExiDocument(&iStream, &exiDoc);
  91. if (errn != 0) {
  92. printf("Problems while decoding EXI stream, err==%d\n", errn);
  93. return errn;
  94. }
  95. #if EXI_STREAM == BYTE_ARRAY
  96. /* setup output stream */
  97. posEncode = 0;
  98. oStream.size = BUFFER_SIZE;
  99. oStream.data = bufferOut;
  100. oStream.pos = &posEncode;
  101. #endif
  102. oStream.buffer = 0;
  103. oStream.capacity = 8;
  104. printf("Start encoding databinding layer to EXI \n");
  105. errn = encode_v2gExiDocument(&oStream, &exiDoc);
  106. if (errn != 0) {
  107. printf("Problems while encoding databinding layer, err==%d\n", errn);
  108. return errn;
  109. }
  110. printf("EXI roundtrip done with success\n");
  111. #if EXI_STREAM == BYTE_ARRAY
  112. /* write to file */
  113. writeBytesToFile(oStream.data, posEncode, argv[2]);
  114. #endif
  115. return errn;
  116. }