main_databinder.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright (C) 2007-2018 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.4
  21. * @contact Richard.Kuntschke@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 "../iso1/iso1EXIDatatypes.h"
  40. #if DEPLOY_ISO1_CODEC == SUPPORT_YES
  41. #include "../iso1/iso1EXIDatatypesEncoder.h"
  42. #include "../iso1/iso1EXIDatatypesDecoder.h"
  43. #endif /* DEPLOY_ISO1_CODEC == SUPPORT_YES */
  44. #include "../iso2/iso2EXIDatatypes.h"
  45. #if DEPLOY_ISO2_CODEC == SUPPORT_YES
  46. #include "../iso2/iso2EXIDatatypesEncoder.h"
  47. #include "../iso2/iso2EXIDatatypesDecoder.h"
  48. #endif /* DEPLOY_ISO2_CODEC == SUPPORT_YES */
  49. #include "../codec/ByteStream.h"
  50. /** EXI Debug mode */
  51. #define EXI_DEBUG 0
  52. #define BUFFER_SIZE 4096
  53. uint8_t bufferIn[BUFFER_SIZE];
  54. uint8_t bufferOut[BUFFER_SIZE];
  55. #if EXI_DEBUG == 1
  56. # define DEBUG_PRINTF(x) printf x
  57. #else
  58. # define DEBUG_PRINTF(x) do {} while (0)
  59. #endif
  60. int main_databinder(int argc, char *argv[]) {
  61. #if DEPLOY_DIN_CODEC == SUPPORT_YES
  62. struct dinEXIDocument dinDoc;
  63. #endif /* DEPLOY_DIN_CODEC == SUPPORT_YES */
  64. #if DEPLOY_ISO1_CODEC == SUPPORT_YES
  65. struct iso1EXIDocument exi1Doc;
  66. #endif /* DEPLOY_ISO1_CODEC == SUPPORT_YES */
  67. #if DEPLOY_ISO2_CODEC == SUPPORT_YES
  68. struct iso2EXIDocument exi2Doc;
  69. #endif /* DEPLOY_ISO2_CODEC == SUPPORT_YES */
  70. int errn = 0;
  71. bitstream_t iStream, oStream;
  72. #if EXI_STREAM == BYTE_ARRAY
  73. size_t posDecode;
  74. size_t posEncode;
  75. #endif /* EXI_STREAM == BYTE_ARRAY */
  76. #if EXI_DEBUG == 1
  77. /* The Eclipse console has buffering problems on Windows e.g, Debug mode */
  78. setvbuf(stdout, NULL, _IONBF, 0);
  79. setvbuf(stderr, NULL, _IONBF, 0);
  80. #endif /*EXI_DEBUG*/
  81. if (argc != 3) {
  82. printf("Usage: %s exiInput exiOutput\n", argv[0]);
  83. return -1;
  84. }
  85. #if EXI_STREAM == BYTE_ARRAY
  86. /* input pos */
  87. posDecode = 0;
  88. /* parse EXI stream to internal byte structures */
  89. errn = readBytesFromFile(argv[1], bufferIn, BUFFER_SIZE, &posDecode);
  90. if (errn != 0) {
  91. printf("Problems while reading file into buffer, err==%d\n", errn);
  92. return errn;
  93. }
  94. posDecode = 0; /* reset position */
  95. #endif /* EXI_STREAM == BYTE_ARRAY */
  96. /* setup input stream */
  97. #if EXI_STREAM == BYTE_ARRAY
  98. iStream.size = BUFFER_SIZE;
  99. iStream.data = bufferIn;
  100. iStream.pos = &posDecode;
  101. #endif /* EXI_STREAM == BYTE_ARRAY */
  102. iStream.buffer = 0;
  103. iStream.capacity = 0;
  104. printf("Start decoding EXI stream to databinding layer \n");
  105. #if DEPLOY_DIN_CODEC == SUPPORT_YES
  106. errn = decode_dinExiDocument(&iStream, &dinDoc);
  107. #endif /* DEPLOY_DIN_CODEC == SUPPORT_YES */
  108. #if DEPLOY_ISO1_CODEC == SUPPORT_YES
  109. errn = decode_iso1ExiDocument(&iStream, &exi1Doc);
  110. #endif /* DEPLOY_ISO1_CODEC == SUPPORT_YES */
  111. #if DEPLOY_ISO2_CODEC == SUPPORT_YES
  112. errn = decode_iso2ExiDocument(&iStream, &exi2Doc);
  113. #endif /* DEPLOY_ISO2_CODEC == SUPPORT_YES */
  114. if (errn != 0) {
  115. printf("Problems while decoding EXI stream, err==%d\n", errn);
  116. return errn;
  117. }
  118. #if EXI_STREAM == BYTE_ARRAY
  119. /* setup output stream */
  120. posEncode = 0;
  121. oStream.size = BUFFER_SIZE;
  122. oStream.data = bufferOut;
  123. oStream.pos = &posEncode;
  124. #endif
  125. oStream.buffer = 0;
  126. oStream.capacity = 8;
  127. printf("Start encoding databinding layer to EXI \n");
  128. #if DEPLOY_DIN_CODEC == SUPPORT_YES
  129. errn = encode_dinExiDocument(&oStream, &dinDoc);
  130. #endif /* DEPLOY_DIN_CODEC == SUPPORT_YES */
  131. #if DEPLOY_ISO1_CODEC == SUPPORT_YES
  132. errn = encode_iso1ExiDocument(&oStream, &exi1Doc);
  133. #endif /* DEPLOY_ISO1_CODEC == SUPPORT_YES */
  134. #if DEPLOY_ISO2_CODEC == SUPPORT_YES
  135. errn = encode_iso2ExiDocument(&oStream, &exi2Doc);
  136. #endif /* DEPLOY_ISO2_CODEC == SUPPORT_YES */
  137. if (errn != 0) {
  138. printf("Problems while encoding databinding layer, err==%d\n", errn);
  139. return errn;
  140. }
  141. printf("EXI roundtrip done with success\n");
  142. #if EXI_STREAM == BYTE_ARRAY
  143. /* write to file */
  144. writeBytesToFile(oStream.data, posEncode, argv[2]);
  145. #endif
  146. return errn;
  147. }