コード例 #1
0
        /// <summary>
        /// Writes a current biometricCluster to file.
        /// </summary>
        /// <param name="bc"></param>
        public void writeLogToFile(biometricCluster bc)
        {
            String lineToWrite = "";

            //Console.WriteLine("write to file");
            using (StreamWriter output = new StreamWriter((filePath), true))
            {
                Int32 unixTimestamp = (Int32)(bc.currentTime.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                int   rawGSRIndex   = bc.receivedCluster.GetIndex("GSR", "RAW");
                int   calGSRIndex   = bc.receivedCluster.GetIndex("GSR", "CAL");
                int   adcRawIndex   = bc.receivedCluster.GetIndex("Internal ADC A13", "RAW");
                int   adcCalIndex   = bc.receivedCluster.GetIndex("Internal ADC A13", "CAL");
                //Console.WriteLine("making string");
                lineToWrite = String.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}", unixTimestamp, bc.currentTime.Hour, bc.currentTime.Minute,
                                            bc.currentTime.Second, bc.currentTime.Millisecond, bc.receivedCluster.GetData()[adcRawIndex],
                                            bc.receivedCluster.GetData()[adcCalIndex], bc.receivedCluster.GetData()[rawGSRIndex],
                                            bc.receivedCluster.GetData()[calGSRIndex]);
                //Console.WriteLine("actually writing to file");
                output.WriteLine(lineToWrite);
                //Console.WriteLine("done");
            }
        }
コード例 #2
0
        /// <summary>
        /// Blanket event handler for packets. Covers a number of events from Shimmer device.
        /// Includes code for marking connection status, notifications, and data packets.
        /// TODO: rework code to make cleaner.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        public void HandleEvent(object sender, EventArgs args)
        {
            CustomEventArgs eventArgs = (CustomEventArgs)args;
            int             indicator = eventArgs.getIndicator();

            switch (indicator)
            {
            case (int)Shimmer.ShimmerIdentifier.MSG_IDENTIFIER_STATE_CHANGE:
                //System.Diagnostics.Debug.Write(((Shimmer)sender).GetDeviceName() + " State = " + ((Shimmer)sender).GetStateString() + System.Environment.NewLine);
                int state = (int)eventArgs.getObject();
                if (state == (int)Shimmer.SHIMMER_STATE_CONNECTED)
                {
                    //labelConnectionState.Text = "Connected";
                    ChangeStatusLabel("Connected to " + ShimmerDevice.GetComPort() + ". Firmware Version: " + ShimmerDevice.GetFirmwareVersionFullName());
                    //ChangeStatusLabel("Connected");
                    //firstTimeTimer = new System.Windows.Forms.Timer();
                    //firstTimeTimer.Tick += new EventHandler(firstTimeCycleConnect);
                    //firstTimeTimer.Interval = (int)(5000);
                    //firstTimeTimer.Start();
                }
                else if (state == (int)Shimmer.SHIMMER_STATE_CONNECTING)
                {
                    //labelConnectionState.Text = "Connecting";
                    ChangeStatusLabel("Connecting");
                }
                else if (state == (int)Shimmer.SHIMMER_STATE_NONE)
                {
                    //labelConnectionState.Text = "Disconnected";
                    ChangeStatusLabel("Disconnected");
                }
                else if (state == (int)Shimmer.SHIMMER_STATE_STREAMING)
                {
                    //labelConnectionState.Text = "Streaming";
                    ChangeStatusLabel("Streaming");
                    if (firstTime)
                    {
                    }
                }
                break;

            case (int)Shimmer.ShimmerIdentifier.MSG_IDENTIFIER_DATA_PACKET:
                // this is essential to ensure the object is not a reference
                DateTime      timestamp     = DateTime.Now;
                ObjectCluster objectCluster = new ObjectCluster((ObjectCluster)eventArgs.getObject());
                List <String> names         = objectCluster.GetNames();
                List <String> formats       = objectCluster.GetFormats();
                List <String> units         = objectCluster.GetUnits();
                List <Double> data          = objectCluster.GetData();

                //add element to list of biometricClusters
                biometricCluster bc = new biometricCluster();
                bc.currentTime     = timestamp;
                bc.receivedCluster = objectCluster;
                storedClusterData.Add(bc);

                //print log to file
                writeLogToFile(bc);

                Console.WriteLine("Current Timestamp: " + timestamp);

                int gsrRawIndex = objectCluster.GetIndex("GSR", "RAW");
                int gsrCalIndex = objectCluster.GetIndex("GSR", "CAL");
                int adcRawIndex = objectCluster.GetIndex("Internal ADC A13", "RAW");
                int adcCalIndex = objectCluster.GetIndex("Internal ADC A13", "CAL");

                for (int i = 0; i < names.Count; i++)
                {
                    //Console.WriteLine(names[i]);
                }

                //Console.WriteLine("Current Raw GSR Readings: " + data[gsrRawIndex]);
                //Console.WriteLine("Current Calculated GSR Readings: " + data[gsrCalIndex]);
                //Console.WriteLine("Current Raw PPG Readings: " + data[adcRawIndex]);
                //Console.WriteLine("Current Calculated PPG Readings: " + data[adcCalIndex]);
                //Console.WriteLine();
                break;

            case (int)Shimmer.ShimmerIdentifier.MSG_IDENTIFIER_NOTIFICATION_MESSAGE:
                //rework this as function?
                string message = (string)eventArgs.getObject();
                System.Diagnostics.Debug.Write(((Shimmer)sender).GetDeviceName() + message + System.Environment.NewLine);
                //Message BOX
                int minorIdentifier = eventArgs.getMinorIndication();
                if (minorIdentifier == (int)ShimmerSDBT.ShimmerSDBTMinorIdentifier.MSG_WARNING)
                {
                    MessageBox.Show(message, ConnectionTest.ApplicationName,
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (minorIdentifier == (int)ShimmerSDBT.ShimmerSDBTMinorIdentifier.MSG_EXTRA_REMOVABLE_DEVICES_DETECTED)
                {
                    MessageBox.Show(message, "Message");
                    FolderBrowserDialog fbd    = new FolderBrowserDialog();
                    DialogResult        result = fbd.ShowDialog();
                    ShimmerDevice.SetDrivePath(fbd.SelectedPath);
                }
                else if (minorIdentifier == (int)ShimmerSDBT.ShimmerSDBTMinorIdentifier.MSG_ERROR)
                {
                    MessageBox.Show(message, ConnectionTest.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (message.Equals("Connection lost"))
                {
                    MessageBox.Show("Connection with device lost while streaming", ConnectionTest.ApplicationName,
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    ChangeStatusLabel(message);
                }

                break;

            default:
                break;
            }
        }