Beispiel #1
0
        /****************************************************************************************************************************
         * FunctionName:SetSSRSMSToDat
         * Parameters In:Tag,ID,ValidMinutes,Reserved,StartTime,Content
         * Parameters Out:DataBuf
         * Return Value:void
         * Device Used:Just for TFT screen devices.sms.dat
         * Function:To convert the parameters to the byte array stored short messages
         * Auther:Darcy
         * Date:Oct.23, 2009
         *****************************************************************************************************************************/
        public void SetSSRSMSToDat(out byte[] DataBuf, int Tag, int ID, int ValidMinutes, int Reserved, string StartTime, string Content)
        {
            DataBuf = new byte[332];
            byte[] ContentBuf = new byte[UDisk.MAX_SSR_SMS_CONTENT_SIZE * 2 + 1];
            byte[] TempBuf    = null;

            SSR_SMS sms = new SSR_SMS();

            sms.Tag          = (byte)Tag;
            sms.ID           = (ushort)ID;
            sms.ValidMinutes = (ushort)ValidMinutes;
            sms.Reserved     = (ushort)Reserved;

            //Encode time from string value type to unit value type
            DateTime dt = new DateTime();

            dt = Convert.ToDateTime(StartTime);
            int Time = ((dt.Year % 100) * 12 * 31 + ((dt.Month - 1) * 31) + dt.Day - 1) * (24 * 60 * 60) + (dt.Hour * 60 + dt.Minute) * 60 + dt.Second;

            sms.StartTime = (uint)Time;

            TempBuf = System.Text.Encoding.Default.GetBytes(Content);
            Array.Copy(TempBuf, sms.Content, TempBuf.Length);

            Array.Copy(Raw.RawSerialize(sms), DataBuf, Marshal.SizeOf(sms));
        }
Beispiel #2
0
        /****************************************************************************************************************************
         * FunctionName:GetSSRSMSFromDat
         * Parameters In:DataBuf
         * Parameters Out:Tag,ID,ValidMinutes,Reserved,StartTime,Content
         * Return Value:void
         * Device Used:Just for TFT screen devices.sms.dat
         * Function:To parse the short messages byte array to independent parameters
         * Auther:Darcy
         * Date:Oct.23, 2009
         *****************************************************************************************************************************/
        public void GetSSRSMSFromDat(byte[] DataBuf, out int Tag, out int ID, out int ValidMinutes, out int Reserved,
                                     out string StartTime, out string Content)
        {
            byte[] ContentBuf = new byte[UDisk.MAX_SSR_SMS_CONTENT_SIZE * 2 + 1];

            SSR_SMS sms = new SSR_SMS();

            sms = (SSR_SMS)Raw.RawDeserialize(DataBuf, typeof(SSR_SMS));

            Tag          = sms.Tag;
            ID           = sms.ID;
            ValidMinutes = sms.ValidMinutes;
            Reserved     = sms.Reserved;

            //decode time from uint value type to string value type
            int Time = (int)sms.StartTime;
            int Year, Month, Day, Hour, Minute, Second;

            Second = Time % 60;
            Time  /= 60;
            Minute = Time % 60;
            Time  /= 60;
            Hour   = Time % 24;
            Time  /= 24;
            Day    = Time % 31 + 1;
            Time  /= 31;
            Month  = Time % 12 + 1;
            Time  /= 12;
            Year   = Time + 2000;
            DateTime dt;

            try
            {
                dt = new DateTime((int)Year, (int)Month, (int)Day, (int)Hour, (int)Minute, (int)Second);
            }
            catch (Exception e)
            {
                dt = new DateTime(1970, 1, 1, 1, 1, 1);
                //MessageBox.Show(e.ToString(), "Error");
                Console.WriteLine(e.ToString(), "Error");
            }
            StartTime = dt.ToString();

            Array.Copy(DataBuf, 11, ContentBuf, 0, UDisk.MAX_SSR_SMS_CONTENT_SIZE * 2 + 1);
            Content = System.Text.Encoding.Default.GetString(ContentBuf);
        }