| 1 |
/* |
| 2 |
* FeliCa2Money |
| 3 |
* |
| 4 |
* Copyright (C) 2001-2008 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 |
// WAON (試作中) |
| 22 |
|
| 23 |
using System; |
| 24 |
using System.Collections.Generic; |
| 25 |
using System.Text; |
| 26 |
using FelicaLib; |
| 27 |
|
| 28 |
namespace FeliCa2Money |
| 29 |
{ |
| 30 |
class Waon : CardWithFelicaLib |
| 31 |
{ |
| 32 |
public Waon() |
| 33 |
{ |
| 34 |
org = "WAON"; |
| 35 |
cardName = "WAON"; |
| 36 |
|
| 37 |
systemCode = (int)SystemCode.Common; |
| 38 |
serviceCode = 0x680b; |
| 39 |
|
| 40 |
//needSort = true; |
| 41 |
|
| 42 |
blocksPerTransaction = 2; // 2ブロックで1履歴 |
| 43 |
maxTransactions = 3; // 履歴数は3 |
| 44 |
} |
| 45 |
|
| 46 |
public override void analyzeCardId(Felica f) |
| 47 |
{ |
| 48 |
byte[] data = f.ReadWithoutEncryption(0x67cf, 0); |
| 49 |
byte[] data2 = f.ReadWithoutEncryption(0x67cf, 1); |
| 50 |
if (data == null || data2 == null) |
| 51 |
{ |
| 52 |
throw new Exception("WAON番号を読み取れません"); |
| 53 |
} |
| 54 |
|
| 55 |
accountId = ""; |
| 56 |
for (int i = 12; i <= 15; i++) |
| 57 |
{ |
| 58 |
accountId += data[i].ToString("X2"); |
| 59 |
} |
| 60 |
for (int i = 0; i <= 3; i++) |
| 61 |
{ |
| 62 |
accountId += data2[i].ToString("X2"); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
// 履歴連番でソートする |
| 67 |
protected override void PostProcess(List<Transaction> list) |
| 68 |
{ |
| 69 |
list.Sort(compareById); |
| 70 |
} |
| 71 |
private static int compareById(Transaction x, Transaction y) |
| 72 |
{ |
| 73 |
int ret = x.id - y.id; |
| 74 |
if (ret < -32768) |
| 75 |
{ |
| 76 |
ret += 65535; // 周回したときの処理 |
| 77 |
} |
| 78 |
return ret; |
| 79 |
} |
| 80 |
|
| 81 |
// トランザクション解析 |
| 82 |
public override bool analyzeTransaction(Transaction t, byte[] data) |
| 83 |
{ |
| 84 |
// ID |
| 85 |
t.id = read2b(data, 13); |
| 86 |
|
| 87 |
// 日付 |
| 88 |
int x = read4b(data, 18); |
| 89 |
int yy = x >> 27; |
| 90 |
int mm = (x >> 23) & 0xf; |
| 91 |
int dd = (x >> 18) & 0x1f; |
| 92 |
int hh = (x >> 13) & 0x1f; |
| 93 |
int min = (x >> 7) & 0x3f; |
| 94 |
t.date = new DateTime(yy + 2005, mm, dd, hh, min, 0); |
| 95 |
|
| 96 |
// 残高 |
| 97 |
x = read3b(data, 21); |
| 98 |
t.balance = (x >> 5) & 0x3ffff; |
| 99 |
|
| 100 |
// 出金額 |
| 101 |
x = read3b(data, 23); |
| 102 |
t.value = -((x >> 3) & 0x3ffff); |
| 103 |
|
| 104 |
// 入金額 |
| 105 |
x = read3b(data, 25); |
| 106 |
t.value += (x >> 2) & 0x1ffff; |
| 107 |
|
| 108 |
// 適用 |
| 109 |
switch (data[17]) |
| 110 |
{ |
| 111 |
case 0x0c: |
| 112 |
case 0x10: |
| 113 |
t.desc = "WAONチャージ"; |
| 114 |
break; |
| 115 |
|
| 116 |
case 0x04: |
| 117 |
default: |
| 118 |
t.desc = "WAON支払"; |
| 119 |
break; |
| 120 |
} |
| 121 |
// TBD : 0-12 に備考が入っているのでこちらを使うべきか? |
| 122 |
|
| 123 |
// トランザクションタイプを自動設定 |
| 124 |
t.GuessTransType(t.value >= 0); |
| 125 |
|
| 126 |
return true; |
| 127 |
} |
| 128 |
} |
| 129 |
} |