Esempio n. 1
0
        public RaceFactoryPanel(Action <RaceDetails> raceOutputRcvr)
        {
            InitializeComponent();
            raceRcvr = raceOutputRcvr;

            if (AntPlusRacerConfig.getInstance().autoLoadAvailableRaceSourcesForRace)
            {
                AntPlusDevMgr antMgr = AntConfigPanel.accessInstance().antMgr;
                for (int i = 0; i < antMgr.deviceList.Count; ++i)
                {
                    AntPlusDevMgr.AntPlus_Connection dev = antMgr.deviceList[i];
                    //Skip devices in use
                    if (dev.dataSource.isInUse || dev.getConnStatus() != AntPlusDevMgr.AntPlus_Connection.ConnState.Connected || isDataSourceReserved(dev.dataSource))
                    {
                        continue;
                    }
                    else
                    {
                        configureRacer(0xFF, dev.dataSource, AntPlusRacerConfig.getInstance().getDefaultRaceTrack(dev.dataSource.getSportType()).distance);
                    }
                }
                if (configuredRacers.Count == 0)
                {
                    DisplayRacerList();
                }
            }
            else
            {
                DisplayRacerList();
            }

            ComboBox_RaceLength.SizeChanged += new SizeChangedEventHandler((sender, args) => comboBoxAutoLblFontSize(sender as ComboBox));
        }
Esempio n. 2
0
        public static AntConfigPanel accessInstance()
        {
            if (instance == null)   //If the initializer failed we will have to rerun it each time
            {
                instance = new AntConfigPanel();
            }

            return(instance);
        }
        private void Button_Reset_Click(object sender, RoutedEventArgs e)
        {
            ushort searchForDeviceNum;

            try
            {
                searchForDeviceNum = ushort.Parse(TextBox_SearchDeviceId.Text);
                AntConfigPanel.accessInstance().antMgr.resetConnection(antPlusConnection, searchForDeviceNum);
            }
            catch (Exception)
            {
                TextBox_SearchDeviceId.Text = "error";
            }
        }
Esempio n. 4
0
        public void showAntConfig()
        {
            prepareForPanelChange(true);

            UIElement antCfg;

            try
            {
                antCfg = AntConfigPanel.getInstanceForDisplay();
            }
            catch (Exception ex)
            {
                Viewbox vb = new Viewbox();
                vb.Child = new Label()
                {
                    Content = "Error: " + ex.Message
                };
                antCfg = vb;
            }

            Grid_Content.Children.Add(antCfg);
            PanelState = panelState.Config;
        }
Esempio n. 5
0
        private void DisplayRacerConfig()
        {
            inRacerConfigScreen = true;

            //TODOb this only shows ant plus sources
            ListBox_RacerOrSources.Items.Clear();
            Button_AddRacer.Visibility     = System.Windows.Visibility.Hidden;
            ComboBox_RaceLength.Visibility = System.Windows.Visibility.Visible;
            Button_Start.Visibility        = System.Windows.Visibility.Hidden;
            Label_DisplayTitle.Content     = "Configure New Racer - Source and Track Length:";
            ComboBox_RaceLength.Items.Clear();

            AntPlusDevMgr antMgr    = AntConfigPanel.accessInstance().antMgr;
            Binding       widthBind = new Binding("ActualWidth");

            widthBind.Source = ListBox_RacerOrSources;

            bool select0 = false;

            dsOnDisplay = new List <DataSourceBase>();

            //Add current source
            if (racerIndexUnderConfig >= 0)
            {
                dsOnDisplay.Add(configuredRacers[racerIndexUnderConfig].dataSource);
                select0 = true;
            }

            for (int i = 0; i < antMgr.deviceList.Count; ++i)
            {
                AntPlusDevMgr.AntPlus_Connection dev = antMgr.deviceList[i];
                //Skip devices in use
                if (dev.dataSource.isInUse || dev.getConnStatus() != AntPlusDevMgr.AntPlus_Connection.ConnState.Connected || isDataSourceReserved(dev.dataSource))
                {
                    continue;
                }
                else
                {
                    dsOnDisplay.Add(dev.dataSource);
                }
            }

            if (dsOnDisplay.Count > 0)
            {
                foreach (DataSourceBase i in dsOnDisplay)
                {
                    //Show as option in list
                    Label name = new Label();
                    name.Content = i.getSportType() + "-" + i.getSourceName();
                    Viewbox vb = new Viewbox();
                    vb.SetBinding(Viewbox.WidthProperty, widthBind);
                    vb.Margin = new Thickness(0, 1, 20, 1);
                    vb.Child  = name;
                    ListBox_RacerOrSources.Items.Add(vb);

                    if (select0)
                    {
                        ListBox_RacerOrSources.SelectedIndex = 0;
                    }

                    Button_RacerAddOrFinish.IsEnabled    = true;
                    Button_RacerRemoveOrCancel.IsEnabled = true;
                }
            }
            else
            {
                Label_DisplayTitle.Content           = "...No Data Sources Available";
                Button_RacerAddOrFinish.IsEnabled    = false;
                Button_RacerRemoveOrCancel.IsEnabled = true;
            }

            Label lbl2 = new Label()
            {
                Content = "Save"
            };
            Viewbox vb2 = new Viewbox()
            {
                Child = lbl2
            };

            Button_RacerAddOrFinish.Content = vb2;
            Label lbl3 = new Label()
            {
                Content = "Cancel"
            };
            Viewbox vb3 = new Viewbox()
            {
                Child = lbl3
            };

            Button_RacerRemoveOrCancel.Content = vb3;
        }
Esempio n. 6
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;
            }
        }
Esempio n. 7
0
        private void decodeCmd(byte[] lastMsgBytes)
        {
            if (lastMsgBytes[0] == (byte)RemoteControlMsgId.RacerCmdId) //Racer CMD ID
            {
                switch ((RemoteControlMsgId)lastMsgBytes[1])
                {
                case RemoteControlMsgId.RequestDataSourceList:
                {
                    List <byte> response = new List <byte> {
                        (byte)AntConfigPanel.accessInstance().antMgr.deviceList.Count
                    };
                    foreach (AntPlusDevMgr.AntPlus_Connection i in AntConfigPanel.accessInstance().antMgr.deviceList)
                    {
                        response.AddRange(new byte[] { i.dataSource.uid,
                                                       (byte)i.dataSource.getSportType(),
                                                       (byte)i.getConnStatus(),
                                                       (byte)(i.dataSource.searchProfile.deviceNumber & 0x00FF),
                                                       (byte)((i.dataSource.searchProfile.deviceNumber & 0xFF00) >> 8),
                                                       i.dataSource.searchProfile.transType,
                                                       i.dataSource.searchProfile.deviceType,
                                                       Convert.ToByte(i.dataSource.isInUse),
                                                       (byte)i.dataSource.getSourceName().Length, });
                        response.AddRange(UTF8Encoding.ASCII.GetBytes(i.dataSource.getSourceName()));
                    }
                    sendResponse(RemoteControlReturnCodes.Success, lastMsgBytes, response);
                    return;
                }

                case RemoteControlMsgId.RaceControl:
                {
                    RacePanel selectedPanel = MainWindow.getInstance().getRacePanel(lastMsgBytes[2]);
                    if (selectedPanel == null)
                    {
                        sendResponse(RemoteControlReturnCodes.Error_PanelDoesntExist, lastMsgBytes);
                        return;
                    }
                    else
                    {
                        selectedPanel.Dispatcher.Invoke((Action <RacePanel, byte[]>)decodeRaceControlCmd, selectedPanel, lastMsgBytes);
                        return;
                    }
                }

                case RemoteControlMsgId.ScreenDisplayControl:
                {
                    RacePanel selectedPanel;
                    if (lastMsgBytes[2] == 0xFF)            //Create new panel
                    {
                        MainWindow wdw = MainWindow.getInstance();
                        selectedPanel = (RacePanel)wdw.Dispatcher.Invoke((Func <RacePanel>)wdw.addRacePanel);
                        if (selectedPanel == null)
                        {
                            sendResponse(RemoteControlReturnCodes.Error_MaxPanelLimitReached, lastMsgBytes);
                            return;
                        }
                    }
                    else
                    {
                        selectedPanel = MainWindow.getInstance().getRacePanel(lastMsgBytes[2]);
                        if (selectedPanel == null)
                        {
                            sendResponse(RemoteControlReturnCodes.Error_PanelDoesntExist, lastMsgBytes);
                            return;
                        }
                    }

                    switch (lastMsgBytes[3])
                    {
                    case 0:             //Show Config
                        selectedPanel.Dispatcher.Invoke((Action)selectedPanel.showAntConfig);
                        break;

                    case 1:             //New Race
                        selectedPanel.Dispatcher.Invoke((Action)selectedPanel.showRaces);
                        break;

                    case 2:             //Record Display
                        selectedPanel.Dispatcher.Invoke((Action)selectedPanel.showRecords);
                        break;

                    case 3:
                        bool ret = (bool)selectedPanel.Dispatcher.Invoke((Func <bool>)selectedPanel.closePanel);
                        if (!ret)
                        {
                            sendResponse(RemoteControlReturnCodes.Error_ClosingLastPanel, lastMsgBytes);
                            return;
                        }
                        break;

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

                    selectedPanel.Dispatcher.Invoke((Action)selectedPanel.hideMenu);
                    sendResponse(RemoteControlReturnCodes.Success, lastMsgBytes);
                    return;
                }

                default:
                    sendResponse(RemoteControlReturnCodes.Error_CmdFormatWrong, lastMsgBytes);
                    return;
                }
            }
            else //device is not a racer cmd
            {
                sendResponse(RemoteControlReturnCodes.Error_CmdFormatWrong, lastMsgBytes);
                return;
            }
        }