Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/src/edy/edy.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 90 - (show annotations) (download) (as text)
Sun Jun 1 13:35:58 2008 UTC (16 years ago) by tmurakam
File MIME type: text/x-csrc
File size: 4443 byte(s)
updated
1 /*
2 felicalib - FeliCa access wrapper library
3
4 Copyright (c) 2007, Takuya Murakami, All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
8 met:
9
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16
17 3. Neither the name of the project nor the names of its contributors
18 may be used to endorse or promote products derived from this software
19 without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 /**
34 @file edy.c
35
36 edy �����_���v
37 */
38
39 #include <stdio.h>
40 #include <time.h>
41
42 #include "felicalib.h"
43
44 static void edy_dump(uint8 *data);
45 static void analyzeTime(int n, struct tm *t);
46 static int read4b(uint8 *p);
47 static int read2b(uint8 *p);
48
49 // �T�[�r�X�R�[�h
50 #define SERVICE_EDY 0x170f
51
52
53 int _tmain(int argc, _TCHAR *argv[])
54 {
55 pasori *p;
56 felica *f;
57 int i;
58 uint8 data[16];
59
60 p = pasori_open(NULL);
61 if (!p) {
62 fprintf(stderr, "PaSoRi open failed.\n");
63 exit(1);
64 }
65 pasori_init(p);
66
67 f = felica_polling(p, POLLING_EDY, 0, 0);
68 if (!f) {
69 fprintf(stderr, "Polling card failed.\n");
70 exit(1);
71 }
72
73 printf("IDm: ");
74 for (i = 0; i < 8; i++) {
75 printf("%02x", f->IDm[i]);
76 }
77 printf("\n");
78
79 for (i = 0; ; i++) {
80 if (felica_read_without_encryption02(f, SERVICE_EDY, 0, (uint8)i, data)) {
81 break;
82 }
83 edy_dump(data);
84 }
85 felica_free(f);
86 pasori_close(p);
87
88 return 0;
89 }
90
91 static void edy_dump(uint8 *data)
92 {
93 int proc, time, value, balance, seq, v;
94 struct tm tt;
95
96 v = read4b(data + 0);
97 proc = v >> 24; // ����
98 seq = v & 0xffffff; // �A��
99 time = read4b(data + 4); // ����
100 value = read4b(data + 8); // ���z
101 balance = read4b(data + 12);// �c��
102
103 // ���t/����
104 analyzeTime(time, &tt);
105 printf("%d/%02d/%02d %02d:%02d:%02d ",
106 tt.tm_year, tt.tm_mon, tt.tm_mday,
107 tt.tm_hour, tt.tm_min, tt.tm_sec);
108
109 switch (proc) {
110 case 0x02:
111 printf("�`���[�W ");
112 break;
113 case 0x20:
114 printf("�x���� ");
115 break;
116 case 0x04:
117 printf("�M�t�g ");
118 break;
119 default:
120 printf("???? ");
121 break;
122 }
123
124 printf("���z:%-5d ", value);
125 printf("�c��:%-5d ", balance);
126 printf("�A��:%d\n", seq);
127 }
128
129 static void analyzeTime(int n, struct tm *t)
130 {
131 time_t tt;
132 struct tm *t2;
133
134 // calculate day
135 memset(t, 0, sizeof(*t));
136 t->tm_year = 2000 - 1900;
137 t->tm_mon = 0;
138 t->tm_mday = 1;
139 t->tm_hour = 0;
140 t->tm_min = 0;
141 t->tm_sec = 0;
142 t->tm_isdst = -1;
143
144 tt = mktime(t);
145 tt += (n >> 17) * 24 * 60 * 60;
146
147 t2 = localtime(&tt);
148 memcpy(t, t2, sizeof(*t));
149
150 t->tm_year += 1900;
151 t->tm_mon += 1;
152
153 // calculate time
154 n = n & 0x1ffff;
155 t->tm_sec = n % 60;
156 n /= 60;
157 t->tm_min = n % 60;
158 t->tm_hour = n / 60;
159 }
160
161 static int read4b(uint8 *p)
162 {
163 int v;
164 v = (*p++) << 24;
165 v |= (*p++) << 16;
166 v |= (*p++) << 8;
167 v |= *p;
168 return v;
169 }
170
171 static int read2b(uint8 *p)
172 {
173 int v;
174 v = (*p++) << 8;
175 v |= *p;
176 return v;
177 }
178
179

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26