example.idl 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. (def-newtype time_micros_t sint64_t)
  2. -- comments should be haskell style, because we're suing parsec's haskell lexer
  3. -- enums default to 32 bit width if you don't really care
  4. (def-enum mode_t
  5. (stabilize 0)
  6. (auto 1))
  7. -- or you can specify a width
  8. (def-enum (armed_t 8)
  9. (disarmed 0)
  10. (armed 1))
  11. (def-struct heartbeat_t
  12. (time time_micros_t)
  13. (armed armed_t))
  14. (def-newtype lat_t sint32_t)
  15. (def-newtype lon_t sint32_t)
  16. -- Todo: allow attaching unit annotations to newtypes. The code generator will
  17. -- provide the units as a human readable comment, and/or in some type/unit
  18. -- system supported by the host language.
  19. -- Todo: allow attaching predicates to newtypes. e.g., lon_t might have some
  20. -- type (degrees * 10e-6), some predicate
  21. -- (lambda (v) (and (gt v -180000000) (lte v 180000000)))
  22. (def-newtype meters_t float_t)
  23. (def-struct coordinate_t
  24. (lat lat_t)
  25. (lon lon_t)
  26. (alt meters_t))
  27. (def-struct timed_coord_t
  28. (lat lat_t)
  29. (lon lon_t)
  30. (alt meters_t)
  31. (time time_micros_t))
  32. -- Todo: the following interface syntax and semantics are a strawman.
  33. -- Interfaces have methods that are either streams or attrs.
  34. -- attrs take a parameter for access control.
  35. -- streams take a parameter for their default period in hz (none should default
  36. -- to zero). they also implicitly define an attr $(steamname)-stream-rate,
  37. -- which permits changing the stream rate at runtime.
  38. (def-interface vehicle_i ()
  39. (heartbeat (stream 10 heartbeat_t)))
  40. -- Interfaces implement java-style inheritance. No shadowing of inherited method
  41. -- names permitted.
  42. (def-interface controllable_vehicle_i (vehicle_i) -- Inherits from interface vehicle
  43. (current_waypoint (attr read coordinate_t))
  44. (next_waypoint (attr readwrite timed_coord_t)))
  45. -- The idea here is that, when negotiating a gidl connection, the client can
  46. -- specify or negotiate what interface is supported.
  47. -- this may be communicated by just sending the string name, or potentially by
  48. -- sending the entire serialized schema. At very least, the client and server
  49. -- should check agreement of their type schemas, probably by having the client
  50. -- send a sha1-hash of the serialized type schema.
  51. -- This allows us to specify various kinds of vehicles might exist without
  52. -- repeating ourselves, and provides a way to
  53. -- manage new functionality without breaking legacy code.