/**************************************************************************************************************************** * 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: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[608]; byte[] TemplateBuf = new byte[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: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); }
/**************************************************************************************************************************** * 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); }
/**************************************************************************************************************************** * FunctionName: SetFaceToDat * Parameters In:Size,PIN,FaceID,Valid,Reserve,ActiveTime,VfCount,Face * Parameters Out:DataBuf * Return Value:void * Device Used:devices supporting faces registering * Function:To convert the independent parameters to bytes arrays DataBuf according to the class Template * Auther:Darcy * Date:Oct.23, 2009 *****************************************************************************************************************************/ public void SetFaceToDat(out byte[] DataBuf, int Size, int PIN, int FaceID, int Valid, int Reserve, int ActiveTime, int VfCount, string Face) { DataBuf = new byte[2576]; byte[] FaceBuf = new byte[2560]; FaceTmp face = new FaceTmp(); face.Size = (ushort)Size; face.PIN = (ushort)PIN; face.FaceID = (byte)FaceID; face.Valid = (byte)Valid; face.Reserve = (ushort)Reserve; face.ActiveTime = (uint)ActiveTime; face.VfCount = (uint)VfCount; Face = Face.Replace(" ", ""); if (Face.Length <= 0) { Face = ""; } byte[] FaceBytes = new byte[Face.Length / 2]; for (int i = 0; i < Face.Length; i += 2) { if (!byte.TryParse(Face.Substring(i, 2), NumberStyles.HexNumber, null, out FaceBytes[i / 2])) { FaceBytes[i / 2] = 0; } } string FaceFromHex = ASCIIEncoding.Default.GetString(FaceBytes); FaceBuf = System.Text.Encoding.Default.GetBytes(FaceFromHex); Array.Copy(FaceBuf, face.Face, FaceFromHex.Length); Array.Copy(Raw.RawSerialize(face), DataBuf, 2576); }