Skip to content

Commit

Permalink
Migrate to new IO library. (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch authored Apr 5, 2024
1 parent 657810b commit 3993d1a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
6 changes: 4 additions & 2 deletions examples/package.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sdk: ^2.0.0-alpha.144
prefixes:
provision: ..
packages:
Expand All @@ -7,5 +8,6 @@ packages:
protobuf: toit-protobuf
toit-protobuf:
url: github.com/toitware/toit-protobuf
version: 1.1.1
hash: 4a67d1e3bf164c411c312a3d7528f24dd7da0583
name: protobuf
version: 1.3.0
hash: a7f6cc96485f5f7b2df8adc3fecc3dcfac8407b6
7 changes: 4 additions & 3 deletions package.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
sdk: ^2.0.0-alpha.54
sdk: ^2.0.0-alpha.144
prefixes:
protobuf: toit-protobuf
packages:
toit-protobuf:
url: github.com/toitware/toit-protobuf
version: 1.1.1
hash: 4a67d1e3bf164c411c312a3d7528f24dd7da0583
name: protobuf
version: 1.3.0
hash: a7f6cc96485f5f7b2df8adc3fecc3dcfac8407b6
4 changes: 2 additions & 2 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: provision
description: Package to support provisioning (setting the WiFi credentials) of an
ESP32 through BLE using a PC or an Android app.
environment:
sdk: ^2.0.0-alpha.54
sdk: ^2.0.0-alpha.144
dependencies:
protobuf:
url: github.com/toitware/toit-protobuf
version: ^1.1.1
version: ^1.3.0
26 changes: 13 additions & 13 deletions src/provision.toit
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// Use of this source code is governed by an MIT-style license that can be
// found in the package's LICENSE file.
import bytes
import encoding.json
import monitor
import net.wifi
import ble
import crypto.aes show *
import io
import protobuf
import .srp
import .proto.session_pb
Expand Down Expand Up @@ -59,14 +59,14 @@ class BLECharacteristic_:
PROPERTIES
PERMISSIONS
desc.to_byte_array

recv_task = task:: recv_task_run

recv_task_run:
characteristic.handle_read_request:
mutex_.do:
result

write data/ByteArray:
result = data

Expand All @@ -76,7 +76,7 @@ class BLECharacteristic_:
mutex_do [block]:
mutex_.do:
block.call

close:
if recv_task:
recv_task.cancel
Expand Down Expand Up @@ -124,7 +124,7 @@ class BLEService_:
ble.BLE_ADVERTISE_FLAGS_BREDR_UNSUPPORTED
--interval=Duration --ms=160
--connection_mode=ble.BLE_CONNECT_MODE_UNDIRECTIONAL

operator [] name/string -> BLECharacteristic_:
return characteristics[name]

Expand Down Expand Up @@ -165,7 +165,7 @@ class Security0_ implements Security:

decrypt data/ByteArray -> ByteArray:
return data

version -> int:
return SecSchemeVersion_SecScheme0

Expand Down Expand Up @@ -226,7 +226,7 @@ class Security2_ implements Security:

decrypt data/ByteArray -> ByteArray:
return (AesGcm.decryptor session_key_[..32] aes_gcm_iv_).decrypt data

version -> int:
return SecSchemeVersion_SecScheme2

Expand Down Expand Up @@ -268,7 +268,7 @@ class ScanProcess_ implements Process_:

run data/ByteArray -> ByteArray:
resp_msg := null

scan := WiFiScanPayload.deserialize (protobuf.Reader data)
if scan.msg == WiFiScanMsgType_TypeCmdScanStart:
scan_start := scan.payload_cmd_scan_start
Expand Down Expand Up @@ -299,14 +299,14 @@ class ScanProcess_ implements Process_:

ap_entries := []
scan_ap.do: |ap/wifi.AccessPoint|
ap_entries.add
ap_entries.add
WiFiScanResult
--ssid=ap.ssid.to_byte_array
--channel=ap.channel
--rssi=ap.rssi
--bssid=ap.bssid
--auth=ap.authmode

resp_msg = WiFiScanPayload
--msg=WiFiScanMsgType_TypeRespScanResult
--status=Status_Success
Expand Down Expand Up @@ -375,7 +375,7 @@ class Provision:

constructor.ble service_name/string security/Security:
return Provision.ble_with_uuid SERVICE_UUID service_name security

constructor.ble_with_uuid service_uuid/ByteArray service_name/string .security_/Security:
service_ = BLEService_ service_uuid service_name

Expand Down Expand Up @@ -446,13 +446,13 @@ class Provision:
if config_task_:
config_task_.cancel
config_task_ = null

service_.close

if not latch_.has_value: latch_.set false

protobuf_message_to_bytes_ message/protobuf.Message -> ByteArray:
buffer := bytes.Buffer
buffer := io.Buffer
w := protobuf.Writer buffer
message.serialize w
return buffer.bytes
Expand Down
6 changes: 4 additions & 2 deletions tests/package.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sdk: ^2.0.0-alpha.144
prefixes:
provision: ..
packages:
Expand All @@ -7,5 +8,6 @@ packages:
protobuf: toit-protobuf
toit-protobuf:
url: github.com/toitware/toit-protobuf
version: 1.1.1
hash: 4a67d1e3bf164c411c312a3d7528f24dd7da0583
name: protobuf
version: 1.3.0
hash: a7f6cc96485f5f7b2df8adc3fecc3dcfac8407b6
2 changes: 1 addition & 1 deletion tests/package.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dependencies:
provision:
path: ..
path: ..

0 comments on commit 3993d1a

Please sign in to comment.