Пример #1
0
        public ActivityDataDoc LoadDataFromBuffer(byte[] buffer)
        {
            hexdump(buffer);

            ActivityDataDoc ret = new ActivityDataDoc();
            ret.data = new List<ActivityDataRow>();

            int cursor = 4; // jump over signature

            ret.version = ((int)buffer[cursor++]) & 0x000000ff;
            ret.year = ((int)buffer[cursor++]) & 0x000000ff;
            ret.month = ((int)buffer[cursor++]) & 0x000000ff;
            ret.day = ((int)buffer[cursor++]) & 0x000000ff;

            while (cursor + 8 < buffer.Length)
            {
                ActivityDataRow row = new ActivityDataRow();

                row.mode = buffer[cursor++];
                row.hour = buffer[cursor++];
                row.minute = buffer[cursor++];
                row.data = new Dictionary<ActivityDataRow.DataType, double>();

                int size = buffer[cursor++];
                int[] meta = new int[size];

                int meta_cursor = 0;
                int meta_cnt = 0;
                for (; meta_cnt < 4 && meta_cursor < size; ++meta_cnt)
                {
                    int _2d = (int)buffer[cursor + meta_cnt];
                    _2d = _2d & 0x000000ff;
                    int left = _2d >> 4;
                    int right = _2d & 0x0f;
                    if (left != 0)
                    {
                        meta[meta_cursor++] = left;
                    }
                    else
                    {
                        break;
                    }
                    if (right != 0)
                    {
                        meta[meta_cursor++] = right;
                    }
                    else
                    {
                        break;
                    }
                }

                if (meta_cursor != size)
                {
                    return null;
                }

                cursor += 4;

                for (int i = 0; i < size; ++i)
                {
                    int dataType = meta[i];
                    if (cursor + 4 >= buffer.Length)
                        break;

                    int rawValue = bytesToInt(buffer, cursor);
                    double value = 0;
                    switch (dataType)
                    {
                        case (int)ActivityDataRow.DataType.DATA_COL_STEP:
                        case (int)ActivityDataRow.DataType.DATA_COL_CADN:
                        case (int)ActivityDataRow.DataType.DATA_COL_HR:
                            value = rawValue;
                            break;
                        case (int)ActivityDataRow.DataType.DATA_COL_DIST:
                        case (int)ActivityDataRow.DataType.DATA_COL_CALS:
                            value = rawValue % 100;
                            value /= 100.0;
                            value += rawValue / 100;
                            break;
                    }

                    row.data.Add((ActivityDataRow.DataType)dataType, value);
                    cursor += 4;
                }

                ret.data.Add(row);
            }

            return ret;
        }
Пример #2
0
 private void OnOverallActivitiesReceived (ActivityDataDoc doc)
 {
     KreyosUtils.Log("BluetoothManager::OnOverallActivitiesReceived", "");
     
     //~~~Display overall data
     ObserverInfo info = new ObserverInfo();
     info.Command = EBTEvent.BTE_OnOverallActivity;
     info.OverallData = doc;
     BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnOverallActivity, info);
 }
Пример #3
0
        private ActivityDataDoc LoadData(DataReader reader)
        {
            //read signature
            int signature = reader.ReadInt32();

            //read head
            ActivityDataDoc ret = new ActivityDataDoc();

            ret.version = (int)reader.ReadByte();
            ret.year = (int)reader.ReadByte();
            ret.month = (int)reader.ReadByte();
            ret.day = (int)reader.ReadByte();

            //read data
            while (reader.UnconsumedBufferLength > 0)
            {
                var row = new ActivityDataRow();

                //row head
                row.mode = reader.ReadByte();
                row.hour = reader.ReadByte();
                row.minute = reader.ReadByte();

                //row meta
                int size = (int)reader.ReadByte();
                byte[] meta = new byte[4];
                reader.ReadBytes(meta);

                //row data
                for (int i = 0, j = 0; meta[i] != 0 && i < 4 && j < size; ++i)
                {
                    int lvalue = meta[i] >> 4;
                    int rvalue = meta[i] & 0x0f;

                    if (j < size)
                    {
                        int rawValue = reader.ReadInt32();
                        ActivityDataRow.DataType dtype = dataTypeMap[lvalue];
                        double value = GetValue(rawValue, dtype);
                        row.data.Add(dtype, value);
                        j++;
                    }

                    if (j < size)
                    {
                        int rawValue = reader.ReadInt32();
                        ActivityDataRow.DataType dtype = dataTypeMap[rvalue];
                        double value = GetValue(rawValue, dtype);
                        row.data.Add(dtype, value);
                        j++;
                    }
                }
                ret.data.Add(row);

            }
            return ret;
        }
Пример #4
0
        /****************************************************************
         * Public Functionalities
         **/
        public void AddActivities (ActivityDataDoc p_data)
        {
            if (p_data == null) { return; }
            if (p_data.data == null) { return; }
            if (p_data.data.Count == 0) { return; }
            List<ActivityDataRow> unitData = (List<ActivityDataRow>)p_data.data;

            foreach (ActivityDataRow row in unitData)
            {
                Kreyos_User_Activities act = new Kreyos_User_Activities();
                act.UpdateFromRow(row);
                this.AddActivity(act);
            }

            this.Save();
        }