first commit
This commit is contained in:
commit
a78669cb31
12 changed files with 2632 additions and 0 deletions
26
.cargo/config.toml
Normal file
26
.cargo/config.toml
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
[target.xtensa-esp32-none-elf]
|
||||||
|
runner = "espflash flash --monitor"
|
||||||
|
|
||||||
|
[env]
|
||||||
|
ESP_LOGLEVEL="DEBUG"
|
||||||
|
# [build]
|
||||||
|
# rustflags = [
|
||||||
|
# "-C", "link-arg=-Tlinkall.x",
|
||||||
|
# "-C", "link-arg=-Trom_functions.x",
|
||||||
|
|
||||||
|
# # trace
|
||||||
|
# "-C", "force-frame-pointers",
|
||||||
|
# "-C", "target-feature=-loop",
|
||||||
|
# ]
|
||||||
|
|
||||||
|
[build]
|
||||||
|
rustflags = [
|
||||||
|
"-C", "link-arg=-Tlinkall.x",
|
||||||
|
"-C", "link-arg=-nostartfiles",
|
||||||
|
]
|
||||||
|
|
||||||
|
target = "xtensa-esp32-none-elf"
|
||||||
|
|
||||||
|
[unstable]
|
||||||
|
build-std = ["alloc", "core"]
|
||||||
|
|
40
.github/workflows/rust_ci.yml
vendored
Normal file
40
.github/workflows/rust_ci.yml
vendored
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
name: Continuous Integration
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths-ignore:
|
||||||
|
- "**/README.md"
|
||||||
|
pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
rust-checks:
|
||||||
|
name: Rust Checks
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
action:
|
||||||
|
- command: build
|
||||||
|
args: --release
|
||||||
|
- command: fmt
|
||||||
|
args: --all -- --check --color always
|
||||||
|
- command: clippy
|
||||||
|
args: --all-targets --all-features --workspace -- -D warnings
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Enable caching
|
||||||
|
uses: Swatinem/rust-cache@v2
|
||||||
|
- name: Setup Rust
|
||||||
|
uses: esp-rs/xtensa-toolchain@v1.5
|
||||||
|
with:
|
||||||
|
default: true
|
||||||
|
buildtargets: esp32
|
||||||
|
ldproxy: false
|
||||||
|
- name: Run command
|
||||||
|
run: cargo ${{ matrix.action.command }} ${{ matrix.action.args }}
|
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
1719
Cargo.lock
generated
Normal file
1719
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
59
Cargo.toml
Normal file
59
Cargo.toml
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
[package]
|
||||||
|
name = "blinky"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["aok"]
|
||||||
|
edition = "2021"
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
lto = "off"
|
||||||
|
[profile.release]
|
||||||
|
lto = "off"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
# hal = { package = "esp32-hal", version = "0.16.0" }
|
||||||
|
# esp-backtrace = { version = "0.9.0", features = ["esp32", "panic-handler", "exception-handler", "print-uart"] }
|
||||||
|
# esp-println = { version = "0.7.0", features = ["esp32"] }
|
||||||
|
defmt = "=0.3.5"
|
||||||
|
critical-section = "1.1.1"
|
||||||
|
atomic-polyfill = "1.0.3"
|
||||||
|
atomic_enum = "0.2.0"
|
||||||
|
# 0433968ed899aebdffcbcf67845acb1a20d5ac37
|
||||||
|
# hal = { package = "esp32-hal", version = "0.16.0", features=["embassy","async","embassy-time-timg0"]}
|
||||||
|
hal = { package = "esp32-hal", version = "0.16.0", features=["embassy","async","embassy-time-timg0", "embassy-executor-thread"]}
|
||||||
|
esp-hal-common = "0.13.1"
|
||||||
|
esp-backtrace = { version = "0.9.0", features = ["esp32", "panic-handler", "exception-handler", "print-uart"] }
|
||||||
|
esp-println = { version = "0.7.0", features = ["esp32", "log"] }
|
||||||
|
log = { version = "0.4.18"}
|
||||||
|
esp-alloc = { version = "0.3.0" }
|
||||||
|
# esp-wifi = { version = "https://github.com/esp-rs/esp-wifi/", rev = "97a2c4c", features = ["esp32", "embedded-svc", "wifi", "embassy-net", "async"] }
|
||||||
|
esp-wifi = { version = "0.1.1", features = ["esp32", "embedded-svc", "wifi", "embassy-net", "async"] }
|
||||||
|
# esp-wifi-sys = { git = "https://github.com/esp-rs/esp-wifi/", rev = "97a2c4c"}
|
||||||
|
esp-wifi-sys = { version = "0.1.0" }
|
||||||
|
smoltcp = { version = "0.10.0", default-features=false, features = ["proto-igmp", "proto-ipv4", "socket-tcp", "socket-icmp", "socket-udp", "medium-ethernet", "proto-dhcpv4", "socket-raw", "socket-dhcpv4"], optional = true}
|
||||||
|
embedded-svc = { version = "0.26.4", default-features = false, features = []}
|
||||||
|
embedded-io = " 0.6.1"
|
||||||
|
heapless = { version = "0.7.16", default-features = false }
|
||||||
|
embassy-time = "0.1.5"
|
||||||
|
embassy-executor = { version="0.3.3", features = ["nightly", "integrated-timers","arch-xtensa"] }
|
||||||
|
# embassy-executor = { version="0.3.3", features = ["nightly", "integrated-timers","arch-xtensa", "executor-thread"] }
|
||||||
|
static_cell = { version = "2.0.0", features = ["nightly"] }
|
||||||
|
embassy-net = { version = "0.2.1", features = ["nightly","tcp","proto-ipv4","medium-ethernet","dhcpv4", "dns", "log", "udp", "medium-ip" ]}
|
||||||
|
embassy-net-driver = { version = "0.2.0"}
|
||||||
|
embassy-sync = "0.4.0"
|
||||||
|
embassy-futures = "0.1.1"
|
||||||
|
embedded-storage = "0.3.0"
|
||||||
|
crc = "3.0.0"
|
||||||
|
rust-mqtt = { version = "0.1.5", default-features = false }
|
||||||
|
esp-storage = { version = "0.3.0", features = ["esp32"] }
|
||||||
|
embedded-hal-async = "1.0.0-rc.1"
|
||||||
|
embedded-io-async = "0.6.0"
|
||||||
|
nb = "1.1.0"
|
||||||
|
# atat = { version = "0.20.0", features = ["async"] }
|
||||||
|
atat = { version="0.20.0", features = ["async", "log"]}
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
# esp32-hal = { git = "https://github.com/esp-rs/esp-hal.git", rev = "0433968ed899aebdffcbcf67845acb1a20d5ac37" }
|
||||||
|
hal = { package = "esp32-hal", git = "https://github.com/esp-rs/esp-hal.git", rev = "0433968ed899aebdffcbcf67845acb1a20d5ac37" }
|
||||||
|
esp-hal-common = { git = "https://github.com/esp-rs/esp-hal.git", rev = "0433968ed899aebdffcbcf67845acb1a20d5ac37" }
|
||||||
|
# esp-wifi = { git = "https://github.com/esp-rs/esp-wifi.git", rev = "0433968ed899aebdffcbcf67845acb1a20d5ac37" }
|
201
LICENSE-APACHE
Normal file
201
LICENSE-APACHE
Normal file
|
@ -0,0 +1,201 @@
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
25
LICENSE-MIT
Normal file
25
LICENSE-MIT
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
Copyright [year] [fullname]
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any
|
||||||
|
person obtaining a copy of this software and associated
|
||||||
|
documentation files (the "Software"), to deal in the
|
||||||
|
Software without restriction, including without
|
||||||
|
limitation the rights to use, copy, modify, merge,
|
||||||
|
publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software
|
||||||
|
is furnished to do so, subject to the following
|
||||||
|
conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice
|
||||||
|
shall be included in all copies or substantial portions
|
||||||
|
of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||||
|
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||||
|
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||||
|
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||||
|
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
0
README.md
Normal file
0
README.md
Normal file
2
rust-toolchain.toml
Normal file
2
rust-toolchain.toml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[toolchain]
|
||||||
|
channel = "esp"
|
334
src/main.rs
Normal file
334
src/main.rs
Normal file
|
@ -0,0 +1,334 @@
|
||||||
|
//! The following wiring is setup:
|
||||||
|
//! - TX => GPIO15
|
||||||
|
//! - RX => GPIO14
|
||||||
|
|
||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
#![feature(utf8_chunks)]
|
||||||
|
mod modem;
|
||||||
|
mod serial;
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
use core::mem::MaybeUninit;
|
||||||
|
use esp_backtrace as _;
|
||||||
|
use esp_println::println;
|
||||||
|
// use hal::embassy::executor::Executor;
|
||||||
|
|
||||||
|
use esp_wifi::{initialize, EspWifiInitFor};
|
||||||
|
|
||||||
|
use embassy_time::{Instant, Duration};
|
||||||
|
use hal::{timer::TimerGroup, Rng};
|
||||||
|
use embassy_executor::Spawner;
|
||||||
|
use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal};
|
||||||
|
use hal::{
|
||||||
|
clock::ClockControl,
|
||||||
|
embassy,
|
||||||
|
gpio::IO,
|
||||||
|
interrupt,
|
||||||
|
uart::{
|
||||||
|
config::{Config, DataBits, Parity, StopBits},
|
||||||
|
TxRxPins,
|
||||||
|
},
|
||||||
|
Delay,
|
||||||
|
peripherals::{Interrupt, Peripherals, UART1},
|
||||||
|
prelude::*,
|
||||||
|
Uart,
|
||||||
|
gpio::GpioPin,
|
||||||
|
};
|
||||||
|
use hal::clock::{CpuClock, Clocks};
|
||||||
|
use esp_hal_common::uart::{config::AtCmdConfig, UartRx, UartTx};
|
||||||
|
use static_cell::make_static;
|
||||||
|
|
||||||
|
use atat::{
|
||||||
|
asynch::{
|
||||||
|
AtatClient,
|
||||||
|
Client,
|
||||||
|
},
|
||||||
|
AtatIngress,
|
||||||
|
Buffers,
|
||||||
|
DefaultDigester,
|
||||||
|
Ingress,
|
||||||
|
AtDigester,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[global_allocator]
|
||||||
|
static ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty();
|
||||||
|
|
||||||
|
fn init_heap() {
|
||||||
|
const HEAP_SIZE: usize = 32 * 1024;
|
||||||
|
static mut HEAP: MaybeUninit<[u8; HEAP_SIZE]> = MaybeUninit::uninit();
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
ALLOCATOR.init(HEAP.as_mut_ptr() as *mut u8, HEAP_SIZE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const AT_CMD: u8 = 0x04;
|
||||||
|
|
||||||
|
const READ_BUF_SIZE: usize = 64;
|
||||||
|
const INGRESS_BUF_SIZE: usize = 1024;
|
||||||
|
const URC_CAPACITY: usize = 128;
|
||||||
|
const URC_SUBSCRIBERS: usize = 3;
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
async fn ingress_task(
|
||||||
|
mut ingress: Ingress<
|
||||||
|
'static,
|
||||||
|
DefaultDigester<modem::Urc>,
|
||||||
|
modem::Urc,
|
||||||
|
INGRESS_BUF_SIZE,
|
||||||
|
URC_CAPACITY,
|
||||||
|
URC_SUBSCRIBERS,
|
||||||
|
>,
|
||||||
|
mut rx: UartRx<'static, UART1>)
|
||||||
|
{
|
||||||
|
log::info!("reading in ingress_task...");
|
||||||
|
ingress.read_from(&mut rx).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
async fn test_send(mut client: Client<'static, UartTx<'static, UART1>, INGRESS_BUF_SIZE>) {
|
||||||
|
let mut state: u8 = 0;
|
||||||
|
loop {
|
||||||
|
match state {
|
||||||
|
0 => {
|
||||||
|
match client.send(&modem::GetModelId).await {
|
||||||
|
Ok(d) => log::info!("GetModelId Sent: {:?}", d),
|
||||||
|
Err(e) => {
|
||||||
|
match e {
|
||||||
|
atat::Error::Timeout => log::error!("[GetModelId] - Timeout Error: {:?}", e),
|
||||||
|
atat::Error::Parse => log::error!("[GetModelId] - Parse Error: Cound not parse: {:?}", e),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1 => {
|
||||||
|
// println!("sending a single message (GetManufacturerId)");
|
||||||
|
// log::info!("sending a single message (GetManufacturerId)");
|
||||||
|
// client.send(&modem::GetManufacturerId).await.unwrap();
|
||||||
|
// log::info!("(GetManufacturerId) sent");
|
||||||
|
match client.send(&modem::GetManufacturerId).await {
|
||||||
|
Ok(d) => log::info!("GetManufacturerId Sent: {:?}", d),
|
||||||
|
Err(e) => {
|
||||||
|
match e {
|
||||||
|
atat::Error::Timeout => log::error!("[GetManufacturerId] - Timeout Error: {:?}", e),
|
||||||
|
atat::Error::Parse => log::error!("[GetManufacturerId] - Parse Error: Cound not parse: {:?}", e),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
2 => {
|
||||||
|
// println!("sending a single message (GetSoftwareVersion)");
|
||||||
|
// log::info!("sending a single message (GetSoftwareVersion)");
|
||||||
|
// client.send(&modem::GetSoftwareVersion).await.unwrap();
|
||||||
|
// log::info!("(GetSoftwareVersion) sent");
|
||||||
|
match client.send(&modem::GetSoftwareVersion).await {
|
||||||
|
Ok(d) => log::info!("GetSoftwareVersion Sent: {:?}", d),
|
||||||
|
Err(e) => {
|
||||||
|
match e {
|
||||||
|
atat::Error::Timeout => log::error!("[GetSoftwareVersion] - Timeout Error: {:?}", e),
|
||||||
|
atat::Error::Parse => log::error!("[GetSoftwareVersion] - Parse Error: Cound not parse: {:?}", e),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
3 => {
|
||||||
|
// println!("sending a single message (GetWifiMac)");
|
||||||
|
// log::info!("sending a single message (GetWifiMac)");
|
||||||
|
// client.send(&modem::GetWifiMac).await.unwrap();
|
||||||
|
// log::info!("(GetWifiMac) sent");
|
||||||
|
match client.send(&modem::GetWifiMac).await {
|
||||||
|
Ok(d) => log::info!("GetWifiMac Sent: {:?}", d),
|
||||||
|
Err(e) => {
|
||||||
|
match e {
|
||||||
|
atat::Error::Timeout => log::error!("[GetWifiMac] - Timeout Error: {:?}", e),
|
||||||
|
atat::Error::Parse => log::error!("[GetWifiMac] - Parse Error: Cound not parse: {:?}", e),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
4 => {
|
||||||
|
// println!("sending a single message (GetAT)");
|
||||||
|
// log::info!("sending a single message (GetAT)");
|
||||||
|
// client.send(&modem::GetAT).await.unwrap();
|
||||||
|
// log::info!("(GetAT) sent");
|
||||||
|
match client.send(&modem::GetAT).await {
|
||||||
|
Ok(d) => log::info!("GetAT Sent: {:?}", d),
|
||||||
|
Err(e) => {
|
||||||
|
match e {
|
||||||
|
atat::Error::Timeout => log::error!("[GetAT] - Timeout Error: {:?}", e),
|
||||||
|
atat::Error::Parse => log::error!("[GetAT] - Parse Error: Cound not parse: {:?}", e),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// log::info!("AT Command Hit");
|
||||||
|
}
|
||||||
|
// _ => state = 0,
|
||||||
|
_ => break,
|
||||||
|
}
|
||||||
|
|
||||||
|
embassy_time::Timer::after(embassy_time::Duration::from_secs(2)).await;
|
||||||
|
// log::info!("{}", state);
|
||||||
|
|
||||||
|
state += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub struct LossyStr<'a>(pub &'a [u8]);
|
||||||
|
|
||||||
|
impl<'a> core::fmt::Debug for LossyStr<'a> {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
match core::str::from_utf8(self.0) {
|
||||||
|
Ok(s) => write!(f, "{:?}", s),
|
||||||
|
Err(_) => write!(f, "{:?}", self.0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[entry]
|
||||||
|
fn main() -> ! {
|
||||||
|
init_heap();
|
||||||
|
esp_println::logger::init_logger_from_env();
|
||||||
|
log::info!("Logger is setup");
|
||||||
|
let peripherals = Peripherals::take();
|
||||||
|
let system = peripherals.SYSTEM.split();
|
||||||
|
let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock240MHz).freeze();
|
||||||
|
let mut delay = Delay::new(&clocks);
|
||||||
|
|
||||||
|
|
||||||
|
let timer_group0 = TimerGroup::new(
|
||||||
|
peripherals.TIMG0,
|
||||||
|
&clocks,
|
||||||
|
);
|
||||||
|
embassy::init(&clocks, timer_group0.timer0);
|
||||||
|
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
||||||
|
interrupt::enable(Interrupt::UART1, interrupt::Priority::Priority1).unwrap();
|
||||||
|
|
||||||
|
let (ingress, client, rx14) =
|
||||||
|
// let (tx, rx, signal) =
|
||||||
|
uart_device_setup(
|
||||||
|
// serial::uart_serial_setup(
|
||||||
|
delay,
|
||||||
|
io.pins.gpio15,
|
||||||
|
io.pins.gpio14,
|
||||||
|
peripherals.UART1,
|
||||||
|
&clocks,
|
||||||
|
);
|
||||||
|
|
||||||
|
println!("Starting embassy executor ...");
|
||||||
|
|
||||||
|
// let executor = make_static!(embassy_executor::Executor::new());
|
||||||
|
// let executor = make_static!(hal::embassy::executor::Executor::new());
|
||||||
|
static CELL: static_cell::StaticCell<hal::embassy::executor::Executor> = static_cell::StaticCell::new();
|
||||||
|
let executor = CELL.init(hal::embassy::executor::Executor::new());
|
||||||
|
executor.run(|spawner| {
|
||||||
|
let _ = spawner.spawn(ingress_task(ingress, rx14));
|
||||||
|
let _ = spawner.spawn(test_send(client));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn uart_device_setup(
|
||||||
|
mut delay: Delay,
|
||||||
|
gpio15: GpioPin<hal::gpio::Unknown, 15>,
|
||||||
|
gpio14: GpioPin<hal::gpio::Unknown, 14>,
|
||||||
|
UART1_per: UART1,
|
||||||
|
clocks: &Clocks<'static>
|
||||||
|
) -> (
|
||||||
|
Ingress<'static, AtDigester<modem::Urc>, modem::Urc, INGRESS_BUF_SIZE, URC_CAPACITY, URC_SUBSCRIBERS>,
|
||||||
|
atat::asynch::Client<'static, UartTx<'static, hal::peripherals::UART1>, INGRESS_BUF_SIZE>,
|
||||||
|
UartRx<'static, UART1>
|
||||||
|
){
|
||||||
|
|
||||||
|
let modem_uart_pins = TxRxPins::new_tx_rx(
|
||||||
|
gpio15.into_push_pull_output(),
|
||||||
|
gpio14.into_floating_input(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let config = Config {
|
||||||
|
baudrate: 115200,
|
||||||
|
data_bits: DataBits::DataBits8,
|
||||||
|
parity: Parity::ParityNone,
|
||||||
|
stop_bits: StopBits::STOP1,
|
||||||
|
};
|
||||||
|
|
||||||
|
// UART interface for the GSM modem
|
||||||
|
let mut uart = Uart::new_with_config(
|
||||||
|
UART1_per,
|
||||||
|
config,
|
||||||
|
Some(modem_uart_pins),
|
||||||
|
&clocks,
|
||||||
|
);
|
||||||
|
uart.set_at_cmd(AtCmdConfig::new(None, None, None, AT_CMD, None));
|
||||||
|
uart.set_rx_fifo_full_threshold(READ_BUF_SIZE as u16).unwrap();
|
||||||
|
// uart.set_rx_fifo_full_threshold(1).unwrap();
|
||||||
|
let (mut tx, mut rx) = uart.split();
|
||||||
|
|
||||||
|
static BUFFERS: Buffers<modem::Urc, INGRESS_BUF_SIZE, URC_CAPACITY, URC_SUBSCRIBERS> =
|
||||||
|
Buffers::<modem::Urc, INGRESS_BUF_SIZE, URC_CAPACITY, URC_SUBSCRIBERS>::new();
|
||||||
|
|
||||||
|
let digester = DefaultDigester::<modem::Urc>::default();
|
||||||
|
// .with_custom_success(|buf| {
|
||||||
|
// let mut mbuf = buf.to_vec(); // Make a mutable copy
|
||||||
|
// let filtered_buf = filter_sequence(&mut mbuf);
|
||||||
|
// let result = core::str::from_utf8(&filtered_buf);//.unwrap_or("Invalid UTF-8");
|
||||||
|
// match result {
|
||||||
|
// Ok(data_str) => {
|
||||||
|
// println!("Valid UTF-8:\n {}", data_str);
|
||||||
|
// }
|
||||||
|
// Err(e) => {
|
||||||
|
// // println!("Invalid UTF-8:\n {:?}", mbuf);
|
||||||
|
// println!("Invalid UTF-8:\n {:?}", e);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// Ok((buf, buf.len()))
|
||||||
|
// });
|
||||||
|
|
||||||
|
// Atat client
|
||||||
|
let config = atat::Config::default()
|
||||||
|
.flush_timeout(Duration::from_millis(2000))
|
||||||
|
.cmd_cooldown(Duration::from_millis(200))
|
||||||
|
.tx_timeout(Duration::from_millis(2000));
|
||||||
|
let (ingress, client) = BUFFERS.split(
|
||||||
|
tx,
|
||||||
|
digester,
|
||||||
|
config,
|
||||||
|
);
|
||||||
|
(ingress, client, rx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn filter_sequence(buf: &mut [u8]) -> &[u8] {
|
||||||
|
let mut read_idx = 0;
|
||||||
|
let mut write_idx = 0;
|
||||||
|
|
||||||
|
while read_idx < buf.len() {
|
||||||
|
let byte = buf[read_idx];
|
||||||
|
|
||||||
|
if byte != 0 && byte != 202 && byte != 61 && byte != 129 && byte != 37
|
||||||
|
{
|
||||||
|
buf[write_idx] = byte;
|
||||||
|
write_idx += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
read_idx += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
&buf[..write_idx]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn replace_newline_with_ctrl_d(input_str: &[u8]) -> alloc::vec::Vec<u8> {
|
||||||
|
// Byte value for Ctrl+D
|
||||||
|
let ctrl_d: u8 = 4;
|
||||||
|
|
||||||
|
// Replace "\n" with Ctrl+D in the input string
|
||||||
|
let mut replaced_str = input_str.to_vec();
|
||||||
|
for byte in replaced_str.iter_mut() {
|
||||||
|
if *byte == b'\n' {
|
||||||
|
*byte = ctrl_d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
replaced_str
|
||||||
|
}
|
96
src/modem/mod.rs
Normal file
96
src/modem/mod.rs
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
//! Responses for General Commands
|
||||||
|
use atat::heapless::String;
|
||||||
|
use atat::atat_derive::AtatUrc;
|
||||||
|
|
||||||
|
use atat::atat_derive::{AtatCmd, AtatResp};
|
||||||
|
|
||||||
|
#[derive(Clone, AtatResp)]
|
||||||
|
pub struct NoResponse;
|
||||||
|
|
||||||
|
#[derive(Clone, AtatCmd)]
|
||||||
|
#[at_cmd("", NoResponse, timeout_ms = 1000)]
|
||||||
|
pub struct AT;
|
||||||
|
|
||||||
|
#[derive(Clone, AtatUrc)]
|
||||||
|
pub enum Urc {
|
||||||
|
#[at_urc("+UMWI")]
|
||||||
|
MessageWaitingIndication(MessageWaitingIndication),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Clone, AtatResp)]
|
||||||
|
pub struct MessageWaitingIndication;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// 4.1 Manufacturer identification
|
||||||
|
/// Text string identifying the manufacturer.
|
||||||
|
#[derive(Clone, Debug, AtatResp)]
|
||||||
|
pub struct ManufacturerId {
|
||||||
|
pub id: String<64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Model identification
|
||||||
|
/// Text string identifying the manufacturer.
|
||||||
|
#[derive(Clone, Debug, AtatResp)]
|
||||||
|
pub struct ModelId {
|
||||||
|
pub id: String<64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Software version identification
|
||||||
|
/// Read a text string that identifies the software version of the module.
|
||||||
|
#[derive(Clone, Debug, AtatResp)]
|
||||||
|
pub struct SoftwareVersion {
|
||||||
|
pub id: String<64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 7.11 Wi-Fi Access point station list +UWAPSTALIST
|
||||||
|
#[derive(Clone, Debug, AtatResp)]
|
||||||
|
pub struct WifiMac {
|
||||||
|
pub mac_addr: atat::heapless_bytes::Bytes<12>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, AtatResp)]
|
||||||
|
pub struct ATCOMMAND {
|
||||||
|
pub id: String<64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
// use atat::atat_derive::AtatCmd;
|
||||||
|
// use responses::*;
|
||||||
|
|
||||||
|
/// 4.1 Manufacturer identification +CGMI
|
||||||
|
///
|
||||||
|
/// Text string identifying the manufacturer.
|
||||||
|
#[derive(Clone, AtatCmd)]
|
||||||
|
#[at_cmd("+CGMI", ManufacturerId)]
|
||||||
|
pub struct GetManufacturerId;
|
||||||
|
|
||||||
|
/// Model identification +CGMM
|
||||||
|
///
|
||||||
|
/// Read a text string that identifies the device model.
|
||||||
|
#[derive(Clone, AtatCmd)]
|
||||||
|
#[at_cmd("+CGMM", ModelId)]
|
||||||
|
pub struct GetModelId;
|
||||||
|
|
||||||
|
/// Software version identification +CGMR
|
||||||
|
///
|
||||||
|
/// Read a text string that identifies the software version of the module
|
||||||
|
#[derive(Clone, AtatCmd)]
|
||||||
|
#[at_cmd("+CGMR", SoftwareVersion)]
|
||||||
|
pub struct GetSoftwareVersion;
|
||||||
|
|
||||||
|
/// 7.12 Wi-Fi MAC address +UWAPMACADDR
|
||||||
|
///
|
||||||
|
/// Lists the currently used MAC address.
|
||||||
|
#[derive(Clone, AtatCmd)]
|
||||||
|
#[at_cmd("+UWAPMACADDR", WifiMac)]
|
||||||
|
pub struct GetWifiMac;
|
||||||
|
|
||||||
|
|
||||||
|
/// 7.12 check if device ok AT
|
||||||
|
///
|
||||||
|
/// Lists the currently used MAC address.
|
||||||
|
#[derive(Clone, AtatCmd)]
|
||||||
|
#[at_cmd("", ATCOMMAND)]
|
||||||
|
pub struct GetAT;
|
120
src/serial.rs
Normal file
120
src/serial.rs
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
use embassy_time::{Timer, Duration};
|
||||||
|
use hal::{peripherals::UART1, gpio::GpioPin};
|
||||||
|
use hal::{
|
||||||
|
uart::{
|
||||||
|
config::{Config, DataBits, Parity, StopBits},
|
||||||
|
TxRxPins,
|
||||||
|
},
|
||||||
|
Uart, clock::Clocks
|
||||||
|
};
|
||||||
|
use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal};
|
||||||
|
use esp_hal_common::uart::config::AtCmdConfig;
|
||||||
|
use esp_hal_common::uart::{ UartRx, UartTx};
|
||||||
|
use esp_backtrace as _;
|
||||||
|
use static_cell::make_static;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
const READ_BUF_SIZE: usize = 64;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
const AT_CMD: u8 = 0x04;
|
||||||
|
|
||||||
|
pub fn uart_serial_setup(gpio1: GpioPin<hal::gpio::Unknown, 15>, gpio3: GpioPin<hal::gpio::Unknown, 14>, uart0_per: UART1, clocks: &Clocks<'static>) -> (
|
||||||
|
UartTx<'static, UART1>,
|
||||||
|
UartRx<'static, UART1>,
|
||||||
|
&'static Signal<NoopRawMutex, usize>,
|
||||||
|
){
|
||||||
|
let config = Config {
|
||||||
|
baudrate: 115200,
|
||||||
|
data_bits: DataBits::DataBits8,
|
||||||
|
parity: Parity::ParityNone,
|
||||||
|
stop_bits: StopBits::STOP1,
|
||||||
|
};
|
||||||
|
|
||||||
|
let pins = TxRxPins::new_tx_rx(
|
||||||
|
gpio1.into_push_pull_output(),
|
||||||
|
gpio3.into_floating_input(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut serial1 = Uart::new_with_config(uart0_per, config, Some(pins), &clocks);
|
||||||
|
serial1
|
||||||
|
.set_rx_fifo_full_threshold(READ_BUF_SIZE as u16)
|
||||||
|
.unwrap();
|
||||||
|
let (tx15, rx14) = serial1.split();
|
||||||
|
|
||||||
|
let signal = &*make_static!(Signal::new());
|
||||||
|
|
||||||
|
(tx15, rx14, signal)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
pub async fn at_writer(mut tx: UartTx<'static, UART1>, signal: &'static Signal<NoopRawMutex, usize>) {
|
||||||
|
use core::fmt::Write;
|
||||||
|
// embedded_io_async::Write::write(
|
||||||
|
// // embedded_io_async::Write::write_all(
|
||||||
|
// &mut tx,
|
||||||
|
// b"AT+CGMI",
|
||||||
|
// // b"AT with EOT (CTRL-D).\r\n",
|
||||||
|
// )
|
||||||
|
// .await
|
||||||
|
// .unwrap();
|
||||||
|
|
||||||
|
embedded_io_async::Write::write(&mut tx, b"AT+CGMI").await.unwrap();
|
||||||
|
// embedded_io_async::Write::write_all(cmd).await.map_err(|_| Error::Write)?;
|
||||||
|
|
||||||
|
// for _ in 0..3 {
|
||||||
|
// match embedded_io_async::Write::write_all(&mut tx, b"AT+CGMI").await {
|
||||||
|
// Ok(_r) => {},//esp_println::println!("SIZE RESPONSE: {:?}", r),
|
||||||
|
// // Err(atat::Error::Timeout) => {},
|
||||||
|
// Err(_) => log::error!("Write Error"),
|
||||||
|
// };
|
||||||
|
// // embedded_io_async::Write::flush(&mut tx).await.unwrap();
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
embedded_io_async::Write::flush(&mut tx).await.unwrap();
|
||||||
|
// loop {
|
||||||
|
// let bytes_read = signal.wait().await;
|
||||||
|
// signal.reset();
|
||||||
|
// write!(&mut tx, "\r\n-- received {} bytes --\r\n", bytes_read).unwrap();
|
||||||
|
// embedded_io_async::Write::flush(&mut tx).await.unwrap();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
#[embassy_executor::task]
|
||||||
|
pub async fn at_reader(mut rx: UartRx<'static, UART1>, signal: &'static Signal<NoopRawMutex, usize>) {
|
||||||
|
const MAX_BUFFER_SIZE: usize = 100 * READ_BUF_SIZE + 16;
|
||||||
|
|
||||||
|
let mut rbuf: [u8; MAX_BUFFER_SIZE] = [0u8; MAX_BUFFER_SIZE];
|
||||||
|
let mut offset = 0;
|
||||||
|
loop {
|
||||||
|
let r = embedded_io_async::Read::read(&mut rx, &mut rbuf[offset..]).await;
|
||||||
|
match r {
|
||||||
|
Ok(len) => {
|
||||||
|
offset += len;
|
||||||
|
// if &rbuf[..offset] == b"OK\r\n" {
|
||||||
|
// esp_println::println!("Received OK response");
|
||||||
|
// } else if &rbuf[..offset] == b"+CME ERROR: 58\r\n" {
|
||||||
|
// esp_println::println!("Received Error response: 58");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// +CME ERROR: 58
|
||||||
|
let data_str = core::str::from_utf8(&rbuf[..offset]).unwrap_or("Invalid UTF-8");
|
||||||
|
// log::info!("Read: {}, data: {}", len, data_str);
|
||||||
|
if data_str.contains("OK") {
|
||||||
|
esp_println::println!("Received OK response");
|
||||||
|
} else if data_str.contains("+CME ERROR: 58") {
|
||||||
|
esp_println::println!("Received Error response: 58");
|
||||||
|
} else {
|
||||||
|
// Timer::after(Duration::from_millis(3000)).await;
|
||||||
|
esp_println::println!("Read: {}, data: {}\n", len, data_str);
|
||||||
|
}
|
||||||
|
// esp_println::println!("Read: {}, data: {}\n", len, data_str);
|
||||||
|
// esp_println::println!("Read: {len}, data: {:?}", &rbuf[..offset]);
|
||||||
|
offset = 0;
|
||||||
|
signal.signal(len);
|
||||||
|
}
|
||||||
|
Err(e) => esp_println::println!("RX Error: {:?}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue