Пример #1
0
        /****************************************************************************************************************************
        * FunctionName:SetSMSToDat
        * Parameters In:Tag,ID,ValidMinutes,Reserved,StartTime,Content
        * Parameters Out:DataBuf
        * Return Value:void
        * Device Used:Just for Black&White screen devices.sms.dat
        * Function:To convert the parameters to the byte array stored short messages
        * Auther:Darcy
        * Date:Oct.23, 2009
        *****************************************************************************************************************************/
        public void SetSMSToDat(out byte[] DataBuf, int Tag, int ID, int ValidMinutes, int Reserved, string StartTime, string Content)
        {
            DataBuf = new byte[72];
            byte[] ContentBuf = new byte[UDisk.MAX_SMS_CONTENT_SIZE+1];
            byte[] TempBuf = null;

            SMS sms = new 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));
        }
Пример #2
0
        /****************************************************************************************************************************
        * FunctionName:GetSMSFromDat
        * Parameters In:DataBuf
        * Parameters Out:Tag,ID,ValidMinutes,Reserved,StartTime,Content
        * Return Value:void
        * Device Used:Just for Black&White screen devices.sms.dat
        * Function:To parse the short messages byte array to independent parameters
        * Auther:Darcy
        * Date:Oct.23, 2009
        *****************************************************************************************************************************/
        public void GetSMSFromDat(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_SMS_CONTENT_SIZE+1];

            SMS sms = new SMS();
            sms=(SMS)Raw.RawDeserialize(DataBuf,typeof(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");
            }
            StartTime = dt.ToString();

            Array.Copy(DataBuf, 11, ContentBuf, 0, UDisk.MAX_SMS_CONTENT_SIZE + 1);

            Content = System.Text.Encoding.Default.GetString(ContentBuf);
        }