static void StartRobotInterface()
 {
     ConsoleFormat.StartRobotInterface();
     t1 = new Thread(() =>
     {
         //Attention, il est nécessaire d'ajouter PresentationFramework, PresentationCore, WindowBase and your wpf window application aux ressources.
         interfaceRobot         = new WpfRobot2RouesInterface(competition);
         interfaceRobot.Loaded += RegisterRobotInterfaceEvents;
         interfaceRobot.ShowDialog();
     });
     t1.SetApartmentState(ApartmentState.STA);
     t1.Start();
 }
示例#2
0
    public void RenderAnsiOutput_GivenFormat_AppliesAnsiEscapeSequences()
    {
        var format1 = new ConsoleFormat(Foreground: Red);
        var format2 = new ConsoleFormat(Foreground: Green);
        var output  = Prompt.RenderAnsiOutput("here is some output", new[]
        {
            new FormatSpan(0, 4, format1),
            new FormatSpan(8, 4, format2),
        }, 100);

        Assert.Equal(
            ToAnsiEscapeSequence(format1) + "here" + Reset + " is " + ToAnsiEscapeSequence(format2) + "some" + Reset + " output" + MoveCursorLeft(19),
            output
            );
    }
示例#3
0
    public async Task ReadLine_CJKCharacters_SyntaxHighlight()
    {
        var format1 = new ConsoleFormat(Foreground: Red);
        var format2 = new ConsoleFormat(Foreground: Blue);
        var format3 = new ConsoleFormat(Foreground: Green);

        var console = ConsoleStub.NewConsole(width: 20);

        console.StubInput($"苹果 o 蓝莓 o avocado o{Enter}");

        var prompt = new Prompt(
            callbacks: new TestPromptCallbacks
        {
            HighlightCallback = new SyntaxHighlighterTestData(new Dictionary <string, AnsiColor>
            {
                { "苹果", format1.Foreground !.Value },
示例#4
0
    public void RenderAnsiOutput_GivenFormatAndWrapping_AppliesAnsiEscapeSequences()
    {
        var format1 = new ConsoleFormat(Foreground: Red);
        var format2 = new ConsoleFormat(Foreground: Green);
        var output  = Prompt.RenderAnsiOutput("here is some output", new[]
        {
            new FormatSpan(0, 4, format1),
            new FormatSpan(8, 4, format2),
        }, 4);

        Assert.Equal(
            expected:
            ToAnsiEscapeSequence(format1) + "here\n" + MoveCursorLeft(3) +
            Reset + " is \n" + MoveCursorLeft(3) +
            ToAnsiEscapeSequence(format2) + "some\n" + MoveCursorLeft(3) +
            Reset + " out\n" + MoveCursorLeft(3) +
            "put" + MoveCursorLeft(3),
            actual: output
            );
    }
        static void Main(string[] args)
        {
            ConsoleFormat.InitMainConsole();


            /// Enregistrement de la license SciChart en début de code

            SciChartSurface.SetRuntimeLicenseKey(ConstVar.SCICHART_RUNTIME_KEY);
            ConsoleFormat.SetupScichartLicenceKey();

            /// Initialisation des modules utilisés dans le robot
            int robotId = (int)RobotId.Robot1;
            int teamId  = (int)TeamId.Team1;

            usbDriver    = new USBVendor();
            msgDecoder   = new MsgDecoder();
            msgEncoder   = new MsgEncoder();
            msgGenerator = new MsgGenerator();
            msgProcessor = new MsgProcessor(robotId, competition);
            ConsoleFormat.SetupAllCommunication();

            xBoxManette = new XBoxController(robotId);
            ConsoleFormat.SetupXboxController();

            logRecorder = new LogRecorder();
            logReplay   = new LogReplay();

            strategyManager = new StrategyEurobot(robotId, teamId, "224.16.32.79");

            #region Communication to Low Lvl
            /// Création des liens entre module, sauf depuis et vers l'interface graphique
            usbDriver.OnUSBuffReceivedEvent             += msgDecoder.BuffReceived;                        // Transmission des messages reçus par l'USB au Message Decoder
            msgDecoder.OnCorrectMessageReceivedEvent    += msgProcessor.ProcessRobotDecodedMessage;        // Transmission les messages décodés par le Message Decoder au Message Processor
            msgGenerator.OnMessageToRobotGeneratedEvent += msgEncoder.EncodeAndSendMessage;                // Envoi des messages du générateur de message à l'encoder
            msgEncoder.OnSendMessageEvent += usbDriver.SendUSBMessage;                                     // Envoi des messages en USB depuis le message encoder
            #endregion

            #region Console
            // Control:
            bool hex_viewer       = false;
            bool hex_sender       = false;
            bool hex_viewer_error = true;
            bool hex_sender_error = true;
            bool hex_processor    = false;
            bool hex_generator    = false;
            #region USB Vendor
            usbDriver.OnDeviceAddedEvent       += ConsoleFormat.PrintNewDeviceAdded;
            usbDriver.OnDeviceRemovedEvent     += ConsoleFormat.PrintDeviceRemoved;
            usbDriver.OnUsbVendorExeptionEvent += ConsoleFormat.PrintUsbErrorExeption;
            #endregion

            #region Hex Viewer
            if (hex_viewer)
            {
                msgDecoder.OnUnknowByteEvent                   += ConsoleFormat.PrintUnknowByte;
                msgDecoder.OnSOFByteReceivedEvent              += ConsoleFormat.PrintSOF;
                msgDecoder.OnFunctionMSBByteReceivedEvent      += ConsoleFormat.PrintFunctionMSB;
                msgDecoder.OnFunctionLSBByteReceivedEvent      += ConsoleFormat.PrintFunctionLSB;
                msgDecoder.OnPayloadLenghtMSBByteReceivedEvent += ConsoleFormat.PrintLenghtMSB;
                msgDecoder.OnPayloadLenghtLSBByteReceivedEvent += ConsoleFormat.PrintLenghtLSB;
                msgDecoder.OnPayloadByteReceivedEvent          += ConsoleFormat.PrintPayloadByte;
                msgDecoder.OnCorrectMessageReceivedEvent       += ConsoleFormat.PrintCorrectChecksum;
                msgDecoder.OnErrorMessageReceivedEvent         += ConsoleFormat.PrintWrongChecksum;
            }
            #endregion

            #region Hex Viewer Error
            if (hex_viewer_error)
            {
                msgDecoder.OnOverLenghtMessageEvent   += ConsoleFormat.PrintOverLenghtWarning;
                msgDecoder.OnUnknowFunctionEvent      += ConsoleFormat.PrintUnknowFunctionReceived;
                msgDecoder.OnWrongLenghtFunctionEvent += ConsoleFormat.PrintWrongFonctionLenghtReceived;
            }
            #endregion

            #region Hex Sender
            if (hex_sender)
            {
                msgEncoder.OnSendMessageByteEvent += ConsoleFormat.PrintSendMsg;
            }

            #endregion

            #region Hex Sender Error
            if (hex_sender_error)
            {
                msgEncoder.OnSerialDisconnectedEvent  += ConsoleFormat.PrintOnSerialDisconnectedError;
                msgEncoder.OnUnknownFunctionSentEvent += ConsoleFormat.PrintUnknowFunctionSent;
                msgEncoder.OnWrongPayloadSentEvent    += ConsoleFormat.PrintWrongFunctionLenghtSent;
            }
            #endregion
            #endregion



            #region Lidar
            lidar        = new SickLidar(17422959); // 18110177
            lidarProcess = new LidarProcess(robotId, teamId);

            lidar.OnLidarDeviceConnectedEvent += lidarProcess.OnNewLidarConnected;
            lidar.OnLidarDeviceConnectedEvent += ConsoleFormat.NewLidarDeviceConnected;
            lidar.PointsAvailable             += lidarProcess.OnRawPointAvailable;

            lidar.Start();
            #endregion

            lidarProcess.OnRawLidarDataEvent += logRecorder.OnRawLidarDataReceived;
            msgProcessor.OnSpeedPolarOdometryFromRobotEvent += logRecorder.OnPolarSpeedDataReceived;

            #region Local World Map
            localWorldMap = new LocalWorldMap(robotId, teamId);
            localWorldMap.OnUpdateRobotLocationEvent += lidarProcess.OnRobotLocation;


            lidarProcess.OnRawLidarPointPolarEvent      += localWorldMap.OnLidarRawPointReceived;
            lidarProcess.OnProcessLidarPolarDataEvent   += localWorldMap.OnLidarProcessedPointReceived;
            lidarProcess.OnProcessLidarLineDataEvent    += localWorldMap.OnLidarProcessedLineReceived;
            lidarProcess.OnProcessLidarCupDataEvent     += localWorldMap.OnLidarProcessedCupReceived;
            lidarProcess.OnLidarSetupRobotLocationEvent += localWorldMap.OnRobotLocation;

            //lidarProcess.OnProcessLidarObjectsDataEvent += localWorldMap.OnLidarProcesObjectsReceived;

            localWorldMap.OnLocalWorldMapEvent += strategyManager.OnLocalWorldMapReceived;

            localWorldMap.Init();
            #endregion

            #region Position2Wheels
            positioning2Wheels = new Positioning2Wheels(robotId);

            msgProcessor.OnSpeedPolarOdometryFromRobotEvent += positioning2Wheels.OnOdometryRobotSpeedReceived;
            positioning2Wheels.OnCalculatedLocationEvent    += localWorldMap.OnRobotLocationArgs;
            #endregion

            #region TrajectoryPlanner
            trajectoryPlanner = new TrajectoryPlanner(robotId);

            trajectoryPlanner.OnNewGhostLocationEvent   += localWorldMap.OnGhostLocation;
            trajectoryPlanner.OnNewRobotLocationEvent   += localWorldMap.OnRobotLocation;
            trajectoryPlanner.OnDestinationReachedEvent += strategyManager.OnGhostLocationReached;

            #endregion

            #region Strategy /!\Need to be Last /! \
            strategyManager.On2WheelsToPolarMatrixSetupEvent += msgGenerator.GenerateMessage2WheelsToPolarMatrixSet;   //Transmission des messages de set-up de la matrice de transformation moteurindepeandt -> polaire en embarqué
            strategyManager.On2WheelsAngleSetupEvent         += msgGenerator.GenerateMessage2WheelsAngleSet;           //Transmission des messages de set-up de la config angulaire des roues en embarqué
            strategyManager.OnOdometryPointToMeterSetupEvent += msgGenerator.GenerateMessageOdometryPointToMeter;      //Transmission des messages de set-up du coeff pointToMeter en embarqué
            strategyManager.OnSetAsservissementModeEvent     += msgGenerator.GenerateMessageSetAsservissementMode;

            strategyManager.OnDestinationReachedEvent += localWorldMap.OnDestinationReached;
            strategyManager.OnWaypointsReachedEvent   += localWorldMap.OnWaypointReached;

            strategyManager.OnSetActualLocationEvent     += trajectoryPlanner.OnUpdateActualLocation;
            strategyManager.OnSetWantedLocationEvent     += trajectoryPlanner.OnUpdateWantedDestination;
            strategyManager.OnGhostCalculationBeginEvent += trajectoryPlanner.OnLaunchCalculation;

            strategyManager.OnSetNewWaypointEvent    += localWorldMap.AddNewWaypointsEvent;
            strategyManager.OnSetNewDestinationEvent += localWorldMap.SetDestinationLocationEvent;

            strategyManager.OnUpdateGhostCalculationOrderEvent += trajectoryPlanner.OnCalculateGhostMovement;

            ConsoleFormat.PrintStrategyBoot();
            strategyManager.InitStrategy(); //à faire après avoir abonné les events !
            #endregion

            if (usingMatchDisplay)
            {
                StartMatchInterface();
            }
            else
            {
                StartRobotInterface();
            }

            ConsoleFormat.EndMainBootSequence();

            while (!exitSystem)
            {
                Thread.Sleep(500);
            }
        }
示例#6
0
 public static string ToAnsiEscapeSequence(ConsoleFormat formatting) =>
 Escape
 + "["
 + string.Join(
示例#7
0
 public FormattedString(string?text, ConsoleFormat formatting)
     : this(text, (text?.Length ?? 0) == 0 ? Array.Empty <FormatSpan>() : new[] { new FormatSpan(0, text !.Length, formatting) })