diff options
-rw-r--r-- | usb-i2c-sl018/tuer-rfid.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/usb-i2c-sl018/tuer-rfid.c b/usb-i2c-sl018/tuer-rfid.c index a50866e..302bcae 100644 --- a/usb-i2c-sl018/tuer-rfid.c +++ b/usb-i2c-sl018/tuer-rfid.c @@ -97,16 +97,16 @@ const uint8_t SL018CMD_ComRedLedOff[] ={2,0x40,0}; const uint8_t SL018CMD_ComGetFirmwareVersion[] ={1,0xF0};
const uint8_t SL018CMD_ComReset[] ={1,SL018_RESET};
-uint8_t recv_twi_buf[256];
+uint8_t twi_recv_buf[256];
typedef struct __attribute__((__packed__))
{
uint8_t len;
uint8_t command;
uint8_t status;
- uint8_t data[sizeof(recv_twi_buf)-3];
+ uint8_t data[sizeof(twi_recv_buf)-3];
} sl018_message_t;
-sl018_message_t* recv_twi_msg = (sl018_message_t *)&recv_twi_buf;
+sl018_message_t* twi_recv_msg = (sl018_message_t *)&twi_recv_buf;
uint8_t card_status =0;
FILE usb_stream;
@@ -173,13 +173,13 @@ int16_t stdio_bytes_received(void) return (int16_t)Serial_IsCharReceived();
}
-bool sl018_cmd_raw(const uint8_t* send_twi_buf, bool wait_for_answer)
+bool sl018_cmd_raw(const uint8_t* twi_send_buf, bool wait_for_answer)
{
uint8_t pos = 0;
//uint8_t ret;
if (TWI_StartTransmission(SL018_ADDR | SL018_WRITE,10) == TWI_ERROR_NoError) {
- for(pos=0; pos<=send_twi_buf[0]; pos++)
- if( ! TWI_SendByte(send_twi_buf[pos])) {
+ for(pos=0; pos<=twi_send_buf[0]; pos++)
+ if( ! TWI_SendByte(twi_send_buf[pos])) {
TWI_StopTransmission();
return 1;
}
@@ -193,9 +193,9 @@ bool sl018_cmd_raw(const uint8_t* send_twi_buf, bool wait_for_answer) _delay_ms(50);
if (TWI_StartTransmission(SL018_ADDR | SL018_READ,10) == TWI_ERROR_NoError) {
- TWI_ReceiveByte(recv_twi_buf, 0);
- for(pos=1; pos<=recv_twi_buf[0]; pos++)
- if (! TWI_ReceiveByte(&recv_twi_buf[pos], (pos == recv_twi_buf[0]) ? 1:0 ) ) {
+ TWI_ReceiveByte(twi_recv_buf, 0);
+ for(pos=1; pos<=twi_recv_buf[0]; pos++)
+ if (! TWI_ReceiveByte(&twi_recv_buf[pos], (pos == twi_recv_buf[0]) ? 1:0 ) ) {
TWI_StopTransmission();
return 1;
}
@@ -216,23 +216,23 @@ bool sl018_reset(void) return 1;
}
-bool sl018_cmd(const uint8_t* send_twi_buf)
+bool sl018_cmd(const uint8_t* twi_send_buf)
{
- if(sl018_cmd_raw(send_twi_buf, 1)) {
+ if(sl018_cmd_raw(twi_send_buf, 1)) {
fprintf(stdio, "I2C error\n\r");
return 0;
} else {
- if(recv_twi_msg->len < 2) {
+ if(twi_recv_msg->len < 2) {
fprintf(stdio,"SL018 Cmd,Error: short message received\n\r");
return 0;
}
- if(recv_twi_msg->status) {
- fprintf(stdio,"SL018 Cmd,Error: '%s','%s'\n\r",SL018_cmd_tostring(recv_twi_msg->command),SL018_status_tostring(recv_twi_msg->status));
+ if(twi_recv_msg->status) {
+ fprintf(stdio,"SL018 Cmd,Error: '%s','%s'\n\r",SL018_cmd_tostring(twi_recv_msg->command),SL018_status_tostring(twi_recv_msg->status));
return 0;
}
- sl018_message_t * send_twi_msg = (sl018_message_t *)send_twi_buf;
- if(send_twi_msg->command != recv_twi_msg->command) {
- fprintf(stdio,"SL018 Cmd,Error: mismatch of sent and received command code: %02X,%02X\n\r",send_twi_msg->command,recv_twi_msg->command);
+ sl018_message_t * twi_send_msg = (sl018_message_t *)twi_send_buf;
+ if(twi_send_msg->command != twi_recv_msg->command) {
+ fprintf(stdio,"SL018 Cmd,Error: mismatch of sent and received command code: %02X,%02X\n\r",twi_send_msg->command,twi_recv_msg->command);
}
}
return 1;
@@ -295,7 +295,7 @@ void handle_stdio(uint8_t cmd) break;
case 'f': //get cardreader firmware version
if(sl018_cmd(SL018CMD_ComGetFirmwareVersion))
- fprintf(stdio, "%s\n\r",recv_twi_msg->data);
+ fprintf(stdio, "%s\n\r",twi_recv_msg->data);
break;
case '4': //turn cardreader led off
if(sl018_cmd(SL018CMD_ComRedLedOff))
@@ -360,19 +360,19 @@ void handle_card(void) fprintf(stdio, "CARD IN: ");
if(sl018_cmd(SL018CMD_ComSelectCard))
{
- uint8_t uid_len = recv_twi_msg->len - sizeof(recv_twi_msg->command) - sizeof(recv_twi_msg->status) - 1;
+ uint8_t uid_len = twi_recv_msg->len - sizeof(twi_recv_msg->command) - sizeof(twi_recv_msg->status) - 1;
if(uid_len == 255 || uid_len > sizeof(keyslot_t) - 1) {
fprintf(stdio,"Invalid uid_len received %d\n\r", uid_len);
return;
}
for (pos=uid_len-1; pos<255; pos--)
- fprintf(stdio,"%02X",recv_twi_msg->data[pos]);
+ fprintf(stdio,"%02X",twi_recv_msg->data[pos]);
fprintf(stdio, "\n\r");
- uint8_t type = recv_twi_msg->data[uid_len];
+ uint8_t type = twi_recv_msg->data[uid_len];
if (0<type && type < 7) {
- if(check_card(recv_twi_msg->data,uid_len)) {
+ if(check_card(twi_recv_msg->data,uid_len)) {
sl018_cmd(SL018CMD_ComRedLedOn);
fprintf(stdio,"Card allowed - opening/closing door\n\r"); // TODO: open/close door!
_delay_ms(255);
|