예제 #1
0
 internal Compiler(ArgHandler args)
 {
     _args = args;
 }
예제 #2
0
        private static int Main(string[] userArgs)
        {
            try
            {
                // Handle args:
                var args = new ArgHandler(userArgs);

                // Search for target device amongst connected usb hid devices:
                var hidManager    = new HidManager();
                var isTargetFound = hidManager.FindDevice((short)args.UsbVendorId, (short)args.UsbProductId);
                if (!isTargetFound)
                {
                    Logger.Log("USB transfer failed.\n", Logger.LOG_INFO);
                    return((int)ExitCode.TransferFailed);
                }
                Console.WriteLine($"USB device found (VendorID {args.UsbVendorId}, ProductID {args.UsbProductId}).");

                // Send break packet:
                var breakPacket = new byte[args.UsbPacketByteSize];
                for (int i = 0; i < breakPacket.Length; i++)
                {
                    breakPacket[i] = 0xFF;
                }
                Logger.Log("Break packet: ", Logger.LOG_DBG);
                if (!hidManager.SendBreakPacket(breakPacket))
                {
                    var e = new Exception($"USB transfer failed.");
                    e.Data.Add("ExitCode", (int)ExitCode.TransferFailed);
                    throw e;
                }

                // Transfer data packets:
                int packetIdx          = 0;
                int packetSuccessCount = 0;
                int totalPackets       = args.UsbPacketList.Count;
                foreach (var dataPacket in args.UsbPacketList)
                {
                    Logger.Log("Data packet " + ++packetIdx + ": ", Logger.LOG_DBG);
                    if (!hidManager.SendDataPacket(dataPacket))
                    {
                        Logger.Log("USB transfer failed.\n", Logger.LOG_INFO);
                        Logger.Log(packetSuccessCount + " out of " + totalPackets + " data-packets sent.\n", Logger.LOG_INFO);
                        return((int)ExitCode.TransferFailed);
                    }
                    packetSuccessCount++;
                }

                if (args.DownloadLightshow)
                {
                    Logger.Log("Break packet: ", Logger.LOG_DBG);
                    if (!hidManager.SendBreakPacket(breakPacket))
                    {
                        Logger.Log("USB transfer failed.\n", Logger.LOG_INFO);
                        return((int)ExitCode.TransferFailed);
                    }
                }

                Logger.Log("USB transfer succeeded: ", Logger.LOG_INFO);
                Logger.Log(packetSuccessCount + " out of " + totalPackets + " data-packets sent.\n", Logger.LOG_INFO);
                return((int)ExitCode.Success);
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
                return(e.Data["ExitCode"] != null ? (int)e.Data["ExitCode"] : 1);
            }
        }
예제 #3
0
        private static int Main(string[] userArgs)
        {
            Console.WriteLine("Starting build...");

            try
            {
                // Handle args:
                var args = new ArgHandler(userArgs);

                if (args.Lines == null && args.Lines.Count() == 0)
                {
                    Console.WriteLine($"Empty or invalid code file.");
                    throw new Exception();
                }

                // Remove comments, extra whitespace, tabs, empty lines, etc:
                var codeLines = CodeCleanup(args.Lines);

                // Store code lines in their respective table:
                PopulateCodeTables(codeLines);

                // Build tables:
                DeviceTable.Build();
                DefineTable.Build();
                FunctionTable.Build();

                // Compile/link start function:
                var compiler     = new Compiler(args);
                var isSuccessful = compiler.Compile(out byte[] lightshowByteArray, out uint contextRegionByteSize, out uint maxInstrPathByteSize, out int threadCount);
                if (lightshowByteArray == null)
                {
                    Console.WriteLine("No build data generated.");
                    throw new Exception();
                }
                if (DeviceTable.Dev.SimulatorBrightnessCoeff == 0)
                {
                    Console.WriteLine("Invalid simulator brightness coefficient.");
                    throw new Exception();
                }
                Console.WriteLine($"Device threads usage: {Math.Round(100f * threadCount / DeviceTable.Proto.MaxThreads, 1):F1}% ({threadCount} of {DeviceTable.Proto.MaxThreads} threads).");
                CheckMemoryUsage(lightshowByteArray, contextRegionByteSize, maxInstrPathByteSize);

                Console.WriteLine("Build completed successfully.");

                // Generate output files (xml/bin):
                var controlPacketGenerator     = new ControlPacketGenerator(args);
                var downloadLightshowByteArray = controlPacketGenerator.GetDownloadLightshowPackets(lightshowByteArray);
                var startLightshowByteArray    = controlPacketGenerator.GetStartLightshowPacket();
                var pauseLightshowByteArray    = controlPacketGenerator.GetPauseLightshowPacket();
                var resumeLightshowByteArray   = controlPacketGenerator.GetResumeLightshowPacket();
                var outputXmlFilePath          = Path.Combine(Path.GetDirectoryName(args.InputFilePath), Path.GetFileNameWithoutExtension(args.InputFilePath) + ".xml");
                var outputBinFilePath          = Path.Combine(Path.GetDirectoryName(args.InputFilePath), Path.GetFileNameWithoutExtension(args.InputFilePath) + ".bin");
                PrintOutput(
                    lightshowByteArray, downloadLightshowByteArray, startLightshowByteArray, pauseLightshowByteArray, resumeLightshowByteArray,
                    outputXmlFilePath, outputBinFilePath);

                return((int)ExitCode.Success);
            }
            catch
            {
                return((int)ExitCode.Fail);
            }
        }
 internal ControlPacketGenerator(ArgHandler args)
 {
     _args = args;
 }