Ejemplo n.º 1
0
        public void DecodeCDStatusCode(string input, byte[] bytes)
        {
            // This function serves as the decoder, where it takes the output of the CD player and makes it human-readable.
            // Send output as the two values and save them.
            string RawHEX   = ByteArrayToString(bytes);
            string ASCIIHEX = ConvertHex(ByteArrayToString(bytes));

            SetText1(RawHEX); // Set raw hex in box 1.

            //Some command add extra FF's so a starting with-check is done with all commands.
            //Starts with 0805412093: No disc in drive.
            //Starts with 0805412095: Table Of Contents ready.
            //Starts with 6f0705412081: TOC Fully read
            //Starts with 6f0705412080: There is no CD or CD that specified request command.
            //Starts with 6f0705410240: Disc ejected.
            //Starts with 6f0705410202: Playback stopped
            //Starts with 6f0705410203: Playback paused
            //Starts with 0705410202: Operation  has  stopped
            //Starts with 6f0c054120200280: Repeat set to off.
            //Starts with 6f0c054120200290: Repeat set to all.
            //Starts with 6f0c0541202002a0: Repeat set to 1 track.
            //Starts with 6f0705412083: Track End. (For pause on 1 track mode)
            //Starts with 6f0705412084: Last 30 seconds of track are now!
            //Starts with 6f0b0541205001: Track selection successful. Add two extra for track number.
            //Starts with 6f0705410201: Started playback.
            //Starts with 502d4431: Model number acknoledgement.
            //Is 0403ff: Impossible command recieved

            if (RawHEX.StartsWith("0805412093")) // This looks at the command 93. No disc in drive.
            {
                //Starts with 0805412093: No disc in drive.
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        SystemStatus.AppendText("No disc in drive!" + Environment.NewLine);
                    }));
                }
            }
            if (RawHEX.StartsWith("0805412095"))
            {
                //Starts with 0805412095: Table Of Contents ready.
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        SystemStatus.AppendText("TOC Ready." + Environment.NewLine);
                    }));
                }
            }
            if (RawHEX.StartsWith("6f0705412081"))
            {
                //Starts with 6f0705412081: TOC Fully read
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        SystemStatus.AppendText("TOC Fully read." + Environment.NewLine);
                    }));
                }
            }
            if (RawHEX.StartsWith("6f0705412080"))
            {
                //Starts with 6f0705412080: There is no CD or CD that specified request command.
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        SystemStatus.AppendText("No CD or non-requested command." + Environment.NewLine);
                    }));
                }
            }
            if (RawHEX.StartsWith("6f0705410240"))
            {
                //Starts with 6f0705410240: Disc ejected.
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        SystemStatus.AppendText("Disc ejected." + Environment.NewLine);
                    }));
                }
            }
            if (RawHEX.StartsWith("6f0705410202"))
            {
                //Starts with 6f0705410202: Playback stopped
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        SystemStatus.AppendText("Playback stopped." + Environment.NewLine);
                    }));
                }
            }
            if (RawHEX.StartsWith("6f0705410203"))
            {
                //Starts with 6f0705410203: Playback paused
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        SystemStatus.AppendText("Playback paused." + Environment.NewLine);
                    }));
                }
            }
            if (RawHEX.StartsWith("0705410202"))
            {
                //Starts with 0705410202: Operation  has  stopped
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        SystemStatus.AppendText("Operation stopped." + Environment.NewLine);
                    }));
                }
            }
            if (RawHEX.StartsWith("6f0c054120200280"))
            {
                //Starts with 6f0c054120200280: Repeat set to off.

                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        SystemStatus.AppendText("Repeat set to off." + Environment.NewLine);
                    }));
                }
            }
            if (RawHEX.StartsWith("6f0c054120200290"))
            {
                //Starts with 6f0c054120200290: Repeat set to all.
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        SystemStatus.AppendText("Repeat set to all tracks." + Environment.NewLine);
                    }));
                }
            }
            if (RawHEX.StartsWith("6f0c0541202002a0"))
            {
                //Starts with 6f0c0541202002a0: Repeat set to 1 track.
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        SystemStatus.AppendText("Repeat set to 1 track." + Environment.NewLine);
                    }));
                }
            }
            if (RawHEX.StartsWith("6f0705412083"))
            {
                //Starts with 6f0705412083: Track End. (For pause on 1 track mode)
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        SystemStatus.AppendText("Track ended." + Environment.NewLine);
                    }));
                }
            }
            if (RawHEX.StartsWith("6f0705412084"))
            {
                //Starts with 6f0705412084: Last 30 seconds of track are now!
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        SystemStatus.AppendText("Track's got 30 sec. left." + Environment.NewLine);
                    }));
                }
            }


            if (RawHEX.StartsWith("6f0b0541205001"))
            {
                //Starts with 6f0b0541205001: Track selection successful. Add two extra for track number.
                // Todo, 6f0b0541205001 has one hex value at the end which is the track number.
                string TrackHEX    = RawHEX.Substring(RawHEX.Length - 2);
                int    TrackNumber = int.Parse(TrackHEX, System.Globalization.NumberStyles.HexNumber);
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        SystemStatus.AppendText("Track switch to " + TrackNumber + " successful!" + Environment.NewLine);
                    }));
                }
            }
            if (RawHEX.StartsWith("6f0705410201"))
            {
                //Starts with 6f0705410201: Start-From command executed.
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        SystemStatus.AppendText("Started playing." + Environment.NewLine);
                    }));
                }
            }
            if (RawHEX.StartsWith("0403ff"))
            {
                //Is 0403ff: Impossible command recieved
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        SystemStatus.AppendText("Impossible action requested?" + Environment.NewLine);
                    }));
                }
            }
            if (RawHEX.StartsWith("502d4431"))
            {
                // LIsten for the start of a model number and acknoledge it in the interface.
                string Model = RawHEX;
                if (InvokeRequired)
                {
                    this.Invoke(new MethodInvoker(delegate
                    {
                        // For some reason needs two NewLines??
                        SystemStatus.AppendText(Environment.NewLine + "Model number: " + "CD" + HexString2Ascii(Model) + Environment.NewLine);
                    }));
                }
            }
        }