public CalibrateSensors() { InitializeComponent(); //this.channels = new ArrayList(); sensors = new SensorAnnotation(Constants.MAX_CONTROLLERS); }
public MITesSamplingRateForm(MITesDataFilterer aMITesDataFilterer, SensorAnnotation sensorConfiguration) { InitializeComponent(); this.aMITesDataFilterer = aMITesDataFilterer; this.sensorConfiguration = sensorConfiguration; InitializeInterface(); }
public HierarchicalClassifier(MITesDecoder aMITesDecoder, Annotation aannotation, SensorAnnotation sannotation, string dataDirectory,GeneralConfiguration configuration) { this.classifiers = new Hashtable(); this.dataDirectory = dataDirectory; Extractor.Initialize(aMITesDecoder, dataDirectory, aannotation, sannotation,configuration); }
public SensorAnnotation parse(int maxReceivers) { SensorAnnotation annotation = new SensorAnnotation(maxReceivers); XmlDocument dom = new XmlDocument(); dom.Load(this.xmlFile); XmlNode xNode = dom.DocumentElement; bool[] countedReceiver = new bool[maxReceivers]; bool firstAccel = false; for (int i = 0; (i < maxReceivers); i++) countedReceiver[i] = false; if ((xNode.Name == Constants.SENSORDATA_ELEMENT) && (xNode.HasChildNodes)) { foreach (XmlAttribute xAttribute in xNode.Attributes) { if (xAttribute.Name == Constants.DATASET_ATTRIBUTE) { annotation.Dataset = xAttribute.Value; } } //Sensor nodes foreach (XmlNode iNode in xNode.ChildNodes) { if (iNode.Name == Constants.RECEIVERS_ELEMENT) { foreach (XmlNode jNode in iNode.ChildNodes) { if (jNode.Name == Constants.RECEIVER_ELEMENT) { Receiver receiver = new Receiver(); foreach (XmlAttribute iAttribute in jNode.Attributes) { //read nodes attributes if (iAttribute.Name == Constants.ID_ATTRIBUTE) { receiver.ID = Convert.ToInt32(iAttribute.Value); } else if (iAttribute.Name == Constants.TYPE_ATTRIBUTE) { receiver.Type = iAttribute.Value; if (receiver.Type == Constants.RECEIVER_BLUETOOTH) annotation.TotalBluetoothReceivers++; else if (receiver.Type == Constants.RECEIVER_USB) annotation.TotalWiredReceivers++; } else if (iAttribute.Name == Constants.PASSKEY_ATTRIBUTE) { receiver.PassKey = iAttribute.Value; } else if (iAttribute.Name == Constants.DECODER_ATTRIBUTE) { receiver.Decoder = iAttribute.Value; } else if (iAttribute.Name == Constants.MAC_ATTRIBUTE) { receiver.MAC = iAttribute.Value; for (int i = 0; (i < Constants.MAC_SIZE); i++) receiver.MacAddress[i] = (byte)(System.Int32.Parse(iAttribute.Value.Substring(i * 2, 2), System.Globalization.NumberStyles.AllowHexSpecifier) & 0xff); } } annotation.Receivers.Add(receiver); annotation.TotalReceivers++; } } } //Backward compatibility else if (iNode.Name == Constants.SENSOR_ELEMENT) { Sensor sensor = new Sensor(); foreach (XmlAttribute iAttribute in iNode.Attributes) { //read nodes attributes if (iAttribute.Name == Constants.CLASS_ATTRIBUTE) { sensor.SensorClass = iAttribute.Value; } else if (iAttribute.Name == Constants.TYPE_ATTRIBUTE) { sensor.Type = iAttribute.Value; } } foreach (XmlNode jNode in iNode.ChildNodes) { //Console.WriteLine(jNode.Name); foreach (XmlAttribute jAttribute in jNode.Attributes) { //read nodes attributes if ((jNode.Name == Constants.ID_ELEMENT) && (jAttribute.Name == Constants.ID_ATTRIBUTE)) { sensor.ID = jAttribute.Value; //if this is an HR sensor if (Convert.ToInt32(jAttribute.Value) == 0) { annotation.IsHR = true; } if ((firstAccel == false) && (Convert.ToInt32(jAttribute.Value) > 0)) { annotation.FirstAccelerometer = Convert.ToInt32(jAttribute.Value); firstAccel = true; } if (annotation.MaximumSensorID < Convert.ToInt32(jAttribute.Value)) annotation.MaximumSensorID = Convert.ToInt32(jAttribute.Value); } else if ((jNode.Name == Constants.OBJECT_ELEMENT) && (jAttribute.Name == Constants.TEXT_ATTRIBUTE)) { sensor.SensorObject = jAttribute.Value; } else if ((jNode.Name == Constants.RECEIVER_ELEMENT) && (jAttribute.Name == Constants.ID_ATTRIBUTE)) { int receiver_id = Convert.ToInt32(jAttribute.Value); if ((receiver_id < maxReceivers) && (receiver_id >= 0)) { annotation.NumberSensors[receiver_id] = annotation.NumberSensors[receiver_id] + 1; sensor.Receiver = jAttribute.Value; if (countedReceiver[receiver_id] == false) { annotation.TotalReceivers++; countedReceiver[receiver_id] = true; } } else throw new Exception("Receiver in sensor file out of bound"); //sensor.Receiver = jAttribute.Value; //if (Convert.ToInt32(sensor.Receiver) == 1) //{ // annotation.SensorCount1++; //} //else if (Convert.ToInt32(sensor.Receiver) == 2) //{ // annotation.SensorCount2++; //} } else if ((jNode.Name == Constants.LOCATION_ELEMENT) && (jAttribute.Name == Constants.TEXT_ATTRIBUTE)) { sensor.Location = jAttribute.Value; } else if ((jNode.Name == Constants.DESCRIPTION_ELEMENT) && (jAttribute.Name == Constants.TEXT_ATTRIBUTE)) { sensor.Description = jAttribute.Value; } else if ((jNode.Name == Constants.DESCRIPTION_ELEMENT) && (jAttribute.Name == Constants.SR_ATTRIBUTE)) { sensor.SamplingRate = 12; //TODO } else if ((jNode.Name == Constants.DISPLAY_ELEMENT) && (jAttribute.Name == Constants.DISPLAY_TYPE_ATTRIBUTE)) { sensor.DisplayType = jAttribute.Value; } else if ((jNode.Name == Constants.DISPLAY_ELEMENT) && (jAttribute.Name == Constants.DISPLAY_X)) { sensor.DisplayX = jAttribute.Value; } else if ((jNode.Name == Constants.DISPLAY_ELEMENT) && (jAttribute.Name == Constants.DISPLAY_Y)) { sensor.DisplayY = jAttribute.Value; } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.XMEAN_ATTRIBUTE)) { sensor.XMean = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.XSTD_ATTRIBUTE)) { sensor.XStd = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.YMEAN_ATTRIBUTE)) { sensor.YMean = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.YSTD_ATTRIBUTE)) { sensor.YStd = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.ZMEAN_ATTRIBUTE)) { sensor.ZMean = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.ZSTD_ATTRIBUTE)) { sensor.ZStd = Convert.ToDouble(jAttribute.Value); } //display element has children if (jNode.Name == Constants.DISPLAY_ELEMENT) { foreach (XmlNode kNode in jNode.ChildNodes) { foreach (XmlAttribute kAttribute in kNode.Attributes) { if ((kNode.Name == Constants.COLOR_ELEMENT) && (kAttribute.Name == Constants.ON_ATTRIBUTE)) { sensor.ColorOn = kAttribute.Value; } else if ((kNode.Name == Constants.COLOR_ELEMENT) && (kAttribute.Name == Constants.OFF_ATTRIBUTE)) { sensor.ColorOff = kAttribute.Value; } } } } } } //if (sensor.SensorClass.ToLower()==Constants.MITES.ToLower()) //{ if (sensor.SensorClass == Constants.BUILTIN) { annotation.HasBuiltinSensors = true; annotation.TotalBuiltInSensors = annotation.TotalBuiltInSensors + 1; } annotation.Sensors.Add(sensor); sensor.Index = annotation.Sensors.IndexOf(sensor); annotation.SensorsIndex.Add(Convert.ToInt32(sensor.ID), sensor.Index); //} // else if (sensor.SensorClass.ToLower()== Constants.BUILTIN.ToLower()) //{ // annotation.HasBuiltinSensors = true; // annotation.BuiltinSensors.Add(sensor); // } } //parsing file information else if (iNode.Name == Constants.SENSORS_ELEMENT) { foreach (XmlNode rNode in iNode.ChildNodes) { if (rNode.Name == Constants.SENSOR_ELEMENT) { Sensor sensor = new Sensor(); foreach (XmlAttribute iAttribute in rNode.Attributes) { //read nodes attributes if (iAttribute.Name == Constants.CLASS_ATTRIBUTE) { sensor.SensorClass = iAttribute.Value; } else if (iAttribute.Name == Constants.TYPE_ATTRIBUTE) { sensor.Type = iAttribute.Value; } } foreach (XmlNode jNode in rNode.ChildNodes) { //Console.WriteLine(jNode.Name); foreach (XmlAttribute jAttribute in jNode.Attributes) { //read nodes attributes if ((jNode.Name == Constants.ID_ELEMENT) && (jAttribute.Name == Constants.ID_ATTRIBUTE)) { sensor.ID = jAttribute.Value; //if this is an HR sensor if (Convert.ToInt32(jAttribute.Value) == 0) { annotation.IsHR = true; } if ((firstAccel == false) && (Convert.ToInt32(jAttribute.Value) > 0)) { annotation.FirstAccelerometer = Convert.ToInt32(jAttribute.Value); firstAccel = true; } if (annotation.MaximumSensorID < Convert.ToInt32(jAttribute.Value)) annotation.MaximumSensorID = Convert.ToInt32(jAttribute.Value); } else if ((jNode.Name == Constants.OBJECT_ELEMENT) && (jAttribute.Name == Constants.TEXT_ATTRIBUTE)) { sensor.SensorObject = jAttribute.Value; } else if ((jNode.Name == Constants.RECEIVER_ELEMENT) && (jAttribute.Name == Constants.ID_ATTRIBUTE)) { int receiver_id = Convert.ToInt32(jAttribute.Value); if ((receiver_id < maxReceivers) && (receiver_id >= 0)) { annotation.NumberSensors[receiver_id] = annotation.NumberSensors[receiver_id] + 1; sensor.Receiver = jAttribute.Value; //if (countedReceiver[receiver_id] == false) //{ // annotation.TotalReceivers++; // countedReceiver[receiver_id] = true; // } } else throw new Exception("Receiver in sensor file out of bound"); //sensor.Receiver = jAttribute.Value; //if (Convert.ToInt32(sensor.Receiver) == 1) //{ // annotation.SensorCount1++; //} //else if (Convert.ToInt32(sensor.Receiver) == 2) //{ // annotation.SensorCount2++; //} } else if ((jNode.Name == Constants.LOCATION_ELEMENT) && (jAttribute.Name == Constants.TEXT_ATTRIBUTE)) { sensor.Location = jAttribute.Value; } else if ((jNode.Name == Constants.DESCRIPTION_ELEMENT) && (jAttribute.Name == Constants.TEXT_ATTRIBUTE)) { sensor.Description = jAttribute.Value; } else if ((jNode.Name == Constants.DESCRIPTION_ELEMENT) && (jAttribute.Name == Constants.SR_ATTRIBUTE)) { sensor.SamplingRate = Convert.ToInt32(jAttribute.Value); //TODO } else if ((jNode.Name == Constants.DISPLAY_ELEMENT) && (jAttribute.Name == Constants.DISPLAY_TYPE_ATTRIBUTE)) { sensor.DisplayType = jAttribute.Value; } else if ((jNode.Name == Constants.DISPLAY_ELEMENT) && (jAttribute.Name == Constants.DISPLAY_X)) { sensor.DisplayX = jAttribute.Value; } else if ((jNode.Name == Constants.DISPLAY_ELEMENT) && (jAttribute.Name == Constants.DISPLAY_Y)) { sensor.DisplayY = jAttribute.Value; } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.XMEAN_ATTRIBUTE)) { sensor.XMean = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.XSTD_ATTRIBUTE)) { sensor.XStd = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.YMEAN_ATTRIBUTE)) { sensor.YMean = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.YSTD_ATTRIBUTE)) { sensor.YStd = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.ZMEAN_ATTRIBUTE)) { sensor.ZMean = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.ZSTD_ATTRIBUTE)) { sensor.ZStd = Convert.ToDouble(jAttribute.Value); } //display element has children if (jNode.Name == Constants.DISPLAY_ELEMENT) { foreach (XmlNode kNode in jNode.ChildNodes) { foreach (XmlAttribute kAttribute in kNode.Attributes) { if ((kNode.Name == Constants.COLOR_ELEMENT) && (kAttribute.Name == Constants.ON_ATTRIBUTE)) { sensor.ColorOn = kAttribute.Value; } else if ((kNode.Name == Constants.COLOR_ELEMENT) && (kAttribute.Name == Constants.OFF_ATTRIBUTE)) { sensor.ColorOff = kAttribute.Value; } } } } } } //if (sensor.SensorClass.ToLower()==Constants.MITES.ToLower()) //{ if (sensor.SensorClass == Constants.BUILTIN) { annotation.HasBuiltinSensors = true; annotation.TotalBuiltInSensors = annotation.TotalBuiltInSensors + 1; } annotation.Sensors.Add(sensor); sensor.Index = annotation.Sensors.IndexOf(sensor); annotation.SensorsIndex.Add(Convert.ToInt32(sensor.ID), sensor.Index); //} // else if (sensor.SensorClass.ToLower()== Constants.BUILTIN.ToLower()) //{ // annotation.HasBuiltinSensors = true; // annotation.BuiltinSensors.Add(sensor); // } } } } } } return annotation; }
public SensorAnnotation parse(int maxReceivers) { SensorAnnotation annotation = new SensorAnnotation(maxReceivers); XmlDocument dom = new XmlDocument(); dom.Load(this.xmlFile); XmlNode xNode = dom.DocumentElement; bool[] countedReceiver = new bool[maxReceivers]; bool firstAccel = false; for (int i = 0; (i < maxReceivers); i++) countedReceiver[i] = false; if ((xNode.Name == Constants.SENSORDATA_ELEMENT) && (xNode.HasChildNodes)) { foreach (XmlAttribute xAttribute in xNode.Attributes) { if (xAttribute.Name == Constants.DATASET_ATTRIBUTE) { annotation.Dataset = xAttribute.Value; } } //Sensor nodes foreach (XmlNode iNode in xNode.ChildNodes) { //parsing file information if (iNode.Name == Constants.SENSOR_ELEMENT) { Sensor sensor = new Sensor(); foreach (XmlAttribute iAttribute in iNode.Attributes) { //read nodes attributes if (iAttribute.Name == Constants.CLASS_ATTRIBUTE) { sensor.SensorClass = iAttribute.Value; } else if (iAttribute.Name == Constants.TYPE_ATTRIBUTE) { sensor.Type = iAttribute.Value; } } foreach (XmlNode jNode in iNode.ChildNodes) { //Console.WriteLine(jNode.Name); foreach (XmlAttribute jAttribute in jNode.Attributes) { //read nodes attributes if ((jNode.Name==Constants.ID_ELEMENT) && (jAttribute.Name == Constants.ID_ATTRIBUTE)) { sensor.ID = jAttribute.Value; //if this is an HR sensor if (Convert.ToInt32(jAttribute.Value) == 0) { annotation.IsHR = true; } if ((firstAccel == false) && (Convert.ToInt32(jAttribute.Value) > 0)) { annotation.FirstAccelerometer = Convert.ToInt32(jAttribute.Value); firstAccel = true; } if (annotation.MaximumSensorID<Convert.ToInt32(jAttribute.Value)) annotation.MaximumSensorID=Convert.ToInt32(jAttribute.Value); } else if ((jNode.Name == Constants.OBJECT_ELEMENT) && (jAttribute.Name == Constants.TEXT_ATTRIBUTE)) { sensor.SensorObject= jAttribute.Value; }else if ((jNode.Name == Constants.RECEIVER_ELEMENT) && (jAttribute.Name == Constants.ID_ATTRIBUTE)) { int receiver_id = Convert.ToInt32(jAttribute.Value); if ((receiver_id < maxReceivers) && (receiver_id >= 0)) { annotation.NumberSensors[receiver_id] = annotation.NumberSensors[receiver_id] + 1; sensor.Receiver = jAttribute.Value; if (countedReceiver[receiver_id] == false) { annotation.TotalReceivers++; countedReceiver[receiver_id] = true; } } else throw new Exception("Receiver in sensor file out of bound"); //sensor.Receiver = jAttribute.Value; //if (Convert.ToInt32(sensor.Receiver) == 1) //{ // annotation.SensorCount1++; //} //else if (Convert.ToInt32(sensor.Receiver) == 2) //{ // annotation.SensorCount2++; //} } else if ((jNode.Name == Constants.LOCATION_ELEMENT) && (jAttribute.Name == Constants.TEXT_ATTRIBUTE)) { sensor.Location = jAttribute.Value; } else if ((jNode.Name == Constants.DESCRIPTION_ELEMENT) && (jAttribute.Name == Constants.TEXT_ATTRIBUTE)) { sensor.Description = jAttribute.Value; } else if ((jNode.Name == Constants.DISPLAY_ELEMENT) && (jAttribute.Name == Constants.DISPLAY_TYPE_ATTRIBUTE)) { sensor.DisplayType = jAttribute.Value; } else if ((jNode.Name == Constants.DISPLAY_ELEMENT) && (jAttribute.Name == Constants.DISPLAY_X)) { sensor.DisplayX = jAttribute.Value; } else if ((jNode.Name == Constants.DISPLAY_ELEMENT) && (jAttribute.Name == Constants.DISPLAY_Y)) { sensor.DisplayY = jAttribute.Value; } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.XMEAN_ATTRIBUTE)) { sensor.XMean = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.XSTD_ATTRIBUTE)) { sensor.XStd = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.YMEAN_ATTRIBUTE)) { sensor.YMean = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.YSTD_ATTRIBUTE)) { sensor.YStd = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.ZMEAN_ATTRIBUTE)) { sensor.ZMean = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.ZSTD_ATTRIBUTE)) { sensor.ZStd = Convert.ToDouble(jAttribute.Value); } //display element has children if (jNode.Name == Constants.DISPLAY_ELEMENT) { foreach (XmlNode kNode in jNode.ChildNodes) { foreach (XmlAttribute kAttribute in kNode.Attributes) { if ( (kNode.Name==Constants.COLOR_ELEMENT) && (kAttribute.Name==Constants.ON_ATTRIBUTE)) { sensor.ColorOn=kAttribute.Value; }else if ( (kNode.Name==Constants.COLOR_ELEMENT) && (kAttribute.Name==Constants.OFF_ATTRIBUTE)) { sensor.ColorOff=kAttribute.Value; } } } } } } annotation.Sensors.Add(sensor); } } } return annotation; }
private void InitializeAnnotator(string dataDirectory) { AXML.Reader reader = new AXML.Reader(Constants.MASTER_DIRECTORY,dataDirectory); if (reader.validate() == false) { throw new Exception("Error Code 0: XML format error - activities.xml does not match activities.xsd!"); } else { this.annotation = reader.parse(); this.annotation.DataDirectory = dataDirectory; SXML.Reader sreader = new SXML.Reader(Constants.MASTER_DIRECTORY, dataDirectory); if (sreader.validate() == false) { throw new Exception("Error Code 0: XML format error - sensors.xml does not match sensors.xsd!"); } else { this.sensors = sreader.parse(Constants.MAX_CONTROLLERS); InitializeTimers(); //InitializeSound(); InitializeInterface(); } } }
public MITesDataCollectionForm(string dataDirectory) { progressMessage = null; Thread t = new Thread(new ThreadStart(ProgressThread)); t.Start(); InitializeComponent(); this.dataDirectory = dataDirectory; //read the sensor configuration file to determine the number of receivers //read the activity configuration file progressMessage="Loading XML protocol and sensors ..."; AXML.Reader reader = new AXML.Reader(Constants.MASTER_DIRECTORY, dataDirectory); if (reader.validate() == false) { throw new Exception("Error Code 0: XML format error - activities.xml does not match activities.xsd!"); } else { this.annotation = reader.parse(); this.annotation.DataDirectory = dataDirectory; SXML.Reader sreader = new SXML.Reader(Constants.MASTER_DIRECTORY, dataDirectory); if (sreader.validate() == false) { throw new Exception("Error Code 0: XML format error - sensors.xml does not match sensors.xsd!"); } else { this.sensors = sreader.parse(Constants.MAX_CONTROLLERS); progressMessage+=" Completed\r\n"; } } if (this.sensors.IsHR) this.maxPlots = this.sensors.Sensors.Count - 1; else this.maxPlots = this.sensors.Sensors.Count; //check number of sensors etc. progressMessage+= "Initializing Timers ..."; InitializeTimers(); progressMessage += " Completed\r\n"; progressMessage += "Initializing GUI ..."; InitializeInterface(); progressMessage += " Completed\r\n"; if ((this.sensors.TotalReceivers > 0) && (this.sensors.TotalReceivers <=Constants.MAX_CONTROLLERS)) { this.mitesControllers = new MITesReceiverController[this.sensors.TotalReceivers]; this.mitesDecoders = new MITesDecoder[this.sensors.TotalReceivers]; this.aMITesActivityCounters = new Hashtable(); //if (this.sensors.IsHR) // this.aMITesActivityCounters = new MITesActivityCounter[this.sensors.Sensors.Count-1]; //else // this.aMITesActivityCounters = new MITesActivityCounter[this.sensors.Sensors.Count - 1]; progressMessage += "Initializing MITes ... searching " + this.sensors.TotalReceivers + " receivers\r\n"; if (InitializeMITes(dataDirectory) == false) { MessageBox.Show("Exiting: You picked a configuration with "+this.sensors.TotalReceivers +" receivers. Please make sure they are attached to the computer."); #if (PocketPC) Application.Exit(); #else Environment.Exit(0); #endif } } progressMessage += "Initializing MITes Quality GUI ..."; InitializeQualityInterface(); progressMessage += " Completed\r\n"; //pass data directory isExtracting = false; Extractor.Initialize( this.mitesDecoders[0], dataDirectory,this.annotation,this.sensors); // MITes Data Filterer stores performance stats for MITes // Initialize all performance counters for all MITES channels //calculate good sampling rate //you need to initialize them all because sometimes mites get data from non-exisiting IDs??? for (int i = 0; i < MITesData.MAX_MITES_CHANNELS; i++) MITesDataFilterer.MITesPerformanceTracker[i] = new MITesPerformanceStats(0); //based on how many receivers and to what channels they are listening adjust the good sampling rate foreach (Sensor sensor in this.sensors.Sensors) { int sensor_id = Convert.ToInt32(sensor.ID); int receiver_id = Convert.ToInt32(sensor.Receiver); if (sensor_id == 0) //HR sensor { MITesDataFilterer.MITesPerformanceTracker[sensor_id].GoodRate =(int)(Constants.HR_SAMPLING_RATE*0.8); MITesDataFilterer.MITesPerformanceTracker[sensor_id].PerfectRate = Constants.HR_SAMPLING_RATE; } else { int goodSamplingRate = (int)((Extractor.Configuration.ExpectedSamplingRate * (1 - Extractor.Configuration.MaximumNonconsecutiveFrameLoss)) / this.sensors.NumberSensors[receiver_id]); MITesDataFilterer.MITesPerformanceTracker[sensor_id].GoodRate = goodSamplingRate; MITesDataFilterer.MITesPerformanceTracker[sensor_id].PerfectRate = (int)((Extractor.Configuration.ExpectedSamplingRate) / this.sensors.NumberSensors[receiver_id]); } } //create some counters for activity counts averageX=new int[this.sensors.MaximumSensorID+1]; averageY= new int[this.sensors.MaximumSensorID+1]; averageZ= new int[this.sensors.MaximumSensorID+1]; averageRawX = new int[this.sensors.MaximumSensorID + 1]; averageRawY = new int[this.sensors.MaximumSensorID + 1]; averageRawZ = new int[this.sensors.MaximumSensorID + 1]; prevX= new int[this.sensors.MaximumSensorID+1]; prevY= new int[this.sensors.MaximumSensorID+1]; prevZ= new int[this.sensors.MaximumSensorID+1]; acCounters = new int[this.sensors.MaximumSensorID + 1]; activityCountWindowSize = 0; activityCountCSVs = new StreamWriter[this.sensors.MaximumSensorID + 1]; samplingCSVs = new StreamWriter[this.sensors.MaximumSensorID + 1]; averagedRaw = new StreamWriter[this.sensors.MaximumSensorID + 1]; masterCSV = new StreamWriter(dataDirectory + "\\MITesSummaryData.csv"); hrCSV = new StreamWriter(dataDirectory + "\\HeartRate_MITes.csv"); string csv_line1 = "UnixTimeStamp,TimeStamp,X,Y,Z"; string csv_line2 = "UnixTimeStamp,TimeStamp,Sampling"; string hr_csv_header = "UnixTimeStamp,TimeStamp,HR"; string master_csv_header = "UnixTimeStamp,TimeStamp"; foreach (Category category in this.annotation.Categories) master_csv_header += ","+ category.Name; foreach (Sensor sensor in this.sensors.Sensors) { int sensor_id = Convert.ToInt32(sensor.ID); string location = sensor.Location.Replace(' ', '-'); if (sensor_id > 0) //exclude HR { activityCountCSVs[sensor_id] = new StreamWriter(dataDirectory + "\\MITes_" +sensor_id.ToString("00")+"_ActivityCount_"+location+".csv"); activityCountCSVs[sensor_id].WriteLine(csv_line1); averagedRaw[sensor_id] = new StreamWriter(dataDirectory + "\\MITes_" + sensor_id.ToString("00") + "_1s-RawMean_" + location + ".csv"); averagedRaw[sensor_id].WriteLine(csv_line1); samplingCSVs[sensor_id] = new StreamWriter(dataDirectory + "\\MITes_" + sensor_id.ToString("00") + "_SampleRate_" + location + ".csv"); samplingCSVs[sensor_id].WriteLine(csv_line2); master_csv_header += ",MITes" + sensor_id.ToString("00") + "_SR," + "MITes" + sensor_id.ToString("00") + "_AVRaw_X," + "MITes" + sensor_id.ToString("00") + "_AVRaw_Y," + "MITes" + sensor_id.ToString("00") + "_AVRaw_Z," + "MITes" + sensor_id.ToString("00") + "_AC_X," + "MITes" + sensor_id.ToString("00") + "_AC_Y," + "MITes" + sensor_id.ToString("00") + "_AC_Z"; } } master_csv_header += ",HR"; this.masterCSV.WriteLine(master_csv_header); this.hrCSV.WriteLine(hr_csv_header); //activityCountCSV=new StreamWriter(dataDirectory+"\\"+Constants.ACTIVITY_COUNT_FILENAME); //string csv_line = ""; //csv_line += "UnixTimeStamp"; //foreach (Sensor sensor in this.sensors.Sensors) //{ // int sensor_id = Convert.ToInt32(sensor.ID); // if (sensor_id > 0) //exclude HR // { // csv_line += ",ACC_" + sensor_id + "_SAMP"; // csv_line += ",ACC_" + sensor_id + "_X"; // csv_line += ",ACC_" + sensor_id + "_Y"; // csv_line += ",ACC_" + sensor_id + "_Z"; // } //} //activityCountCSV.WriteLine(csv_line); UnixTime.InitializeTime(); //passed to adjust time when its granularity is not good #if (PocketPC) this.tabControl1.SelectedIndex= 0; #endif isCollectingSimpleData = false; isCollectingDetailedData = false; isPlotting = true; //simple data collection per second //this.tws = new TextWriter[MITesData.MAX_MITES_CHANNELS]; //for (int i = 0; (i < MITesData.MAX_MITES_CHANNELS); i++) // this.tws[i] = null; //this.mitesLastTimeStamps=new double[MITesData.MAX_MITES_CHANNELS]; //this.mitesSampleCounters= new int[MITesData.MAX_MITES_CHANNELS]; //this.xs=new int[MITesData.MAX_MITES_CHANNELS]; //this.ys = new int[MITesData.MAX_MITES_CHANNELS]; //this.zs = new int[MITesData.MAX_MITES_CHANNELS]; //For demo //this.textBoxHR.Visible = false; //this.textBoxAC3.Visible = false; //this.label11.Text = ""; bool startReceiverThreads = true; for (int i = 0; (i<this.sensors.TotalReceivers); i++) { if ((this.mitesControllers[i] == null) || (this.mitesControllers[i].GetComPortNumber() == 0)) startReceiverThreads = false; } if (startReceiverThreads == true) isStartedReceiver = true; else { Application.Exit(); } t.Abort(); #if (PocketPC) #else this.ShowForms(); #endif //Last thing enable the timers this.readDataTimer.Enabled = true; this.qualityTimer.Enabled = true; this.HRTimer.Enabled = true; }
public SensorAnnotation parse(int maxReceivers) { SensorAnnotation annotation = new SensorAnnotation(maxReceivers); XmlDocument dom = new XmlDocument(); dom.Load(this.xmlFile); XmlNode xNode = dom.DocumentElement; bool[] countedReceiver = new bool[maxReceivers]; bool firstAccel = false; for (int i = 0; (i < maxReceivers); i++) { countedReceiver[i] = false; } if ((xNode.Name == Constants.SENSORDATA_ELEMENT) && (xNode.HasChildNodes)) { foreach (XmlAttribute xAttribute in xNode.Attributes) { if (xAttribute.Name == Constants.DATASET_ATTRIBUTE) { annotation.Dataset = xAttribute.Value; } } //Sensor nodes foreach (XmlNode iNode in xNode.ChildNodes) { if (iNode.Name == Constants.RECEIVERS_ELEMENT) { foreach (XmlNode jNode in iNode.ChildNodes) { if (jNode.Name == Constants.RECEIVER_ELEMENT) { Receiver receiver = new Receiver(); foreach (XmlAttribute iAttribute in jNode.Attributes) { //read nodes attributes if (iAttribute.Name == Constants.ID_ATTRIBUTE) { receiver.ID = Convert.ToInt32(iAttribute.Value); } else if (iAttribute.Name == Constants.TYPE_ATTRIBUTE) { receiver.Type = iAttribute.Value; if (receiver.Type == Constants.RECEIVER_BLUETOOTH) { annotation.TotalBluetoothReceivers++; } else if (receiver.Type == Constants.RECEIVER_USB) { annotation.TotalWiredReceivers++; } } else if (iAttribute.Name == Constants.PASSKEY_ATTRIBUTE) { receiver.PassKey = iAttribute.Value; } else if (iAttribute.Name == Constants.DECODER_ATTRIBUTE) { receiver.Decoder = iAttribute.Value; } else if (iAttribute.Name == Constants.MAC_ATTRIBUTE) { receiver.MAC = iAttribute.Value; for (int i = 0; (i < Constants.MAC_SIZE); i++) { receiver.MacAddress[i] = (byte)(System.Int32.Parse(iAttribute.Value.Substring(i * 2, 2), System.Globalization.NumberStyles.AllowHexSpecifier) & 0xff); } } } annotation.Receivers.Add(receiver); annotation.TotalReceivers++; } } } //Backward compatibility else if (iNode.Name == Constants.SENSOR_ELEMENT) { Sensor sensor = new Sensor(); foreach (XmlAttribute iAttribute in iNode.Attributes) { //read nodes attributes if (iAttribute.Name == Constants.CLASS_ATTRIBUTE) { sensor.SensorClass = iAttribute.Value; } else if (iAttribute.Name == Constants.TYPE_ATTRIBUTE) { sensor.Type = iAttribute.Value; } } foreach (XmlNode jNode in iNode.ChildNodes) { //Console.WriteLine(jNode.Name); foreach (XmlAttribute jAttribute in jNode.Attributes) { //read nodes attributes if ((jNode.Name == Constants.ID_ELEMENT) && (jAttribute.Name == Constants.ID_ATTRIBUTE)) { sensor.ID = jAttribute.Value; //if this is an HR sensor if (Convert.ToInt32(jAttribute.Value) == 0) { annotation.IsHR = true; } if ((firstAccel == false) && (Convert.ToInt32(jAttribute.Value) > 0)) { annotation.FirstAccelerometer = Convert.ToInt32(jAttribute.Value); firstAccel = true; } if (annotation.MaximumSensorID < Convert.ToInt32(jAttribute.Value)) { annotation.MaximumSensorID = Convert.ToInt32(jAttribute.Value); } } else if ((jNode.Name == Constants.OBJECT_ELEMENT) && (jAttribute.Name == Constants.TEXT_ATTRIBUTE)) { sensor.SensorObject = jAttribute.Value; } else if ((jNode.Name == Constants.RECEIVER_ELEMENT) && (jAttribute.Name == Constants.ID_ATTRIBUTE)) { int receiver_id = Convert.ToInt32(jAttribute.Value); if ((receiver_id < maxReceivers) && (receiver_id >= 0)) { annotation.NumberSensors[receiver_id] = annotation.NumberSensors[receiver_id] + 1; sensor.Receiver = jAttribute.Value; if (countedReceiver[receiver_id] == false) { annotation.TotalReceivers++; countedReceiver[receiver_id] = true; } } else { throw new Exception("Receiver in sensor file out of bound"); } //sensor.Receiver = jAttribute.Value; //if (Convert.ToInt32(sensor.Receiver) == 1) //{ // annotation.SensorCount1++; //} //else if (Convert.ToInt32(sensor.Receiver) == 2) //{ // annotation.SensorCount2++; //} } else if ((jNode.Name == Constants.LOCATION_ELEMENT) && (jAttribute.Name == Constants.TEXT_ATTRIBUTE)) { sensor.Location = jAttribute.Value; } else if ((jNode.Name == Constants.DESCRIPTION_ELEMENT) && (jAttribute.Name == Constants.TEXT_ATTRIBUTE)) { sensor.Description = jAttribute.Value; } else if ((jNode.Name == Constants.DESCRIPTION_ELEMENT) && (jAttribute.Name == Constants.SR_ATTRIBUTE)) { sensor.SamplingRate = 12; //TODO } else if ((jNode.Name == Constants.DISPLAY_ELEMENT) && (jAttribute.Name == Constants.DISPLAY_TYPE_ATTRIBUTE)) { sensor.DisplayType = jAttribute.Value; } else if ((jNode.Name == Constants.DISPLAY_ELEMENT) && (jAttribute.Name == Constants.DISPLAY_X)) { sensor.DisplayX = jAttribute.Value; } else if ((jNode.Name == Constants.DISPLAY_ELEMENT) && (jAttribute.Name == Constants.DISPLAY_Y)) { sensor.DisplayY = jAttribute.Value; } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.XMEAN_ATTRIBUTE)) { sensor.XMean = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.XSTD_ATTRIBUTE)) { sensor.XStd = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.YMEAN_ATTRIBUTE)) { sensor.YMean = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.YSTD_ATTRIBUTE)) { sensor.YStd = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.ZMEAN_ATTRIBUTE)) { sensor.ZMean = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.ZSTD_ATTRIBUTE)) { sensor.ZStd = Convert.ToDouble(jAttribute.Value); } //display element has children if (jNode.Name == Constants.DISPLAY_ELEMENT) { foreach (XmlNode kNode in jNode.ChildNodes) { foreach (XmlAttribute kAttribute in kNode.Attributes) { if ((kNode.Name == Constants.COLOR_ELEMENT) && (kAttribute.Name == Constants.ON_ATTRIBUTE)) { sensor.ColorOn = kAttribute.Value; } else if ((kNode.Name == Constants.COLOR_ELEMENT) && (kAttribute.Name == Constants.OFF_ATTRIBUTE)) { sensor.ColorOff = kAttribute.Value; } } } } } } //if (sensor.SensorClass.ToLower()==Constants.MITES.ToLower()) //{ if (sensor.SensorClass == Constants.BUILTIN) { annotation.HasBuiltinSensors = true; annotation.TotalBuiltInSensors = annotation.TotalBuiltInSensors + 1; } annotation.Sensors.Add(sensor); sensor.Index = annotation.Sensors.IndexOf(sensor); annotation.SensorsIndex.Add(Convert.ToInt32(sensor.ID), sensor.Index); //} // else if (sensor.SensorClass.ToLower()== Constants.BUILTIN.ToLower()) //{ // annotation.HasBuiltinSensors = true; // annotation.BuiltinSensors.Add(sensor); // } } //parsing file information else if (iNode.Name == Constants.SENSORS_ELEMENT) { foreach (XmlNode rNode in iNode.ChildNodes) { if (rNode.Name == Constants.SENSOR_ELEMENT) { Sensor sensor = new Sensor(); foreach (XmlAttribute iAttribute in rNode.Attributes) { //read nodes attributes if (iAttribute.Name == Constants.CLASS_ATTRIBUTE) { sensor.SensorClass = iAttribute.Value; } else if (iAttribute.Name == Constants.TYPE_ATTRIBUTE) { sensor.Type = iAttribute.Value; } } foreach (XmlNode jNode in rNode.ChildNodes) { //Console.WriteLine(jNode.Name); foreach (XmlAttribute jAttribute in jNode.Attributes) { //read nodes attributes if ((jNode.Name == Constants.ID_ELEMENT) && (jAttribute.Name == Constants.ID_ATTRIBUTE)) { sensor.ID = jAttribute.Value; //if this is an HR sensor if (Convert.ToInt32(jAttribute.Value) == 0) { annotation.IsHR = true; } if ((firstAccel == false) && (Convert.ToInt32(jAttribute.Value) > 0)) { annotation.FirstAccelerometer = Convert.ToInt32(jAttribute.Value); firstAccel = true; } if (annotation.MaximumSensorID < Convert.ToInt32(jAttribute.Value)) { annotation.MaximumSensorID = Convert.ToInt32(jAttribute.Value); } } else if ((jNode.Name == Constants.OBJECT_ELEMENT) && (jAttribute.Name == Constants.TEXT_ATTRIBUTE)) { sensor.SensorObject = jAttribute.Value; } else if ((jNode.Name == Constants.RECEIVER_ELEMENT) && (jAttribute.Name == Constants.ID_ATTRIBUTE)) { int receiver_id = Convert.ToInt32(jAttribute.Value); if ((receiver_id < maxReceivers) && (receiver_id >= 0)) { annotation.NumberSensors[receiver_id] = annotation.NumberSensors[receiver_id] + 1; sensor.Receiver = jAttribute.Value; //if (countedReceiver[receiver_id] == false) //{ // annotation.TotalReceivers++; // countedReceiver[receiver_id] = true; // } } else { throw new Exception("Receiver in sensor file out of bound"); } //sensor.Receiver = jAttribute.Value; //if (Convert.ToInt32(sensor.Receiver) == 1) //{ // annotation.SensorCount1++; //} //else if (Convert.ToInt32(sensor.Receiver) == 2) //{ // annotation.SensorCount2++; //} } else if ((jNode.Name == Constants.LOCATION_ELEMENT) && (jAttribute.Name == Constants.TEXT_ATTRIBUTE)) { sensor.Location = jAttribute.Value; } else if ((jNode.Name == Constants.DESCRIPTION_ELEMENT) && (jAttribute.Name == Constants.TEXT_ATTRIBUTE)) { sensor.Description = jAttribute.Value; } else if ((jNode.Name == Constants.DESCRIPTION_ELEMENT) && (jAttribute.Name == Constants.SR_ATTRIBUTE)) { sensor.SamplingRate = Convert.ToInt32(jAttribute.Value); //TODO } else if ((jNode.Name == Constants.DISPLAY_ELEMENT) && (jAttribute.Name == Constants.DISPLAY_TYPE_ATTRIBUTE)) { sensor.DisplayType = jAttribute.Value; } else if ((jNode.Name == Constants.DISPLAY_ELEMENT) && (jAttribute.Name == Constants.DISPLAY_X)) { sensor.DisplayX = jAttribute.Value; } else if ((jNode.Name == Constants.DISPLAY_ELEMENT) && (jAttribute.Name == Constants.DISPLAY_Y)) { sensor.DisplayY = jAttribute.Value; } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.XMEAN_ATTRIBUTE)) { sensor.XMean = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.XSTD_ATTRIBUTE)) { sensor.XStd = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.YMEAN_ATTRIBUTE)) { sensor.YMean = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.YSTD_ATTRIBUTE)) { sensor.YStd = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.ZMEAN_ATTRIBUTE)) { sensor.ZMean = Convert.ToDouble(jAttribute.Value); } else if ((jNode.Name == Constants.CALIBRATION_ELEMENT) && (jAttribute.Name == Constants.ZSTD_ATTRIBUTE)) { sensor.ZStd = Convert.ToDouble(jAttribute.Value); } //display element has children if (jNode.Name == Constants.DISPLAY_ELEMENT) { foreach (XmlNode kNode in jNode.ChildNodes) { foreach (XmlAttribute kAttribute in kNode.Attributes) { if ((kNode.Name == Constants.COLOR_ELEMENT) && (kAttribute.Name == Constants.ON_ATTRIBUTE)) { sensor.ColorOn = kAttribute.Value; } else if ((kNode.Name == Constants.COLOR_ELEMENT) && (kAttribute.Name == Constants.OFF_ATTRIBUTE)) { sensor.ColorOff = kAttribute.Value; } } } } } } //if (sensor.SensorClass.ToLower()==Constants.MITES.ToLower()) //{ if (sensor.SensorClass == Constants.BUILTIN) { annotation.HasBuiltinSensors = true; annotation.TotalBuiltInSensors = annotation.TotalBuiltInSensors + 1; } annotation.Sensors.Add(sensor); sensor.Index = annotation.Sensors.IndexOf(sensor); annotation.SensorsIndex.Add(Convert.ToInt32(sensor.ID), sensor.Index); //} // else if (sensor.SensorClass.ToLower()== Constants.BUILTIN.ToLower()) //{ // annotation.HasBuiltinSensors = true; // annotation.BuiltinSensors.Add(sensor); // } } } } } } return(annotation); }
public MITesDataCollectionForm(string dataDirectory) { //where data is being stored this.dataDirectory = dataDirectory; //Initialize high resolution unix timer UnixTime.InitializeTime(); //Initialize and start GUI progress thread progressMessage = null; aProgressThread = new Thread(new ThreadStart(ProgressThread)); aProgressThread.Start(); #region Load Configuration files //load the activity and sensor configuration files progressMessage = "Loading XML protocol and sensors ..."; AXML.Reader reader = new AXML.Reader(Constants.MASTER_DIRECTORY, dataDirectory); #if (!PocketPC) if (reader.validate() == false) { throw new Exception("Error Code 0: XML format error - activities.xml does not match activities.xsd!"); } else { #endif this.annotation = reader.parse(); this.annotation.DataDirectory = dataDirectory; SXML.Reader sreader = new SXML.Reader(Constants.MASTER_DIRECTORY, dataDirectory); #if (!PocketPC) if (sreader.validate() == false) { throw new Exception("Error Code 0: XML format error - sensors.xml does not match sensors.xsd!"); } else { #endif this.sensors = sreader.parse(Constants.MAX_CONTROLLERS); progressMessage += " Completed\r\n"; //TODO: remove BT components progressMessage += "Loading configuration file ..."; MITesFeatures.core.conf.ConfigurationReader creader = new MITesFeatures.core.conf.ConfigurationReader(dataDirectory); this.configuration = creader.parse(); progressMessage += " Completed\r\n"; #if (!PocketPC) } } #endif #endregion Load Configuration files //Initialize 1 master decoder this.masterDecoder = new MITesDecoder(); #region Initialize External Data Reception Channels //Initialize Data reception for Bluetooth and USB if ((this.sensors.TotalReceivers > 0) && (this.sensors.TotalReceivers <= Constants.MAX_CONTROLLERS)) { //Initialize arrays to store USB and Bluetooth controllers this.mitesControllers = new MITesReceiverController[this.sensors.TotalWiredReceivers]; #if (PocketPC) this.bluetoothControllers = new BluetoothController[this.sensors.TotalBluetoothReceivers]; // this.ts = new Thread[this.sensors.TotalBluetoothReceivers]; #endif //Initialize array to store Bluetooth connection status //this.bluetoothConnectionStatus = new bool[this.sensors.TotalBluetoothReceivers]; //Initialize a decoder for each sensor this.mitesDecoders = new MITesDecoder[this.sensors.TotalReceivers]; this.aMITesActivityCounters = new Hashtable(); #if (PocketPC) #region Bluetooth reception channels initialization //Initialize and search for wockets connections progressMessage += "Initializing Bluetooth receivers ... searching " + this.sensors.TotalBluetoothReceivers+ " BT receivers\r\n"; //Try to initialize all Bluetooth receivers 10 times then exit int initializationAttempt = 0; while (initializationAttempt <= 10) { if (InitializeBluetoothReceivers() == false) { initializationAttempt++; if (initializationAttempt == 10) { MessageBox.Show("Exiting: Some Bluetooth receivers in your configuration were not initialized."); Application.Exit(); System.Diagnostics.Process.GetCurrentProcess().Kill(); } else progressMessage += "Failed to initialize all BT connections. Retrying (" + initializationAttempt + ")...\r\n"; } else break; Thread.Sleep(2000); } #endregion Bluetooth reception channels initialization #endif #region USB reception channels initialization if (InitializeUSBReceivers() == false) { MessageBox.Show("Exiting: Some USB receivers in your configuration were not initialized."); #if (PocketPC) Application.Exit(); System.Diagnostics.Process.GetCurrentProcess().Kill(); #else Environment.Exit(0); #endif } #endregion USB reception channels initialization } #endregion Initialize External Data Reception Channels #if (PocketPC) #region Initialize Builtin Data Reception Channels if (InitializeBuiltinReceivers() == false) { MessageBox.Show("Exiting: A built in receiver channel was not found."); Application.Exit(); System.Diagnostics.Process.GetCurrentProcess().Kill(); } #endregion Initialize Builtin Data Reception Channels #endif #region Initialize GUI Components //initialize the interface components InitializeComponent(); //Initialize GUI timers progressMessage += "Initializing Timers ..."; InitializeTimers(); progressMessage += " Completed\r\n"; //Initialize different GUI components progressMessage += "Initializing GUI ..."; InitializeInterface(); progressMessage += " Completed\r\n"; this.isPlotting = true; //count the number of accelerometers if (this.sensors.IsHR) this.maxPlots = this.sensors.Sensors.Count - 1; else this.maxPlots = this.sensors.Sensors.Count; SetFormPositions(); if (this.sensors.TotalReceivers > 0) aMITesPlotter = new MITesScalablePlotter(this.panel1, MITesScalablePlotter.DeviceTypes.IPAQ, maxPlots, this.masterDecoder, GetGraphSize(false)); else aMITesPlotter = new MITesScalablePlotter(this.panel1, MITesScalablePlotter.DeviceTypes.IPAQ, maxPlots, this.masterDecoder, GetGraphSize(false)); //Override the resize event #if (PocketPC) this.Resize += new EventHandler(OnResize); #else this.form1.Resize += new EventHandler(OnResizeForm1); this.form1.FormClosing += new FormClosingEventHandler(form_FormClosing); this.form2.Resize += new EventHandler(OnResizeForm2); this.form2.FormClosing += new FormClosingEventHandler(form_FormClosing); this.form3.Resize += new EventHandler(OnResizeForm3); this.form3.FormClosing += new FormClosingEventHandler(form_FormClosing); this.form4.Resize += new EventHandler(OnResizeForm4); this.form4.FormClosing += new FormClosingEventHandler(form_FormClosing); #endif //Initialize the quality interface progressMessage += "Initializing MITes Quality GUI ..."; InitializeQualityInterface(); progressMessage += " Completed\r\n"; //Remove classifier tabs #if (PocketPC) this.tabControl1.TabPages.RemoveAt(4); this.tabControl1.SelectedIndex = 0; #else this.ShowForms(); #endif #endregion Initialize GUI Components #region Initialize Feature Extraction this.isExtracting = false; if (this.sensors.TotalReceivers > 0) // if there is at least 1 MIT //Extractor.Initialize(this.mitesDecoders[0], dataDirectory, this.annotation, this.sensors, this.configuration); Extractor.Initialize(this.masterDecoder, dataDirectory, this.annotation, this.sensors, this.configuration); else if (this.sensors.Sensors.Count > 0) // only built in Extractor.Initialize(new MITesDecoder(), dataDirectory, this.annotation, this.sensors, this.configuration); #endregion Initialize Feature Extraction #region Initialize Quality Tracking variables InitializeQuality(); #endregion Initialize Quality Tracking variables #region Initialize Logging InitializeLogging(dataDirectory); #endregion Initialize Logging #region Initialize CSV Storage (PC Only) #if (!PocketPC) //create some counters for activity counts averageX = new int[this.sensors.MaximumSensorID + 1]; averageY = new int[this.sensors.MaximumSensorID + 1]; averageZ = new int[this.sensors.MaximumSensorID + 1]; averageRawX = new int[this.sensors.MaximumSensorID + 1]; averageRawY = new int[this.sensors.MaximumSensorID + 1]; averageRawZ = new int[this.sensors.MaximumSensorID + 1]; prevX = new int[this.sensors.MaximumSensorID + 1]; prevY = new int[this.sensors.MaximumSensorID + 1]; prevZ = new int[this.sensors.MaximumSensorID + 1]; acCounters = new int[this.sensors.MaximumSensorID + 1]; activityCountWindowSize = 0; activityCountCSVs = new StreamWriter[this.sensors.MaximumSensorID + 1]; samplingCSVs = new StreamWriter[this.sensors.MaximumSensorID + 1]; averagedRaw = new StreamWriter[this.sensors.MaximumSensorID + 1]; masterCSV = new StreamWriter(dataDirectory + "\\MITesSummaryData.csv"); hrCSV = new StreamWriter(dataDirectory + "\\HeartRate_MITes.csv"); string csv_line1 = "UnixTimeStamp,TimeStamp,X,Y,Z"; string csv_line2 = "UnixTimeStamp,TimeStamp,Sampling"; string hr_csv_header = "UnixTimeStamp,TimeStamp,HR"; string master_csv_header = "UnixTimeStamp,TimeStamp"; foreach (Category category in this.annotation.Categories) master_csv_header += "," + category.Name; foreach (Sensor sensor in this.sensors.Sensors) { int sensor_id = Convert.ToInt32(sensor.ID); string location = sensor.Location.Replace(' ', '-'); if (sensor_id > 0) //exclude HR { activityCountCSVs[sensor_id] = new StreamWriter(dataDirectory + "\\MITes_" + sensor_id.ToString("00") + "_ActivityCount_" + location + ".csv"); activityCountCSVs[sensor_id].WriteLine(csv_line1); averagedRaw[sensor_id] = new StreamWriter(dataDirectory + "\\MITes_" + sensor_id.ToString("00") + "_1s-RawMean_" + location + ".csv"); averagedRaw[sensor_id].WriteLine(csv_line1); samplingCSVs[sensor_id] = new StreamWriter(dataDirectory + "\\MITes_" + sensor_id.ToString("00") + "_SampleRate_" + location + ".csv"); samplingCSVs[sensor_id].WriteLine(csv_line2); master_csv_header += ",MITes" + sensor_id.ToString("00") + "_SR," + "MITes" + sensor_id.ToString("00") + "_AVRaw_X," + "MITes" + sensor_id.ToString("00") + "_AVRaw_Y," + "MITes" + sensor_id.ToString("00") + "_AVRaw_Z," + "MITes" + sensor_id.ToString("00") + "_AC_X," + "MITes" + sensor_id.ToString("00") + "_AC_Y," + "MITes" + sensor_id.ToString("00") + "_AC_Z"; } } master_csv_header += ",HR"; this.masterCSV.WriteLine(master_csv_header); this.hrCSV.WriteLine(hr_csv_header); #endif #endregion Initialize CSV Storage (PC Only) #region Start Collecting Data this.collectDataMode = true; #if (PocketPC) this.isCollectingDetailedData = false; #else this.isCollectingDetailedData = true; #endif //if (this.sensors.TotalReceivers > 0) // isStartedReceiver = true; //Start the built in polling thread #if (PocketPC) if (this.sensors.HasBuiltinSensors) { this.pollingThread = new Thread(new ThreadStart(this.pollingData)); this.pollingThread.Priority = ThreadPriority.Lowest; this.pollingThread.Start(); } #endif //Terminate the progress thread progressThreadQuit = true; //Enable all timer functions this.readDataTimer.Enabled = true; this.qualityTimer.Enabled = true; if (this.sensors.IsHR) this.HRTimer.Enabled = true; #endregion Start Collecting Data }
public MITesDataCollectionForm() { //Initialize the UNIX QueryPerformanceCounter UnixTime.InitializeTime(); //intialize the mode of the software this.collectDataMode = false; this.isCollectingDetailedData = false; this.isPlotting = false; this.isExtracting = false; //initialize the progress thread progressMessage = null; aProgressThread = new Thread(new ThreadStart(ProgressThread)); aProgressThread.Start(); //initialize the interface components InitializeComponent(); //Initialize where the data will be stored and where the configuration //files exist this.dataDirectory = Constants.DEFAULT_DATA_STORAGE_DIRECTORY; //load the activity and sensor configuration files progressMessage = "Loading XML protocol and sensors ..."; AXML.Reader reader = new AXML.Reader(Constants.MASTER_DIRECTORY, Constants.DEFAULT_DATA_STORAGE_DIRECTORY); this.annotation = reader.parse(); this.annotation.DataDirectory = Constants.DEFAULT_DATA_STORAGE_DIRECTORY; SXML.Reader sreader = new SXML.Reader(Constants.MASTER_DIRECTORY, Constants.DEFAULT_DATA_STORAGE_DIRECTORY); this.sensors = sreader.parse(Constants.MAX_CONTROLLERS); progressMessage += " Completed\r\n"; progressMessage += "Loading configuration file ..."; MITesFeatures.core.conf.ConfigurationReader creader = new MITesFeatures.core.conf.ConfigurationReader(Constants.DEFAULT_DATA_STORAGE_DIRECTORY); this.configuration = creader.parse(); progressMessage += " Completed\r\n"; //calculate how many plots to be drawn if (this.sensors.IsHR) this.maxPlots = this.sensors.Sensors.Count - 1; else this.maxPlots = this.sensors.Sensors.Count; //Initialize the timers progressMessage += "Initializing Timers ..."; InitializeTimers(); progressMessage += " Completed\r\n"; //Initialize different GUI components progressMessage += "Initializing GUI ..."; InitializeInterface(); progressMessage += " Completed\r\n"; #if (PocketPC) this.tabControl1.TabPages.RemoveAt(4); this.tabControl1.TabPages.RemoveAt(3); this.tabControl1.TabPages.RemoveAt(2); this.tabControl1.TabPages.RemoveAt(0); this.tabControl1.SelectedIndex = 0; #endif progressThreadQuit = true; }
//This constructor initializes the software for calibration of a list //of sensors public MITesDataCollectionForm(SensorAnnotation uncalibratedSensors, string dataDirectory) { //Initialize the UNIX timer to use QueryPerformanceCounter UnixTime.InitializeTime(); //Setup the initial state of the calibration variables this.sensors = uncalibratedSensors; this.currentCalibrationSensorIndex = 0; this.calCounter = 0; #if (PocketPC) this.horizontalMITes = (System.Drawing.Image)new System.Drawing.Bitmap(Constants.MITES_HORIZONTAL_96_96); this.verticalMITes = (System.Drawing.Image)new System.Drawing.Bitmap(Constants.MITES_VERTICAL_96_96); #else this.horizontalMITes = (System.Drawing.Image)new System.Drawing.Bitmap(Constants.MITES_HORIZONTAL_288_288); this.verticalMITes = (System.Drawing.Image)new System.Drawing.Bitmap(Constants.MITES_VERTICAL_288_288); #endif //create a dummy annotation this.annotation = new Annotation(); //make sure the software will not collect or extract features this.collectDataMode = false; this.isClassifying = false; this.isExtracting = false; this.isCollectingDetailedData = false; //setup where the sensordata file will be stored this.dataDirectory = dataDirectory; //setup plotting parameters isPlotting = true; this.maxPlots = this.sensors.Sensors.Count; //Spawn the progress thread progressMessage = null; aProgressThread = new Thread(new ThreadStart(ProgressThread)); aProgressThread.Start(); //Intialize the interface of the forms InitializeComponent(); progressMessage += "Initializing Timers ..."; InitializeTimers(); progressMessage += " Completed\r\n"; progressMessage += "Initializing GUI ..."; InitializeInterface(); progressMessage += " Completed\r\n"; progressMessage += "Loading configuration file ..."; MITesFeatures.core.conf.ConfigurationReader confreader = new MITesFeatures.core.conf.ConfigurationReader(dataDirectory); this.configuration = confreader.parse(); progressMessage += " Completed\r\n"; #if (PocketPC) //setup the Bluetooth if needed if (this.configuration.Connection == MITesFeatures.core.conf.Constants.SOFTWARE_CONNECTION_BLUETOOTH) { progressMessage += "Initializing Bluetooth ..."; /* this.bt = new BluetoothController(); try { this.bluetoothPort = bt.initialize(this.configuration.MacAddress, this.configuration.Passkey); } catch (Exception e) { progressMessage += " Failed\r\n"; MessageBox.Show("Failed to find Bluetooth Device... exiting!"); bt.close(); Application.Exit(); System.Diagnostics.Process.GetCurrentProcess().Kill(); } */ progressMessage += " Completed\r\n"; } #endif //Intialize the MITes Receivers, decoders and counters based //on the chosen sensors if ((this.sensors.TotalReceivers > 0) && (this.sensors.TotalReceivers <= Constants.MAX_CONTROLLERS)) { this.mitesControllers = new MITesReceiverController[this.sensors.TotalReceivers]; this.mitesDecoders = new MITesDecoder[this.sensors.TotalReceivers]; //this.aMITesActivityCounters = new Hashtable(); progressMessage += "Initializing MITes ... searching " + this.sensors.TotalReceivers + " receivers\r\n"; if (InitializeMITes(dataDirectory) == false) { MessageBox.Show("Exiting: You picked a configuration with " + this.sensors.TotalReceivers + " receivers. Please make sure they are attached to the computer."); #if (PocketPC) /* bt.close(); */ Application.Exit(); System.Diagnostics.Process.GetCurrentProcess().Kill(); #else Environment.Exit(0); Application.Exit(); #endif } } //Setup the resize event for each different form #if (PocketPC) this.Resize += new EventHandler(OnResize); #else this.form1.Resize += new EventHandler(OnResizeForm1); this.form1.FormClosing += new FormClosingEventHandler(form_FormClosing); this.form2.Resize += new EventHandler(OnResizeForm2); this.form2.FormClosing += new FormClosingEventHandler(form_FormClosing); this.form3.Resize += new EventHandler(OnResizeForm3); this.form3.FormClosing += new FormClosingEventHandler(form_FormClosing); this.form4.Resize += new EventHandler(OnResizeForm4); this.form4.FormClosing += new FormClosingEventHandler(form_FormClosing); #endif //Initialize the interface for reporting the quality of the MITes //transmission progressMessage += "Initializing MITes Quality GUI ..."; InitializeQualityInterface(); progressMessage += " Completed\r\n"; //Intialize the MITes performance tracking objects for (int i = 0; i < MITesData.MAX_MITES_CHANNELS; i++) MITesDataFilterer.MITesPerformanceTracker[i] = new MITesPerformanceStats(0); foreach (Sensor sensor in this.sensors.Sensors) { int sensor_id = Convert.ToInt32(sensor.ID); int receiver_id = Convert.ToInt32(sensor.Receiver); if (sensor_id == 0) //HR sensor { MITesDataFilterer.MITesPerformanceTracker[sensor_id].GoodRate = (int)(Constants.HR_SAMPLING_RATE * 0.8); MITesDataFilterer.MITesPerformanceTracker[sensor_id].PerfectRate = Constants.HR_SAMPLING_RATE; } else { int goodSamplingRate = 150; MITesDataFilterer.MITesPerformanceTracker[sensor_id].GoodRate = goodSamplingRate; MITesDataFilterer.MITesPerformanceTracker[sensor_id].PerfectRate = 180; } } #if (PocketPC) this.tabControl1.SelectedIndex = 0; #endif progressThreadQuit = true; //remove unnecessary forms or pages #if (PocketPC) this.tabControl1.TabPages.RemoveAt(1); this.tabControl1.TabPages.RemoveAt(2); //this.tabControl1.TabPages.RemoveAt(3); #else this.ShowForms(); #endif //Only enable the read data time since we are just calibrating this.readDataTimer.Enabled = true; }