/// <summary>
        /// 取得したバイナリデータからSensor データクラスを作成し登録する。
        /// </summary>
        /// <param name="rcvbuffer"></param>
        private void CreateSensorData()
        {
            SensorData sensorData = new SensorData();

            // n Byte読み出し
            sensorData.TaskProcessTime = taskTime;
            sensorData.TouchSenser = 0;
            sensorData.ReflectionSensor = 0;
            sensorData.SonerSensor = 0;
            double gyro = random.NextDouble() * 3;
            sensorData.GyroSensor = (int)gyro;
            sensorData.A_Power = 0;

            double powerL = random.NextDouble() * 100;
            double powerR = random.NextDouble() * 100;
            currentOdoL += (powerL * 5 * 0.004);
            currentOdoR += (powerR * 5 * 0.004);
            sensorData.B_Power = (int)powerL;
            sensorData.B_Odometer = (int)currentOdoL;
            sensorData.C_Power = (int)powerR;
            sensorData.C_Odometer = (int)currentOdoR;
            sensorData.Battery = 7.5;

            // beforeOdoL = currentOdoL;
            // beforeOdoR = currentOdoR;

            // センサデータ をコンテナに追加(排他処理付)
            sensorDataContainer.Enqueue(sensorData);

            taskTime += 0.004;
        }
        /// <summary>
        /// 取得したバイナリデータからSensor データクラスを作成し登録する。
        /// </summary>
        /// <param name="rcvbuffer"></param>
        private int ConvertSensorData(byte[] rcvbuffer)
        {
            if (null == rcvbuffer) { return 0; }

            int maxSize = rcvbuffer.Length;
            int seekPos = 0;
            const int ReadByte = 4;
            const int SensorDataSize = 4 * 11;

            // データが
            while (seekPos + SensorDataSize <= maxSize)
            {
                SensorData sensorData = new SensorData(); 

                // n Byte読み出し
                sensorData.A_Power = rcvbuffer[seekPos + ReadByte];
                seekPos += ReadByte;
                sensorData.B_Power = rcvbuffer[seekPos + ReadByte];
                seekPos += ReadByte;
                sensorData.B_Odometer = rcvbuffer[seekPos + ReadByte];
                seekPos += ReadByte;
                sensorData.Battery = rcvbuffer[seekPos + ReadByte];
                seekPos += ReadByte;
                sensorData.C_Power = rcvbuffer[seekPos + ReadByte];
                seekPos += ReadByte;
                sensorData.C_Odometer = rcvbuffer[seekPos + ReadByte];
                seekPos += ReadByte;
                sensorData.GyroSensor = rcvbuffer[seekPos + ReadByte];
                seekPos += ReadByte;
                sensorData.ReflectionSensor = rcvbuffer[seekPos + ReadByte];
                seekPos += ReadByte;
                sensorData.SonerSensor = rcvbuffer[seekPos + ReadByte];
                seekPos += ReadByte;
                sensorData.TouchSenser = rcvbuffer[seekPos + ReadByte];
                seekPos += ReadByte;
                sensorData.TaskProcessTime = rcvbuffer[seekPos + ReadByte];
                seekPos += ReadByte;

                // センサデータ をコンテナに追加(排他処理付)
                sensorDataContainer.Enqueue(sensorData);
            }

            return maxSize - seekPos;
        }
Ejemplo n.º 3
0
 public static SensorData GetRootAsSensorData(ByteBuffer _bb, SensorData obj) { return (obj.__init(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
        /// <summary>
        /// Queue にデータを追加
        /// </summary>
        /// <param name="data"></param>
        public void Enqueue(SensorData data)
        {
            try
            {
                lock (SyncObject)
                {
                    senserQueueDataContainer.Enqueue(data);
                }
            }
            catch (Exception e)
            {
                throw;
            }

            return ;
        }