コード例 #1
0
ファイル: TeslaGuiForm.cs プロジェクト: mandad/AntDataReader
 /// <summary>
 /// Puts data to web server for database storage
 /// </summary>
 /// <param name="toPass">The data from the sensor</param>
 /// <param name="sensorType">The type of sensor from which the data was taken</param>
 /// <param name="boardId">The ID of the board</param>
 private void WriteToWeb(object[] toPass, DataDecoder.SensorType sensorType, int boardId)
 {
     writeCount++;
     if ((!simulatedToolStripMenuItem.Checked || (writeCount > 10)) && !thrdWebSubmit.IsBusy)
     {
         writeCount = 0;
         switch (sensorType)
         {
             case DataDecoder.SensorType.Temperature:
                 thrdWebSubmit.RunWorkerAsync("http://www.dmanda.com/capstone/putdata.php?datatype=temp&id=" + boardId.ToString()
                     + "&data[0]=" + toPass[0].ToString());
                 break;
             case DataDecoder.SensorType.Accelerometer:
                 thrdWebSubmit.RunWorkerAsync("http://www.dmanda.com/capstone/putdata.php?datatype=accel&id=" + boardId.ToString()
                     + "&data[0]=" + toPass[0].ToString() + "&data[1]=" + toPass[1].ToString() + "&data[2]=" + toPass[2].ToString());
                 break;
             case DataDecoder.SensorType.Button:
                 thrdWebSubmit.RunWorkerAsync("http://www.dmanda.com/capstone/putdata.php?datatype=button&id=" + boardId.ToString()
                     + "&data[0]=" + toPass[0].ToString());
                 break;
         }
     }
 }
コード例 #2
0
ファイル: TeslaGuiForm.cs プロジェクト: mandad/AntDataReader
 /// <summary>
 /// Writes data to a local log file
 /// </summary>
 /// <remarks>File format is [Sensor type],[Board ID],[Data1],[Data2],...</remarks>
 /// <param name="toPass">The data from the sensor</param>
 /// <param name="sensorType">The type of sensor from which the data was taken</param>
 /// <param name="boardId">The ID of the board</param>
 private void WriteToFile(object[] toPass, DataDecoder.SensorType sensorType, int boardId)
 {
     if (fsLog != null)
     {
         switch (sensorType)
         {
             case DataDecoder.SensorType.Temperature:
                 swLog.WriteLine("Temp," + boardId.ToString() + "," + toPass[0].ToString());
                 break;
             case DataDecoder.SensorType.Accelerometer:
                 swLog.WriteLine("Accel," + boardId.ToString() + "," + toPass[0].ToString() + "," + toPass[1].ToString()
                     + "," + toPass[2].ToString());
                 break;
             case DataDecoder.SensorType.Button:
                 swLog.WriteLine("Temp," + boardId.ToString() + "," + toPass[0].ToString());
                 break;
         }
     }
 }
コード例 #3
0
ファイル: TeslaGuiForm.cs プロジェクト: mandad/AntDataReader
 /// <summary>
 /// Writes data to a log file and the web
 /// </summary>
 /// <param name="toPass">The data from the sensor</param>
 /// <param name="sensorType">The type of sensor from which the data was taken</param>
 /// <param name="boardId">The ID of the board</param>
 private void WriteInfo(object[] toPass, DataDecoder.SensorType sensorType, int boardId)
 {
     if (recordDataToolStripMenuItem.Checked)
     {
         WriteToWeb(toPass, sensorType, boardId);
     }
     if (saveToFileToolStripMenuItem.Checked)
     {
         WriteToFile(toPass, sensorType, boardId);
     }
 }
コード例 #4
0
ファイル: TeslaGuiForm.cs プロジェクト: mandad/AntDataReader
        /// <summary>
        /// Updates the GUI from another thread to avoid conflicts
        /// </summary>
        /// <param name="senseType">The type of the sensor data to update</param>
        /// <param name="boardID">The board from which the data originated</param>
        /// <param name="parameters">The data values required by that sensor</param>
        private void UpdateGUIFunction(DataDecoder.SensorType senseType, int boardID, object[] parameters)
        {
            HideShowBlocks();

            lblError.Text = "";
            lblLastMessage.Text = DateTime.Now.ToLongTimeString();
            switch (senseType)
            {
                case DataDecoder.SensorType.Temperature:
                    //update label
                    lblTemp.Text = parameters[0].ToString();
                    lblTempF.Text = (Convert.ToDouble(parameters[0]) * 9 / 5 + 32).ToString();

                    //draw graph
                    DrawTempGraph();

                    //chrtTempHist.Data.DataSource = graphPts;
                    //chrtTempHist.Data.DataBind();
                    break;
                case DataDecoder.SensorType.Accelerometer:
                    double accelX = (Convert.ToDouble(parameters[0]) - 2047.5) / 2047.5 * 2;
                    double accelY = (Convert.ToDouble(parameters[1]) - 2047.5) / 2047.5 * 2;
                    double accelZ = (Convert.ToDouble(parameters[2]) - 2047.5) / 2047.5 * 2;
                    lblAccelX.Text = Math.Round(accelX, 2).ToString() + " G";
                    lblAccelY.Text = Math.Round(accelY, 2).ToString() + " G";
                    lblAccelZ.Text = Math.Round(accelZ, 2).ToString() + " G";
                    userControl11.UpdateDisplay(accelX, accelY, accelZ);
                    break;
                case DataDecoder.SensorType.Button:
                    if ((bool)parameters[0])
                    {
                        lblButtonPress.BackColor = Color.Blue;
                    }
                    else
                    {
                        lblButtonPress.BackColor = Color.White;
                    }
                    break;
                case DataDecoder.SensorType.Unknown:
                    lblError.Text = "Unknown Sensor Type";
                    break;
            }
        }
コード例 #5
0
ファイル: TeslaGuiForm.cs プロジェクト: mandad/AntDataReader
 /// <summary>
 /// Invokes the GUI update to make it thread safe
 /// </summary>
 /// <param name="passIn">The data needed to update the GUI for that sensor</param>
 /// <param name="sensor">Sensor type of data to update</param>
 /// <param name="sensorBoard">The ID of the sensor board transmitting the data</param>
 private void RemoteDisplayUpdate(object[] passIn, DataDecoder.SensorType sensor, int sensorBoard)
 {
     if (!this.IsDisposed)
     {
         object[] pass = new object[3];
         pass[0] = sensor;
         pass[1] = sensorBoard;
         pass[2] = passIn;
         try
         {
             this.Invoke(this.updateGUI, pass);
         }
         catch { }
     }
 }
コード例 #6
0
ファイル: TeslaGuiForm.cs プロジェクト: mandad/AntDataReader
        /// <summary>
        /// Puts the data into a format for display
        /// </summary>
        /// <param name="readData">The full packet received from ANT</param>
        private void ProcessData(byte[] readData)
        {
            if (antComm.ChecksumVerify(readData))
            {
                DataDecoder data = new DataDecoder(readData);
                if (data.Sensor != DataDecoder.SensorType.InvalidData)
                {
                    object[] toPass;
                    lastRecieved[DataDecoder.SensorType.Accelerometer]++;
                    lastRecieved[DataDecoder.SensorType.Button]++;
                    lastRecieved[DataDecoder.SensorType.Temperature]++;
                    lastRecieved[data.Sensor] = 0;
                    switch (data.Sensor)
                    {
                        case DataDecoder.SensorType.Temperature:
                            //convert to voltage
                            double dataValue = GetADCVoltage(data.ProcessedData[0].value);
                            //convert to temperature
                            //dataValue = (dataValue - .5) * 100;   //TMP 36
                            dataValue = tempConv.GetTemp(dataValue);
                            dataValue = Math.Round(dataValue, 2);
                            pastTemps.Enqueue(dataValue);
                            if (pastTemps.Count == 150)
                            {
                                pastTemps.Dequeue();
                            }
                            toPass = new object[1];
                            toPass[0] = dataValue;
                            break;
                        case DataDecoder.SensorType.Accelerometer:
                            double xValue = data.ProcessedData[0].value;
                            double yValue = data.ProcessedData[1].value;
                            double zValue = data.ProcessedData[2].value;

                            toPass = new object[3];
                            toPass[0] = Math.Round(xValue, 3);
                            toPass[1] = Math.Round(yValue, 3);
                            toPass[2] = Math.Round(zValue, 3);
                            break;
                        case DataDecoder.SensorType.Button:
                            toPass = new object[1];
                            toPass[0] = Convert.ToBoolean(data.ProcessedData[0].value);
                            break;
                        default:
                            toPass = new object[1];
                            break;
                    }
                    WriteInfo(toPass, data.Sensor, data.DeviceID);
                    RemoteDisplayUpdate(toPass, data.Sensor, data.DeviceID);
                }
            }
        }