2010-11-17 15:56:10 +00:00
|
|
|
"General IE based message handling"
|
2010-11-22 16:11:08 +00:00
|
|
|
Object subclass: DataIE [
|
2010-11-22 21:46:45 +00:00
|
|
|
| data |
|
2010-11-22 16:11:08 +00:00
|
|
|
|
|
|
|
<category: 'osmo-messages'>
|
2010-11-22 21:46:45 +00:00
|
|
|
DataIE class >> initWith: aData [
|
2010-11-22 16:11:08 +00:00
|
|
|
^ self new
|
|
|
|
data: aData;
|
|
|
|
yourself
|
|
|
|
]
|
|
|
|
|
|
|
|
type [
|
2010-11-22 21:46:45 +00:00
|
|
|
^ data at: 1
|
2010-11-22 16:11:08 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
type: aType [
|
2010-11-22 21:46:45 +00:00
|
|
|
data at: 1 put: aType.
|
2010-11-22 16:11:08 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
data [
|
|
|
|
^ data
|
|
|
|
]
|
|
|
|
|
|
|
|
data: aData [
|
|
|
|
data := aData.
|
|
|
|
]
|
|
|
|
|
|
|
|
writeOn: aMsg [
|
|
|
|
aMsg putByteArray: data.
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2010-11-17 09:26:28 +00:00
|
|
|
Object subclass: IEMessage [
|
2010-11-19 08:02:26 +00:00
|
|
|
<category: 'osmo-messages'>
|
2010-11-17 09:26:28 +00:00
|
|
|
| ies type |
|
|
|
|
|
|
|
|
IEMessage class >> initWith: type [
|
2010-11-19 08:02:26 +00:00
|
|
|
<category: 'creation'>
|
2010-11-17 09:26:28 +00:00
|
|
|
^ (self new)
|
|
|
|
type: type;
|
|
|
|
yourself
|
|
|
|
]
|
|
|
|
|
2010-11-22 16:11:08 +00:00
|
|
|
IEMessage class >> findIE: type with: data from: IEBase [
|
|
|
|
"TODO: This needs to move some basic dispatch class"
|
|
|
|
"Find the IE that handles the type specified"
|
|
|
|
|
|
|
|
IEBase allSubclassesDo: [:each |
|
|
|
|
each elementId = type
|
|
|
|
ifTrue: [
|
|
|
|
^ each parseFrom: data.
|
|
|
|
].
|
|
|
|
].
|
|
|
|
|
2010-11-24 14:20:56 +00:00
|
|
|
^ Exception signal: 'Unsupported IE type: ', type asString.
|
2010-11-22 16:11:08 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
IEMessage class >> decode: aByteArray with: IEBase [
|
|
|
|
| msg dat |
|
|
|
|
msg := IEMessage initWith: (aByteArray at: 1).
|
|
|
|
|
|
|
|
dat := aByteArray copyFrom: 2.
|
|
|
|
[dat isEmpty not] whileTrue: [
|
|
|
|
| type size data |
|
|
|
|
type := dat at: 1.
|
|
|
|
size := dat at: 2.
|
2010-11-22 21:46:45 +00:00
|
|
|
data := dat copyFrom: 1 to: 2 + size.
|
2010-11-22 16:11:08 +00:00
|
|
|
dat := dat copyFrom: 3 + size.
|
|
|
|
|
|
|
|
msg addIe: (self findIE: type with: data from: IEBase).
|
|
|
|
].
|
|
|
|
|
|
|
|
^ msg
|
|
|
|
]
|
|
|
|
|
2010-11-17 09:26:28 +00:00
|
|
|
type: aType [
|
2010-11-19 08:02:26 +00:00
|
|
|
<category: 'creation'>
|
2010-11-17 09:26:28 +00:00
|
|
|
type := aType.
|
|
|
|
]
|
|
|
|
|
2010-11-22 16:11:08 +00:00
|
|
|
type [
|
|
|
|
^ type
|
|
|
|
]
|
|
|
|
|
2010-11-17 09:26:28 +00:00
|
|
|
addIe: aIe [
|
2010-11-19 08:02:26 +00:00
|
|
|
<category: 'creation'>
|
2010-11-17 09:26:28 +00:00
|
|
|
self ies add: aIe.
|
|
|
|
]
|
|
|
|
|
|
|
|
ies [
|
2010-11-19 08:02:26 +00:00
|
|
|
<category: 'access'>
|
2010-11-17 09:26:28 +00:00
|
|
|
ies isNil ifTrue: [
|
|
|
|
ies := OrderedCollection new.
|
|
|
|
].
|
|
|
|
|
|
|
|
^ ies
|
|
|
|
]
|
|
|
|
|
2010-11-23 19:55:31 +00:00
|
|
|
findIE: type ifAbsent: block [
|
|
|
|
"Find the IE with the type"
|
|
|
|
self ies do: [:each |
|
|
|
|
each type = type
|
|
|
|
ifTrue: [
|
|
|
|
^ each
|
|
|
|
].
|
|
|
|
].
|
|
|
|
|
|
|
|
^ block value.
|
|
|
|
]
|
|
|
|
|
2010-11-23 21:01:42 +00:00
|
|
|
findIE: type ifPresent: block [
|
|
|
|
"Find the IE with the type"
|
|
|
|
self ies do: [:each |
|
|
|
|
each type = type
|
|
|
|
ifTrue: [
|
|
|
|
^ block value: each
|
|
|
|
].
|
|
|
|
].
|
|
|
|
|
|
|
|
^ nil.
|
|
|
|
]
|
|
|
|
|
2010-11-20 00:20:00 +00:00
|
|
|
writeOn: aMsg [
|
2010-11-19 08:02:26 +00:00
|
|
|
<category: 'creation'>
|
2010-11-17 09:26:28 +00:00
|
|
|
aMsg putByte: type.
|
|
|
|
|
2010-11-20 00:20:00 +00:00
|
|
|
self ies do: [:each | each writeOn: aMsg ]
|
2010-11-17 09:26:28 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2010-11-19 18:12:44 +00:00
|
|
|
Object subclass: BCD [
|
|
|
|
<category: 'osmo-message'>
|
|
|
|
<comment: 'Class to deal with Binary Coded Decimals'>
|
|
|
|
BCD class >> encode: aNumber [
|
|
|
|
<category: 'access'>
|
|
|
|
| col num |
|
|
|
|
col := OrderedCollection new.
|
|
|
|
|
|
|
|
num := aNumber.
|
|
|
|
1 to: 3 do: [:each |
|
|
|
|
col add: num \\ 10.
|
|
|
|
num := num // 10.
|
|
|
|
].
|
|
|
|
|
|
|
|
^ col reverse asByteArray
|
|
|
|
]
|
2010-11-23 19:08:49 +00:00
|
|
|
|
|
|
|
BCD class >> decode: aByteArray [
|
|
|
|
<category: 'access'>
|
|
|
|
| num cum |
|
|
|
|
|
|
|
|
num := 0.
|
|
|
|
cum := 1.
|
|
|
|
aByteArray size to: 1 by: -1 do: [:each |
|
|
|
|
| at |
|
|
|
|
num := num + ((aByteArray at: each) * cum).
|
|
|
|
cum := cum * 10.
|
|
|
|
].
|
|
|
|
|
|
|
|
^ num
|
|
|
|
]
|
2010-11-19 18:12:44 +00:00
|
|
|
]
|
2010-11-17 09:26:28 +00:00
|
|
|
|