Class: Rho::NdefRecord

Inherits:
Object show all
Defined in:
lib/extensions/nfc/nfc.rb

Constant Summary collapse

TNF_ABSOLUTE_URI =

3-bit TNF (Type Name Format) field: Indicates how to interpret the type field

3
TNF_EMPTY =
0
TNF_EXTERNAL_TYPE =
4
TNF_MIME_MEDIA =
2
TNF_UNCHANGED =
6
TNF_UNKNOWN =
5
TNF_WELL_KNOWN =
1
RTD_TEXT =

RTD Text types. For use with TNF_WELL_KNOWN

[0x54]
RTD_URI =

“U”

[0x55]
RTD_SMART_POSTER =

“Sp”

[0x53, 0x70]
RTD_ALTERNATIVE_CARRIER =

“ac”

[0x61, 0x63]
RTD_HANDOVER_CARRIER =

“Hc”

[0x48, 0x63]
RTD_HANDOVER_REQUEST =

“Hr”

[0x48, 0x72]
RTD_HANDOVER_SELECT =

“Hs”

[0x48, 0x73]
ID =
'id'
TNF =
'tnf'
TYPE =
'type'
PAYLOAD =
'payload'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.convert_RTD_to_string(rtd) ⇒ Object

convert byte[] type to string



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/extensions/nfc/nfc.rb', line 130

def self.convert_RTD_to_string(rtd)
     res = 'unknown'
     if rtd == RTD_TEXT
          res = 'RTD_TEXT'
     end
     if rtd == RTD_URI
          res = 'RTD_URI'
     end
     if rtd == RTD_SMART_POSTER
          res = 'RTD_SMART_POSTER'
     end
     if rtd == RTD_ALTERNATIVE_CARRIER
          res = 'RTD_ALTERNATIVE_CARRIER'
     end
     if rtd == RTD_HANDOVER_CARRIER
          res = 'RTD_HANDOVER_CARRIER'
     end
     if rtd == RTD_HANDOVER_REQUEST
          res = 'RTD_HANDOVER_REQUEST'
     end
     if rtd == RTD_HANDOVER_SELECT
          res = 'RTD_HANDOVER_SELECT'
     end
     return res
end

.convert_Tnf_to_string(tnf) ⇒ Object

convert int tnf to string



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/extensions/nfc/nfc.rb', line 103

def self.convert_Tnf_to_string(tnf)
     res = 'unknown'
     if tnf == TNF_ABSOLUTE_URI
          res = 'TNF_ABSOLUTE_URI'
     end
     if tnf == TNF_EMPTY
          res = 'TNF_EMPTY'
     end
     if tnf == TNF_EXTERNAL_TYPE
          res = 'TNF_EXTERNAL_TYPE'
     end
     if tnf == TNF_MIME_MEDIA
          res = 'TNF_MIME_MEDIA'
     end
     if tnf == TNF_UNCHANGED
          res = 'TNF_UNCHANGED'
     end
     if tnf == TNF_UNKNOWN
          res = 'TNF_UNKNOWN'
     end
     if tnf == TNF_WELL_KNOWN
          res = 'TNF_WELL_KNOWN'
     end
     return res
end

Instance Method Details

#get_byte_arrayObject

return raw byte[]



86
87
88
# File 'lib/extensions/nfc/nfc.rb', line 86

def get_byte_array
    return @byte_array
end

#get_idObject

return byte[]



61
62
63
# File 'lib/extensions/nfc/nfc.rb', line 61

def get_id
    return @id
end

#get_payloadObject

return byte[]



76
77
78
# File 'lib/extensions/nfc/nfc.rb', line 76

def get_payload
    return @payload
end

#get_payload_as_stringObject

return string



81
82
83
# File 'lib/extensions/nfc/nfc.rb', line 81

def get_payload_as_string
    return @payload_as_string
end

#get_tnfObject

return int



66
67
68
# File 'lib/extensions/nfc/nfc.rb', line 66

def get_tnf
    return @tnf
end

#get_typeObject

return byte[]



71
72
73
# File 'lib/extensions/nfc/nfc.rb', line 71

def get_type
    return @type
end

#init_from_byte_array(array) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/extensions/nfc/nfc.rb', line 32

def init_from_byte_array(array)
    @byte_array = array
    if array != nil
        hash = Nfc.convert_byte_array_to_NdeRecord_hash(@byte_array)
        @id = hash[ID]
        @tnf = hash[TNF]
        @type = hash[TYPE]
        @payload = hash[PAYLOAD]
        @payload_as_string = hash['payload_as_string']
    else
        @id = nil
        @tnf = 0
        @type = nil
        @payload = nil
        @payload_as_string = nil
    end           
end

#init_from_hash(hash) ⇒ Object

hash :

'id' - byte[]
'tnf' - int
'type' - byte[]
'payload' - byte[]


55
56
57
58
# File 'lib/extensions/nfc/nfc.rb', line 55

def init_from_hash(hash)
    byte_arr = Nfc.convert_NdeRecord_hash_to_byte_array(hash)
    init_from_byte_array(byte_arr)
end

#make_hashObject

return hash hash :

'id' - byte[]
'tnf' - int
'type' - byte[]
'payload' - byte[]
'payload_as_string' - string


97
98
99
100
# File 'lib/extensions/nfc/nfc.rb', line 97

def make_hash
    hash = { 'id' => @id, 'tnf' => @tnf, 'type' => @type, 'payload' => @payload, 'payload_as_string' => @payload_as_string}
    return hash
end