Created
June 29, 2014 16:20
-
-
Save Akkiesoft/f0187ba9278441486ee6 to your computer and use it in GitHub Desktop.
libpafe-rubyでwaonの使用日時と残高を表示するやつ。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
require "pasori" | |
pasori = Pasori.open | |
felica = pasori.felica_polling | |
pasori.felica_polling(Felica::POLLING_EDY) {|felica2| | |
# waon | |
get = 0 | |
latest = 0 | |
balance = 0 | |
felica2.each.with_index(0x680b) {|l,cnt| | |
print cnt | |
if (cnt % 2 == 1) | |
data = l.unpack('NNNCnCC') | |
if (latest < data[4]) | |
print "!" | |
latest = data[4] | |
get = 1 | |
end | |
next | |
end | |
if (6 < cnt) | |
break | |
end | |
data = l.unpack('CCCCCCCC') | |
if (get == 1) | |
year = (data[2] >> 3) + 2005 | |
month = (data[2] & 0x07) << 1 | data[3] >> 7 | |
day = (data[3] >> 2) & 0x1f | |
hour = (data[3] & 0x3) << 3 | data[4] >> 5 | |
min = (data[4] & 0x1f) << 1 | data[5] >> 7 | |
# BALANCE(取得までの流れ) | |
# printf("%X, %X, %X\n", data[5],data[6],data[7]) | |
# printf("-> %X, %X, %X\n", (data[5] & 0x7f), data[6], data[7] >> 7) | |
# printf("-> %X, %X, %X\n", (data[5] & 0x7f) << 11, data[6] << 3, data[7] >> 5) | |
balance = (data[5] & 0x7f) << 11 | data[6] << 3 | data[7] >> 5 | |
printf("%04d/%02d/%02d %02d:%02d %d", year, month, day, hour, min, balance) | |
get = 0 end | |
} | |
print "#{balance}" | |
} | |
felica.close | |
pasori.close | |
print "\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment