Пример #1
0
        public void StatusUpdate()
        {
            PMUSBInterface.CSAFECommand cmd = CreateCommand();
            cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_GETSERIAL_CMD);

            List <uint> data = cmd.Execute();

            uint currentbyte = 0;
            uint datalength  = 0;

            if (data[(int)currentbyte] == (uint)PMUSBInterface.CSAFECommands.CSAFE_GETSERIAL_CMD)
            {
                currentbyte++;
                datalength = data[(int)currentbyte];
                currentbyte++;

                Serial += (char)data[(int)currentbyte];
                Serial += (char)data[(int)currentbyte + 1];
                Serial += (char)data[(int)currentbyte + 2];
                Serial += (char)data[(int)currentbyte + 3];
                Serial += (char)data[(int)currentbyte + 4];
                Serial += (char)data[(int)currentbyte + 5];
                Serial += (char)data[(int)currentbyte + 6];
                Serial += (char)data[(int)currentbyte + 7];
                Serial += (char)data[(int)currentbyte + 8];

                currentbyte += datalength;
            }

            IsStatusInited = true;
        }
Пример #2
0
 public void Start()
 {
     PMUSBInterface.CSAFECommand cmd = CreateCommand();
     cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_GOHAVEID_CMD);
     cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_GOINUSE_CMD);
     cmd.Execute();
 }
Пример #3
0
 public void Reset()
 {
     PMUSBInterface.CSAFECommand cmd = CreateCommand();
     cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_GOFINISHED_CMD);
     cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_GOIDLE_CMD);
     cmd.Execute();
 }
Пример #4
0
        public void Test()
        {
            PMUSBInterface.CSAFECommand cmd = CreateCommand();

            /*cmd.CommandsBytes.Add(0x21);
            *  cmd.CommandsBytes.Add(0x03);
            *  cmd.CommandsBytes.Add(0x03);
            *  cmd.CommandsBytes.Add(0x00);
            *  cmd.CommandsBytes.Add(0x21);
            *  cmd.CommandsBytes.Add(0x1a);
            *  cmd.CommandsBytes.Add(0x07);
            *  cmd.CommandsBytes.Add(0x05);
            *  cmd.CommandsBytes.Add(0x05);
            *  cmd.CommandsBytes.Add(0x80);
            *  cmd.CommandsBytes.Add(0xf4);
            *  cmd.CommandsBytes.Add(0x01);
            *  cmd.CommandsBytes.Add(0x00);
            *  cmd.CommandsBytes.Add(0x00);
            *  cmd.CommandsBytes.Add(0x34);
            *  cmd.CommandsBytes.Add(0x03);
            *  cmd.CommandsBytes.Add(0x2c);
            *  cmd.CommandsBytes.Add(0x01);
            *  cmd.CommandsBytes.Add(0x58);*/
            cmd.CommandsBytes.Add(0x24);
            cmd.CommandsBytes.Add(0x02);
            cmd.CommandsBytes.Add(0x00);
            cmd.CommandsBytes.Add(0x00);
            cmd.CommandsBytes.Add(0x85);

            List <uint> ret = cmd.Execute();
        }
Пример #5
0
        public TimeSpan GetTimeWork()
        {
            PMUSBInterface.CSAFECommand cmd = CreateCommand();
            cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_GETTWORK_CMD);
            List <uint> data = cmd.Execute();

            return(new TimeSpan((int)data[2], (int)data[3], (int)data[4]));
        }
Пример #6
0
        public uint GetHorizontalDistance()
        {
            PMUSBInterface.CSAFECommand cmd = CreateCommand();
            cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_GETHORIZONTAL_CMD);
            List <uint> data = cmd.Execute();
            uint        dist = (data[3] * 256) + data[2];

            return(dist);
        }
Пример #7
0
 public void SetWorkout(PMUSBInterface.WorkoutTypes type)
 {
     PMUSBInterface.CSAFECommand cmd = CreateCommand();
     cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_SETPROGRAM_CMD);
     cmd.CommandsBytes.Add(0x02);
     cmd.CommandsBytes.Add((uint)type);
     cmd.CommandsBytes.Add(0x00);
     cmd.Execute();
 }
Пример #8
0
        public void HighResolutionUpdate()
        {
            // Get the stroke state
            PMUSBInterface.CSAFECommand cmd = CreateCommand();
            cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_SETUSERCFG1_CMD);
            cmd.CommandsBytes.Add(0x02);
            cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_PM_GET_STROKESTATE);
            cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_PM_GET_WORKOUTSTATE);

            List <uint> data        = cmd.Execute();
            uint        currentbyte = 0;
            uint        datalength  = 0;

            if (data[(int)currentbyte] == (uint)PMUSBInterface.CSAFECommands.CSAFE_SETUSERCFG1_CMD)
            {
                currentbyte += 2;
            }

            if (data[(int)currentbyte] == (uint)PMUSBInterface.CSAFECommands.CSAFE_PM_GET_STROKESTATE)
            {
                currentbyte++;
                datalength = data[(int)currentbyte];
                currentbyte++;

                switch (data[(int)currentbyte])
                {
                case 0:
                case 1:
                    StrokePhase = StrokePhase.Catch;
                    break;

                case 2:
                    StrokePhase = StrokePhase.Drive;
                    break;

                case 3:
                    StrokePhase = StrokePhase.Dwell;
                    break;

                case 4:
                    StrokePhase = StrokePhase.Recovery;
                    break;
                }
                currentbyte++;
            }
            if (data[(int)currentbyte] == (uint)PMUSBInterface.CSAFECommands.CSAFE_PM_GET_WORKOUTSTATE)
            {
                currentbyte++;
                datalength = data[(int)currentbyte];
                currentbyte++;

                WorkoutState = data[(int)currentbyte];

                currentbyte += datalength;
            }
        }
Пример #9
0
 public void SetTimeWork(TimeSpan time)
 {
     PMUSBInterface.CSAFECommand cmd = CreateCommand();
     cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_SETTWORK_CMD);
     cmd.CommandsBytes.Add(0x03);
     //cmd.CommandsBytes.Add(0x00);
     //cmd.CommandsBytes.Add(0x07);
     //cmd.CommandsBytes.Add(0x1E);
     cmd.CommandsBytes.Add(BitConverter.GetBytes(time.Hours)[0]);
     cmd.CommandsBytes.Add(BitConverter.GetBytes(time.Minutes)[0]);
     cmd.CommandsBytes.Add(BitConverter.GetBytes(time.Seconds)[0]);
     cmd.Execute();
 }
Пример #10
0
        public TimeSpan GetWorkTime()
        {
            while (true)
            {
                PMUSBInterface.CSAFECommand cmd = CreateCommand();
                cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_SETUSERCFG1_CMD1);
                cmd.CommandsBytes.Add(0x01);
                cmd.CommandsBytes.Add(0xA0); //worktime CSAFE_PM_GET_WORKTIME
                List <uint> data = cmd.Execute();
                Console.Clear();
                Console.WriteLine(data[2] + "," + data[3] + "," + data[4] + "," + data[5] + "," + data[6] + "," + data[7] + "," + data[8] + "," + data[9] + "," + data[10]);
                Thread.Sleep(100);
            }
            TimeSpan t = new TimeSpan();

            return(t);
        }
Пример #11
0
        public void SetHorizontalDistance(int value, PMUSBInterface.CSAFEUnits unit)
        {
            PMUSBInterface.CSAFECommand cmd = CreateCommand();
            cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_SETHORIZONTAL_CMD);
            cmd.CommandsBytes.Add(0x03);
            byte[] bytes = BitConverter.GetBytes(value);

            /*switch (unit)
             * {
             *  case PMUSBInterface.CSAFEUnits.Kilometers:
             *      cmd.CommandsBytes.Add(bytes[0]);
             *      cmd.CommandsBytes.Add(0x00);
             *      break;
             *  case PMUSBInterface.CSAFEUnits.Meters:*/
            cmd.CommandsBytes.Add(bytes[0]);
            cmd.CommandsBytes.Add(bytes[1]);

            /*        break;
             * }*/
            cmd.CommandsBytes.Add((uint)unit);
            //cmd.CommandsBytes.Add(0x85);
            cmd.Execute();
        }
Пример #12
0
        public void LowResolutionUpdate()
        {
            PMUSBInterface.CSAFECommand cmd = CreateCommand();

            // Header and number of extension commands.
            cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_SETUSERCFG1_CMD);
            cmd.CommandsBytes.Add(0x03);

            // Three PM3 extension commands.
            cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_PM_GET_DRAGFACTOR);
            cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_PM_GET_WORKDISTANCE);
            cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_PM_GET_WORKTIME);

            // Standard commands.
            cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_GETPACE_CMD);
            cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_GETPOWER_CMD);
            cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_GETCADENCE_CMD);
            cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_GETHRCUR_CMD);
            cmd.CommandsBytes.Add((uint)PMUSBInterface.CSAFECommands.CSAFE_GETCALORIES_CMD);

            List <uint> data = cmd.Execute();

            uint currentbyte = 0;
            uint datalength  = 0;

            if (data[(int)currentbyte] == (uint)PMUSBInterface.CSAFECommands.CSAFE_SETUSERCFG1_CMD)
            {
                currentbyte += 2;
            }
            if (data[(int)currentbyte] == (uint)PMUSBInterface.CSAFECommands.CSAFE_PM_GET_DRAGFACTOR)
            {
                currentbyte++;
                datalength = data[(int)currentbyte];
                currentbyte++;

                DragFactor = data[(int)currentbyte];

                currentbyte += datalength;
            }
            if (data[(int)currentbyte] == (uint)PMUSBInterface.CSAFECommands.CSAFE_PM_GET_WORKDISTANCE)
            {
                currentbyte++;
                datalength = data[(int)currentbyte];
                currentbyte++;

                uint distanceTemp = (data[(int)currentbyte] + (data[(int)currentbyte + 1] << 8) + (data[(int)currentbyte + 2] << 16) + (data[(int)currentbyte + 3] << 24)) / 10;
                uint fractionTemp = data[(int)currentbyte + 4];

                Distance = (float)distanceTemp + ((float)fractionTemp / 10.0f);

                currentbyte += datalength;
            }
            if (data[(int)currentbyte] == (uint)PMUSBInterface.CSAFECommands.CSAFE_PM_GET_WORKTIME)
            {
                currentbyte++;
                datalength = data[(int)currentbyte];
                currentbyte++;

                if (datalength == 5)
                {
                    uint timeInSeconds = (data[(int)currentbyte] + (data[(int)currentbyte + 1] << 8) + (data[(int)currentbyte + 2] << 16) + (data[(int)currentbyte + 3] << 24)) / 100;
                    uint fraction      = data[(int)currentbyte + 4];

                    Worktime = (float)timeInSeconds + ((float)fraction / 100.0f);
                }
                currentbyte += datalength;
            }
            if (data[(int)currentbyte] == (uint)PMUSBInterface.CSAFECommands.CSAFE_GETPACE_CMD)
            {
                currentbyte++;
                datalength = data[(int)currentbyte];
                currentbyte++;

                // Pace is in seconds/Km
                uint pace = data[(int)currentbyte] + (data[(int)currentbyte + 1] << 8);
                // get pace in seconds / 500m
                double fPace = pace / 2.0;
                Pace = (float)fPace;

                currentbyte += datalength;
            }
            if (data[(int)currentbyte] == (uint)PMUSBInterface.CSAFECommands.CSAFE_GETPOWER_CMD)
            {
                currentbyte++;
                datalength = data[(int)currentbyte];
                currentbyte++;

                Power = data[(int)currentbyte] + (data[(int)currentbyte + 1] << 8);

                currentbyte += datalength;
            }
            if (data[(int)currentbyte] == (uint)PMUSBInterface.CSAFECommands.CSAFE_GETCADENCE_CMD)
            {
                currentbyte++;
                datalength = data[(int)currentbyte];
                currentbyte++;

                uint currentSPM = data[(int)currentbyte];

                if (0 < currentSPM)
                {
                    nSPM += currentSPM;
                    nSPMReads++;

                    SPM    = currentSPM;
                    SPMAvg = ((float)nSPM * 1.0f) / ((float)nSPMReads * 1.0f);
                }

                currentbyte += datalength;
            }
            if (data[(int)currentbyte] == (uint)PMUSBInterface.CSAFECommands.CSAFE_GETHRCUR_CMD)
            {
                currentbyte++;
                datalength = data[(int)currentbyte];
                currentbyte++;

                uint currentHeartBeat = data[(int)currentbyte];
                Heartrate = currentHeartBeat;

                currentbyte += datalength;
            }
            if (data[(int)currentbyte] == (uint)PMUSBInterface.CSAFECommands.CSAFE_GETCALORIES_CMD)
            {
                currentbyte++;
                datalength = data[(int)currentbyte];
                currentbyte++;

                uint currentCalories = data[(int)currentbyte] + (data[(int)currentbyte + 1] << 8);
                Calories = currentCalories;

                currentbyte += datalength;
            }
        }