Пример #1
0
        public void showRaceFactory()
        {
            prepareForPanelChange(true);
            raceConfig = null;

            RaceFactoryPanel toAdd;

            if (ss_isActive && ss_savedPanel != null)
            {
                toAdd       = ss_savedPanel;
                ss_isActive = false;
            }
            else
            {
                toAdd = new RaceFactoryPanel(factoryComplete);
            }

            Grid_Content.Children.Add(toAdd);
            PanelState = panelState.RaceFactory;

            ss_lastActivity = DateTime.Now;

            if (AntPlusRacerConfig.getInstance().RecordScreenSaverTimeout_negativeIsOff > 0)
            {
                ss_ScreenSaverTimer.Start();
            }
        }
Пример #2
0
        public void showRecords()
        {
            if (ss_isActive)
            {
                ss_savedPanel = Grid_Content.Children[0] as RaceFactoryPanel;
            }

            prepareForPanelChange(true);

            Grid_Content.Children.Add(new TrackRecords.RecordDisplayPanel());
            PanelState = panelState.RecordDisplay;
        }
Пример #3
0
        private void decodeRaceControlCmd(RacePanel selectedPanel, byte[] lastMsgBytes)
        {
            switch (lastMsgBytes[3])
            {
            case 0:     //start
            {
                if (selectedPanel.PanelState != RacePanel.panelState.RaceFactory)
                {
                    sendResponse(RemoteControlReturnCodes.Error_PanelInWrongState, lastMsgBytes);
                    return;
                }

                RaceFactoryPanel factoryPanel = selectedPanel.Grid_Content.Children[0] as RaceFactoryPanel;
                if (!factoryPanel.startRace())
                {
                    sendResponse(RemoteControlReturnCodes.Error_RacersNotConfigured, lastMsgBytes);
                    return;
                }
                sendResponse(RemoteControlReturnCodes.Success, lastMsgBytes);
                return;
            }

            case 1:     //restart
            {
                if (selectedPanel.PanelState != RacePanel.panelState.Racing)
                {
                    sendResponse(RemoteControlReturnCodes.Error_PanelInWrongState, lastMsgBytes);
                    return;
                }

                selectedPanel.raceConfig.disposeRace();
                selectedPanel.raceConfig = new RaceDetails(selectedPanel.raceConfig.racerDetails, selectedPanel.raceConfig.target_type);
                selectedPanel.raceConfig.startRace(selectedPanel);
                sendResponse(RemoteControlReturnCodes.Success, lastMsgBytes);
                return;
            }

            case 2:     //cancel race
            {
                if (selectedPanel.PanelState != RacePanel.panelState.RaceFactory &&
                    selectedPanel.PanelState != RacePanel.panelState.Racing &&
                    selectedPanel.PanelState != RacePanel.panelState.PostRaceDisplay &&
                    selectedPanel.PanelState != RacePanel.panelState.PostRaceResults)
                {
                    sendResponse(RemoteControlReturnCodes.Error_PanelInWrongState, lastMsgBytes);
                    return;
                }

                selectedPanel.showRaceFactory();
                sendResponse(RemoteControlReturnCodes.Success, lastMsgBytes);
                return;
            }

            case 3:     //get current racer list
            {
                if (selectedPanel.PanelState != RacePanel.panelState.RaceFactory &&
                    selectedPanel.PanelState != RacePanel.panelState.Racing &&
                    selectedPanel.PanelState != RacePanel.panelState.PostRaceDisplay &&
                    selectedPanel.PanelState != RacePanel.panelState.PostRaceResults)
                {
                    sendResponse(RemoteControlReturnCodes.Error_PanelInWrongState, lastMsgBytes);
                    return;
                }


                List <RacerDetails> racerList;
                if (selectedPanel.PanelState == RacePanel.panelState.RaceFactory)
                {
                    racerList = ((RaceFactoryPanel)selectedPanel.Grid_Content.Children[0]).configuredRacers;
                }
                else
                {
                    racerList = selectedPanel.raceConfig.racerDetails;
                }


                List <byte> retMsg = new List <byte> {
                    (byte)racerList.Count
                };
                for (byte i = 0; i < racerList.Count; ++i)
                {
                    RacerDetails racer = racerList[i];
                    retMsg.Add(i);
                    retMsg.Add(racer.dataSource.uid);
                    retMsg.Add((byte)((ushort)racer.targetValue & 0xFF));
                    retMsg.Add((byte)(((ushort)racer.targetValue & 0xFF00) >> 8));
                    ushort curDistance = (ushort)racer.dataSource.getCurrentDistance();
                    retMsg.Add((byte)((ushort)curDistance & 0xFF));
                    retMsg.Add((byte)(((ushort)curDistance & 0xFF00) >> 8));
                    if (racer.racerRecordInfo != null)
                    {
                        if (!String.IsNullOrWhiteSpace(racer.racerRecordInfo.FirstName))
                        {
                            retMsg.Add(1);
                            retMsg.Add((byte)racer.racerRecordInfo.FirstName.Length);
                            retMsg.AddRange(UTF8Encoding.ASCII.GetBytes(racer.racerRecordInfo.FirstName));
                        }
                        if (!String.IsNullOrWhiteSpace(racer.racerRecordInfo.LastName))
                        {
                            retMsg.Add(2);
                            retMsg.Add((byte)racer.racerRecordInfo.LastName.Length);
                            retMsg.AddRange(UTF8Encoding.ASCII.GetBytes(racer.racerRecordInfo.LastName));
                        }
                        if (!String.IsNullOrWhiteSpace(racer.racerRecordInfo.PhoneNumber))
                        {
                            retMsg.Add(3);
                            retMsg.Add((byte)racer.racerRecordInfo.PhoneNumber.Length);
                            retMsg.AddRange(UTF8Encoding.ASCII.GetBytes(racer.racerRecordInfo.PhoneNumber));
                        }
                        if (!String.IsNullOrWhiteSpace(racer.racerRecordInfo.Email))
                        {
                            retMsg.Add(4);
                            retMsg.Add((byte)racer.racerRecordInfo.Email.Length);
                            retMsg.AddRange(UTF8Encoding.ASCII.GetBytes(racer.racerRecordInfo.Email));
                        }
                    }
                    retMsg.Add(0);          //Null term options list
                }
                sendResponse(RemoteControlReturnCodes.Success, lastMsgBytes, retMsg);
                return;
            }

            case 4:     //Config race
            {
                if (selectedPanel.PanelState != RacePanel.panelState.RaceFactory)
                {
                    if (selectedPanel.PanelState == RacePanel.panelState.ScreenSaverRecordDisplay)
                    {
                        selectedPanel.Dispatcher.Invoke((Action)selectedPanel.showRaceFactory);
                    }
                    else
                    {
                        sendResponse(RemoteControlReturnCodes.Error_PanelInWrongState, lastMsgBytes);
                        return;
                    }
                }

                selectedPanel.ss_lastActivity = DateTime.Now.Add(new TimeSpan(0, 0, 5));            //Give ourselves 5 seconds of extra time before screensaver to process ant messages
                RaceFactoryPanel factoryPanel = selectedPanel.Grid_Content.Children[0] as RaceFactoryPanel;

                if (lastMsgBytes[5] == 0xFF)
                {
                    if (factoryPanel.removeRacer(lastMsgBytes[4]))
                    {
                        sendResponse(RemoteControlReturnCodes.Success, lastMsgBytes);
                        return;
                    }
                    else
                    {
                        sendResponse(RemoteControlReturnCodes.Error_RacerDoesntExist, lastMsgBytes);
                        return;
                    }
                }

                byte sourceID = lastMsgBytes[5];

                DataSources.DataSourceBase dataSrc = null;
                foreach (AntPlusDevMgr.AntPlus_Connection i in AntConfigPanel.accessInstance().antMgr.deviceList)
                {
                    if (i.dataSource.uid == sourceID)
                    {
                        dataSrc = i.dataSource;
                        if (i.getConnStatus() != AntPlusDevMgr.AntPlus_Connection.ConnState.Connected)
                        {
                            sendResponse(RemoteControlReturnCodes.Error_DataSourceNotConnected, lastMsgBytes);
                            return;
                        }
                        break;
                    }
                }
                if (dataSrc == null)
                {
                    sendResponse(RemoteControlReturnCodes.Error_DataSourceDoesntExist, lastMsgBytes);
                    return;
                }

                double trackDist = 0;
                //Get the default (first) track for the given sport type
                foreach (AntPlusRacerConfig.RaceTrack i in AntPlusRacerConfig.getInstance().enabledRaceTracks)
                {
                    if (i.sportType == dataSrc.getSportType())
                    {
                        trackDist = i.distance;
                        break;
                    }
                }

                //decode options
                string firstName = null;
                string lastName  = null;
                string phoneNum  = null;
                string emailAdr  = null;
                int    curPos    = 6;
                while (curPos < lastMsgBytes.Length && lastMsgBytes[curPos] != 0)         //0 is the end of list marker
                {
                    int option = lastMsgBytes[curPos];
                    switch (option)
                    {
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                        int    strLength = lastMsgBytes[curPos + 1];
                        string str       = UTF8Encoding.ASCII.GetString(lastMsgBytes.Skip(curPos + 2).Take(strLength).ToArray());
                        switch (option)
                        {
                        case 1:
                            firstName = str;
                            break;

                        case 2:
                            lastName = str;
                            break;

                        case 3:
                            phoneNum = str;
                            break;

                        case 4:
                            emailAdr = str;
                            break;
                        }
                        curPos += 2 + strLength;
                        break;

                    default:
                        sendResponse(RemoteControlReturnCodes.Error_CmdFormatWrong, lastMsgBytes);
                        return;
                    }
                }

                if (curPos >= lastMsgBytes.Length)          //If we ended without hitting the end of the list
                {
                    sendResponse(RemoteControlReturnCodes.Error_CmdFormatWrong, lastMsgBytes);
                    return;
                }

                //Finally create/change the racer
                int ret = factoryPanel.configureRacer(lastMsgBytes[4], dataSrc, trackDist, firstName, lastName, phoneNum, emailAdr);

                if (ret == 0)
                {
                    sendResponse(RemoteControlReturnCodes.Success, lastMsgBytes);
                }
                else if (ret == -1)
                {
                    sendResponse(RemoteControlReturnCodes.Error_DataSourceInUse, lastMsgBytes);
                }
                else if (ret == -2)
                {
                    sendResponse(RemoteControlReturnCodes.Error_RacerDoesntExist, lastMsgBytes);
                }
                return;
            }

            default:
                sendResponse(RemoteControlReturnCodes.Error_CmdFormatWrong, lastMsgBytes);
                return;
            }
        }