Beispiel #1
0
		/** 
		 *	Fills a plot data array with time information and data readings
		 *  from a given node and sensor. 
		 * 
		 * @author      Martin Turon
		 * @version     2004/4/27    mturon      Initial version
		 */
		public int FillNode(MoteInfo moteInfo, string sensor, out double[] xData, out double[] yData) 
		{
			ushort nodeid = moteInfo.m_nodeid;
			
			OdbcManager db = theOdbcManager.Instance;
			db.Connect();
			DataSet dSet = db.CreateDataSet(
			db.GetNodeDataCommand(nodeid, sensor));	
			db.Disconnect();

			int size = 0, i = 0;
			try 
			{
				size = dSet.Tables[0].Rows.Count - 1;
				if (size < 0) size = 0;

				xData = new double[size];
				yData = new double[size];
			
				foreach (DataRow dRow in dSet.Tables[0].Rows)
				{
					try 
					{
						if (i >= size) break;
						DateTime rtime = Convert.ToDateTime(dRow["result_time"]);
						object data = dRow[sensor];
						if (data.GetType() == Type.GetType("System.DBNull")) continue;
						yData[i] = Convert.ToDouble(data);
						xData[i] = rtime.ToOADate();
						++i;
					} 
					catch (Exception ex) 
					{
						theOdbcManager.Instance.ErrorLog("\n" + ex.ToString());
					}
				}	
			} 
			catch (Exception ex) 
			{
				theOdbcManager.Instance.ErrorLog("\n" + ex.ToString());
				xData = new double[0];
				yData = new double[0];
			}
	
			return size;
		}
Beispiel #2
0
		// ======================= METHODS ===========================
		public MoteTable() 
		{	
			// Assign the color table
			InitColors(
				0x7F0000FF, 0x7F00FF00, 0x7FFFFF00,
				0x7F00FFFF, 0x7FFF0000, 0x7FFF00FF,
                0x7FFF8080, 0x7F80FF80, 0x7F8080FF,
				0x7FFFFF80, 0x7F80FFFF, 0x7FFF80FF,
				0x7FCC4080, 0x7F40CC80, 0x7F4080CC,
				0x7FCCCC40, 0x7F40CCCC, 0x7FCC40CC);
			
			// Always initialize with a Gateway.
			MoteInfo gatewayInfo = new MoteInfo();
			gatewayInfo.m_nodeid = 0;
			gatewayInfo.m_parent = 0;
			gatewayInfo.m_name = "Gateway";
			Add(gatewayInfo.m_nodeid, gatewayInfo);
		}
Beispiel #3
0
		/** Attach this DataGrid to the current database. */
		public void Load() 
		{
			OdbcManager db = theOdbcManager.Instance;
			db.Connect();
			DataSet dSet = db.CreateDataSet(db.GetMoteInfoCommand());	
			db.Disconnect();

			this.Clear();
			if (null == dSet) return;

			MoteInfo moteInfo;
			foreach (DataRow dRow in dSet.Tables[0].Rows)
			{
				ushort nodeid = Convert.ToUInt16(dRow["mote_id"].ToString());
				bool   exists = this.ContainsKey(nodeid);
				if (!exists) 
				{
					moteInfo = new MoteInfo();
					moteInfo.m_nodeid = nodeid;
					moteInfo.m_name = "[S]";
					byte[] nameBytes = (byte[])dRow["moteinfo"];
					for (int i = 0; i < nameBytes.Length; i++) 
					{
						char c = Convert.ToChar(nameBytes[i]);
						if (c == 0) break;
						moteInfo.m_name += c;
					}
				} 
				else 
				{
					moteInfo = (MoteInfo)this[nodeid];
					moteInfo.m_name = "[S]" + moteInfo.m_name;
				}
				
				moteInfo.m_x      = Convert.ToInt32(dRow["x_coord"].ToString());
				moteInfo.m_y      = Convert.ToInt32(dRow["y_coord"].ToString());
				moteInfo.m_z      = Convert.ToInt32(dRow["z_coord"].ToString());
				moteInfo.m_color  = m_colors[nodeid % m_colors.Length];
				moteInfo.m_flags  = MoteFlags.MF_SAVED;
				//moteInfo.m_calib  = (byte[])dRow["calib"];

				if (!exists) Add(nodeid, moteInfo);
			}

			Update();
		}		
Beispiel #4
0
		public void Update() 
		{
			OdbcManager db = theOdbcManager.Instance;
			db.Connect();
			DataSet dSet = db.CreateDataSet(db.GetLastResultCommand());	
			db.Disconnect();
			
			try 
			{
				foreach (DataRow dRow in dSet.Tables[0].Rows)
				{
					try 
					{
						string nodenum = dRow["nodeid"].ToString();
						if ("" == nodenum) continue;			// Ignore null nodes
						ushort nodeid = Convert.ToUInt16(nodenum);
						//if (0 == nodeid) continue;				// Ignore gateway

						MoteInfo moteInfo;
						if (this.ContainsKey(nodeid)) 
						{
							// Update the mote with latest parent, epoch, and result time
							moteInfo = (MoteInfo)this[nodeid];
							// Stuff name until casting of byte[] to string works.
							moteInfo.m_name = "[R]" + moteInfo.m_name;
						} 
						else 
						{
							// This mote is reporting data, but isn't saved yet.
							moteInfo = new MoteInfo();
							moteInfo.m_nodeid = nodeid;
							moteInfo.m_name   = "[N] Node " + nodeid;
							moteInfo.m_flags  = 0;

							/// TODO: testing only...
							theOdbcManager.Instance.ErrorLog("\nFixed position for node " + nodeid);
							moteInfo.m_x = 10;
							moteInfo.m_y = 10;

							Add(nodeid, moteInfo);
						}			
						// Common update for both new and existing nodes.
						moteInfo.m_parent = Convert.ToUInt16(dRow["parent"].ToString());
						moteInfo.m_epoch  = Convert.ToUInt16(dRow["epoch"].ToString());
						moteInfo.m_time   = dRow["result_time"].ToString();
					}
					catch (Exception ex) 
					{
						theOdbcManager.Instance.ErrorLog("\n" + ex.ToString());
					}
				}
			} 
			catch (Exception ex) 
			{
				theOdbcManager.Instance.ErrorLog("\n" + ex.ToString());
			}
		}
		/** 
		 * Creates a new mote in the task_mote_info database 
		 * @version      2004/3/25    mturon      Initial version
		 */
		public void SaveMoteNew(MoteInfo moteInfo) 
		{
			string sqlInsert = "INSERT INTO task_mote_info (mote_id, " +
                "x_coord, y_coord, z_coord, calib, " +
                "moteinfo, clientinfo_name) " +
                "VALUES ( " +
                moteInfo.m_nodeid + ", " +
                moteInfo.m_x + ", " +
				moteInfo.m_y + ", " +
                moteInfo.m_z + ", '' , '" +
                moteInfo.m_name + "', '" + m_Client + "')";

			OdbcCommand command = new OdbcCommand(sqlInsert, m_Connection);
			try 
			{
				command.ExecuteNonQuery();
			} 
			catch (Exception ex) 
			{
				ErrorLog("\nError: adding new mote to database\n" + ex.Message);
			}			
		}