Kreyos.SDK.Bluetooth.SportsDataRow.loadFromBuffer C# (CSharp) Method

loadFromBuffer() public static method

public static loadFromBuffer ( byte buf ) : SportsDataRow
buf byte
return SportsDataRow
        public static SportsDataRow loadFromBuffer(byte[] buf)
        {
            SportsDataRow row = new SportsDataRow();

            row.data = new Dictionary<DataType, double>();

            int cursor = 0;
            int grid_num = ((int)buf[cursor]) & 0x000000ff; cursor++;

            // + ET 041514 : Commented because it limit the showing of values
            //if (grid_num > 5)
            //return null;

            int data_start_offset = cursor + grid_num;
            for (int i = 0; i < grid_num - 1; ++i)
            {
                //get the value
                int key = ((int)buf[cursor]) & 0x000000ff;
                int intvalue = Protocol.bytesToInt(buf, data_start_offset + i * 4);
                cursor++;

                switch (key)
                {
                    case (int)DataType.DATA_WORKOUT:
                        row.seconds_elapse = intvalue;
                        break;

                    case (int)DataType.DATA_SPEED:
                    case (int)DataType.DATA_SPEED_AVG:
                    case (int)DataType.DATA_SPEED_TOP:
                        double speedValue = (double)intvalue * 36 / 1000;
                        // row.data.Insert(key, Math.Round(speedValue * 100.0) / 100.0);
                        row.data.Add((DataType)key, Math.Round(speedValue * 100.0) / 100.0);
                        break;
                    
                    case (int)DataType.DATA_DISTANCE:
                        // row.data.Insert(key, (double)(intvalue) / 10);
                         row.data.Add((DataType)key, (double)(intvalue)/ 10);
                        break;
                    
                    default:
                        // row.data.Insert(key, (double)(intvalue));
                        row.data.Add((DataType)key, (double)(intvalue));
                        break;
                }
            }

            return row;
        }
SportsDataRow