main_databinder.c 4.6 KB

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