From 2b3ce18bca6f8bfd348c1122682211431bd4932b Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Fri, 4 Oct 2024 16:48:06 +0200 Subject: [PATCH] Cleanups and make it worke again. --- .github/dependabot.yml | 8 ++++++++ .github/workflows/publish.yml | 20 ++++++++++++++++++-- .gitignore | 1 + examples/package.lock | 5 +++++ examples/sara_r4.toit | 4 ++-- package.yaml | 2 ++ src/cellular_connector.toit | 23 +++++++++++++---------- 7 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .gitignore diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..03b0284 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" # Necessary to update action hashs. + directory: "/" + schedule: + interval: "weekly" + # Allow up to 3 opened pull requests for github-actions versions. + open-pull-requests-limit: 3 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f15b942..f31185c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,12 +1,28 @@ +# Zero-Clause BSD License + +# Copyright (C) 2023 Toitware ApS. + +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted. + +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + name: Publish package on: push: tags: - - 'v*' + - 'v[0-9]+.[0-9]+.[0-9]+' + - 'v[0-9]+.[0-9]+.[0-9]+-*' jobs: create-release: name: Create new release runs-on: ubuntu-latest steps: - name: Publish - uses: toitlang/pkg-publish@v1.0.2 + uses: toitlang/pkg-publish@v1.5.0 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..162e249 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.packages/ diff --git a/examples/package.lock b/examples/package.lock index 57adbb7..4bbf48d 100644 --- a/examples/package.lock +++ b/examples/package.lock @@ -10,26 +10,31 @@ packages: cellular: cellular cellular: url: github.com/toitware/cellular + name: cellular version: 1.0.0 hash: 0fdbcd9cc5a0a96eac12ab634881bea5ef12114f prefixes: gnss_location: toit-gnss-location pkg-http: url: github.com/toitlang/pkg-http + name: http version: 1.5.0 hash: 538c761a0f01d532ab9982a3f8f996e552311f4b toit-gnss-location: url: github.com/toitware/toit-gnss-location + name: gnss_location version: 1.0.2 hash: e9457f50c5260f9451e823a39d435e3655125bb0 prefixes: location: toit-location toit-location: url: github.com/toitware/toit-location + name: location version: 1.0.0 hash: 080665c10587c1ef82e26b993dda7fa560cf2075 ublox-cellular: url: github.com/toitware/ublox-cellular + name: u_blox_cellular version: 0.1.1 hash: 031958609749e7705a694978a50d43bdd3a91cb9 prefixes: diff --git a/examples/sara_r4.toit b/examples/sara_r4.toit index 23bbee1..529708a 100644 --- a/examples/sara_r4.toit +++ b/examples/sara_r4.toit @@ -19,10 +19,10 @@ RESET_N_NUM ::= 4 main: pwr_on := gpio.Pin PWR_ON_NUM - pwr_on.config --output --open_drain + pwr_on.configure --output --open_drain pwr_on.set 1 reset_n := gpio.Pin RESET_N_NUM - reset_n.config --output --open_drain + reset_n.configure --output --open_drain reset_n.set 1 tx := gpio.Pin TX_PIN_NUM rx := gpio.Pin RX_PIN_NUM diff --git a/package.yaml b/package.yaml index d94d032..198b7bc 100644 --- a/package.yaml +++ b/package.yaml @@ -1,3 +1,5 @@ +name: cellular-connector +description: Strategy for connecting with a cellular modem. dependencies: cellular: url: github.com/toitware/cellular diff --git a/src/cellular_connector.toit b/src/cellular_connector.toit index 8a154bc..6473b15 100644 --- a/src/cellular_connector.toit +++ b/src/cellular_connector.toit @@ -3,11 +3,11 @@ // found in the LICENSE file. import cellular -import device import encoding.ubjson import gpio import log import net +import system.storage class Configuration: is_always_online/bool @@ -208,7 +208,7 @@ class Connector: finally: // Wait for chip to signal power-off. if rts_: - rts_.config --output + rts_.configure --output rts_.set 0 wait_for_quiescent_ @@ -234,7 +234,7 @@ class Connector: // Block until a value has been sustained for at least $SUSTAIN_FOR_DURATION_. wait_for_quiescent_: logger_.debug "waiting for quiescent rx pin" - rx_.config --input + rx_.configure --input while true: value := rx_.get @@ -312,27 +312,30 @@ class CellularInfo: return cellular.Operator value[0] --rat=value[1] class StateStore: + static STORE_PATH_ ::= "toit.io/cellular_connector" static STORE_INFO_KEY_ ::= "connect info" static STORE_PSM_KEY_ ::= "is psm" - store_ := device.FlashStore + + bucket_/storage.Bucket constructor: + bucket_ = storage.Bucket.open --flash STORE_PATH_ store bytes/ByteArray -> bool: - store_.set STORE_INFO_KEY_ bytes + bucket_[STORE_INFO_KEY_] = bytes // TODO can we return bool here? return true load -> ByteArray?: - return store_.get STORE_INFO_KEY_ + return bucket_.get STORE_INFO_KEY_ remove: - store_.delete STORE_INFO_KEY_ + bucket_.remove STORE_INFO_KEY_ take_is_psm -> bool: - is_psm := store_.get STORE_PSM_KEY_ - if is_psm: store_.delete STORE_PSM_KEY_ + is_psm := bucket_.get STORE_PSM_KEY_ + if is_psm: bucket_.remove STORE_PSM_KEY_ return is_psm ? true : false set_use_psm -> none: - store_.set STORE_PSM_KEY_ (ByteArray 0) + bucket_[STORE_PSM_KEY_] = #[]