public void Main(string arg) { // If setupcomplete is false, run Setup method. if (setupcomplete == false) { Echo("Running setup."); Setup(); } else { string tag1 = "Traffic Control"; IGC.RegisterBroadcastListener(tag1); // Create a list for broadcast listeners. List <IMyBroadcastListener> listeners = new List <IMyBroadcastListener>(); // The method argument below is the list we wish IGC to populate with all Listeners we've made. // Our Listener we created will be at index 0, because we only have that one Listener so far. IGC.GetBroadcastListeners(listeners); // We don't want to try receiving messages if we don't have any. // So we access the HasPendingMessage property to check if our Listener has any unread messages. if (listeners[0].HasPendingMessage) { MyIGCMessage message = new MyIGCMessage(); message = listeners[0].AcceptMessage(); string messagetext = message.Data.ToString(); if (messagetext.Contains("Requesting Docking Clearance")) { IMyShipConnector dockingPort = GridTerminalSystem.GetBlockWithName("Docking Port 1") as IMyShipConnector; string messageOut = "Clearance denied."; if (dockingPort != null) { messageOut = $"Clearance granted. Proceed to Docking Port #{dockingPort.EntityId} at {dockingPort.Position.ToString()}"; } IGC.SendBroadcastMessage(tag1, messageOut, TransmissionDistance.TransmissionDistanceMax); } } } }
public Program() { Runtime.UpdateFrequency = UpdateFrequency.Update10; antenna = GridTerminalSystem.GetBlockWithName("Antenna") as IMyRadioAntenna; up1 = GridTerminalSystem.GetBlockWithName("up1") as IMyPistonBase; up2 = GridTerminalSystem.GetBlockWithName("up2") as IMyPistonBase; out1 = GridTerminalSystem.GetBlockWithName("out1") as IMyPistonBase; out2 = GridTerminalSystem.GetBlockWithName("out2") as IMyPistonBase; antenna.AttachedProgrammableBlock = Me.EntityId; IGC.RegisterBroadcastListener(Channel); IGC.GetBroadcastListeners(listeners); listeners[0].SetMessageCallback("door"); }
public void Main(string arg) { if (setupcomplete == false) { Echo("Running setup."); Setup(); } else if (setupcomplete == true && requestSent == false) { string messageOut = "Requesting Docking Clearance"; IGC.SendBroadcastMessage(tag1, messageOut, TransmissionDistance.TransmissionDistanceMax); Echo("Requesting Clearance"); requestSent = true; } else if (requestSent == true && clearanceReceived == false) { // Now that we've requested clearance, listen for a clearance response. IGC.RegisterBroadcastListener(tag1); List <IMyBroadcastListener> listeners = new List <IMyBroadcastListener>(); IGC.GetBroadcastListeners(listeners); Echo("checking messages"); if (listeners[0].HasPendingMessage) { Echo("message received"); clearance = listeners[0].AcceptMessage(); clearanceReceived = true; } else { requestSent = false; } } else if (clearanceReceived == true) { Echo(clearance.Data.ToString()); } }
public void SearchForILSMessages() { List <MyIni> ActiveILSTransmitters = new List <MyIni>(); List <IMyBroadcastListener> listeners = new List <IMyBroadcastListener>(); IGC.GetBroadcastListeners(listeners); // Parse any messages from active listeners on the selected channel. listeners.ForEach(listener => { if (!listener.IsActive) { return; } if (listener.Tag != ILSAntennaChannel) { return; } if (listener.HasPendingMessage) { ActiveILSTransmitters.Add( ParseBroadcastedMessage(listener.AcceptMessage()) ); } }); double shortestDistance = 99999; MyIni selectedILSTransmitter = new MyIni(); // Select the transmitter closest to the ship. ActiveILSTransmitters.ForEach(transmitter => { string _GPS = transmitter.Get("TouchdownZone", "GPSA").ToString(); double distance = CalculateShipDistanceFromGPSString(_GPS); if (distance < shortestDistance) { selectedILSTransmitter = transmitter; } }); if (ActiveILSTransmitters.Count == 0) { Echo("Not able to connect to any ILS transmitter signals."); return; } // Select appropriate runway from the chosen transmitter. string GPSA = selectedILSTransmitter.Get("TouchdownZone", "GPSA").ToString(); string GPSB = selectedILSTransmitter.Get("TouchdownZone", "GPSB").ToString(); string HeadingA = selectedILSTransmitter.Get("Runway", "HeadingA").ToString(); string HeadingB = selectedILSTransmitter.Get("Runway", "HeadingB").ToString(); double TouchdownZoneADistance = CalculateShipDistanceFromGPSString(GPSA); double TouchdownZoneBDistance = CalculateShipDistanceFromGPSString(GPSB); string ActingLocalizer, ActingGlideSlope, ActiveHeading; if (TouchdownZoneADistance < TouchdownZoneBDistance) { ActingGlideSlope = GPSA; ActingLocalizer = GPSB; ActiveHeading = HeadingA; } else { ActingGlideSlope = GPSB; ActingLocalizer = GPSA; ActiveHeading = HeadingB; } config.Set("TouchdownZone", "GPSA", GPSA); config.Set("TouchdownZone", "GPSB", GPSB); config.Set("Runway", "HeadingA", HeadingA); config.Set("Runway", "HeadingB", HeadingB); config.Set("LocalizerData", "RWYHDG", ActiveHeading); config.Set("LocalizerData", "GPS", ActingLocalizer); config.Set("GlideSlopeData", "GPS", ActingGlideSlope); SaveStorage(); ShipShouldListenForILS = false; ShipHasSelectedILS = true; }
public void Main(string argument, UpdateType updateSource) { Runtime.UpdateFrequency = UpdateFrequency.Update100 | UpdateFrequency.Update10; IMyTextPanel textPanel = (IMyTextPanel)GridTerminalSystem.GetBlockWithName(lcdName); IMyRemoteControl remoteControl = (IMyRemoteControl)GridTerminalSystem.GetBlockWithName(remoteControllerName); // If setupcomplete is false, run Setup method. if (!setupcomplete) { Echo("Running setup."); Setup(); } else { // To create a listener, we use IGC to access the relevant method. // We pass the same tag argument we used for our message. IGC.RegisterBroadcastListener(broadcastChannel); // Create a list for broadcast listeners. List <IMyBroadcastListener> listeners = new List <IMyBroadcastListener>(); // The method argument below is the list we wish IGC to populate with all Listeners we've made. // Our Listener will be at index 0, since it's the only one we've made so far. IGC.GetBroadcastListeners(listeners); if (listeners[0].HasPendingMessage) { // Let's create a variable for our new message. // Remember, messages have the type MyIGCMessage. MyIGCMessage message = new MyIGCMessage(); // Time to get our message from our Listener (at index 0 of our Listener list). // We do this with the following method: message = listeners[0].AcceptMessage(); // A message is a struct of 3 variables. To read the actual data, // we access the Data field, convert it to type string (unboxing), // and store it in the variable messagetext. string messagetext = message.Data.ToString(); // We can also access the tag that the message was sent with. string messagetag = message.Tag; //Here we store the "address" to the Programmable Block (our friend's) that sent the message. long sender = message.Source; //Do something with the information! Echo("Message received with tag" + messagetag + "\n\r"); Echo("from address " + sender.ToString() + ": \n\r"); Echo(messagetext); allmessage += $"\n new message \n {messagetext}\n{messagetext.Split(':')[2]}"; textPanel.WriteText(allmessage); List <MyWaypointInfo> myWaypoints = new List <MyWaypointInfo>(); string gpsname = messagetext.Split(':')[1]; double x = 0; double y = 0; double z = 0; try { x = Convert.ToDouble(messagetext.Split(':')[2]); y = Convert.ToDouble(messagetext.Split(':')[3]); z = Convert.ToDouble(messagetext.Split(':')[4]); } catch (Exception e) { Echo(e.Message); } Echo(messagetext.Split('1')[0]); myWaypoints.Add(new MyWaypointInfo(gpsname, x, y, z)); remoteControl.ClearWaypoints(); remoteControl.AddWaypoint(myWaypoints[0]); remoteControl.SetCollisionAvoidance(true); remoteControl.SetAutoPilotEnabled(true); } } int textlength = textPanel.GetText().Length; if (textlength > 100) { allmessage = ""; } }
public void Main(string argument, UpdateType updateSource) { //screen that you write text into and send IMyTextPanel lcdWritingScreen = (IMyTextPanel)GridTerminalSystem.GetBlockWithName(lcdTextSender); //screen that recives IMyTextPanel lcdRecieverScreen = (IMyTextPanel)GridTerminalSystem.GetBlockWithName(MessageReciverScreen); // If setupcomplete is false, run Setup method. if (!setupcomplete) { Echo("Running setup."); Setup(); } else { // Create our message. We first make it a string, and then we "box" it as an object type. string messageOut = lcdWritingScreen.GetText(); // Through the IGC variable we issue the broadcast method. IGC is "pre-made", // so we don't have to declare it ourselves, just go ahead and use it. IGC.SendBroadcastMessage(broadcastChannel, messageOut, TransmissionDistance.TransmissionDistanceMax); // To create a listener, we use IGC to access the relevant method. // We pass the same tag argument we used for our message. IGC.RegisterBroadcastListener(broadcastChannel); // Create a list for broadcast listeners. List <IMyBroadcastListener> listeners = new List <IMyBroadcastListener>(); // The method argument below is the list we wish IGC to populate with all Listeners we've made. // Our Listener will be at index 0, since it's the only one we've made so far. IGC.GetBroadcastListeners(listeners); if (listeners[0].HasPendingMessage) { // Let's create a variable for our new message. // Remember, messages have the type MyIGCMessage. MyIGCMessage message = new MyIGCMessage(); // Time to get our message from our Listener (at index 0 of our Listener list). // We do this with the following method: message = listeners[0].AcceptMessage(); // A message is a struct of 3 variables. To read the actual data, // we access the Data field, convert it to type string (unboxing), // and store it in the variable messagetext. string messagetext = message.Data.ToString(); // We can also access the tag that the message was sent with. string messagetag = message.Tag; //Here we store the "address" to the Programmable Block (our friend's) that sent the message. long sender = message.Source; //Do something with the information! Echo("Message received with tag" + messagetag + "\n\r"); Echo("from address " + sender.ToString() + ": \n\r"); Echo(messagetext); allmessage += $"\n new message \n {messagetext}"; lcdRecieverScreen.WriteText(allmessage); } } }