| 1 |
/* |
| 2 |
* FeliCa2Money |
| 3 |
* |
| 4 |
* Copyright (C) 2001-2007 Takuya Murakami |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include <vcl.h> |
| 22 |
#pragma hdrstop |
| 23 |
#include <stdio.h> |
| 24 |
#include "Card.h" |
| 25 |
#include "Transaction.h" |
| 26 |
#include "SfcPeep.h" |
| 27 |
#include "Suica.h" |
| 28 |
|
| 29 |
// |
| 30 |
// Suica |
| 31 |
// |
| 32 |
|
| 33 |
SuicaCard::SuicaCard(void) |
| 34 |
{ |
| 35 |
Ident = "Suica"; |
| 36 |
CardName = "Suica"; |
| 37 |
prevBalance = UndefBalance; |
| 38 |
} |
| 39 |
|
| 40 |
int SuicaCard::ReadCard(void) |
| 41 |
{ |
| 42 |
// |
| 43 |
// IDm�������� |
| 44 |
// |
| 45 |
if (SfcPeep->Execute("-i") < 0) return -1; |
| 46 |
|
| 47 |
// ���s�����m�F |
| 48 |
TStringList *lines = SfcPeep->Lines(); |
| 49 |
if (lines->Count < 1) { |
| 50 |
// no data |
| 51 |
return -1; |
| 52 |
} |
| 53 |
AnsiString head = lines->Strings[0]; |
| 54 |
lines->Delete(0); |
| 55 |
|
| 56 |
if (head.SubString(1,4) != "IDm:") { |
| 57 |
return -1; |
| 58 |
} |
| 59 |
CardId = head.SubString(5, head.Length() - 4); |
| 60 |
|
| 61 |
// |
| 62 |
// �����f�[�^�������� |
| 63 |
// |
| 64 |
if (SfcPeep->Execute("-h") < 0) return -1; |
| 65 |
|
| 66 |
// ���s���`�F�b�N |
| 67 |
lines = SfcPeep->Lines(); |
| 68 |
if (lines->Count < 1) { |
| 69 |
// no data |
| 70 |
return -1; |
| 71 |
} |
| 72 |
head = lines->Strings[0]; |
| 73 |
if (head.SubString(1,5) != "HT00:") { |
| 74 |
return -1; |
| 75 |
} |
| 76 |
|
| 77 |
// transaction ���� |
| 78 |
if (ParseLines(lines, true) < 0) { |
| 79 |
return -1; |
| 80 |
} |
| 81 |
return 0; |
| 82 |
} |
| 83 |
|
| 84 |
// |
| 85 |
// �g�����U�N�V�������X�g |
| 86 |
// |
| 87 |
Transaction *SuicaCard::GenerateTransaction(int nrows, AnsiString *rows, int *err) |
| 88 |
{ |
| 89 |
// 0:�[�����R�[�h,1:����,2:���t����, |
| 90 |
// 3:�������R�[�h,4:���w���R�[�h,5:������,6:���w��, |
| 91 |
// 7:�o�����R�[�h,8:�o�w���R�[�h,9:�o����,10:�o�w��, |
| 92 |
// 11:�c��,12:�����A�� |
| 93 |
|
| 94 |
// �c�� |
| 95 |
long balance = rows[11].ToInt(); |
| 96 |
long value; |
| 97 |
|
| 98 |
// �����z�v�Z |
| 99 |
// Suica ���e���������A�c�������L�^������������ (ouch!) |
| 100 |
// �������A�O���c�����������������z���v�Z���� |
| 101 |
// �������A�������P�����������s�\���������������� |
| 102 |
if (prevBalance == UndefBalance) { |
| 103 |
prevBalance = balance; |
| 104 |
*err = 0; |
| 105 |
return NULL; |
| 106 |
} else { |
| 107 |
value = balance - prevBalance; |
| 108 |
prevBalance = balance; |
| 109 |
} |
| 110 |
|
| 111 |
// ���� |
| 112 |
AnsiString desc = rows[1]; |
| 113 |
if (desc == "----") { |
| 114 |
return NULL; // ���G���g�� |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
Transaction *trans = new Transaction; |
| 119 |
|
| 120 |
trans->value = value; |
| 121 |
trans->balance = balance; |
| 122 |
|
| 123 |
// ���t |
| 124 |
AnsiString date = rows[2]; |
| 125 |
trans->date.year = date.SubString(1, 2).ToInt() + 2000; |
| 126 |
trans->date.month = date.SubString(5, 2).ToInt(); |
| 127 |
trans->date.date = date.SubString(9, 2).ToInt(); |
| 128 |
|
| 129 |
trans->date.hour = 0; |
| 130 |
trans->date.minutes = 0; |
| 131 |
trans->date.seconds = 0; |
| 132 |
|
| 133 |
// ID |
| 134 |
AnsiString hex = "0x"; |
| 135 |
hex += rows[12]; |
| 136 |
trans->id = StrToInt(hex.c_str()); |
| 137 |
|
| 138 |
// ���� |
| 139 |
AnsiString memo; |
| 140 |
if (!rows[5].IsEmpty()) { |
| 141 |
// �^���������A���������K�p������ |
| 142 |
desc += " "; |
| 143 |
desc += rows[5]; |
| 144 |
|
| 145 |
// ���l�����o����/�w�����L�� |
| 146 |
memo = rows[5] + "(" + rows[6] + ")"; |
| 147 |
if (!rows[9].IsEmpty()) { |
| 148 |
memo += " - " + rows[9] + "(" + rows[10] + ")"; |
| 149 |
} |
| 150 |
} else { |
| 151 |
// �����������������A9, 10 ���X�������� |
| 152 |
if (!rows[9].IsEmpty() && rows[9] != "���o�^") { |
| 153 |
desc += " "; |
| 154 |
desc += rows[9]; |
| 155 |
} |
| 156 |
if (!rows[10].IsEmpty() && rows[10] != "���o�^") { |
| 157 |
desc += " "; |
| 158 |
desc += rows[10]; |
| 159 |
} |
| 160 |
|
| 161 |
// �������� |
| 162 |
if (desc == "����") { |
| 163 |
// ���o�^�X�������K�p��������"����"�������������������B |
| 164 |
// �������AMoney �����������������������X���������������������A |
| 165 |
// �s���������B�����A�������������������t�������� |
| 166 |
desc += " "; |
| 167 |
desc += rows[12]; |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
if (value < 0) { |
| 172 |
trans->SetTransactionType(desc.c_str(), T_OUTGO); |
| 173 |
} else { |
| 174 |
trans->SetTransactionType(desc.c_str(), T_INCOME); |
| 175 |
} |
| 176 |
|
| 177 |
trans->desc = sjis2utf8(desc); |
| 178 |
if (!memo.IsEmpty()) { |
| 179 |
trans->memo = sjis2utf8(memo); |
| 180 |
} |
| 181 |
|
| 182 |
return trans; |
| 183 |
} |