Exemple #1
0
 void switch_(string filename)
 {
   File file;
   if (filename.Length == 0)
   {
     error("no file specified");
   }
   else if (!files.TryGetValue(filename, out file))
   {
     error("file not found");
   }
   else if (file.device == null)
   {
     error("not a device");
   }
   else if (!(file.device is NetworkDevice))
   {
     error("not a network device");
   }
   else
   {
     NetworkDevice nd = file.device as NetworkDevice;
     success(Lib.BuildString("!SWITCH ", nd.id().ToString()));
   }
 }
Exemple #2
0
  // call automation scripts and transfer data
  public void update(Vessel environment, double elapsed_s)
  {
    // do nothing if there is no EC left on the vessel
    resource_info ec = ResourceCache.Info(environment, "ElectricCharge");
    if (ec.amount <= double.Epsilon)
    {
      return;
    }

    // get current states
    vessel_info vi = Cache.VesselInfo(environment);
    Vessel.Situations situation = environment.situation;
    bool sunlight = vi.sunlight > double.Epsilon;
    bool power = ec.level >= 0.15; //< 15%
    bool radiation = vi.radiation <= 0.00001388; //< 0.05 rad/h
    bool signal = vi.link.linked;

    // check for state changes and call scripts
    if (situation != prev_situation)
    {
      switch(situation)
      {
        case Vessel.Situations.LANDED:
        case Vessel.Situations.SPLASHED:
          execute("run", "auto/situation_landed", string.Empty, environment);
          break;

        case Vessel.Situations.FLYING:
          execute("run", "auto/situation_atmo", string.Empty, environment);
          break;

        case Vessel.Situations.ORBITING:
        case Vessel.Situations.SUB_ORBITAL:
        case Vessel.Situations.ESCAPING:
          execute("run", "auto/situation_space", string.Empty, environment);
          break;
      }
    }

    if (sunlight != prev_sunlight)
    {
      execute("run", sunlight ? "auto/sun_visible" : "auto/sun_occluded", string.Empty, environment);
    }

    if (power != prev_power)
    {
      execute("run", power ? "auto/power_nominal" : "auto/power_low", string.Empty, environment);
    }

    if (radiation != prev_radiation)
    {
      execute("run", radiation ? "auto/radiation_nominal" : "auto/radiation_high", string.Empty, environment);
    }

    if (signal != prev_signal)
    {
      execute("run", signal ? "auto/signal_linked" : "auto/signal_unlinked", string.Empty, environment);
    }

    // remember previous state
    prev_situation = situation;
    prev_sunlight = sunlight;
    prev_power = power;
    prev_signal = signal;
    prev_radiation = radiation;


    // create network devices
    boot_network(environment);

    // transmit all files flagged for transmission to their destination
    List<string> to_remove = new List<string>();
    foreach(var pair in files)
    {
      // if file must be sent
      string filename = pair.Key;
      File file = pair.Value;
      if (file.send.Length > 0)
      {
        // get target
        File target;
        if (files.TryGetValue(file.send, out target))
        {
          // target is alive, get it
          NetworkDevice nd = target.device as NetworkDevice;
          Computer remote_machine = DB.VesselData(nd.id()).computer;

          // zero-data files are transmitted instantly
          if (file.data <= double.Epsilon)
          {
            // add file to remote machine, overwrite as necessary
            if (remote_machine.files.ContainsKey(filename))
            {
              remote_machine.files.Remove(filename);
            }
            remote_machine.files.Add(filename, new File(file.content));

            // flag local file for removal
            to_remove.Add(filename);
          }
          // science data files are transmitted over time
          else
          {
            // TODO: [SCIENCE] send science data file
            // remember: subtract amount from file.value until it is zero, then remove the file if reach zero
          }
        }
        else
        {
          // the target doesn't exist, don't send but keep it in case it comes alive later
        }
      }
    }

    // delete local files flagged for removal
    foreach(string s in to_remove) files.Remove(s);

    // delete network devices
    cleanup();

  }