Skip to content

Commit 3dafb59

Browse files
committed
Add Intersects Message
1 parent 9a20b8b commit 3dafb59

3 files changed

Lines changed: 45 additions & 12 deletions

File tree

examples/KerbalSimpitAllFeedbackDemo/KerbalSimpitAllFeedbackDemo.ino

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ bool lastButtonState = HIGH; // To find when the button changes state
1515

1616
KerbalSimpit mySimpit(Serial); // Declare a KerbalSimpit object that will communicate using the "Serial" device.
1717

18-
const int NUMBER_OF_STEPS = 52; //The selectionIndex will be reset to 0 after reaching NUMBER_OF_STEPS-1
18+
const int NUMBER_OF_STEPS = 54; //The selectionIndex will be reset to 0 after reaching NUMBER_OF_STEPS-1
1919
int selectionIndex = 0; // increased when pushing the continue button to display different Values
2020
unsigned long timestampLastSent; // When was the last time something was sent to print on screen
2121
const int SENDING_INTERVAL = 1000; // in milliseconds. How often to print data to screen
@@ -25,8 +25,8 @@ const int SENDING_INTERVAL = 1000; // in milliseconds. How often to print data
2525
bool echoReceived = false;
2626
float myAltitudeSeaLevel;
2727
float myAltitudeSurface;
28-
int32_t myTimeToApoapsis;
29-
int32_t myTimeToPeriapsis;
28+
int32_t myTime1;
29+
int32_t myTime2;
3030
byte myCurrentSASMode;
3131
int16_t mySASModeAvailability;
3232
bool myCustomActionGroups[10];
@@ -156,6 +156,7 @@ void setup() {
156156
mySimpit.registerChannel(ATMO_CONDITIONS_MESSAGE);
157157
mySimpit.registerChannel(VESSEL_NAME_MESSAGE);
158158
mySimpit.registerChannel(VESSEL_CHANGE_MESSAGE);
159+
mySimpit.registerChannel(INTERSECTS_MESSAGE);
159160

160161
// |---------------------|
161162
// | Echo & Echo Request |
@@ -231,7 +232,7 @@ void loop()
231232
mySimpit.printToKSP("Apoapsis " + String(myFloatStorage2, 0) + " Periapsis " + String(myFloatStorage1, 0), PRINT_TO_SCREEN);
232233
} break;
233234
case 13: { //Apsides Times
234-
mySimpit.printToKSP("Time to Ap " + String(myTimeToApoapsis) + " Time to Pe " + String(myTimeToPeriapsis), PRINT_TO_SCREEN);
235+
mySimpit.printToKSP("Time to Ap " + String(myTime1) + " Time to Pe " + String(myTime2), PRINT_TO_SCREEN);
235236
} break;
236237
case 14: { //Maneuver part 1
237238
mySimpit.printToKSP("Mnv Time " + String(myFloatStorage1, 0) + " dvNxt " + String(myFloatStorage2, 0) + " dur " + String(myFloatStorage3, 0), PRINT_TO_SCREEN);
@@ -456,6 +457,12 @@ void loop()
456457
" 5:" + String((int)myAdvancedActionGroups[4]), PRINT_TO_SCREEN);
457458
//And so on for all 10 action groups
458459
} break;
460+
case 52: { //Intersect info first intersect
461+
mySimpit.printToKSP("Intsct1 d " + String(myFloatStorage1, 0) + " v " + String(myFloatStorage2, 0) + " t " + String(myTime1), PRINT_TO_SCREEN);
462+
} break;
463+
case 53: { //Intersect info second intersect
464+
mySimpit.printToKSP("Intsct2 d " + String(myFloatStorage3, 0) + " v " + String(myFloatStorage4, 0) + " t " + String(myTime2), PRINT_TO_SCREEN);
465+
} break;
459466
default: {
460467
//mySimpit.printToKSP(F("Unknown selectionIndex"), PRINT_TO_SCREEN);
461468
} break;
@@ -640,9 +647,6 @@ void loop()
640647
case 46:
641648
mySimpit.requestMessageOnChannel(VESSEL_NAME_MESSAGE);
642649
break;
643-
644-
645-
646650
case 47:
647651
mySimpit.requestMessageOnChannel(INTAKE_AIR_MESSAGE);
648652
break;
@@ -659,6 +663,10 @@ void loop()
659663
case 51:
660664
mySimpit.requestMessageOnChannel(ADVANCED_CAGSTATUS_MESSAGE);
661665
break;
666+
case 52:
667+
case 53:
668+
mySimpit.requestMessageOnChannel(INTERSECTS_MESSAGE);
669+
break;
662670
}
663671
}
664672
}
@@ -905,8 +913,8 @@ void messageHandler(byte messageType, byte msg[], byte msgSize) {
905913
if (msgSize == sizeof(apsidesTimeMessage) && selectionIndex == 13)
906914
{
907915
apsidesTimeMessage apsidesTimeMsg = parseMessage<apsidesTimeMessage>(msg);
908-
myTimeToPeriapsis = apsidesTimeMsg.periapsis;
909-
myTimeToApoapsis = apsidesTimeMsg.apoapsis;
916+
myTime1 = apsidesTimeMsg.apoapsis;
917+
myTime2 = apsidesTimeMsg.periapsis;
910918
}
911919
} break;
912920
case MANEUVER_MESSAGE: {
@@ -1143,6 +1151,18 @@ void messageHandler(byte messageType, byte msg[], byte msgSize) {
11431151
myBool2 = true;
11441152
}
11451153
} break;
1154+
case INTERSECTS_MESSAGE: {
1155+
if (msgSize == sizeof(intersectsMessage) && (selectionIndex == 52 || selectionIndex == 53))
1156+
{
1157+
intersectsMessage intersectsMsg = parseMessage<intersectsMessage>(msg);
1158+
myFloatStorage1 = intersectsMsg.distanceAtIntersect1;
1159+
myFloatStorage2 = intersectsMsg.velocityAtIntersect1;
1160+
myTime1 = intersectsMsg.timeToIntersect1;
1161+
myFloatStorage3 = intersectsMsg.distanceAtIntersect2;
1162+
myFloatStorage4 = intersectsMsg.velocityAtIntersect2;
1163+
myTime2 = intersectsMsg.timeToIntersect2;
1164+
}
1165+
} break;
11461166
default: {
11471167

11481168
} break;

src/KerbalSimpitMessageTypes.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,11 @@ enum OutboundPackets
271271
1 for vessel switching
272272
2 for docking
273273
3 for undocking. */
274-
VESSEL_CHANGE_MESSAGE = 51
275-
274+
VESSEL_CHANGE_MESSAGE = 51,
275+
/** Information about intersects with a target orbit.
276+
This channel delivers messages about the intersects between the
277+
active vessel and a target. Messages on this channel contain a intersectsMessage. */
278+
INTERSECTS_MESSAGE = 60
276279
};
277280

278281
/** Inbound packets.
@@ -304,7 +307,7 @@ enum InboundPackets
304307
result in the next stage being activated.
305308
For all other action groups, multiple activate requests will have
306309
no effect.
307-
*/
310+
*/
308311
AGACTIVATE_MESSAGE = 13,
309312
/** Deactivate the given standard Action Group(s). */
310313
AGDEACTIVATE_MESSAGE = 14,

src/PayloadStructs.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ struct targetMessage {
146146
float velocityPitch; /**< Pitch of the velocity to the target. Only available in KSP1. */
147147
} __attribute__((packed));
148148

149+
/** A Intersect information message. If an intersect does not exist, the according values are negative. */
150+
struct intersectsMessage {
151+
float distanceAtIntersect1; /**< Relative distance at the first intercept. */
152+
int32_t timeToIntersect1; /**< Time to the first intercept in seconds. */
153+
float velocityAtIntersect1; /**< Relative velocity at the first intercept. */
154+
float distanceAtIntersect2; /**< Relative distance at the second intercept. */
155+
int32_t timeToIntersect2; /**< Time to the second intercept in seconds. */
156+
float velocityAtIntersect2; /**< Relative velocity at the second intercept. */
157+
} __attribute__((packed));
158+
149159
/** An Airspeed information message. */
150160
struct airspeedMessage {
151161
float IAS; /**< Indicated airspeed. */

0 commit comments

Comments
 (0)