Skip to content

Instantly share code, notes, and snippets.

@Akkiesoft Akkiesoft/waon.rb
Created Jun 29, 2014

Embed
What would you like to do?
libpafe-rubyでwaonの使用日時と残高を表示するやつ。
# 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
You can’t perform that action at this time.