void print_help(void)
{
- fprintf(stderr, "r - initial RESET, required after power-on\n");
- fprintf(stderr, "i - C:2 insert permit request\n");
- fprintf(stderr, "s - C10 C/R status request\n");
- fprintf(stderr, "S - C11 sensor status\n");
- fprintf(stderr, "1 - Reads ISO #1 and sends data\n");
- fprintf(stderr, "2 - Reads ISO #2 and sends data\n");
- fprintf(stderr, "3 - Reads ISO #3 and sends data\n");
- fprintf(stderr, "m - Sends the read data in memory by this command\n");
- fprintf(stderr, "M - Sends multi-tracks data in the memory by this command and parameter\n");
- fprintf(stderr, "q - close serial and quite\n");
- fprintf(stderr, "h - this help\n");
+ fprintf(stderr, "r - initial RESET, required after power-on\n");
+ fprintf(stderr, "i - C:2 insert permit request\n");
+ fprintf(stderr, "s - C10 C/R status request\n");
+ fprintf(stderr, "S - C11 sensor status\n");
+ fprintf(stderr, "1 - Reads ISO #1 and sends data\n");
+ fprintf(stderr, "2 - Reads ISO #2 and sends data\n");
+ fprintf(stderr, "3 - Reads ISO #3 and sends data\n");
+ fprintf(stderr, "m - Sends the read data in memory by this command\n");
+ fprintf(stderr, "M - Sends multi-tracks data in the memory by this command and parameter\n");
+ fprintf(stderr, "q - close serial and quite\n");
+ fprintf(stderr, "h - this help\n");
}
int process_user_cmd(char *rxbuf, int len, int ufd)
send_command(ufd, "C30", 3);
in_cmd = 1;
break;
+ case 'E':
+ fprintf(stderr, "Eject request... ");
+ send_command(ufd, "C31", 3);
+ in_cmd = 1;
+ break;
case 's':
fprintf(stderr, "Status request... ");
send_command(ufd, "C10", 3);
send_command(ufd, "C63", 3);
in_cmd = 1;
break;
+ case 'R':
+ fprintf(stderr, "Status request... ");
+ send_command(ufd, "C687", 4);
+ in_cmd = 1;
+ break;
+ case 'm':
+ fprintf(stderr, "Status request... ");
+ send_command(ufd, "C69", 3);
+ in_cmd = 1;
+ break;
+ case 'M':
+ fprintf(stderr, "Status request... ");
+ send_command(ufd, "C6A7", 4);
+ in_cmd = 1;
+ break;
+ case 'w':
+ fprintf(stderr, "Status request... ");
+ send_command(ufd, "C731234", 7);
+ in_cmd = 1;
+ break;
case 'h':
print_help();
in_cmd = 0;
return in_cmd;
}
+void print_multi_track(char *rxbuf, int len)
+{
+int bpos = 0, t, i;
+int t1len, t2len, t3len;
+char tmpstr[4];
+
+ fprintf(stderr, "tracks requested: %c\n", rxbuf[bpos++]);
+ memset(tmpstr, 0, 4);
+ t=0;
+ tmpstr[t++] = rxbuf[bpos++];
+ tmpstr[t++] = rxbuf[bpos++];
+ fprintf(stderr, "t#1 read result: %s\n", tmpstr);
+ t=0;
+ tmpstr[t++] = rxbuf[bpos++];
+ tmpstr[t++] = rxbuf[bpos++];
+ fprintf(stderr, "t#2 read result: %s\n", tmpstr);
+ t=0;
+ tmpstr[t++] = rxbuf[bpos++];
+ tmpstr[t++] = rxbuf[bpos++];
+ fprintf(stderr, "t#3 read result: %s\n", tmpstr);
+ memset(tmpstr, 0, 4);
+
+ t=0;
+ tmpstr[t++] = rxbuf[bpos++];
+ tmpstr[t++] = rxbuf[bpos++];
+ tmpstr[t++] = rxbuf[bpos++];
+ t1len = atoi(tmpstr);
+ fprintf(stderr, "t#1 read len: %d\n", t1len);
+ t=0;
+ tmpstr[t++] = rxbuf[bpos++];
+ tmpstr[t++] = rxbuf[bpos++];
+ tmpstr[t++] = rxbuf[bpos++];
+ t2len = atoi(tmpstr);
+ fprintf(stderr, "t#2 read len: %d\n", t2len);
+ t=0;
+ tmpstr[t++] = rxbuf[bpos++];
+ tmpstr[t++] = rxbuf[bpos++];
+ tmpstr[t++] = rxbuf[bpos++];
+ t3len = atoi(tmpstr);
+ fprintf(stderr, "t#3 read len: %d\n", t3len);
+
+ fprintf(stderr, "t#1 data: '");
+ for (i=0; i<t1len; i++) {
+ unsigned char c = rxbuf[bpos++];
+ if (c > 31 || c < 128)
+ fprintf(stderr, "%c", c);
+ else
+ fprintf(stderr, "0x%02x ", c);
+ }
+ fprintf(stderr, "'\n");
+
+ fprintf(stderr, "t#2 data: '");
+ for (i=0; i<t2len; i++) {
+ unsigned char c = rxbuf[bpos++];
+ if (c > 31 || c < 128)
+ fprintf(stderr, "%c", c);
+ else
+ fprintf(stderr, "0x%02x ", c);
+ }
+ fprintf(stderr, "'\n");
+
+ fprintf(stderr, "t#3 data: '");
+ for (i=0; i<t3len; i++) {
+ unsigned char c = rxbuf[bpos++];
+ if (c > 31 || c < 128)
+ fprintf(stderr, "%c", c);
+ else
+ fprintf(stderr, "0x%02x ", c);
+ }
+ fprintf(stderr, "'\n");
+}
+
void process_read_packet(char *rxbuf, int rxpos)
{
int bpos;
+char cmd[2];
bpos = 2; // index into read buffer
if (rxbuf[bpos] == 'P') {
fprintf(stderr, "positive, ");
bpos++;
- fprintf(stderr, "cmd was '%c%c', ", rxbuf[bpos], rxbuf[bpos+1]);
- bpos+=2;
+ cmd[0] = rxbuf[bpos++];
+ cmd[1] = rxbuf[bpos++];
+ fprintf(stderr, "cmd was '%c%c', ", cmd[0], cmd[1]);
+
if (rxbuf[bpos]=='0' && rxbuf[bpos+1]=='0') {
fprintf(stderr, "no card present, ");
} else if (rxbuf[bpos]=='0' && rxbuf[bpos+1]=='1') {
fprintf(stderr, "negative, ");
bpos++;
fprintf(stderr, "cmd was '%c%c', ", rxbuf[bpos], rxbuf[bpos+1]);
- bpos+=2;
+ bpos += 2;
if (rxbuf[bpos]=='0' && rxbuf[bpos+1]=='0') {
fprintf(stderr, "undefined command, ");
} else if (rxbuf[bpos]=='0' && rxbuf[bpos+1]=='1') {
} else if (rxbuf[bpos]=='4' && rxbuf[bpos+1]=='6') {
fprintf(stderr, "Jitter read error, ");
} else
- fprintf(stderr, "stat is '%c%c', ", rxbuf[bpos], rxbuf[bpos+1]);
+ fprintf(stderr, "unknown stat '%c%c', ", rxbuf[bpos], rxbuf[bpos+1]);
}
- bpos+=2;
- if (bpos < rxpos-3)
+
+ bpos += 2;
+ if (bpos < rxpos-3) {
fprintf(stderr, "\ndata: ");
- while (bpos < rxpos-3) {
- unsigned char c = rxbuf[bpos++];
- if (c > 31 || c < 128)
- fprintf(stderr, "%c", c);
- else
- fprintf(stderr, "0x%02x ", c);
-
+ if (cmd[0] == '6' && cmd[1] == 'A') {
+ print_multi_track((rxbuf+bpos), rxpos-3);
+ } else {
+ while (bpos < rxpos-3) {
+ unsigned char c = rxbuf[bpos++];
+ if (c > 31 || c < 128)
+ fprintf(stderr, "%c", c);
+ else
+ fprintf(stderr, "0x%02x ", c);
+ }
+ fprintf(stderr, "\n");
+ }
}
- fprintf(stderr, "\n");
}
int main(int argc, char **argv)
{
char *ser_dev;
char rxbuf[256];
-int ufd, rxlen=0, rxpos=0, ret;
+int ufd, rxlen=0, rxpos=0, ret=0;
int in_cmd = 0;
fd_set rfds;
struct timeval tval;
tval.tv_usec = 5000000;
fprintf(stderr, "OMRON MVFW card reader terminal\non serial %s\nEnter 'h' for help\n", ser_dev);
- while (1) {
+ while (ret >= 0) {
ret = select((ufd+1), &rfds, NULL, NULL, &tval);
if (ret == 0) {
FD_ZERO(&rfds);
process_read_packet(rxbuf, rxpos);
memset(rxbuf, 0, 256);
rxpos = 0;
- } else
- fprintf(stderr, "buf not complete yet\n");
+ } //else
+ // fprintf(stderr, "buf not complete yet\n");
}
if (FD_ISSET(0, &rfds)) {
// fprintf(stderr, "**** keypress\n");
return 0;
}
+