msg-type.lisp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. ;; Different kinds of message field types.
  2. (defconstant +msg-type-unstructured+ 0)
  3. (defconstant +msg-type-bit+ 0)
  4. (defconstant +msg-type-boolean+ 0)
  5. (defconstant +msg-type-integer-16+ 1)
  6. (defconstant +msg-type-integer-32+ 2)
  7. (defconstant +msg-type-char+ 8)
  8. (defconstant +msg-type-byte+ 9)
  9. (defconstant +msg-type-integer-8+ 9)
  10. (defconstant +msg-type-real+ 10)
  11. (defconstant +msg-type-integer-64+ 11)
  12. (defconstant +msg-type-string+ 12)
  13. (defconstant +msg-type-codes+
  14. `((,+msg-type-unstructured+ :type-unstructured)
  15. (,+msg-type-bit+ :type-bit)
  16. (,+msg-type-boolean+ :type-boolean)
  17. (,+msg-type-integer-16+ :type-integer-16)
  18. (,+msg-type-integer-32+ :type-integer-32)
  19. (,+msg-type-char+ :type-char)
  20. (,+msg-type-byte+ :type-byte)
  21. (,+msg-type-integer-8+ :type-integer-8)
  22. (,+msg-type-real+ :type-real)
  23. (,+msg-type-integer-64+ :type-integer-64)
  24. (,+msg-type-string+ :type-string)))
  25. (defun translate-msg-type-bits (value)
  26. "Return the code from a type symbol."
  27. (translate-foreign-list value +msg-type-codes+ :to))
  28. (defun translate-msg-type-symbol (value)
  29. "Return the symbol from a type code."
  30. (translate-foreign-list value +msg-type-codes+ :from))
  31. (defconstant +msg-type-name-bits+ #xff "Type name mask.")
  32. (defconstant +max-msg-type-name+ #xff "Max type name mask.")
  33. (defun clear-type-name! (val)
  34. "Clear the type name field."
  35. (boole boole-andc2 val +msg-type-name-bits+))
  36. (defun set-type-name! (val type)
  37. "Set the type name field."
  38. (boole boole-ior
  39. (clear-type-name! val)
  40. (boole boole-and (translate-msg-type-bits type)
  41. +max-msg-type-name+)))
  42. (defun get-type-name (val)
  43. "Return the type name field in a symbol."
  44. (translate-msg-type-symbol
  45. (boole boole-and val +msg-type-name-bits+)))
  46. (defconstant +msg-type-size-bits+ #xff00 "The size field mask.")
  47. (defconstant +max-msg-type-size+ #xff "Max size field.")
  48. (defconstant +msg-type-size-shift+ 8 "Shift in the unsigned int.")
  49. (defun clear-type-size! (val)
  50. "Clear the type size field."
  51. (boole boole-andc2 val +msg-type-size-bits+))
  52. (defun set-type-size! (val size)
  53. "Set the type size field."
  54. (boole boole-ior
  55. (clear-type-size! val)
  56. (ash (boole boole-and +max-msg-type-size+ size)
  57. +msg-type-size-shift+)))
  58. (defun get-type-size (val)
  59. "Return the size field."
  60. (ash (boole boole-and +msg-type-size-bits+ val)
  61. (- +msg-type-size-shift+)))
  62. (defconstant +msg-type-number-bits+ #xfff0000 "Type number mask.")
  63. (defconstant +max-msg-type-number+ #xfff "Max type number.")
  64. (defconstant +msg-type-number-shift+ 16 "Type number shift in the unsigned int.")
  65. (defun clear-type-number! (val)
  66. "Clear the type number field."
  67. (boole boole-andc2 val
  68. +msg-type-number-bits+))
  69. (defun set-type-number! (val number)
  70. "Set the type number field."
  71. (boole boole-ior
  72. (clear-type-number! val)
  73. (ash (boole boole-and
  74. number +max-msg-type-number+)
  75. +msg-type-number-shift+)))
  76. (defun get-type-number (val)
  77. "Return the type number."
  78. (ash (boole boole-and val +msg-type-number-bits+)
  79. (- +msg-type-number-shift+)))
  80. (defun set-type-boolean! (val yes bit-pos)
  81. "Set a specific bit in the unsigned int."
  82. (let ((val2 (ash #x1 bit-pos)))
  83. (if yes
  84. (boole boole-ior val val2)
  85. (boole boole-andc2 val val2))))
  86. (defun set-type-inline! (val yes)
  87. "Set inline field."
  88. (set-type-boolean! val yes 28))
  89. (defun set-type-longform! (val yes)
  90. "Set longform field."
  91. (set-type-boolean! val yes 29))
  92. (defun set-type-deallocate! (val yes)
  93. "Set deallocate field."
  94. (set-type-boolean! val yes 30))
  95. (defun set-type-unused! (val yes)
  96. "Set unused field."
  97. (set-type-boolean! val yes 31))
  98. (defctype <msg-type> :unsigned-int)
  99. (defconstant +msg-type-size+ (foreign-type-size <msg-type>))