MethodsBag.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 2017-03-02
  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. #ifndef METHODS_BAG_C
  29. #define METHODS_BAG_C
  30. #include "MethodsBag.h"
  31. #include "ErrorCodes.h"
  32. static const uint16_t smallLengths[] = { 0, 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4,
  33. 4, 4, 4 };
  34. int exiGetCodingLength(size_t characteristics, size_t* codingLength) {
  35. /* Note: we could use range expressions in switch statements but those are non-standard */
  36. /* e.g., case 1 ... 5: */
  37. int errn = 0;
  38. if (characteristics < 17) {
  39. *codingLength = smallLengths[characteristics];
  40. } else if (characteristics < 33) {
  41. /* 17 .. 32 */
  42. *codingLength = 5;
  43. } else if (characteristics < 65) {
  44. /* 33 .. 64 */
  45. *codingLength = 6;
  46. } else if (characteristics < 129) {
  47. /* 65 .. 128 */
  48. *codingLength = 7;
  49. } else if (characteristics < 257) {
  50. /* 129 .. 256 */
  51. *codingLength = 8;
  52. } else if (characteristics < 513) {
  53. /* 257 .. 512 */
  54. *codingLength = 9;
  55. } else if (characteristics < 1025) {
  56. /* 513 .. 1024 */
  57. *codingLength = 10;
  58. } else if (characteristics < 2049) {
  59. /* 1025 .. 2048 */
  60. *codingLength = 11;
  61. } else if (characteristics < 4097) {
  62. /* 2049 .. 4096 */
  63. *codingLength = 12;
  64. } else if (characteristics < 8193) {
  65. /* 4097 .. 8192 */
  66. *codingLength = 13;
  67. } else if (characteristics < 16385) {
  68. /* 8193 .. 16384 */
  69. *codingLength = 14;
  70. } else if (characteristics < 32769) {
  71. /* 16385 .. 32768 */
  72. *codingLength = 15;
  73. } else {
  74. /* 32769 .. 65536 */
  75. *codingLength = 16;
  76. }
  77. return errn;
  78. }
  79. uint8_t numberOf7BitBlocksToRepresent(uint32_t n) {
  80. /* assert (n >= 0); */
  81. /* 7 bits */
  82. if (n < 128) {
  83. return 1;
  84. }
  85. /* 14 bits */
  86. else if (n < 16384) {
  87. return 2;
  88. }
  89. /* 21 bits */
  90. else if (n < 2097152) {
  91. return 3;
  92. }
  93. /* 28 bits */
  94. else if (n < 268435456) {
  95. return 4;
  96. }
  97. /* 35 bits */
  98. else {
  99. /* int, 32 bits */
  100. return 5;
  101. }
  102. }
  103. #endif