Beispiel #1
0
 private void logbook_BatteryTest_Result(object o, CommandResultEventArgs e)
 {
     int batValue = e.Result[1];
      string printString = "\rBattery level: " + batValue.ToString();
      if (batValue <= 180)
      {
     printString += " (Low!)";
      }
      else if (batValue == 254)
      {
     printString += " (Good)";
      }
      log.Append("logbook_BatteryTest_Result", printString.Replace("\r", "\r\n"));
 }
 void logbook_CommandResult(object sender, CommandResultEventArgs e)
 {
     log.Append("logbook_CommandResult", "Logbook Command Result");
     UpdateTextBoxInvoke(textBox1, String.Format("{0}: {1}", e.Command.name, Logbook.ConvertChars(Encoding.ASCII.GetString(e.Result))), logLines);
 }
        private void GotResult()
        {
            // got the right amount of bytes in the response
            // so disable the timeout timer and then
            // check the confirmation char
            commandTimer.Dispose();

            lock (this)
            {
                waitingForResponse = false;
                if (InputBuffer()[0] == currentCommand.commandConfirm)
                {
                    responseReceived = true;
                    CommandResultEventArgs ev = new CommandResultEventArgs(this.InputBuffer(), currentCommand);
                    OnCommandResult(ev);
                }
                else
                {
                    //raise an event to say the command wasn't confirmed
                    OnCommandFailed(new CommandFailedEventArgs(currentCommand, InputBuffer(), "Logbook didn't confirm command!"));
                }
            }
        }
 // The protected OnCommandResult method raises the event by invoking
 // the delegates. The sender is always this, the current instance
 // of the class.
 protected virtual void OnCommandResult(CommandResultEventArgs e)
 {
     if (CommandResult != null)
     {
         // Invokes the delegates.
         CommandResult(this, e);
         // Send next command in queue
         sendNextCommand();
     }
 }
Beispiel #5
0
        private void GotResultThread()
        {
            while (active)
             {
            gotResult.WaitOne();
            if (results.Count > 0)
            {
               byte[] input = results.Dequeue();

               // got the right amount of bytes in the response
               // so disable the timeout timer and then
               // check the confirmation char
               waitingForResponse = false;
               if (input[0] == currentCommand.commandConfirm)
               {
                  responseReceived = true;
                  CommandResultEventArgs ev = new CommandResultEventArgs(input, currentCommand);
                  OnCommandResult(ev);
               }
               else
               {
                  //raise an event to say the Command wasn't confirmed
                  FireCommandFailed(new CommandFailedEventArgs(currentCommand, input, "Logbook didn't confirm Command!"));
               }
            }
             }
        }
Beispiel #6
0
 private void logbook_ReadASCII_Result(object o, CommandResultEventArgs ev)
 {
     processASCIIReading(ev.Result);
 }
Beispiel #7
0
        private void logbook_GetSensorRanges_Result(object o, CommandResultEventArgs e)
        {
            string printString = "Sensors ranges: {";
             for (int i = 1; i <= 4; i++)
             {
            CurrentSensors[i - 1].Range = Convert.ToInt32(e.Result[i]);
            printString += String.Format("{0} ", e.Result[i]);
             }
             printString += "}";
             log.Append("logbook_GetSensorRanges_Result", printString);

             if (sensorIDsUpdated == false)
             {
            log.Append("logbook_GetSensorRanges_Result", "Requesting sensor IDs");
            logbook_sendCommand(Logbook.Command.IdentifySensors);
             }
             sensorRangesUpdated = true;
             UpdateSensorTypes();
        }
Beispiel #8
0
 private void logbook_IdentifySensors_Result(object o, CommandResultEventArgs e)
 {
     string printString = "Sensor IDs: {";
      for (int i = 1; i <= 4; i++)
      {
     CurrentSensors[i - 1].ID = Convert.ToInt32(e.Result[i]);
     printString += String.Format("{0} ", e.Result[i]);
      }
      printString += "}";
      log.Append("logbook_IdentifySensors_Result", printString);
      sensorIDsUpdated = true;
      UpdateSensorTypes();
 }
Beispiel #9
0
 private void logbook_GetBatteryLevel_Result(object o, CommandResultEventArgs e)
 {
     int batStat = e.Result[1];
      string printString = "\rBattery level: " + batStat.ToString();
      switch (batStat)
      {
     case 0:
        printString += "Battery critical";
        break;
     case 1:
        printString += "Battery empty (<10% remaining)";
        break;
     case 2:
        printString += "Less than 33% remaining";
        break;
     case 3:
        printString += "Between 33% and 66% remaining";
        break;
     case 4:
        printString += "Over 66% remaining";
        break;
     case 5:
        printString += "Full battery (ext. power)";
        break;
     case 6:
        printString += "Mains power, dead battery";
        break;
     case 7:
        printString += "No battery";
        break;
     default:
        printString += "Unknown response";
        break;
      }
      printString = printString.Replace("\r", "\r\n");
      log.Append("logbook_GetBatteryLevel_Result", printString);
 }
Beispiel #10
0
        private void logbook_CommandResult(object o, CommandResultEventArgs e)
        {
            if (e.Command.Equals(Logbook.Command.ReadASCII))
             {
            logbook_ReadASCII_Result(o, e);
            if ((runningMode == RunningModes.Started) || takeReadings)
            {
               logbook.sendCommand(Logbook.Command.ReadASCII);
            }
            return;
             }
             if (e.Command.Equals(Logbook.Command.BatteryTest))
             {
            logbook_BatteryTest_Result(o, e);
            return;
             }
             if (e.Command.Equals(Logbook.Command.KeepAwake))
             {
            return;
             }
             if (e.Command.Equals(Logbook.Command.GetBatteryLevel))
             {
            logbook_GetBatteryLevel_Result(o, e);
            return;
             }
             if (e.Command.Equals(Logbook.Command.ConfirmExtendedProtocol))
             {
            return;
             }
             if (e.Command.Equals(Logbook.Command.InputPowerOn))
             {
            return;
             }
             if (e.Command.Equals(Logbook.Command.IdentifySensors))
             {
            logbook_IdentifySensors_Result(o, e);
            return;
             }
             if (e.Command.Equals(Logbook.Command.GetSensorRanges))
             {
            logbook_GetSensorRanges_Result(o, e);
            return;
             }

             string printString = "";
             foreach (byte letter in e.Result)
             {
            //serverMessagesBox.Text += Convert.ToChar(letter) + "\r\n";
            //charsBox.Text += letter.ToString() + " ";
            printString += Logbook.ConvertChar(letter);
             }
             log.Append("logbook_CommandResult", String.Format("Logbook command result: {0}", printString));
        }
 void logbook_CommandResult(object sender, CommandResultEventArgs e)
 {
     log.Append("logbook_CommandResult", "Logbook Command Result");
     UpdateTextBoxInvoke(textBox1, String.Format("{0}: {1}", e.Command.name, e.Result), logLines);
 }
Beispiel #12
0
 // The protected OnCommandResult method raises the event by invoking
 // the delegates. The sender is always this, the current instance
 // of the class.
 protected virtual void OnCommandResult(CommandResultEventArgs e)
 {
     commandFailedCount = 0;
     if (CommandResult != null)
     {
         // Invokes the delegates.
         CommandResult(this, e);
         // Send next Command in queue
         if (disconnectAfterResult)
         {
             ClosePort();
             FireOnDisconnected();
         }
         else
         {
             commandQWait.Set();
         }
     }
 }
 void logbook_CommandResult(object sender, CommandResultEventArgs e)
 {
     if (e.Command == Logbook.Command.ReadASCII)
      {
     UpdateLabel(testReadingLabel, Logbook.ConvertChars(Encoding.ASCII.GetString(e.Result, 0, e.Result.Length)));
      }
      if (e.Command == Logbook.Command.InputPowerOn)
      {
     logbook.sendCommand(Logbook.Command.IdentifySensors);
      }
      if (e.Command == Logbook.Command.IdentifySensors)
      {
     StringBuilder sb = new StringBuilder();
     bool first = true;
     foreach (byte b in e.Result)
     {
        if (!first)
        {
           sb.AppendFormat("[{0}]", (uint)b);
        }
        else
        {
           first = false;
        }
     }
     sensorIDs = sb.ToString();
     gotIDs = true;
     logbook.sendCommand(Logbook.Command.GetSensorRanges);
      }
      if (e.Command == Logbook.Command.GetSensorRanges)
      {
     StringBuilder sb = new StringBuilder();
     bool first = true;
     foreach (byte b in e.Result)
     {
        if (!first)
        {
           sb.AppendFormat("[{0}]", (uint)b);
        }
        else
        {
           first = false;
        }
     }
     sensorRanges = sb.ToString();
     UpdateLabel(identifyLabel, sensorRanges + "\r\n" + sensorIDs);
      }
 }