コード例 #1
0
 private void SaveMITesData(MITesData aMITesData)
 {
     if (isActive && (bwPLFormat != null))
     {
         for (int i = 0; i < MITesData.MIN_NUM_RAW_BYTES; i++)
         {
             bwPLFormat.WriteByte(aMITesData.rawBytes[i]);
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Test method.
        /// </summary>
        public static void Main()
        {
            long m1;
            long m2;

            m1 = GC.GetTotalMemory(false);
            MITesData[] md = new MITesData[10000];
            for (int i = 0; i < 10000; i++)
            {
                md[i] = new MITesData();
            }
            m2 = GC.GetTotalMemory(false);

            Console.WriteLine("Size: " + (m2 - m1));

            Thread.Sleep(10000);
        }
コード例 #3
0
        private void AddSample(MITesData aMITesData)
        {
            int    channel       = aMITesData.channel;
            double unixTimeStamp = aMITesData.unixTimeStamp;
            int    indx          = GetIndex(channel);

            if (indx == -1)
            {
                Console.WriteLine("ERROR: Got an invalid channel number for an accelerometer: " + channel);
                return;
            }

            if (((unixTimeStamp - sampleTime) > 330) || // More than 330 ms so save previous
                (isSampFilled[indx]))                   // Already have this sensor value so start new
            {
                SaveSampleLine();
                sampleTime = unixTimeStamp;
            }

            if (sampleTime == 0)
            {
                sampleTime = unixTimeStamp;
            }

            sx[indx]           = aMITesData.x;
            sy[indx]           = aMITesData.y;
            sz[indx]           = aMITesData.z;
            isSampFilled[indx] = true;

            if (aMITesData.x != 0)
            {
                sxNonZero[indx] = aMITesData.x;
            }
            if (aMITesData.y != 0)
            {
                syNonZero[indx] = aMITesData.y;
            }
            if (aMITesData.z != 0)
            {
                szNonZero[indx] = aMITesData.z;
            }
        }
コード例 #4
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
 /// <summary>
 /// The UNIX time at which each MITesData object is decoded is recorded. 
 /// </summary>
 /// <param name="aMITesData">The object in which to store the time.</param>
 public void SetUnixTime(MITesData aMITesData)
 {
     
     aMITesData.unixTimeStamp = UnixTime.GetUnixTime();
     //lastUnixTime = aMITesData.unixTimeStamp;
     //  QueryPerformanceCounter(out aMITesData.highPrecisionTime);
 }
コード例 #5
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
        /// <summary>
        /// Decode data that has been saved by MITesLogger (always send multiple of 4 bytes). A MITesLogger saves
        /// MITesData. This reads it back in so it behaves exactly as data read from the 
        /// serial port. Useful for "playing back" data that has been saved. 
        /// </summary>
        /// <param name="numPackets">The number of packets to read.</param>
        /// <param name="someData">The array in which the resulting MITesData will be stored.</param>
        /// <param name="dataIndex">The current index of the array in which the MITesData will be stored. (This will append data onto the end of existing data if needed).</param>
        /// <param name="br">A ByteReader object that has been opened to the proper file.</param>
        /// <returns>The new index for the someData array.</returns>
        public int DecodeMITesLoggerDataOld(int numPackets, MITesData[] someData, int dataIndex, ByteReader br)
        {
            int valuesGrabbed = 0;
            for (int i = 0; i < numPackets; i++)
            {
                if (timeCount == 0)
                {
                    timeStamp = MITesLoggerReaderNew.ReadTimeStamp(br);
                    Console.WriteLine("TIME: " + timeStamp);
                }

                timeCount++;
                if (timeCount == MITesLoggerNew.TIMESTAMP_AFTER_SAMPLES)
                {
                    timeCount = 0;
                }

                br.ReadByte(tempByte);
                packet[0] = tempByte[0];
                br.ReadByte(tempByte);
                packet[1] = tempByte[0];
                br.ReadByte(tempByte);
                packet[2] = tempByte[0];
                br.ReadByte(tempByte);
                packet[3] = tempByte[0];
                br.ReadByte(tempByte);
                packet[4] = tempByte[0];
                br.ReadByte(tempByte);
                diffMS = (int)tempByte[0];

                Thread.Sleep(diffMS);
                timeStamp += diffMS; // MAYBE WORKS? SSI 

                if (dataIndex >= someData.Length)
                    Warning("MAX_MITES_DATA too small! Losing info. Size:" + someData.Length);
                else
                {
                    DecodeLastPacket(someData[dataIndex], false); // Don't swap bytes
                    someData[dataIndex].timeStamp = timeStamp; // Set the time
                    dataIndex++;
                }
                valuesGrabbed++;
            }

            if (valuesGrabbed != numPackets)
                Console.WriteLine("ERROR: something wrong!!!");

            if (valuesGrabbed < someData.Length)
                return valuesGrabbed;
            else
                return someData.Length;
        }
コード例 #6
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
 /// <summary>
 /// The time at which each MITesData object is decoded is recorded. 
 /// </summary>
 /// <param name="aMITesData">The object in which to store the time.</param>
 private void SetTime(MITesData aMITesData)
 {
     aMITesData.timeStamp = Environment.TickCount;
     //Console.WriteLine ("Settime: " + aMITesData.timeStamp);
 }
コード例 #7
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
        public int DecodeWocketsData(byte[] bytes, int numBytes, MITesData[] someData, int dataIndex)
        {
            int i = 0;
            int valuesGrabbed = 0;
            bool header_started=false;
            //if (decoderlog==null)
              //  decoderlog = new StreamWriter("\\Wockets\\decoding.txt",true);       
            if (numBytes != 0) // Have some data
            {
                while (i < numBytes)
                {                    
                    if ((bytes[i] & 0x80) != 0) //grab the next 6 bytes
                    {
                        packet2Position = 0;
                        header_started = true;
                    }
          
                    if ( (header_started==true) && (packet2Position<WOCKET_PACKET_SIZE))
                        packet2[packet2Position] = bytes[i];

                    packet2Position++;
                    i++;

                   /* if (dataIndex == MAX_MITES_DATA)
                    {
                        decoderlog.WriteLine("DataIndex: " +dataIndex);
                        decoderlog.Flush();
                    }*/
                    if ((packet2Position == WOCKET_PACKET_SIZE)) //a full packet was received
                    {
                        DecodeWocketsFrame(someData[dataIndex], packet2);
                        if (dataIndex<MAX_MITES_DATA-1)
                            dataIndex++;
                        packet2Position = 0;
                        header_started = false;
                        valuesGrabbed++;
                         
                    }
                    //else
                    //{
                     //   decoderlog.WriteLine("Overflow while decoding");
                    //}
                }
            }

            //decoderlog.WriteLine("Decoded: " + valuesGrabbed);
            //decoderlog.Flush();

            if (valuesGrabbed < someData.Length)
                return valuesGrabbed;
            else
                return someData.Length;
        }
コード例 #8
0
		/// <summary>
		/// Test method.
		/// </summary>
		public static void Main()
		{
			long m1;
			long m2;

			m1 = GC.GetTotalMemory(false);
			MITesData[] md = new MITesData[10000];
			for (int i = 0; i < 10000; i++)
				md[i] = new MITesData();
			m2 = GC.GetTotalMemory(false); 

			Console.WriteLine("Size: " + (m2-m1));

			Thread.Sleep (10000);

		}
コード例 #9
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
 private void DecodeLastPacket(MITesData aMITesData)
 {
     DecodeLastPacket(aMITesData, SWAP_BYTES); // Default to swap bytes
 }
コード例 #10
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
 public void DecodeSparkfunFrame(MITesData aMITesData, byte[] raw)
 {
     aMITesData.channel = 26;
     aMITesData.x = (short)((((short)raw[4])<<8) | ((short)raw[5]));
     aMITesData.y = (short)((((short)raw[6]) << 8) | ((short)raw[7]));
     aMITesData.z = (short)((((short)raw[8]) << 8) | ((short)raw[9]));
     aMITesData.type = ((int)MITesTypes.ACCEL);
     SetTime(aMITesData);
     SetUnixTime(aMITesData);
 }
コード例 #11
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
        private void DecodeCurrentTrainingPacket(MITesData aMITesData)
        {
            Debug("Decode Current TRAINING packet");
            Console.WriteLine("Decode Current TRAINING packet");

            //			aMITesData.sensorValue = (((packet[3] & 0xFF) << 3) | ((packet[4] & 0xE0) >> 5));
            //			aMITesData.resendID = (byte) ((packet[4] & 0x1C) >> 2);
            //
            //			if (((packet[4] & 0x02) >> 1) == 1)
            //				aMITesData.isBatteryLow = true;
            //			else
            //				aMITesData.isBatteryLow = false;
            //			
            //			if ((packet[4] & 0x01) == 1)
            //				aMITesData.isAlive = true;
            //			else
            //				aMITesData.isAlive = false;
        }
コード例 #12
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
        private void DecodeCurrentPacket(MITesData aMITesData)
        {
            Debug("Decode Current packet");
            Console.WriteLine("Decode Current packet");
            aMITesData.type = (int)MITesTypes.CURRENT;

            // First check if packet from training mode. If so, special decode
            //			if ((aMITesData.rawBytes[4] & 0x400) == 0x400) 
            //			{
            //				DecodeCurrentTrainingPacket(aMITesData);
            //			}
            //			else
            DecodeGenericPacket(aMITesData);
        }
コード例 #13
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
        private void DecodeSwitchPacket(MITesData aMITesData)
        {

            // A value of 512 indicates noise 

            aMITesData.type = (int)MITesTypes.STATIC;
            Debug("Decode static switch packet");

            aMITesData.sensorValue = (((packet[3] & 0xFF) << 1) | ((packet[4] & 0xE0) >> 7));
            aMITesData.recentActivationsValue = ((packet[4] & 0x60) >> 5);

            aMITesData.resendID = (byte)((packet[4] & 0x1C) >> 2);

            if (((packet[4] & 0x02) >> 1) == 1)
                aMITesData.isBatteryLow = true;
            else
                aMITesData.isBatteryLow = false;

            if ((packet[4] & 0x01) == 1)
                aMITesData.isAlive = true;
            else
                aMITesData.isAlive = false;

            //			Console.WriteLine("********************  Decode static switch packet");
            //			Console.WriteLine("********************  ID: " + aMITesData.id);
            //			Console.WriteLine("********************  Value: " + aMITesData.sensorValue);
            //			Console.WriteLine("********************  Activations: " + aMITesData.recentActivationsValue);
            //			Console.WriteLine("********************  Alive: " + aMITesData.isAlive);
            //			if (aMITesData.isAlive)
            //				Console.WriteLine("********************  Alive: " + aMITesData.isAlive);

        }
コード例 #14
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
 private void DecodeUVPacket(MITesData aMITesData)
 {
     Debug("Decode UV packet");
     aMITesData.type = (int)MITesTypes.UV;
     DecodeGenericPacket(aMITesData);
 }
コード例 #15
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
        private void DecodeGenericPacket(MITesData aMITesData)
        {
            aMITesData.sensorValue = (((packet[3] & 0xFF) << 3) | ((packet[4] & 0xE0) >> 5));
            aMITesData.resendID = (byte)((packet[4] & 0x1C) >> 2);

            if (((packet[4] & 0x02) >> 1) == 1)
                aMITesData.isBatteryLow = true;
            else
                aMITesData.isBatteryLow = false;

            if ((packet[4] & 0x01) == 1)
                aMITesData.isAlive = true;
            else
                aMITesData.isAlive = false;
        }
コード例 #16
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
        private void DecodeAccelerometerPacket(MITesData aMITesData)
        {
            Debug("Decode Accelerometer MITe sensor");

            aMITesData.channel = packet[0];
            //Console.WriteLine ("Channel: " + packet[0]);
            

            x = packet[1];
            y = packet[2];
            z = packet[3];
            xyz = packet[4];
      

            if (aMITesData.channel == MAX_CHANNEL)
            {
                xyz2 = packet[5];
                aMITesData.type = (byte)(xyz2 & 0x0F); 
                aMITesData.x = (short)(x | ((xyz & 0xF0) << 4));
                aMITesData.y = (short)(y | ((xyz & 0x0F) << 8));
                aMITesData.z = (short)(z | ((xyz2 & 0xF0) << 4));

            }
            else
            {
                aMITesData.type = (int)MITesTypes.ACCEL; // Type label used for Accelerometers
                aMITesData.x = (short)(x | ((xyz & 0xC0) << 2));
                aMITesData.y = (short)(y | ((xyz & 0x30) << 4));
                aMITesData.z = (short)(z | ((xyz & 0x0C) << 6));
            }

            //Debug(aMITesData.channel + ": x " + x + " y " + y + " z " + z);
            //Console.WriteLine(aMITesData.channel + ": x " + x + " y " + y + " z " + z);
        }
コード例 #17
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
        /// <summary>
        /// reate an object to process incoming serial port data and convert it 
        /// into a useful MITesData format that can be processed by many classes.
        /// </summary>
        /// <param name="maxMITesData">The maximum number of MITesData objects that can be stored. If this is too small, data will be lost. Too large, and mobile devices may run out of storage or run slowly.</param>
        public MITesDecoder(int maxMITesData)
        {
            someMITesData = new MITesData[maxMITesData];
            someMITesDataMerged = new MITesData[maxMITesData];

            // All datastructures created in advance, so value of maxMITesData impacts storage,
            // but the amount of space used will be consistent.
            for (int i = 0; i < someMITesData.Length; i++)
                someMITesData[i] = new MITesData();
            
        }
コード例 #18
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
 /// <summary>
 /// The UNIX time at which each MITesData object is decoded is recorded. 
 /// </summary>
 /// <param name="aMITesData">The object in which to store the time.</param>
 /// <param name="aTime">The time to use.</param>
 public void SetUnixTime(MITesData aMITesData, double aTime)
 {
     aMITesData.unixTimeStamp = aTime;
     lastUnixTime = aTime;
 }
コード例 #19
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
 private void DecodeRangePacket(MITesData aMITesData)
 {
     Debug("Decode Range Beacon packet");
     aMITesData.type = (int)MITesTypes.RANGE;
     DecodeGenericPacket(aMITesData);
 }
コード例 #20
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
        /// <summary>
        /// 
        /// </summary>
        /// <param name="aMITesData"></param>
        /// <param name="isSwapBytes"></param>
        public void DecodeLastPacket(MITesData aMITesData, bool isSwapBytes)
        {
            aMITesData.ResetVals();

            Debug("Packet: " + packet[0]
                + " " + packet[1]
                + " " + packet[2]
                + " " + packet[3]
                + " " + packet[4]);

            if (packet[0] == STATIC_CHANNEL)
            {
                if (isSwapBytes)
                {
                    // This is a hack to fix the swap byte problem
                    temp = packet[2];
                    packet[2] = packet[1];
                    packet[1] = temp;
                    temp = packet[4];
                    packet[4] = packet[3];
                    packet[3] = temp;
                }

                SetRawBytes(aMITesData);
                DecodeOtherPacket(aMITesData);
                SetTime(aMITesData);
                SetUnixTime(aMITesData);

            }
            else if (IsAccelerometerChannel(packet[0]))
            {
                SetRawBytes(aMITesData);
                DecodeAccelerometerPacket(aMITesData);
                SetTime(aMITesData);
                SetUnixTime(aMITesData);
                
            }
            else
            {
                Warning("Invalid channel: " + packet[0]);
            }

            Debug("Data:" + aMITesData);
        }
コード例 #21
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
 private void DecodeLightPacket(MITesData aMITesData)
 {
     Debug("Decode light packet");
     aMITesData.type = (int)MITesTypes.LIGHT;
     DecodeGenericPacket(aMITesData);
 }
コード例 #22
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
        //set the sync bit,no compession, length and channel
    //frame.byte1 |= 0xA8 | UNCOMPRESSED_LENGTH;
    //frame.byte2 |= (crc>>1);
    //frame.byte3 |= ((crc<<7)>>1) | ((unsigned char) ((x>>4)&0x3f));
    //frame.byte4 |=  ((unsigned char) ((x<<3) &0x78)) | ((unsigned char) ((y>>7)&0x07));
    //frame.byte5 |= ((unsigned char) (y&0x7f));
    //frame.byte6 |= ((unsigned char) ((z>>3)&0x7f));
    //frame.byte7 |= ((unsigned char) ((z<<4)&0x70));

        public void DecodeWocketsFrame(MITesData aMITesData,byte[] raw)
        {
            aMITesData.channel = (byte)((raw[0]&0x38)>>3);
            aMITesData.x= (short)((((short)(raw[2]&0x3f))<<4) | (((short)(raw[3]&0x78))>>3));
            aMITesData.y = (short)((((short)(raw[3] & 0x07)) << 7) | ((short)(raw[4] & 0x7f)));
            aMITesData.z = (short)((((short)(raw[5] & 0x7f)) << 3) | (((short)(raw[6] & 0x70)) >> 4));
            aMITesData.type = ((int)MITesTypes.ACCEL);
            SetTime(aMITesData);
            SetUnixTime(aMITesData);         
        }
コード例 #23
0
 private void SaveMITesData(MITesData aMITesData)
 {
     if (isActive && (bwPLFormat != null))
     {
         for (int i = 0; i < MITesData.MIN_NUM_RAW_BYTES; i++)
         {
             bwPLFormat.WriteByte(aMITesData.rawBytes[i]);
         }
     }
 }
コード例 #24
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
        public int DecodeSparkfunData(byte[] bytes, int numBytes, MITesData[] someData, int dataIndex)
        {
            int i = 0;
            int valuesGrabbed = 0;
            bool header_started = false;

            if (numBytes != 0) // Have some data
            {
                while (i < numBytes)
                {
                    if ((bytes[i])=='#') //grab the next 6 bytes
                    {
                        packet3Position = 0;
                        header_started = true;
                    }

                    if ((header_started == true) && (packet3Position < SPARKFUN_PACKET_SIZE))
                        packet3[packet3Position] = bytes[i];

                    packet3Position++;
                    i++;
                    if ((packet3Position == SPARKFUN_PACKET_SIZE) && (packet3[SPARKFUN_PACKET_SIZE-1]=='$')) //a full packet was received
                    {
                        DecodeSparkfunFrame(someData[dataIndex], packet3);
                        dataIndex++;
                        packet3Position = 0;
                        header_started = false;
                        valuesGrabbed++;
                    }
                }
            }

            if (valuesGrabbed < someData.Length)
                return valuesGrabbed;
            else
                return someData.Length;
        }
コード例 #25
0
        private void AddSample(MITesData aMITesData)
        {
            int channel = aMITesData.channel;
            double unixTimeStamp = aMITesData.unixTimeStamp;
            int indx = GetIndex(channel);

            if (indx == -1)
            {
                Console.WriteLine("ERROR: Got an invalid channel number for an accelerometer: " + channel);
                return;
            }

            if (((unixTimeStamp - sampleTime) > 330) ||  // More than 330 ms so save previous 
                (isSampFilled[indx]))    // Already have this sensor value so start new
            {
                SaveSampleLine(); 
                sampleTime = unixTimeStamp; 
            }

            if (sampleTime == 0)
                sampleTime = unixTimeStamp;

            sx[indx] = aMITesData.x;
            sy[indx] = aMITesData.y;
            sz[indx] = aMITesData.z;
            isSampFilled[indx] = true;

            if (aMITesData.x != 0)
                sxNonZero[indx] = aMITesData.x;
            if (aMITesData.y != 0)
                syNonZero[indx] = aMITesData.y;
            if (aMITesData.z != 0)
                szNonZero[indx] = aMITesData.z;
        }
コード例 #26
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
        /// <summary>
        /// The main call to decode data grabbed from the serial port int MITesData objects.
        /// </summary>
        /// <param name="bytes">Incoming bytes from the serial port.</param>
        /// <param name="numBytes">Number of incoming bytes from the serial port.</param>
        /// <param name="someData">The array in which the resulting MITesData will be stored.</param>
        /// <param name="dataIndex">The current index of the array in which the MITesData will be stored. (This will append data onto the end of existing data if needed).</param>
        /// <returns>The new index for the someData array.</returns>
        public int DecodeMITesData(byte[] bytes, int numBytes, MITesData[] someData, int dataIndex)
        {
            int i = 0;
            int valuesGrabbed = 0;
            int variablePacketSize = MIN_PACKET_SIZE;

            //tw = new System.IO.StreamWriter("C:\\Test\\test.txt", true);

            //Console.WriteLine(" BB ");
            if (numBytes != 0) // Have some data
            {
                //tw.Write("(GOT DATA: " + numBytes + ")");
                //tw.Flush();
                while (i < numBytes)
                {
                    v = bytes[i] & 0xff;

                    //tw.Write("(" + i + ",v: " + v + ",LV: " + lV + ",PP: " + packetPosition + "," + dataIndex + ")" + " ");
                    //tw.Flush();

                    // First check if got a reset and start of packet
                    if ((packetPosition == NO_HEADER_SEEN) && (v == PACKET_MARKER))
                    {
                        packetPosition = FIRST_HEADER_SEEN;
                    }
                    // Any two markers in a row is *always* a packet. This will occasionally cause an error. 
                    else if ((v == PACKET_MARKER) && (lV == PACKET_MARKER))
                    {
                        packetPosition = 0;
                    }
                    // Must have seen header 
                    else if (packetPosition >= 0) // Must have seen header
                    {
                        packet[packetPosition] = bytes[i];

                        //set the size of the packet
                        if ((packetPosition == 0) && (IsValidChannelSelective(packet[packetPosition])))
                        {
                            if ((packet[packetPosition] == MAX_CHANNEL))
                                variablePacketSize = MAX_PACKET_SIZE;
                            else
                                variablePacketSize = MIN_PACKET_SIZE;
                        }

                        // Sanity check. Make sure channel is valid ... if not, reset and wait for new header
                        if ((packetPosition == 0) && (!IsValidChannelSelective(packet[packetPosition])))
                        {
                            if (v == PACKET_MARKER)
                              packetPosition = FIRST_HEADER_SEEN;
                            else
                              packetPosition = NO_HEADER_SEEN;

 

                        }
                        else
                        {
                            packetPosition++;
                            //if (packetPosition == PACKET_SIZE)
                            if (packetPosition == variablePacketSize)
                            {
                                if (dataIndex >= someData.Length)
                                {
                                    Warning("MAX_MITES_DATA too small! Losing info. Size:" + someData.Length);
                      //              tw.Write("(LosingInfo)");
                      //              tw.Flush();

                                }
                                else
                                {
                                    DecodeLastPacket(someData[dataIndex]);
                                    dataIndex++;
                                }

                                packetPosition = 0; // Reset to listen for new packet
                                valuesGrabbed++;
                            }
                        }
                    }
                    else
                    {
                        // Either a reset (new header) or loss of data
                        if (v != PACKET_MARKER)
                            packetPosition = NO_HEADER_SEEN;
                        else
                            packetPosition = FIRST_HEADER_SEEN; 
                     //   Warning("Data loss? " + lV + " " + v);
                     //   tw.Write("(DL?)");
                     //   tw.Flush();
                    }
//                    tw.Write("(SET_LV: " + v + ")");
//                    tw.Flush();
                    lV = v;
                    i++;
                }

                //tw.WriteLine();
            }
            //tw.Close();
            if (valuesGrabbed < someData.Length)
                return valuesGrabbed;
            else
                return someData.Length;
        }
コード例 #27
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
        /// <summary>
        /// Decode data that has been saved by MITesLogger (always send multiple of 4 bytes). A MITesLogger saves
        /// MITesData. This reads it back in so it behaves exactly as data read from the 
        /// serial port. Useful for "playing back" data that has been saved. 
        /// </summary>
        /// <param name="numPackets">The number of packets to read.</param>
        /// <param name="someData">The array in which the resulting MITesData will be stored.</param>
        /// <param name="dataIndex">The current index of the array in which the MITesData will be stored. (This will append data onto the end of existing data if needed).</param>
        /// <param name="br">A ByteReader object that has been opened to the proper file.</param>
        /// <param name="isPLFormat">True if PLFormat, false if older version.</param>
        /// <returns>The new index for the someData array.</returns>
        public int DecodeMITesLoggerData(int numPackets, MITesData[] someData, int dataIndex, ByteReader br, bool isPLFormat)
        {
            if (isPLFormat)
                return DecodeMITesLoggerDataPLFormat(numPackets, someData, dataIndex, br);

            if (numPackets == 0)
                return DecodeMITesLoggerDataVariable(numPackets, someData, dataIndex, br);

            int valuesGrabbed = 0;
            for (int i = 0; i < numPackets; i++)
            {
                timeStamp = MITesLoggerReaderNew.ReadTimeStamp(br);
                //Console.WriteLine ("TIME: " + timeStamp);
                diffMS = timeStamp - lastTimeStamp;
                if ((lastTimeStamp != 0) && (timeStamp != 0))
                {
                    //Console.WriteLine ("Sleep: " + diffMS);
                    Thread.Sleep(diffMS);
                }
                lastTimeStamp = timeStamp;

                br.ReadByte(tempByte);
                packet[0] = tempByte[0];
                br.ReadByte(tempByte);
                packet[1] = tempByte[0];
                br.ReadByte(tempByte);
                packet[2] = tempByte[0];
                br.ReadByte(tempByte);
                packet[3] = tempByte[0];
                br.ReadByte(tempByte);
                packet[4] = tempByte[0];


                if (dataIndex >= someData.Length)
                    Warning("MAX_MITES_DATA too small! Losing info. Size:" + someData.Length);
                else
                {
                    DecodeLastPacket(someData[dataIndex], false); // Don't swap bytes
                    someData[dataIndex].timeStamp = timeStamp; // Set the time
                    dataIndex++;
                }
                valuesGrabbed++;
            }

            if (valuesGrabbed != numPackets)
                Console.WriteLine("ERROR: something wrong!!!");

            if (valuesGrabbed < someData.Length)
                return valuesGrabbed;
            else
                return someData.Length;
        }
コード例 #28
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
 private void DecodeTempPacket(MITesData aMITesData)
 {
     Debug("Decode temp packet");
     aMITesData.type = (int)MITesTypes.TEMP;
     DecodeGenericPacket(aMITesData);
 }
コード例 #29
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
        /// <summary>
        /// Decode data that has been saved by MITesLogger (always send multiple of 4 bytes). A MITesLogger saves
        /// MITesData. This reads it back in so it behaves exactly as data read from the 
        /// serial port. Useful for "playing back" data that has been saved. 
        /// </summary>
        /// <param name="numPackets">The number of packets to read.</param>
        /// <param name="someData">The array in which the resulting MITesData will be stored.</param>
        /// <param name="dataIndex">The current index of the array in which the MITesData will be stored. (This will append data onto the end of existing data if needed).</param>
        /// <param name="br">A ByteReader object that has been opened to the proper file.</param>
        /// <returns>The new index for the someData array.</returns>
        public int DecodeMITesLoggerDataVariable(int numPackets, MITesData[] someData, int dataIndex, ByteReader br)
        {
            if (isWaitTime)
                Console.WriteLine("Waiting: " + timeToWait);

            if (!isWaitTime)
            {
                //Get time to wait
                timeStamp = MITesLoggerReaderNew.ReadTimeStamp(br);

                if (timeStamp == MITesData.NONE)
                {
                    Console.WriteLine("End of file.");
                    return 0;
                }

                diffMS = timeStamp - lastTimeStamp;
                if ((lastTimeStamp != 0) && (timeStamp != 0))
                    timeToWait = diffMS;
                else
                    timeToWait = 0;
                lastTimeStamp = timeStamp;
                lastTimeStampTime = Environment.TickCount;
                isWaitTime = true;
                return 0;
            }
            else
            {
                if ((Environment.TickCount - lastTimeStampTime) >= timeToWait)
                {
                    br.ReadByte(tempByte);
                    packet[0] = tempByte[0];
                    br.ReadByte(tempByte);
                    packet[1] = tempByte[0];
                    br.ReadByte(tempByte);
                    packet[2] = tempByte[0];
                    br.ReadByte(tempByte);
                    packet[3] = tempByte[0];
                    br.ReadByte(tempByte);
                    packet[4] = tempByte[0];
                    DecodeLastPacket(someData[dataIndex], false); // Don't swap bytes
                    someData[dataIndex].timeStamp = timeStamp; // Set the time
                    dataIndex++;
                    isWaitTime = false;
                    return 1;
                }
                else
                    return 0;
            }
        }
コード例 #30
0
ファイル: MITesLoggerReader.cs プロジェクト: katadam/wockets
        public int DecodeWocketsPLFormat(MITesData[] someData, int dataIndex, ByteReader br)
        {
            isEndFile = false;

            // Determine if consumed next data point from each file. Value of 0 indicates yes and get next value.

            if (dTimeStamp == 0)
                dTimeStamp = ReadUnixTimeStamp(br, dLastTimeStamp);

            debugCount++;

            DateTime dt = new DateTime();
            UnixTime.GetDateTime((long)dTimeStamp, out dt);

            //if (((dTimeStamp1 != MITesData.NONE) && (dTimeStamp2 != MITesData.NONE)) &&
            //    ((dt1.Second != dt2.Second) || (dt1.Minute != dt2.Minute)))
            //{
            //    //isLastMatch = false;
            //        Console.WriteLine("DATES: " + Environment.NewLine + dt1 + Environment.NewLine + dt2 + "    " + debugCount);
            //}

            if (dTimeStamp == (double)MITesData.NONE)
            {
                //Console.WriteLine("End of file 1: " + GetDateTime(lastGoodTime1) + " " + GetDateTime(lastGoodTime2));
                isEndFile = true;
            }

            if (isEndFile)
            {
                Console.WriteLine("End of both files.");
                return 0;
            }

            // If at this point, there is some data to read in one of the files

            #region Thread wait (do in the future)
            // Insert waiting code here in the future for graphing capability option
            //diffMS1 = (int)(dTimeStamp1 - dLastTimeStamp1);
            //if ((dLastTimeStamp1 != 0) && (dTimeStamp1 != 0))
            //    timeToWait1 = diffMS1;
            //else
            //    timeToWait1 = 0;

            //diffMS2 = (int)(dTimeStamp1 - dLastTimeStamp1);
            //if ((dLastTimeStamp1 != 0) && (dTimeStamp1 != 0))
            //    timeToWait2 = diffMS1;
            //else
            //    timeToWait2 = 0;

            //// Wait the right number of MS if needed from last time data grabbed
            //diffTime = Environment.TickCount - lastTimeStampTime;
            //if ((timeToWait - diffTime) > 0)
            //{
            //    Thread.Sleep(timeToWait - diffTime);
            //    timeToWait = 0;
            //}

            #endregion

            if ((dTimeStamp != -1) && (dLastTimeStamp != -1) && (dTimeStamp < dLastTimeStamp))
                Console.WriteLine("Jumpback1: " + debugCount);

            dLastTimeStamp = dTimeStamp;
            lastTimeStampTime = Environment.TickCount;

            //DateTime junkme = new DateTime();
            //UnixTime.GetDateTime((long) dTimeStamp1, out junkme);
            //Console.WriteLine("                               DTIMESTAMP1: " + junkme);

            //UnixTime.GetDateTime((long)dTimeStamp2, out junkme);
            //Console.WriteLine("                               DTIMESTAMP2: " + junkme);

            // Read packet that is first in time from whichever file. Leave other be

            if ((dTimeStamp != 0) && (!isEndFile))
            {
                lastGoodTime = dTimeStamp;
            }

            else
            {
                Console.WriteLine("ERROR2 -- Should not be here!! ----------------------------");
            }

            br.ReadByte(tempByte);
            aMITesDecoder.packet2[0] = tempByte[0];
            br.ReadByte(tempByte);
            aMITesDecoder.packet2[1] = tempByte[0];
            br.ReadByte(tempByte);
            aMITesDecoder.packet2[2] = tempByte[0];
            br.ReadByte(tempByte);
            aMITesDecoder.packet2[3] = tempByte[0];
            br.ReadByte(tempByte);
            aMITesDecoder.packet2[4] = tempByte[0];
            br.ReadByte(tempByte);
            aMITesDecoder.packet2[5] = tempByte[0];
            br.ReadByte(tempByte);
            aMITesDecoder.packet2[6] = tempByte[0];

            //if the packet is for an HTC phone (i.e. packet[1]>=50)... read 1 additional byte
            aMITesDecoder.DecodeWocketsFrame(someData[dataIndex], aMITesDecoder.packet2);
            //aMITesDecoder.DecodeLastPacket(someData[dataIndex], false); // Don't swap bytes

            //Console.WriteLine("FileUsed: " + fileUsed);

            someData[dataIndex].timeStamp = UnixTime.IntTimeFromUnixTime(dTimeStamp, aRefDate);

            aMITesDecoder.SetUnixTime(someData[dataIndex], dTimeStamp); // Set the time
            someData[dataIndex].fileID = 1;
            dTimeStamp = 0; // Reset so gets read next time from file

            //            dataIndex++;
            return 1;
        }
コード例 #31
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
        private void DecodeOtherPacket(MITesData aMITesData)
        {
            Debug("Decode non-accelerometer MITe sensor!");

            aMITesData.channel = packet[0];

            id = (((packet[1] & 0xFF) << 4) | ((packet[2] & 0xF0) >> 4));

            if (!ISValidID(id))
                Warning("Invalid ID: " + id);

            // SSI Check here ot ensure valid conversion?
            aMITesData.id = (short)id;

            type = (packet[2] & 0x0F);

            if (!ISValidType(type))
                Warning("Invalid Type: " + type);

            aMITesData.type = (byte)type;

            switch (type)
            {
                case ((int)MITesTypes.STATIC):
                    DecodeSwitchPacket(aMITesData);
                    break;
                case ((int)MITesTypes.LIGHT):
                    DecodeLightPacket(aMITesData);
                    break;
                case ((int)MITesTypes.RANGE):
                    DecodeRangePacket(aMITesData);
                    break;
                case ((int)MITesTypes.HR):
                    DecodeHRPacket(aMITesData);
                    break;
                case ((int)MITesTypes.CURRENT):
                    DecodeCurrentPacket(aMITesData);
                    break;
                case ((int)MITesTypes.UV):
                    DecodeUVPacket(aMITesData);
                    break;
                case ((int)MITesTypes.TEMP):
                    DecodeTempPacket(aMITesData);
                    break;
                case ((int)MITesTypes.IR):
                    break;
                default:
                    Warning("Unhandled MITesData type: " + type);
                    break;
            }
        }
コード例 #32
0
//		private byte[] saveByteBuffer = new byte[BYTE_SAVE_CHUNK];
//		private int byteSaveCount = 0;
//
//		private void SaveLastPacket(ByteWriter byteWriter)
//		{
//			SaveLastPacket(byteWriter, false); // Don't force to save, store in buffer OK
//		}


		private void SaveMITesData(MITesData aMITesData)
		{
            if (isActive)
            {
                for (int i = 0; i < MITesData.NUM_RAW_BYTES; i++)
                {
                    bw.WriteByte(aMITesData.rawBytes[i]);
                    bwPLFormat.WriteByte(aMITesData.rawBytes[i]);
                }
            }
		}
コード例 #33
0
ファイル: MITesDecoder.cs プロジェクト: intille/mitessoftware
        // R
        /// <summary>
        /// Raw bytes are stored with each MITesData so data can be easily saved back out again in an 
        /// efficient format 
        /// </summary>
        /// <param name="aMITesData">The object in which to store the raw bytes.</param>
        private void SetRawBytes(MITesData aMITesData)
        {

            aMITesData.rawBytes[0] = packet[0];
            aMITesData.rawBytes[1] = packet[1];
            aMITesData.rawBytes[2] = packet[2];
            aMITesData.rawBytes[3] = packet[3];
            aMITesData.rawBytes[4] = packet[4];

            if (packet[0]==MITesDecoder.MAX_CHANNEL)
                aMITesData.rawBytes[5] = packet[5];
            else
                aMITesData.rawBytes[5] = 0;
           
            
           //System.IO.TextWriter tw = new System.IO.StreamWriter("C:\\Test\\test.txt", true);
            //tw.WriteLine("D: " + packet[0] + " " + packet[1] + " " + packet[2] + " " + packet[3] + " " + packet[4]);
            //tw.Close();
        }