Zhenfeng Huang / GT511C3
Revision:
1:0208a671ce89
Parent:
0:90c64cb9db58
--- a/GT511C3.cpp	Fri Jan 03 16:00:00 2014 +0000
+++ b/GT511C3.cpp	Fri Feb 04 08:45:33 2022 +0000
@@ -105,6 +105,32 @@
     return 0;
 }
 
+int GT511C3::SendData(unsigned char *data,unsigned long size)
+{
+    const unsigned char fixedbuf[4] = { 0x5A,0xA5,0x01,0x00 };
+    unsigned short sum = 0;
+    int i;
+
+    for(i = 0;i < 4;i++){
+        while(!writeable());
+        putc(fixedbuf[i]);
+        sum += fixedbuf[i];
+    }    
+    
+    for(i = 0;i < size;i++){
+        while(!writeable());
+        putc(data[i]);
+        sum += data[i];
+    }
+    
+    while(!writeable());
+    putc((unsigned char)(sum & 0xff));
+    while(!writeable());
+    putc((unsigned char)((sum >> 8) & 0xff));
+    
+    return 0;
+}
+
 int GT511C3::RecvData(unsigned char *data,unsigned long size)
 {
     const unsigned char fixedbuf[4] = { 0x5A,0xA5,0x01,0x00 };
@@ -335,6 +361,30 @@
     return -1;
 }
 
+int GT511C3::SetTemplate(int ID, unsigned char *data, unsigned long size)
+{
+    unsigned long Parameter = ID;
+    unsigned short Response = 0;
+    int sts = 0;
+
+    sts = SendRecv(CMD_SetTemplate,&Parameter,&Response);
+    
+    if ((sts != 0) || (Response != CMD_Ack))
+        return -1;
+    
+    sts = SendData(data, size);
+    
+    if (sts != 0)
+        return -2;
+        
+    sts = RecvResponse(&Parameter, &Response);
+    
+    if ((sts != 0) || (Response != CMD_Ack))
+        return -3;
+    
+    return 0;
+}
+
 int GT511C3::DeleteID(int ID)
 {
     unsigned long Parameter = ID;
@@ -346,3 +396,15 @@
         return 0;
     return -1;
 }
+
+int GT511C3::DeleteAllIDs()
+{
+    unsigned long Parameter = 0;
+    unsigned short Response = 0;
+    int sts = 0;
+
+    sts = SendRecv(CMD_DeleteAll,&Parameter,&Response);
+    if((sts == 0) && (Response == CMD_Ack))
+        return 0;
+    return -1;
+}
\ No newline at end of file