File tree Expand file tree Collapse file tree 4 files changed +4
-30
lines changed Expand file tree Collapse file tree 4 files changed +4
-30
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import ...devices as devices
33import ...messages as messages
44import ...util.docs show message-bytes-to-docs-url
55import ...util.resilience show catch-and-restart
6- import ...util.idgen show IdGenerator RandomIdGenerator SequentialIdGenerator
6+ import ...util.idgen show IdGenerator SequentialIdGenerator
77import ...util.bytes show stringify-all-bytes byte-array-to-list
88import .message-handler show MessageHandler
99import io.reader show Reader
@@ -46,8 +46,8 @@ class Comms:
4646 // Allow passing in handlers to register on creation
4747 --handlers / List?/* <MessageHandler>*/ = []
4848 // Customizable id generator for message ids
49- // Defaults to a random uint32 generator
50- --idGenerator / IdGenerator = ( RandomIdGenerator --lowerBound = 1 --upperBound = 4_294_967_295 )
49+ // Defaults to a sequential generator starting at 1, max 4_294_967_295 ( uint32 max)
50+ --idGenerator / IdGenerator = ( SequentialIdGenerator --start = 1 --maxId = 4_294_967_295 )
5151 --startInbound / bool = true // Start the inbound reader (polling the device on I2C for messages)
5252 --open / bool = true // Send Open message and heartbeats to keep connection alive
5353 --reinitOnStart / bool = true // Reinitialize the device on start. Clearing buffers and subscriptions. Primarily for high throughput cases.
Original file line number Diff line number Diff line change @@ -40,11 +40,6 @@ class Message:
4040 msg .header .data .add-data-uint8 Header .TYPE-MESSAGE-METHOD method
4141 return msg
4242
43- with-random-msg-id -> Message :
44- randomUint32 := ( random 4_294_967_295 ) + 1
45- header .data .add-data-uint32 Header .TYPE_MESSAGE_ID randomUint32
46- return this
47-
4843 msgId -> int? :
4944 if header .data .has-data Header .TYPE_MESSAGE_ID : return header .data .get-data-uint Header .TYPE_MESSAGE_ID
5045 return null
Original file line number Diff line number Diff line change @@ -11,15 +11,4 @@ class SequentialIdGenerator implements IdGenerator:
1111
1212 next -> int :
1313 nextId_ = ( nextId_ + 1 ) % maxId_
14- return nextId_
15-
16- class RandomIdGenerator implements IdGenerator :
17- lowerBound_ := 0
18- upperBound_ := 0
19-
20- constructor --lowerBound / int --upperBound / int :
21- lowerBound_ = lowerBound
22- upperBound_ = upperBound
23-
24- next -> int :
25- return random lowerBound_ upperBound_
14+ return nextId_
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import lightbug.util.idgen
22
33main :
44 sequential
5- random
65
76sequential :
87 g := idgen .SequentialIdGenerator --start = 1 --maxId = 3
@@ -13,12 +12,3 @@ sequential:
1312 print "❌ idgen sequential Wanted $ it got $ i "
1413 else:
1514 print "✅ idgen sequential Got $ i "
16-
17- random :
18- g := idgen .RandomIdGenerator --lowerBound = 1 --upperBound = 3
19- for i := 0 ; i < 10 ; i ++:
20- it := g .next
21- if it < 1 or it > 3 :
22- print "❌ idgen random Out of bounds $ it "
23- else:
24- print "✅ idgen random Got $ it (in bounds)"
You can’t perform that action at this time.
0 commit comments