#ifndef COMMANDSSM30_H_
#define COMMANDSSM30_H_

#include <Arduino.h>


// DOCUMENTATION
/*
RESPONSE CODES
*/
const uint8_t SM30_ERR_SUCCESS = 0x00; // Success for command execute
const uint8_t SM30_ERR_FAIL=0x01; //  Fail for instruction execute
const uint8_t SM30_ERR_VERIFY= 0x11; //  One to one match fail
const uint8_t SM30_ERR_IDENTIFY =0x12; //  Identify fail, no matched template
const uint8_t SM30_ERR_TMPL_EMPTY= 0x13; //  The appointed Template Data is Null
const uint8_t SM30_ERR_TMPL_NOT_EMPTY =0x14; //  Existed template for the appointed ID.
const uint8_t SM30_ERR_ALL_TMPL_EMPTY =0x15; //  All templates are Null, Without enrolled Template.
const uint8_t SM30_ERR_EMPTY_ID_NOEXIST= 0x16; //  Without available Template ID.
const uint8_t SM30_ERR_BROKEN_ID_NOEXIST= 0x17; //  Without damaged Template.
const uint8_t SM30_ERR_INVALID_TMPL_DATA =0x18; //  Appointed Template Data invalid.
const uint8_t SM30_ERR_DUPLICATION_ID =0x19; //  The fingerprint has been enrolled.
const uint8_t SM30_ERR_BAD_QUALITY =0x21; //  Bad quality fingerprint image.
const uint8_t SM30_ERR_TIME_OUT =0x23; //  During Time Out period, no finger is detected
const uint8_t SM30_ERR_NOT_AUTHORIZED =0x24; 
    // Not authorized by the password
    // If set password, and not use Verify Device Password command, then all commands would return error code
    // expect Test Connection, Verify Device Password;
    // If no password, all commands are available without the password.
const uint8_t SM30_ERR_GENERALIZE =0x30; //  Generalize template data fail
const uint8_t SM30_ERR_FP_CANCEL =0x41; //  Relative fingerprint command have been cancelled
const uint8_t SM30_ERR_INTERNAL =0x50; //  Internal error
const uint8_t SM30_ERR_MEMORY =0x51; //  Memory Error
const uint8_t SM30_ERR_EXCEPTION =0x52; //  Firmware error.
const uint8_t SM30_ERR_INVALID_TMPL_NO =0x60; //  Template No. is invalid
const uint8_t SM30_ERR_INVALID_SEC_VAL =0x61; //  The Value of Security Level is invalid
const uint8_t SM30_ERR_INVALID_TIME_OUT =0x62; //  The Value of Time Out is invalid
const uint8_t SM30_ERR_INVALID_BAUDRATE =0x63; //  The Value of Baudrate is invalid
const uint8_t SM30_ERR_DEVICE_ID_EMPTY =0x64; //  Not setting Device ID
const uint8_t SM30_ERR_INVALID_DUP_VAL =0x65; //  Option Value of Duplication Check is invalid
const uint8_t SM30_ERR_INVALID_PARAM =0x70; //  Parameter is invalid.
const uint8_t SM30_ERR_NO_RELEASE =0x71; //  In process of IdentifyFree command,
    // Finger is not release
const uint8_t SM30_GD_DOWNLOAD_SUCCESS =0xA1; //  Download Template data was successful
const uint16_t SM30_GD_NEED_FIRST_SWEEP =0xFFF1; //  Waiting input fingerprint for first time.
const uint16_t SM30_GD_NEED_SECOND_SWEEP =0xFFF2; //  Waiting input fingerprint for second time.
const uint16_t SM30_GD_NEED_THIRD_SWEEP =0xFFF3; //  Waiting input fingerprint for third time.
const uint16_t SM30_GD_NEED_RELEASE_FINGER= 0xFFF4; //  Lift finger
const uint8_t SM30_GD_DETECT_FINGER =0x01; //  Detect an finger on sensor when execute “Finger Detect” command
const uint8_t SM30_GD_NO_DETECT_FINGER =0x00; //  Detect no any finger on sensor when execute “Finger Detect” command
const uint8_t SM30_GD_TEMPLATE_NOT_EMPTY= 0x01; //  The appointed Template are not empty
const uint8_t SM30_GD_TEMPLATE_EMPTY =0x00; //  The appointed Template have been emptied


// COMMANDS
const uint16_t SM30_CMD_VERIFY = 0x0101;           // 1:1 match, an template in Ram Buffer match with an template in DB
const uint16_t SM30_CMD_IDENTIFY = 0x0102;           
const uint16_t SM30_CMD_ENROLL = 0x0103;  
const uint16_t SM30_CMD_ENROLL_ONE_TIME = 0x0104;  
const uint16_t SM30_CMD_CLEAR_TEMPLATE = 0x0105;  
const uint16_t SM30_CMD_CLEAR_ALL_TEMPLATES = 0x0106;  
const uint16_t SM30_CMD_GET_EMPTY_ID = 0x0107;  
const uint16_t SM30_CMD_GET_TEMPLATE_STATUS = 0x0108;  
const uint16_t SM30_CMD_GET_BROKEN_TEMPLATE = 0x0109;  
const uint16_t SM30_CMD_READ_TEMPLATE = 0x010A;  
const uint16_t SM30_CMD_WRITE_TEMPLATE = 0x010B;  
const uint16_t SM30_CMD_SET_SECURITY_LEVEL = 0x010C;  
const uint16_t SM30_CMD_GET_SECURITY_LEVEL = 0x010D;  
const uint16_t SM30_CMD_SET_FINGER_TIMEOUT = 0x010E;  
const uint16_t SM30_CMD_GET_FINGER_TIMEOUT = 0x010F;  
const uint16_t SM30_CMD_SET_DEVICE_ID = 0x0110;
const uint16_t SM30_CMD_GET_DEVICE_ID = 0x0111;  
const uint16_t SM30_CMD_GET_FW_VERSION = 0x0112;  
const uint16_t SM30_CMD_FINGER_DETECT = 0x0113;  
const uint16_t SM30_CMD_SET_BAUDRATE = 0x01;  
const uint16_t SM30_CMD_SET_DUPLICATION_CHECK = 0x0115;  
const uint16_t SM30_CMD_GET_DUPLICATION_CHECK = 0x0116;  
const uint16_t SM30_CMD_ENTER_STANDBY_MODE = 0x0117;  
const uint16_t SM30_CMD_ENROLL_AND_STORE_IN_RAM = 0x0118;  
const uint16_t SM30_CMD_GET_ENROLL_DATA = 0x0119;  
const uint16_t SM30_CMD_GET_FEATURE_DATA_OF_FINGERPRINT = 0x011A; 
const uint16_t SM30_CMD_VERIFY_DOWNLOADED_FEATURE_WITH_CAPTURED_FP = 0x011B; 
const uint16_t SM30_CMD_IDENTIFY_DOWLOADED_FEATURE = 0x011C;
const uint16_t SM30_CMD_GET_DEVICE_NAME  = 0x0121; 
const uint16_t SM30_CMD_SENSOR_LED_CONTROLL = 0x0124; 
const uint16_t SM30_CMD_IDENTIFY_FREE = 0x0125; 
const uint16_t SM30_CMD_SET_DEVICE_PASSWORD = 0x0126; 
const uint16_t SM30_CMD_VERIFY_DEVICE_PASSWORD = 0x0127; 
const uint16_t SM30_CMD_GET_ENROLL_COUNT = 0x0128; 
const uint16_t SM30_CMD_FP_CANCEL = 0x0130; 
const uint16_t SM30_CMD_TEST_CONNECTION = 0x0150; 

const uint16_t SM30_REGULAR_PACKET_LENGTH = 24; // command and response packets
const uint16_t SM30_DATA_PACKET_RESPONSE_LENGTH = 12;
const uint16_t SM30_TEMPLATE_DATA_PACKET_LENGTH = 0x01F2; // 2 bites prefix + 2 bytes data+2 bytes len+ 2 bites user+498 template + 2 bytes checksum (508)
const uint16_t SM30_TEMPLATE_BUFFER_LENGHT = 0x01FC;
#endif
