Skip to content

Commit

Permalink
Merge pull request #43 from ZiwKerman/v1.0-beta-legacyIR-binding
Browse files Browse the repository at this point in the history
V1.0 beta with legacy IR binding
  • Loading branch information
ZiwKerman committed Mar 2, 2016
2 parents 2bc20e9 + ad9ab89 commit b124c31
Show file tree
Hide file tree
Showing 13 changed files with 1,160 additions and 618 deletions.
2 changes: 1 addition & 1 deletion IRSequencer/IRSequencer/API/IRWrapper.cs
Expand Up @@ -259,7 +259,7 @@ public string Name

public Vessel Vessel
{
get { return (Vessel)vesselProperty.GetValue(actualControlGroup, null); }
get { return vesselProperty != null ? (Vessel)vesselProperty.GetValue(actualControlGroup, null) : null; }
}

public string ForwardKey
Expand Down
44 changes: 42 additions & 2 deletions IRSequencer/IRSequencer/Core/Sequence.cs
Expand Up @@ -3,6 +3,11 @@

namespace IRSequencer.Core
{
/// <summary>
/// Implements a Sequence of BasicCommands.
/// Each Sequence must start and end at a certain SequencerState (could be the same one).
/// As Sequence is supposed to operate only for ActiveVessel there is no link to a vessel at this level.
/// </summary>
public class Sequence
{
internal List<BasicCommand> commands;
Expand All @@ -14,6 +19,11 @@ public class Sequence
public bool isLocked = false; //sequence is Locked if any of the servos in its commands list are busy
public string name = "";
public string keyShortcut = "";
public readonly Guid sequenceID;

public SequencerState startState, endState;

public bool autoStart = false;

public bool IsPaused {
get
Expand All @@ -33,6 +43,12 @@ public Sequence ()
{
commands = new List<BasicCommand>();
name = "New Sequence";
sequenceID = Guid.NewGuid ();
}

public Sequence(string newID) : this()
{
sequenceID = new Guid (newID);
}

public Sequence (BasicCommand b) : this()
Expand All @@ -45,6 +61,8 @@ public Sequence (Sequence baseSequence) :this()
//commands.AddRange(baseSequence.commands);
baseSequence.commands.ForEach ((BasicCommand bc) => commands.Add (new BasicCommand (bc)));
name = "Copy of " + baseSequence.name;
startState = baseSequence.startState;
endState = baseSequence.endState;
}

public void Resume(int commandIndex)
Expand Down Expand Up @@ -97,7 +115,7 @@ public void Resume(int commandIndex)
//else we are either finished, or most likely waiting for commands to finish.
}

public void Start()
public void Start(SequencerState currentState)
{
Logger.Log("[Sequencer] Sequence started", Logger.Level.Debug);

Expand All @@ -108,6 +126,12 @@ public void Start()
Logger.Log ("[Sequencer] Cannot start sequence " + name + " as it is Locked", Logger.Level.Debug);
return;
}

if (currentState != startState)
{
Logger.Log ("[Sequencer] Cannot start sequence " + name + " because its start state is not current state", Logger.Level.Debug);
return;
}
//if the sequence is marked as Finished - reset it and start anew.
if (isFinished)
Reset();
Expand Down Expand Up @@ -240,7 +264,23 @@ public void SetFinished()
public string Serialize()
{
var serializedSequence = name.Replace('<',' ').Replace('>',' ').Replace('|',' ') + "|"
+ isLooped + "|" + keyShortcut.Replace ("<", "").Replace (">", "").Replace ("|", "") + "<";
+ isLooped + "|" + keyShortcut.Replace ("<", "").Replace (">", "").Replace ("|", "") + "|" + autoStart;

//begin states block
if(startState == null || endState == null)
{
//somehow we got legacy Sequeces to serialize, just post an Error
Logger.Log("In Sequencer 1.0 and higher Sequences must have non-empty startState and endState", Logger.Level.Warning);

}
else
{
serializedSequence += "|" + startState.stateID + "|" + endState.stateID;
}
//end states block

//begin commands block;
serializedSequence += "<";

if (commands == null)
return serializedSequence + ">";
Expand Down
36 changes: 36 additions & 0 deletions IRSequencer/IRSequencer/Core/SequencerState.cs
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;

namespace IRSequencer.Core
{
/// <summary>
/// Implements State as in Finite State Machine for Sequencer.
/// Each Sequence is supposed to begin and end at a certain State (could be the same State).
/// Ideally a Vessel could have multiple Sequencers and thus multiple States, but for now we assume it has one.
/// This will be remedied when we tie Sequencer to ModuleSequencer and allow multiple sequencers per vessel.
/// Each Vessel/Sequencer is supposed to have at least one SequencerState (Default/Idle).
/// </summary>
public class SequencerState
{

public string stateName = "Default";

public readonly Guid stateID;

public SequencerState ()
{
stateID = Guid.NewGuid ();
}

public SequencerState (string newID)
{
stateID = new Guid (newID);
}

public string Serialize()
{
return stateID.ToString () + ":" + stateName.Replace (':', ' ');
}
}
}

0 comments on commit b124c31

Please sign in to comment.