public const int MAX_SSR_SMS_CONTENT_SIZE = 160; //the max length of short message in the TFT screen devices /**************************************************************************************************************************** * FunctionName:GetSSRUserInfoFromDat * Parameters In:PDataBuf * Parameters Out:PIN,Privilege,Password,Name,Card,Group,TimeZones(string),PIN2(string) * Return Value:void * Device Used:user.dat in TFT screen Device * Function:To parse the bytes arrays from user.dat according to the class SSR_User and get out the independent parameters * Auther:Darcy * Date:Oct.23, 2009 *****************************************************************************************************************************/ public void GetSSRUserInfoFromDat(byte[] DataBuf, out int PIN, out int Privilege, out string Password, out string Name, out int Card, out int Group, out string TimeZone, out string PIN2) { byte[] PasswordBuf = new byte[8]; byte[] NameBuf = new byte[24]; byte[] TimeZoneBuf = new byte[8]; byte[] PIN2Buf = new byte[24]; SSR_User ssruser = new SSR_User(); ssruser = (SSR_User)Raw.RawDeserialize(DataBuf, typeof(SSR_User)); PIN = ssruser.PIN; Privilege = ssruser.Privilege; Array.Copy(DataBuf, 3, PasswordBuf, 0, 8); Password = System.Text.Encoding.Default.GetString(PasswordBuf); //"default" is to read the system's current ANSI code page encoding Array.Copy(DataBuf, 11, NameBuf, 0, 24); Name = System.Text.Encoding.Default.GetString(NameBuf); Card = 0; for (int i = 35; i <= 38; i++) { Card += Convert.ToInt32(DataBuf[i] * System.Math.Pow(16, 2 * (i - 35))); } Group = ssruser.Group; Array.Copy(DataBuf, 40, TimeZoneBuf, 0, 8); TimeZone = System.Text.Encoding.Default.GetString(TimeZoneBuf); Array.Copy(DataBuf, 48, PIN2Buf, 0, 24); PIN2 = System.Text.Encoding.Default.GetString(PIN2Buf); }
/**************************************************************************************************************************** * FunctionName:SetSSRUserInfoToDat * Parameters In:PIN,Privilege,Password,Name,Card,Group,TimeZones(string),PIN2(string) * Parameters Out:DataBuf * Return Value:void * Device Used:user.dat in TFT screen Device * Function:To convert the independent parameters to bytes arrays DataBuf according to the class SSR_User * Auther:Darcy * Date:Oct.23, 2009 *****************************************************************************************************************************/ public void SetSSRUserInfoToDat(out byte[] DataBuf, int PIN, int Privilege, string Password, string Name, int Card, int Group, string TimeZones, string PIN2) { DataBuf = new byte[72]; byte[] PasswordBuf = new byte[8]; byte[] NameBuf = new byte[24]; byte[] CardBuf = new byte[4]; byte[] TimeZonesBuf = new byte[8]; byte[] PIN2Buf = new byte[24]; SSR_User ssruser = new SSR_User(); ssruser.PIN = (ushort)PIN; ssruser.Privilege = (byte)Privilege; PasswordBuf = System.Text.Encoding.Default.GetBytes(Password); Array.Copy(PasswordBuf, ssruser.Password, 8); NameBuf = System.Text.Encoding.Default.GetBytes(Name); Array.Copy(NameBuf, ssruser.Name, 24); CardBuf = BitConverter.GetBytes(Card); Array.Copy(CardBuf, ssruser.Card, 4); ssruser.Group = (byte)Group; TimeZonesBuf = System.Text.Encoding.Default.GetBytes(TimeZones); ssruser.TimeZones[0] = (ushort)TimeZonesBuf[0]; //whether to use timezones or not (0 stands for yes,1 stands for defining by yourself) ssruser.TimeZones[1] = (ushort)TimeZonesBuf[1]; //(if you use the timezones)timezoune1 ssruser.TimeZones[2] = (ushort)TimeZonesBuf[2]; //timezone2 ssruser.TimeZones[3] = (ushort)TimeZonesBuf[3]; //timezone3 PIN2Buf = System.Text.Encoding.Default.GetBytes(PIN2); Array.Copy(PIN2Buf, ssruser.PIN2, 24); Array.Copy(Raw.RawSerialize(ssruser), DataBuf, 72); }