コード例 #1
0
ファイル: Module.cs プロジェクト: robness/Vixen
        internal static bool Send(Data RdsData, string rdsText, bool force = false)
        {
            // Darren... is this still needed?
            //We dont want to keep hammering the RDS device with updates if they havent changed.
            if (!force && lastRdsText.Equals(rdsText))
            {
                return(false);
            }

            lastRdsText = rdsText;

            switch (RdsData.HardwareID)
            {
            case Hardware.MRDS192:
            case Hardware.MRDS1322:
                var portName = string.Format("COM{0}", RdsData.PortNumber);
                using (var rdsPort = new RdsSerialPort(portName, RdsData.Slow ? 2400 : 19200))
                {
                    Logging.Info("Sending to RDS serial device data:{0} at time:{1}", rdsText, DateTime.Now);
                    rdsPort.Send(rdsText);
                }
                return(false);

            case Hardware.VFMT212R:
            case Hardware.HTTP:
                Task.Factory.StartNew(() => {
                    try {
                        //string url = RdsData.HttpUrl.ToLower().Replace("{text}",HttpUtility.UrlEncode(rdsText)).Replace("{time}", HttpUtility.UrlEncode(DateTime.Now.ToLocalTime().ToShortTimeString()));
                        //JC 11/27/16- replaced with line below to remove lowercase force
                        string url = RdsData.HttpUrl.Replace("{text}", HttpUtility.UrlEncode(rdsText)).Replace("{time}", HttpUtility.UrlEncode(DateTime.Now.ToLocalTime().ToShortTimeString()));
                        Logging.Info("Sending web request to url:{0} at time:{1}", url, DateTime.Now);
                        WebRequest request = WebRequest.Create(url);
                        if (RdsData.RequireHTTPAuthentication)
                        {
                            request.Credentials = new NetworkCredential(RdsData.HttpUsername, RdsData.HttpPassword);
                        }
                        request.GetResponse();
                    } catch (Exception e) {
                        Logging.Error(e, e.Message);
                        lastRdsText = string.Empty;
                    }
                });
                return(true);

            default:
                return(false);
            }
        }
コード例 #2
0
ファイル: Module.cs プロジェクト: komby/vixen
        internal static bool Send(Data RdsData, string rdsText, string rdsArtist = null, bool sendps = false)
        {
            // Darren... is this still needed?
            //We dont want to keep hammering the RDS device with updates if they havent changed.
            if (lastRdsText.Equals(rdsText))
            {
                return(true);
            }
            else
            {
                lastRdsText = rdsText;
            }

            Console.WriteLine("Sending {0}: {1}", rdsText, DateTime.Now);
            switch (RdsData.HardwareID)
            {
            case Hardware.MRDS192:
            case Hardware.MRDS1322:
                var portName = string.Format("COM{0}", RdsData.PortNumber);
                using (var rdsPort = new RdsSerialPort(portName, RdsData.Slow ? 2400 : 19200))
                {
                    rdsPort.Send(rdsText);
                }

                //NativeMethods.ConnectionSetup(RdsData.ConnectionMode, RdsData.PortNumber, RdsData.BiDirectional, RdsData.Slow );
                //if (NativeMethods.Connect()) {
                //	try {
                //		int i, Len;
                //		byte[] Data;

                //		if (sendps) {
                //			Data = new byte[9];
                //			Data[0] = 0x02;             // buffer address
                //			Len = 8;
                //		} else {
                //			//need to set byte at 0x1F to 1 to enable RT
                //			NativeMethods.Send(1, new byte[1] { 0x1F });

                //			Data = new byte[65];
                //			Data[0] = 0x20;             // buffer address for RadioText
                //			Len = 64;                   // character length
                //		}

                //		for (i = 1; i <= Len; i++)
                //			Data[i] = 0x20; // fill 64 blank spaces first

                //		for (i = 0; i < rdsText.Length; i++) {
                //			byte vOut = Convert.ToByte(rdsText[i]);
                //			Data[i + 1] = vOut;
                //		}
                //		if (NativeMethods.Send(Len, Data))
                //			return true;
                //		else
                //			return false;
                //	} finally {
                //		NativeMethods.Disconnect();
                //	}
                //}
                return(false);

            case Hardware.VFMT212R:
            case Hardware.HTTP:
                System.Threading.Tasks.Task.Factory.StartNew(() => {
                    try {
                        string url = RdsData.HttpUrl.ToLower().Replace("{text}", HttpUtility.UrlEncode(rdsText)).Replace("{time}", HttpUtility.UrlEncode(DateTime.Now.ToLocalTime().ToShortTimeString()));
                        if (sendps)
                        {
                            //TODO: Enable the sendps code here.
                        }
                        WebRequest request = WebRequest.Create(url);
                        if (RdsData.RequireHTTPAuthentication)
                        {
                            request.Credentials = new NetworkCredential(RdsData.HttpUsername, RdsData.HttpPassword);
                        }
                        var response = request.GetResponse();
                    } catch (Exception e) {
                        Logging.ErrorException(e.Message, e);
                        lastRdsText = string.Empty;
                    }
                });
                return(true);

            default:
                return(false);
            }
        }
コード例 #3
0
ファイル: Module.cs プロジェクト: Jchuchla/vixen
        internal static bool Send(Data RdsData, string rdsText, string rdsArtist = null, bool sendps=false)
        {
            //We dont want to keep hammering the RDS device with updates if they havent changed.
            if (lastRdsText.Equals(rdsText))
                return true;
            else
                lastRdsText=rdsText;

            Console.WriteLine("Sending {0}: {1}", rdsText, DateTime.Now);
            switch (RdsData.HardwareID) {
                case Hardware.MRDS192:
                case Hardware.MRDS1322:
                    var portName = string.Format("COM{0}", RdsData.PortNumber);
                    using (var rdsPort = new RdsSerialPort(portName, RdsData.Slow ? 2400 : 19200))
                    {
                        rdsPort.Send(rdsText);
                    }

                    //NativeMethods.ConnectionSetup(RdsData.ConnectionMode, RdsData.PortNumber, RdsData.BiDirectional, RdsData.Slow );
                    //if (NativeMethods.Connect()) {
                    //	try {
                    //		int i, Len;
                    //		byte[] Data;

                    //		if (sendps) {
                    //			Data = new byte[9];
                    //			Data[0] = 0x02;             // buffer address
                    //			Len = 8;
                    //		} else {
                    //			//need to set byte at 0x1F to 1 to enable RT
                    //			NativeMethods.Send(1, new byte[1] { 0x1F });

                    //			Data = new byte[65];
                    //			Data[0] = 0x20;             // buffer address for RadioText
                    //			Len = 64;                   // character length
                    //		}

                    //		for (i = 1; i <= Len; i++)
                    //			Data[i] = 0x20; // fill 64 blank spaces first

                    //		for (i = 0; i < rdsText.Length; i++) {
                    //			byte vOut = Convert.ToByte(rdsText[i]);
                    //			Data[i + 1] = vOut;
                    //		}
                    //		if (NativeMethods.Send(Len, Data))
                    //			return true;
                    //		else
                    //			return false;
                    //	} finally {
                    //		NativeMethods.Disconnect();
                    //	}
                    //}
                    return false;
                case Hardware.VFMT212R:
                case Hardware.HTTP:
                    System.Threading.Tasks.Task.Factory.StartNew(() => {
                        try {
                            string url = RdsData.HttpUrl.ToLower().Replace("{text}",HttpUtility.UrlEncode(rdsText)).Replace("{time}", HttpUtility.UrlEncode(DateTime.Now.ToLocalTime().ToShortTimeString()));
                            if (sendps) {
                                //TODO: Enable the sendps code here.
                            }
                            WebRequest request = WebRequest.Create(url);
                            if (RdsData.RequireHTTPAuthentication) {
                                request.Credentials= new NetworkCredential(RdsData.HttpUsername, RdsData.HttpPassword);
                            }
                            var response = request.GetResponse();
                        } catch (Exception e) {
                            Logging.ErrorException(e.Message, e);
                            lastRdsText=string.Empty;
                        }
                    });
                    return true;
                default:
                    return false;
            }
        }