MethodsBag.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /*******************************************************************
  19. *
  20. * @author Daniel.Peintner.EXT@siemens.com
  21. * @version 2011-12-02
  22. * @contact Joerg.Heuer@siemens.com
  23. *
  24. * <p>Code generated by EXIdizer</p>
  25. ********************************************************************/
  26. #ifndef METHODS_BAG_C
  27. #define METHODS_BAG_C
  28. #include "MethodsBag.h"
  29. #include "EXITypes.h"
  30. static const int smallLengths[] = { 0, 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4,
  31. 4, 4, 4 };
  32. int exiGetCodingLength(uint32_t characteristics, uint16_t* codingLength) {
  33. if (characteristics < 17) {
  34. *codingLength = smallLengths[characteristics];
  35. return 0;
  36. } else if (characteristics < 33) {
  37. /* 17 .. 32 */
  38. *codingLength = 5;
  39. return 0;
  40. } else if (characteristics < 65) {
  41. /* 33 .. 64 */
  42. *codingLength = 6;
  43. return 0;
  44. } else if (characteristics < 129) {
  45. /* 65 .. 128 */
  46. *codingLength = 7;
  47. return 0;
  48. } else if (characteristics < 257) {
  49. /* 129 .. 256 */
  50. *codingLength = 8;
  51. return 0;
  52. } else if (characteristics < 513) {
  53. /* 257 .. 512 */
  54. *codingLength = 9;
  55. return 0;
  56. } else if (characteristics < 1025) {
  57. /* 513 .. 1024 */
  58. *codingLength = 10;
  59. return 0;
  60. } else {
  61. /*
  62. return (int) Math.ceil(Math.log((double) (characteristics))
  63. / Math.log(2.0)); */
  64. return EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
  65. }
  66. }
  67. uint8_t numberOf7BitBlocksToRepresent(uint32_t n) {
  68. /* assert (n >= 0); */
  69. /* 7 bits */
  70. if (n < 128) {
  71. return 1;
  72. }
  73. /* 14 bits */
  74. else if (n < 16384) {
  75. return 2;
  76. }
  77. /* 21 bits */
  78. else if (n < 2097152) {
  79. return 3;
  80. }
  81. /* 28 bits */
  82. else if (n < 268435456) {
  83. return 4;
  84. }
  85. /* 35 bits */
  86. else {
  87. /* int, 32 bits */
  88. return 5;
  89. }
  90. }
  91. #endif