/**************************************************************************************************************************** * FunctionName:SetTemplateToDat * Parameters In:Size,PIN,FingerID,Valid,Template * Parameters Out:DataBuf * Return Value:void * Device Used:template.dat in Black&White screen devices using 9.0 arithmetic * Function:To convert the independent parameters to bytes arrays DataBuf according to the class Template * Explanation:To write according to the max finger templage 602bytes * Auther:Darcy * Date:Oct.23, 2009 *****************************************************************************************************************************/ public void SetTemplateToDat(out byte[] DataBuf, int Size, int PIN, int FingerID, int Valid, string Template) { DataBuf = new byte[2048]; //[608]; byte[] TemplateBuf = new byte[2048]; //[602]; Templates9 tmp = new Templates9(); tmp.Size = (ushort)Size; tmp.PIN = (ushort)PIN; tmp.FingerID = (byte)FingerID; tmp.Valid = (byte)Valid; Template = Template.Replace(" ", ""); if (Template.Length <= 0) { Template = ""; } byte[] TemplateBytes = new byte[Template.Length / 2]; for (int i = 0; i < Template.Length; i += 2) { if (!byte.TryParse(Template.Substring(i, 2), NumberStyles.HexNumber, null, out TemplateBytes[i / 2])) { TemplateBytes[i / 2] = 0; } } string TemplateFromHex = ASCIIEncoding.Default.GetString(TemplateBytes); TemplateBuf = System.Text.Encoding.Default.GetBytes(TemplateFromHex); Array.Copy(TemplateBuf, tmp.Template, TemplateFromHex.Length); Array.Copy(Raw.RawSerialize(tmp), DataBuf, 608); }
/**************************************************************************************************************************** * 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)); }
/**************************************************************************************************************************** * FunctionName:SetUserInfoToDat * Parameters In:PIN,Privilege,Password,Name,Card,Group,TimeZones,PIN2 * Parameters Out:DataBuf * Return Value:void * Device Used:user.dat in Black&White screen Device * Function:To convert the independent parameters to bytes arrays DataBuf according to the class User * Auther:Darcy * Date:Oct.23, 2009 *****************************************************************************************************************************/ public void SetUserInfoToDat(out byte[] DataBuf, int PIN, int Privilege, string Password, string Name, int Card, int Group, int TimeZone, int PIN2) { DataBuf = new byte[28]; byte[] PasswordBuf = new byte[5]; byte[] NameBuf = new byte[8]; byte[] CardBuf = new byte[5]; User user = new User(); user.PIN = (ushort)PIN; user.Privilege = (byte)Privilege; PasswordBuf = System.Text.Encoding.Default.GetBytes(Password); Array.Copy(PasswordBuf, user.Password, 5); NameBuf = System.Text.Encoding.Default.GetBytes(Name); Array.Copy(NameBuf, user.Name, 8); CardBuf = BitConverter.GetBytes(Card); Array.Copy(CardBuf, user.Card, 4);//Although we have defined 5 bytes to store the card number,but in fact 4bytes is enough(an integer data) user.Group = (byte)Group; TimeZone = user.TimeZones; user.PIN2 = (ushort)PIN2; Array.Copy(Raw.RawSerialize(user), 0, DataBuf, 0, 28); }
/**************************************************************************************************************************** * FunctionName:SetUDataToDat * Parameters In:PIN,SmsID * Parameters Out:DataBuf * Return Value:void * Device Used:For Black&White screen devices. udata.dat * Function:To convert imported parameters to the byte array * Auther:Darcy * Date:Oct.23, 2009 *****************************************************************************************************************************/ public void SetUDataToDat(out byte[] DataBuf, int PIN, int SmsID) { DataBuf = new byte[4]; UData udata = new UData(); udata.PIN = (ushort)PIN; udata.SmsID = (ushort)SmsID; Array.Copy(Raw.RawSerialize(udata), DataBuf, 4); }