ksp-serial.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Copyright (C) 2023 Daniele Lacamera <root@danielinux.net>
  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 by
  6. * 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. #ifndef KSP_SERIAL_H
  18. #define KSP_SERIAL_H
  19. #include <stdint.h>
  20. typedef struct __attribute__((packed)) vesselData {
  21. uint8_t id; //1
  22. float AP; //2
  23. float PE; //3
  24. float SemiMajorAxis; //4
  25. float SemiMinorAxis; //5
  26. float VVI; //6
  27. float e; //7
  28. float inc; //8
  29. float G; //9
  30. int32_t TAp; //10
  31. int32_t TPe; //11
  32. float TrueAnomaly; //12
  33. float Density; //13
  34. int32_t period; //14
  35. float RAlt; //15
  36. float Alt; //16
  37. float Vsurf; //17
  38. float Lat; //18
  39. float Lon; //19
  40. float LiquidFuelTot; //20
  41. float LiquidFuel; //21
  42. float OxidizerTot; //22
  43. float Oxidizer; //23
  44. float EChargeTot; //24
  45. float ECharge; //25
  46. float MonoPropTot; //26
  47. float MonoProp; //27
  48. float IntakeAirTot; //28
  49. float IntakeAir; //29
  50. float SolidFuelTot; //30
  51. float SolidFuel; //31
  52. float XenonGasTot; //32
  53. float XenonGas; //33
  54. float LiquidFuelTotS; //34
  55. float LiquidFuelS; //35
  56. float OxidizerTotS; //36
  57. float OxidizerS; //37
  58. uint32_t MissionTime; //38
  59. float deltaTime; //39
  60. float VOrbit; //40
  61. uint32_t MNTime; //41
  62. float MNDeltaV; //42
  63. float Pitch; //43
  64. float Roll; //44
  65. float Heading; //45
  66. uint16_t ActionGroups; //46 status bit order:SAS, RCS, Light, Gear, Brakes, Abort, Custom01 - 10
  67. uint8_t SOINumber; //47 SOI Number (decimal format: sun-planet-moon e.g. 130 = kerbin, 131 = mun)
  68. uint8_t MaxOverHeat; //48 Max part overheat (% percent)
  69. float MachNumber; //49
  70. float IAS; //50 Indicated Air Speed
  71. uint8_t CurrentStage; //51 Current stage number
  72. uint8_t TotalStage; //52 TotalNumber of stages
  73. float TargetDist; //53 Distance to targeted vessel (m)
  74. float TargetV; //54 Target vessel relative velocity (m/s)
  75. uint8_t NavballSASMode; //55 Combined byte for navball target mode and SAS mode
  76. // First four bits indicate AutoPilot mode:
  77. // 0 SAS is off //1 = Regular Stability Assist //2 = Prograde
  78. // 3 = RetroGrade //4 = Normal //5 = Antinormal //6 = Radial In
  79. // 7 = Radial Out //8 = Target //9 = Anti-Target //10 = Maneuver node
  80. // Last 4 bits set navball mode. (0=ignore,1=ORBIT,2=SURFACE,3=TARGET)
  81. } vesselData_t;
  82. typedef struct __attribute__((packed)) handShakePacket {
  83. uint8_t id;
  84. uint8_t M1;
  85. uint8_t M2;
  86. uint8_t M3;
  87. } handShakePacket_t;
  88. typedef struct __attribute__((packed)) controlPacket {
  89. uint8_t id;
  90. uint8_t MainControls; // SAS RCS Lights Gear Brakes Precision Abort Stage
  91. uint8_t Mode; // 0 = stage, 1 = docking, 2 = map
  92. uint16_t ControlGroup; // control groups 1-10 in 2 bytes
  93. uint8_t NavBallSASMode; // other stuff
  94. uint8_t AdditionalControlByte1;
  95. int16_t Pitch; // -1000 -> 1000
  96. int16_t Roll; // -1000 -> 1000
  97. int16_t Yaw; // -1000 -> 1000
  98. int16_t TX; // -1000 -> 1000
  99. int16_t TY; // -1000 -> 1000
  100. int16_t TZ; // -1000 -> 1000
  101. int16_t WheelSteer; // -1000 -> 1000
  102. int16_t Throttle; // 0 -> 1000
  103. int16_t WheelThrottle; // 0 -> 1000
  104. } controlPacket_t;
  105. extern vesselData_t *cur_vdata;
  106. void ksp_serial_send(const void *data, uint8_t len);
  107. #endif