Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ksc messages #1972

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/source/_images/commands/uplink_window.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 35 additions & 1 deletion doc/source/commands/communication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Communication
=============

kOS allows you to write scripts that communicate with scripts running on other processors within the same vessel
(inter-processor communication) or on other vessels (inter-vessel communication).
(inter-processor communication) or on other vessels (inter-vessel communication) or as a receiver of messages from
the KSC.

Limitations
-----------
Expand Down Expand Up @@ -144,6 +145,39 @@ The receiving CPU will use :attr:`CORE:MESSAGES` to access its message queue::
PRINT "Unexpected message: " + RECEIVED:CONTENT.
}

Sending messages to vessel from KSC
-----------------------------------

.. versionadded:: ??

It is possible to send messages to the active vessel from the Kerbal Space Center, e.g. for sending instructions.
To do this, first change to the vessel you want to send the message to. Then open an uplink channel via a button
in the main kOS window:

.. figure:: /_images/commands/uplink_channel_button.png
:width: 30 %


This opens a new window where you can type and send the message:

.. figure:: /_images/commands/uplink_window.png
:width: 50 %

Key Notes:

1. Name of the vessel the uplink is open to.
2. Time to receive the last message sent (will be ``NO MESSAGE SENT`` if none has been sent yet and ``RECEIVED``
if the last message sent was already received).
3. You can type the message here.
4. Sends the message.
5. Closes the uplink window.

The message (its ``CONTENT``) will be a string. It is the job of the receiver to parse it into something useful (if needed).
The message can be sent only if the active vessel's :global:`HOMECONNECTION` is connected. The message behaves in the same
way as if it was sent from another vessel, except for :attr:`Message:SENDER` and :attr:`Message:HASSENDER` that indicate
that the source is the KSC and not a vessel (see their reference for details).


.. _connectivityManagers:

Connectivity Managers
Expand Down
2 changes: 2 additions & 0 deletions doc/source/general/settingsWindows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ and visa versa.)

Here is an annotated image of the control panel and what it does:

TODO - replace with new image

.. figure:: /_images/general/controlPanelWindow.png
:width: 80 %

Expand Down
27 changes: 17 additions & 10 deletions doc/source/structures/communication/message.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Structure
- date this message was received at
* - :attr:`SENDER`
- :struct:`Vessel` or :struct:`Boolean`
- vessel which has sent this message, or Boolean false if sender vessel is now gone
- vessel which has sent this message, or Boolean false if sender vessel is now gone, or Boolean true if the sender is the KSC
* - :attr:`HASSENDER`
- :struct:`Boolean`
- Tests whether or not the sender vessel still exists.
Expand Down Expand Up @@ -71,11 +71,16 @@ Structure
:type: :struct:`Vessel` or :struct:`Boolean`

Vessel which has sent this message, or a boolean false value if
the sender vessel no longer exists.
the sender vessel no longer exists, or a boolean true value if the
message was sent from KSC.

If the sender of the message doesn't exist anymore (see the explanation
for :attr:`HASSENDER`), this suffix will return a different type
altogether. It will be a :struct:`Boolean` (which is false).
If the sender of the message is an existing vessel, this suffix will
return that vessel. In all other cases, this suffix will return a
:struct:`Boolean` with the value:

* ``false`` if the sender of the message is a vessel that no
longer exists (see :attr:`HASSENDER` for explanation),
* ``true`` if the message was sent from KSC.

You can check for this condition either by using the :attr:`HASSENDER`
suffix, or by checking the ``:ISTYPE`` suffix of the sender to
Expand All @@ -89,11 +94,13 @@ Structure
when it was processed by the receiving script, it's possibile that
the vessel that sent the message might not exist anymore. It could
have either exploded, or been recovered, or been merged into another
vessel via docking. You can check the value of the ``:HASSENDER``
suffix to find out if the sender of the message is still a valid vessel.
If :attr:`HASSENDER` is false, then :attr:`SENDER` won't give you an
object of type :struct:`Vessel` and instead will give you just a
:struct:`Boolean` false.
vessel via docking. Another possible case is that the message was not
sent from a vessel at all but from the KSC.

You can check the value of the ``:HASSENDER`` suffix to find out if
the sender of the message is still a valid vessel. If :attr:`HASSENDER`
is false, then :attr:`SENDER` won't give you an object of type
:struct:`Vessel` and instead will give you just a :struct:`Boolean`.

.. attribute:: Message:CONTENT

Expand Down
26 changes: 26 additions & 0 deletions src/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"windows": {
"command": "msbuild"
},
"linux": {
"command": "xbuild"
},
"args": [
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true"
],
"taskSelector": "/t:",
"showOutput": "silent",
"tasks": [
{
"taskName": "build",
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
}
]
}
25 changes: 25 additions & 0 deletions src/kOS/Communication/KscTarget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using kOS.Suffixed;

namespace kOS.Communication
{
[Safe.Utilities.KOSNomenclature("KscTarget", KOSToCSharp = false)]
public class KscTarget : VesselTarget {
private static readonly KscTarget kscTarget = new KscTarget();

public static KscTarget Instance
{
get {
return kscTarget;
}
}

private KscTarget()
{}

public override Guid GetGuid()
{
return Guid.Empty;
}
}
}
2 changes: 1 addition & 1 deletion src/kOS/Communication/MessageStructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Structure GetVesselTarget()

if (vessel == null)
{
return new BooleanValue(false);
return new BooleanValue(KscTarget.Instance.GetGuid().ToString().Equals(Message.Vessel));
}

return new VesselTarget(vessel, shared);
Expand Down
32 changes: 31 additions & 1 deletion src/kOS/Screen/KOSToolbarWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public class KOSToolbarWindow : MonoBehaviour

private bool uiGloballyHidden = false;

private UplinkWindow uplinkWindow;

/// <summary>
/// Unity hates it when a MonoBehaviour has a constructor,
/// so all the construction work is here instead:
Expand Down Expand Up @@ -114,6 +116,8 @@ public void Awake()
GameObject.DontDestroyOnLoad(this);

fontPicker = null;

uplinkWindow = gameObject.AddComponent<UplinkWindow>();
}

// TODO - Remove this next method after verifying KSP 1.1 works without it:
Expand Down Expand Up @@ -427,7 +431,10 @@ public void DrawWindow(int windowID)
CountBeginVertical();
CountBeginHorizontal();

CountBeginVertical();
DrawActiveCPUsOnPanel();
DrawActiveVesselLink();
CountEndVertical();

CountBeginVertical("", 150);
GUILayout.Label("CONFIG VALUES", headingLabelStyle);
Expand Down Expand Up @@ -609,7 +616,7 @@ private string TelnetStatusMessage()

private void DrawActiveCPUsOnPanel()
{
scrollPos = GUILayout.BeginScrollView(scrollPos, panelSkin.scrollView, GUILayout.MinWidth(260), GUILayout.Height(windowRect.height - 60));
scrollPos = GUILayout.BeginScrollView(scrollPos, panelSkin.scrollView, GUILayout.MinWidth(260), GUILayout.Height(windowRect.height - 90));

CountBeginVertical();
Vessel prevVessel = null;
Expand Down Expand Up @@ -640,6 +647,29 @@ private void DrawActiveCPUsOnPanel()
GUILayout.EndScrollView();
}

private void DrawActiveVesselLink()
{
Vessel thisVessel = FlightGlobals.ActiveVessel;

CountBeginVertical();
if (thisVessel == null)
{
GUILayout.Label("No active vessel.");
}
else
{
if (GUILayout.Button(uplinkWindow.IsOpen ?
new GUIContent("Close uplink channel") :
new GUIContent("Open uplink channel to active vessel")))
{
SafeHouse.Logger.SuperVerbose("KOSToolBarWindow: toggle uplink");
uplinkWindow.AttachTo(thisVessel);
uplinkWindow.Toggle();
}
}
CountEndVertical();
}

private void DrawPartRow(Part part)
{
CountBeginHorizontal();
Expand Down
Loading