mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Compare commits
429 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6fb3a64ba2 | ||
|
|
3af4c5591e | ||
|
|
cce94b9d92 | ||
|
|
86f48a2fb6 | ||
|
|
381c0b7823 | ||
|
|
8f33cff6ea | ||
|
|
9d00cd3492 | ||
|
|
3e0b2d861d | ||
|
|
a1217af4c6 | ||
|
|
58bf5c5008 | ||
|
|
7e61a34df3 | ||
|
|
2fb788f817 | ||
|
|
f887756a71 | ||
|
|
5d915134a3 | ||
|
|
7516dff802 | ||
|
|
03ef931fb2 | ||
|
|
437881f0ed | ||
|
|
c736b1e353 | ||
|
|
d682e98a66 | ||
|
|
bdfe87e1cb | ||
|
|
5c2ced1093 | ||
|
|
f87f470415 | ||
|
|
2e86718973 | ||
|
|
013aebcc05 | ||
|
|
b33045189f | ||
|
|
600c3d7563 | ||
|
|
ebce2d4ee9 | ||
|
|
16b7aee42f | ||
|
|
d33e275ca3 | ||
|
|
da4074c9a5 | ||
|
|
f716d2ccdd | ||
|
|
7567e08227 | ||
|
|
6aca9ffee5 | ||
|
|
f5740dbf31 | ||
|
|
d163afc6b1 | ||
|
|
1b60dd1ae7 | ||
|
|
795ef28f79 | ||
|
|
8e155c9276 | ||
|
|
6831ad0eae | ||
|
|
8f7bf2fd2c | ||
|
|
f389f11669 | ||
|
|
37994b3cc5 | ||
|
|
27f8f2c4e6 | ||
|
|
01e637cdf4 | ||
|
|
1b2a0ea130 | ||
|
|
b8135ea639 | ||
|
|
c49faa7337 | ||
|
|
4511d74a9e | ||
|
|
afd82f7ac4 | ||
|
|
db3f109c7d | ||
|
|
ab678e6c88 | ||
|
|
330e99381e | ||
|
|
7e314b2cc3 | ||
|
|
4fb034858a | ||
|
|
d494b9d3ac | ||
|
|
4034d0ad51 | ||
|
|
9fec689117 | ||
|
|
6c4b92270e | ||
|
|
a22b270749 | ||
|
|
9f27ce5899 | ||
|
|
27f9b9f2e8 | ||
|
|
2e7da862c8 | ||
|
|
bb2b4e30b2 | ||
|
|
f47467271f | ||
|
|
cdc773100c | ||
|
|
a3b67d3eb6 | ||
|
|
ef12ed62df | ||
|
|
2f6b3796f2 | ||
|
|
6163bc392b | ||
|
|
475bc29cc8 | ||
|
|
c4f5269c83 | ||
|
|
13ad59ac12 | ||
|
|
2259244eb2 | ||
|
|
725423c50c | ||
|
|
14963032c3 | ||
|
|
e1fe232254 | ||
|
|
9cafcbcab5 | ||
|
|
f4076258f1 | ||
|
|
866b5bcb30 | ||
|
|
289bbfd393 | ||
|
|
68a64ac554 | ||
|
|
0a95da00f1 | ||
|
|
32d97683f8 | ||
|
|
c3654486c7 | ||
|
|
b5184012c4 | ||
|
|
fc0c6f61d2 | ||
|
|
53bb2a6ad1 | ||
|
|
da9f7a6540 | ||
|
|
2a1dae6336 | ||
|
|
ada2db0739 | ||
|
|
14ee38a0d9 | ||
|
|
2c700a90b0 | ||
|
|
da04c2c444 | ||
|
|
5f70b75e90 | ||
|
|
02cac07a77 | ||
|
|
a3a6b5127f | ||
|
|
ef6fa8030e | ||
|
|
561376696b | ||
|
|
d34fa1c1ad | ||
|
|
9022f51ea5 | ||
|
|
4723cc3f4e | ||
|
|
8c471105fe | ||
|
|
b9902bbd78 | ||
|
|
c5afd86b9a | ||
|
|
b756d2e1f1 | ||
|
|
5c7d81b900 | ||
|
|
7e9574f98d | ||
|
|
053ae53f19 | ||
|
|
8f77ad5830 | ||
|
|
be4fc0908f | ||
|
|
6ec2ac19d0 | ||
|
|
bed34a0b9a | ||
|
|
134038c1ce | ||
|
|
003b2e37d4 | ||
|
|
8014ef68c0 | ||
|
|
563c4fa6ea | ||
|
|
d1d6b45e8e | ||
|
|
f148a1413c | ||
|
|
bb3636e2d5 | ||
|
|
133789517a | ||
|
|
7e0bd980f2 | ||
|
|
883acbaa4b | ||
|
|
d10e762a7d | ||
|
|
94e40d82f3 | ||
|
|
9315cf6a55 | ||
|
|
eb9726bbcc | ||
|
|
4014fc4b3e | ||
|
|
ccc01433b7 | ||
|
|
ee3687430b | ||
|
|
6f6038ebcd | ||
|
|
0921796054 | ||
|
|
dba4690a88 | ||
|
|
b3aac7b182 | ||
|
|
5b5248929e | ||
|
|
8f45d6f688 | ||
|
|
37f8b4fd1b | ||
|
|
5f5a8a9cdd | ||
|
|
3f616a47c8 | ||
|
|
694524cb6f | ||
|
|
747ac62733 | ||
|
|
c76a4d0172 | ||
|
|
d2dd9f5a5b | ||
|
|
ae9c8edbca | ||
|
|
f71ffeabb7 | ||
|
|
6ebd50ab85 | ||
|
|
241ff93bf4 | ||
|
|
2d17624ddb | ||
|
|
ce70f43113 | ||
|
|
f825363606 | ||
|
|
86f1b3881d | ||
|
|
c2f910ffe3 | ||
|
|
9066523229 | ||
|
|
016c81291e | ||
|
|
e75e19eb00 | ||
|
|
545d473220 | ||
|
|
873bd6973d | ||
|
|
9320f54a73 | ||
|
|
68e2042fd6 | ||
|
|
b490233988 | ||
|
|
c2ef2fced5 | ||
|
|
3a75b098d1 | ||
|
|
242a2ea843 | ||
|
|
ce736c267a | ||
|
|
c88cd3c5f3 | ||
|
|
59940b3311 | ||
|
|
05785e82b3 | ||
|
|
50253a6a77 | ||
|
|
13f3bedb2f | ||
|
|
6310a9fabc | ||
|
|
eb087713a4 | ||
|
|
3e81f36dce | ||
|
|
fe4e47219e | ||
|
|
ec8f63f06d | ||
|
|
5ec33f5d4d | ||
|
|
adafa00b87 | ||
|
|
31647a934c | ||
|
|
e9c96c5456 | ||
|
|
3b3fca2e8b | ||
|
|
a53a4f44de | ||
|
|
60caede5dd | ||
|
|
eae7f8f8d7 | ||
|
|
04dfa682c9 | ||
|
|
62a4a93dec | ||
|
|
7aa2d3fee2 | ||
|
|
22bcfdc29f | ||
|
|
0e9dbcbc77 | ||
|
|
68c78222e1 | ||
|
|
22b4f451ea | ||
|
|
15ba034ce5 | ||
|
|
17bb6edfd2 | ||
|
|
65c5a068d8 | ||
|
|
68d3b845b2 | ||
|
|
22f030ebb8 | ||
|
|
f5703ff107 | ||
|
|
3b77eb35cf | ||
|
|
054326454b | ||
|
|
b763f1289b | ||
|
|
8ead9337d1 | ||
|
|
d8fb141bc4 | ||
|
|
a698799a7d | ||
|
|
5e3722a10e | ||
|
|
c16a2a1f94 | ||
|
|
e2960c3f82 | ||
|
|
08404e700f | ||
|
|
6d77201ba0 | ||
|
|
eef0a15194 | ||
|
|
6895c05321 | ||
|
|
c453728ab5 | ||
|
|
273afb73f4 | ||
|
|
84dd4c3685 | ||
|
|
33eae0c30d | ||
|
|
9bc93991e7 | ||
|
|
ed70a587ec | ||
|
|
fe2973522e | ||
|
|
f5f62ee02d | ||
|
|
cd160250a6 | ||
|
|
588ac3e8ac | ||
|
|
76de9b890e | ||
|
|
42ff234204 | ||
|
|
4113a072c2 | ||
|
|
232cbee697 | ||
|
|
1b77ed783b | ||
|
|
41b8e4f99c | ||
|
|
c61d56935b | ||
|
|
6e779a0520 | ||
|
|
d8fbd607d4 | ||
|
|
01f3c391f0 | ||
|
|
5bbdf3b9f8 | ||
|
|
b4741de50c | ||
|
|
d19ba1c492 | ||
|
|
ae76f8f58d | ||
|
|
b05f38abd0 | ||
|
|
51bfa68bdd | ||
|
|
fa4207ddfd | ||
|
|
3ca6a66d9b | ||
|
|
f1c5394570 | ||
|
|
0105346a11 | ||
|
|
96fafc5fb4 | ||
|
|
29546bb13a | ||
|
|
b0e9fa02e8 | ||
|
|
f257b7fba5 | ||
|
|
6fff4939e4 | ||
|
|
a8e0d2693d | ||
|
|
c440da2ea8 | ||
|
|
f1144ca5cc | ||
|
|
3cc2d90fda | ||
|
|
48c9e8a9a9 | ||
|
|
f4c4387e05 | ||
|
|
a1987b61b4 | ||
|
|
f8924182d3 | ||
|
|
d0e95c5fba | ||
|
|
1cefb7b6bc | ||
|
|
794c5202f4 | ||
|
|
98653566a8 | ||
|
|
a605533213 | ||
|
|
1e20948d83 | ||
|
|
4801816357 | ||
|
|
d60363a64c | ||
|
|
5c45150f58 | ||
|
|
d3993da6d4 | ||
|
|
00f3ea9b7f | ||
|
|
e8114ca0a4 | ||
|
|
de0a7c547f | ||
|
|
76a7a56e85 | ||
|
|
9744fcafcf | ||
|
|
c4878a90d7 | ||
|
|
ae461dc296 | ||
|
|
10eedd4ad2 | ||
|
|
fa41771e65 | ||
|
|
a1a4dc4642 | ||
|
|
7dbb806311 | ||
|
|
97537853a8 | ||
|
|
e1e3e298bf | ||
|
|
c5dac4fd33 | ||
|
|
51300cc4f0 | ||
|
|
3ad090caf7 | ||
|
|
fba73f98db | ||
|
|
2db87ede53 | ||
|
|
fca76a017d | ||
|
|
7915c1a445 | ||
|
|
6c75ec553d | ||
|
|
fc54df1f22 | ||
|
|
0afae5d3ee | ||
|
|
e028544cd0 | ||
|
|
5eb649278a | ||
|
|
418a43d96e | ||
|
|
00c8124a0a | ||
|
|
78f96bd32c | ||
|
|
d8fb1ab0ca | ||
|
|
a208c9908a | ||
|
|
2b6a79b9f0 | ||
|
|
2fff4d36d0 | ||
|
|
fd6a246908 | ||
|
|
901e00bba3 | ||
|
|
eea46a2005 | ||
|
|
2ee1f5c224 | ||
|
|
3e50191107 | ||
|
|
4369d5b66f | ||
|
|
70913fe120 | ||
|
|
83f826349b | ||
|
|
00f57c9992 | ||
|
|
0becfa3274 | ||
|
|
6fee8514f4 | ||
|
|
10255d52d0 | ||
|
|
6720da3b88 | ||
|
|
ed4ac0c797 | ||
|
|
d45c9b1a22 | ||
|
|
91459c2490 | ||
|
|
593f9495f4 | ||
|
|
6c520090c6 | ||
|
|
67640d4a00 | ||
|
|
58c9489b92 | ||
|
|
553b67e406 | ||
|
|
4269ec835d | ||
|
|
e572255fd2 | ||
|
|
bfefd04b55 | ||
|
|
ed66c72ca1 | ||
|
|
14f598e11e | ||
|
|
7193e6f0c9 | ||
|
|
72399c4fe6 | ||
|
|
1777206de7 | ||
|
|
1c32555c2a | ||
|
|
4307e81760 | ||
|
|
3d7d9c85b5 | ||
|
|
02b60e9fb3 | ||
|
|
c93922fd36 | ||
|
|
838c110876 | ||
|
|
a42f3f78d1 | ||
|
|
93e49ab5a2 | ||
|
|
ed0386d2c4 | ||
|
|
63dced047f | ||
|
|
cf6e8b963b | ||
|
|
07864a0e78 | ||
|
|
c9c5f03c10 | ||
|
|
e6ffbd9058 | ||
|
|
812dee8e54 | ||
|
|
d9dc1ff698 | ||
|
|
c01baca157 | ||
|
|
5c441f22c2 | ||
|
|
8134cd3486 | ||
|
|
46a72d8254 | ||
|
|
bdca5a27ec | ||
|
|
3c7c865e59 | ||
|
|
59cd3a1379 | ||
|
|
98052936b0 | ||
|
|
a486ba581b | ||
|
|
df5379bac5 | ||
|
|
5656381cc3 | ||
|
|
d461751a71 | ||
|
|
88ef473362 | ||
|
|
d3bd5d8e17 | ||
|
|
148a3c1da1 | ||
|
|
3bedd85e7c | ||
|
|
ab905d8e0c | ||
|
|
8fe5dde4b8 | ||
|
|
b5ca54c56e | ||
|
|
fd1003533c | ||
|
|
ec2cf476bb | ||
|
|
afc9e3be5b | ||
|
|
5651c1c5d7 | ||
|
|
65b3353f57 | ||
|
|
791b1df27e | ||
|
|
f5c8d5233c | ||
|
|
5635f30135 | ||
|
|
cbb8ad8362 | ||
|
|
b540f16734 | ||
|
|
2f3583ebde | ||
|
|
36e4c672a7 | ||
|
|
cee560dd8b | ||
|
|
fcf760f0d7 | ||
|
|
a6f1b8d546 | ||
|
|
4f509594d8 | ||
|
|
4008969ca7 | ||
|
|
c16e004757 | ||
|
|
309a2abfd4 | ||
|
|
269974c244 | ||
|
|
0cdc3ce045 | ||
|
|
f6905b4213 | ||
|
|
725faa5455 | ||
|
|
e1774664dd | ||
|
|
35c9b40982 | ||
|
|
b533312d45 | ||
|
|
c6f319ecb0 | ||
|
|
b6672c1704 | ||
|
|
ae604d12e2 | ||
|
|
4782faf47f | ||
|
|
4a1c213409 | ||
|
|
27b8c1b82a | ||
|
|
76eb17e4d4 | ||
|
|
a2bbab0684 | ||
|
|
dfe5f827f9 | ||
|
|
ea7f43e60c | ||
|
|
4e9d29c88d | ||
|
|
6a955b08e1 | ||
|
|
20a40edd36 | ||
|
|
42739c0817 | ||
|
|
2915d26a19 | ||
|
|
e2e974958e | ||
|
|
6b084a53b8 | ||
|
|
a21809b090 | ||
|
|
cd24797961 | ||
|
|
f4dc46d002 | ||
|
|
93e6efc001 | ||
|
|
12f20c84e3 | ||
|
|
419fbdc3fa | ||
|
|
a4f0d4da53 | ||
|
|
1aaecef419 | ||
|
|
6c19cd0750 | ||
|
|
845e683fc9 | ||
|
|
d3ac8e7b1f | ||
|
|
c6beed8265 | ||
|
|
7c32e5a21e | ||
|
|
73c1129be7 | ||
|
|
374c2ad113 | ||
|
|
c80f833a06 | ||
|
|
784201ea2e | ||
|
|
2cba4b863f | ||
|
|
fba56318f8 | ||
|
|
48a2298e81 | ||
|
|
6f9e41152b | ||
|
|
134fa87a5c | ||
|
|
eaab692d4d | ||
|
|
a40097f837 | ||
|
|
b00b0e872f | ||
|
|
4768db5311 | ||
|
|
c2aa3489fd | ||
|
|
ad9b93dc52 | ||
|
|
a97b2c00cd | ||
|
|
bf7b032649 |
64 changed files with 8578 additions and 1713 deletions
|
|
@ -1,27 +0,0 @@
|
|||
# Use the latest 2.1 version of CircleCI pipeline process engine.
|
||||
# See: https://circleci.com/docs/2.0/configuration-reference
|
||||
version: 2.1
|
||||
|
||||
# Define a job to be invoked later in a workflow.
|
||||
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
|
||||
jobs:
|
||||
build-tio:
|
||||
# Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
|
||||
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
|
||||
docker:
|
||||
- image: cimg/base:edge
|
||||
# Add steps to the job
|
||||
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
|
||||
steps:
|
||||
- checkout
|
||||
- run: sudo apt-get -qq update
|
||||
- run: sudo apt-get install -y bash-completion git meson libinih-dev
|
||||
- run: git clone https://github.com/tio/tio.git
|
||||
- run: cd tio && meson build --prefix $HOME/test/tio && ninja -C build install
|
||||
|
||||
# Invoke jobs via workflows
|
||||
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
|
||||
workflows:
|
||||
build-tio-workflow:
|
||||
jobs:
|
||||
- build-tio
|
||||
5
.clang-format
Normal file
5
.clang-format
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
BasedOnStyle: llvm
|
||||
IndentWidth: 4
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
BreakBeforeBraces: Allman
|
||||
7
.github/workflows/codeql-buildscript.sh
vendored
Normal file
7
.github/workflows/codeql-buildscript.sh
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
pip3 install meson -U
|
||||
pip3 install ninja -U
|
||||
sudo apt-get install -y liblua5.2-dev libglib2.0-dev
|
||||
meson setup build
|
||||
meson compile -C build
|
||||
126
.github/workflows/codeql.yml
vendored
Normal file
126
.github/workflows/codeql.yml
vendored
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main", "master" ]
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
pull_request:
|
||||
branches: '*'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
# Runner size impacts CodeQL analysis time. To learn more, please see:
|
||||
# - https://gh.io/recommended-hardware-resources-for-running-codeql
|
||||
# - https://gh.io/supported-runners-and-hardware-resources
|
||||
# - https://gh.io/using-larger-runners
|
||||
# Consider using larger runners for possible analysis time improvements.
|
||||
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-22.04' }}
|
||||
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'cpp' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
|
||||
# Use only 'java' to analyze code written in Java, Kotlin or both
|
||||
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
|
||||
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
|
||||
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
|
||||
# queries: security-extended,security-and-quality
|
||||
queries: security-and-quality
|
||||
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
#- name: Autobuild
|
||||
# uses: github/codeql-action/autobuild@v3
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
||||
|
||||
# If the Autobuild fails above, remove it and uncomment the following three lines.
|
||||
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
|
||||
|
||||
- run: |
|
||||
./.github/workflows/codeql-buildscript.sh
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v3
|
||||
with:
|
||||
category: "/language:${{matrix.language}}"
|
||||
upload: false
|
||||
id: step1
|
||||
|
||||
# Filter out rules with low severity or high false positve rate
|
||||
# Also filter out warnings in third-party code
|
||||
- name: Filter out unwanted errors and warnings
|
||||
uses: advanced-security/filter-sarif@v1
|
||||
with:
|
||||
patterns: |
|
||||
-**:cpp/path-injection
|
||||
-**:cpp/world-writable-file-creation
|
||||
-**:cpp/poorly-documented-function
|
||||
-**:cpp/potentially-dangerous-function
|
||||
-**:cpp/use-of-goto
|
||||
-**:cpp/integer-multiplication-cast-to-long
|
||||
-**:cpp/comparison-with-wider-type
|
||||
-**:cpp/leap-year/*
|
||||
-**:cpp/ambiguously-signed-bit-field
|
||||
-**:cpp/suspicious-pointer-scaling
|
||||
-**:cpp/suspicious-pointer-scaling-void
|
||||
-**:cpp/unsigned-comparison-zero
|
||||
-**/cmake*/Modules/**
|
||||
input: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif
|
||||
output: ${{ steps.step1.outputs.sarif-output }}/cpp.sarif
|
||||
|
||||
- name: Upload CodeQL results to code scanning
|
||||
uses: github/codeql-action/upload-sarif@v3
|
||||
with:
|
||||
sarif_file: ${{ steps.step1.outputs.sarif-output }}
|
||||
category: "/language:${{matrix.language}}"
|
||||
|
||||
- name: Upload CodeQL results as an artifact
|
||||
if: success() || failure()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: codeql-results
|
||||
path: ${{ steps.step1.outputs.sarif-output }}
|
||||
retention-days: 5
|
||||
|
||||
- name: Fail if an error is found
|
||||
run: |
|
||||
./.github/workflows/fail_on_error.py \
|
||||
${{ steps.step1.outputs.sarif-output }}/cpp.sarif
|
||||
34
.github/workflows/fail_on_error.py
vendored
Executable file
34
.github/workflows/fail_on_error.py
vendored
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
# Return whether SARIF file contains error-level results
|
||||
def codeql_sarif_contain_error(filename):
|
||||
with open(filename, 'r') as f:
|
||||
s = json.load(f)
|
||||
|
||||
for run in s.get('runs', []):
|
||||
rules_metadata = run['tool']['driver']['rules']
|
||||
if not rules_metadata:
|
||||
rules_metadata = run['tool']['extensions'][0]['rules']
|
||||
|
||||
for res in run.get('results', []):
|
||||
if 'ruleIndex' in res:
|
||||
rule_index = res['ruleIndex']
|
||||
elif 'rule' in res and 'index' in res['rule']:
|
||||
rule_index = res['rule']['index']
|
||||
else:
|
||||
continue
|
||||
try:
|
||||
rule_level = rules_metadata[rule_index]['defaultConfiguration']['level']
|
||||
except IndexError as e:
|
||||
print(e, rule_index, len(rules_metadata))
|
||||
else:
|
||||
if rule_level == 'error':
|
||||
return True
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
if codeql_sarif_contain_error(sys.argv[1]):
|
||||
sys.exit(1)
|
||||
30
.github/workflows/macos.yml
vendored
Normal file
30
.github/workflows/macos.yml
vendored
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
name: MacOS build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: macos-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.x'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
brew install meson ninja lua
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
meson setup build
|
||||
meson compile -C build --verbose
|
||||
meson install -C build
|
||||
31
.github/workflows/ubuntu.yml
vendored
Normal file
31
.github/workflows/ubuntu.yml
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
name: Ubuntu build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.x'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install -y bash-completion git meson liblua5.2-dev libglib2.0-dev
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
meson setup build --prefix $HOME/opt/tio
|
||||
meson compile -C build --verbose
|
||||
meson install -C build
|
||||
2
.typos.toml
Normal file
2
.typos.toml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[default]
|
||||
extend-ignore-words-re = ["tio"]
|
||||
25
AUTHORS
25
AUTHORS
|
|
@ -41,5 +41,30 @@ Rui Chen <rui@chenrui.dev>
|
|||
Ralph Siemsen <ralphs@netwinder.org>
|
||||
Victor Oliveira <rhapsodyv@gmail.com>
|
||||
Attila Veghelyi <aveghelyi@dension.com>
|
||||
Vyacheslav Patkov <slava@patkov.ru>
|
||||
Bill Hass <billhass@umich.edu>
|
||||
Peter van Dijk <peter@7bits.nl>
|
||||
Braden Young <braden@somewearlabs.com>
|
||||
Wes Koerber <wkoerber@acsd4u.com>
|
||||
HiFiPhile <admin@hifiphile.com>
|
||||
Paul Ruizendaal <pnr@planet.nl>
|
||||
Fredrik Svedberg <fredrik@svedberg.us>
|
||||
Sebastian <sebastian.krahmer@gmail.com>
|
||||
Mingjie Shen <shen497@purdue.edu>
|
||||
Brian <bayuan@purdue.edu>
|
||||
Davis C <davisclaib@gmail.com>
|
||||
KhazAkar <damianzrb@zohomail.eu>
|
||||
Eliot Alan Foss <eliotfoss@gmail.com>
|
||||
Robert Lipe <robertlipe@gpsbabel.org>
|
||||
Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
|
||||
Tomka Gergely <tomkatudor@gmail.com>
|
||||
Steve Marple <stevemarple@googlemail.com>
|
||||
konosubakonoakua <ailike_meow@qq.com>
|
||||
Keith Hill <k_hill@unitronlp.com>
|
||||
Lubov66 <radolevanja@gmail.com>
|
||||
V <v@anomalous.eu>
|
||||
Samuel Holland <samuel@sholland.org>
|
||||
David Ordnung <david.ordnung@googlemail.com>
|
||||
|
||||
|
||||
Thanks to everyone who has contributed to this project.
|
||||
|
|
|
|||
2
LICENSE
2
LICENSE
|
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2014-2022 Martin Lund <martin.lund@keep-it-simple.com>
|
||||
Copyright (c) 2014-2025 Martin Lund <martin.lund@keep-it-simple.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
|
|
|
|||
896
NEWS
896
NEWS
|
|
@ -1,5 +1,871 @@
|
|||
=== tio v3.9 (2025-04-13) ===
|
||||
|
||||
|
||||
|
||||
Changes since tio v3.8 (2024-11-30):
|
||||
|
||||
* Fix parsing of timestamp options
|
||||
|
||||
* codeql: Upgrade to upload-artifact@v4
|
||||
|
||||
* Update plaintext man page
|
||||
|
||||
* Add character mapping examples
|
||||
|
||||
* Fix pattern matching memory corruption
|
||||
|
||||
Samuel Holland:
|
||||
|
||||
* Don't add null characters to the expect buffer
|
||||
|
||||
They prevent regexec() from seeing the remainder of the buffer.
|
||||
|
||||
V:
|
||||
|
||||
* Disable stdout buffering globally
|
||||
|
||||
This makes it possible to pipe output to other programs cleanly.
|
||||
|
||||
Lubov66:
|
||||
|
||||
* docs: edited the license date
|
||||
|
||||
Jakob Haufe:
|
||||
|
||||
* Manpage: Fix backslash encoding
|
||||
|
||||
Literal backslash needs to be written as \e.
|
||||
|
||||
|
||||
|
||||
Changes since tio v3.7 (2024-08-31):
|
||||
|
||||
* Rename git version to simply version
|
||||
|
||||
* Clean up lua API
|
||||
|
||||
Rename modem_send() to send()
|
||||
Rename send to write()
|
||||
|
||||
* Zero initialize buffer in read_string()
|
||||
|
||||
* Use version from git
|
||||
|
||||
* Fix memory leak in base62_encode()
|
||||
|
||||
* Fix name declaration conflict with socket send()
|
||||
|
||||
* Add clang-format spec
|
||||
|
||||
Keith Hill:
|
||||
|
||||
+ Add system timestamps to lua read() and new lua read_line() per global options
|
||||
+ Add missing timestamp-format epoch
|
||||
+ Update send_ to use fsync and tcdrain like normal tty_sync does
|
||||
+ Rework read_line to save partial line at timeout
|
||||
+ Simplified read_line to reduce cyclomatic complexity
|
||||
+ renamed example files read.lua and read_line.lua
|
||||
+ moved #define READ_LINE_SIZE to top of file
|
||||
+ renamed g_linebuf to linebuf, and moved it into read_line as a static variable
|
||||
|
||||
|
||||
|
||||
Changes since tio v3.6 (2024-07-19):
|
||||
|
||||
* Remove unnecessary sync in line input mode
|
||||
|
||||
This caused a problem for some highly timing sensitive modem read-eval-print
|
||||
loops because the input line and line termination characters (cr/nl) would be
|
||||
shifted out on the UART with too big delay inbetween because of two
|
||||
syncs.
|
||||
|
||||
* Fix socket send call on platforms without MSG_NOSIGNAL
|
||||
|
||||
To fix build issue encountered on MacOS Catalina but may apply to other
|
||||
platforms.
|
||||
|
||||
Steve Marple:
|
||||
|
||||
* Add "epoch" timestamp option
|
||||
|
||||
Add an option that prints the timestamp as the number of seconds since
|
||||
the Unix epoch.
|
||||
|
||||
Tomka Gergely:
|
||||
|
||||
* The log-directory options is not read from the configuration file.
|
||||
|
||||
|
||||
|
||||
Changes since tio v3.5 (2024-06-29):
|
||||
|
||||
* Add configuration file include directive
|
||||
|
||||
To include the contents of another configuration file simply do e.g.:
|
||||
|
||||
[include raspberrypi.conf]
|
||||
|
||||
Also, included file can include other files which can include other
|
||||
files etc.
|
||||
|
||||
This feature is useful for managing many configuration files and sharing
|
||||
configuration files with others.
|
||||
|
||||
* Mention how to list key commands in help output
|
||||
|
||||
* Fix hex output mode when using normal input mode
|
||||
|
||||
In this combination of modes the input character was not forwarded to
|
||||
the tty device. This fix makes sure it is forwarded.
|
||||
|
||||
* Fix uptime on MacOS
|
||||
|
||||
On MacOS the birth time is apparently not available so we use
|
||||
modification time instead.
|
||||
|
||||
* Improve warning upon failing connect
|
||||
|
||||
Add device path to warning when connect fails.
|
||||
|
||||
* Fix crashy search_reset() on macOS
|
||||
|
||||
* Clean up shadow variable
|
||||
|
||||
* Clean up readline code
|
||||
|
||||
* Improve listing of long device names
|
||||
|
||||
* Fix listing of serial devices on macOS
|
||||
|
||||
Heinrich Schuchardt:
|
||||
|
||||
* Print correct 'Done' timestamp for X- and Y-modem transfers
|
||||
|
||||
Call tio_printf() after completing xymodem_send().
|
||||
|
||||
Robert Lipe:
|
||||
|
||||
* Recompute listing_device_name_length_max for MacOS case, too.
|
||||
|
||||
|
||||
|
||||
Changes since tio v3.4:
|
||||
|
||||
* Clarify input and output direction of map flags
|
||||
|
||||
* Rename mapping flag MSB2LSB to IMSB2LSB
|
||||
|
||||
This is the correct naming since we are changing the input bit order on
|
||||
input from the serial device.
|
||||
|
||||
* Add OIGNCR mapping flag
|
||||
|
||||
Ignores CR on output to serial device.
|
||||
|
||||
* Fix line input mode ignoring characters ABCD
|
||||
|
||||
* Fix tainted print
|
||||
|
||||
Jakob Haufe:
|
||||
|
||||
* Fix typos
|
||||
|
||||
|
||||
|
||||
Changes since tio v3.3:
|
||||
|
||||
* Update configuration output
|
||||
|
||||
* Clean up script run interaction text
|
||||
|
||||
* Fix unbounded writes
|
||||
|
||||
* Add history and editing feature to line input mode
|
||||
|
||||
Use up and down arrow keys to navigate history.
|
||||
|
||||
Use left and right arrow keys to move cursor back and forth.
|
||||
|
||||
We try mimic the behaviour of GNU readline which we can not use because
|
||||
we also need to react to key commands.
|
||||
|
||||
* Reuse socket address
|
||||
|
||||
To avoid having to wait for socket timeout when restarting server.
|
||||
|
||||
* Fix line input mode
|
||||
|
||||
Fix so that ABCD are no longer ignored.
|
||||
|
||||
* Make sure ICRNL, IGNCR, INLCR take effect
|
||||
|
||||
* Include correct header for poll()
|
||||
|
||||
* Add group write permission to xymodem received file
|
||||
|
||||
* Fix missing open() flags in xymodem_receive()
|
||||
|
||||
Vyacheslav Patkov:
|
||||
|
||||
* Show current mappings in the configuration printout
|
||||
|
||||
* Use "ctrl-t m" to change mappings interactively
|
||||
|
||||
* Prompt for Lua script or shell command in interactive session
|
||||
|
||||
Eliot Alan Foss:
|
||||
|
||||
* Added support to receive XMODEM-CRC files from the connected serial port.
|
||||
|
||||
|
||||
|
||||
Changes since tio v3.2:
|
||||
|
||||
* Force destructive backspace when using local echo
|
||||
|
||||
Only takes effect in normal output mode.
|
||||
|
||||
* Fix local-echo in configuration file
|
||||
|
||||
* Clean up includes
|
||||
|
||||
* Force socket write operation to ignore any signals
|
||||
|
||||
* Man page cleanup
|
||||
|
||||
|
||||
|
||||
Changes since tio v3.1:
|
||||
|
||||
* Do not print error when using --list with broken config file
|
||||
|
||||
* Clean up completion script
|
||||
|
||||
* Add option '--exec <command>' for running shell command
|
||||
|
||||
Runs shell command with I/O redirected to device.
|
||||
|
||||
* Make sure all error output is directed to stderr
|
||||
|
||||
* Fix shadow variables
|
||||
|
||||
* Update man page
|
||||
|
||||
* Fix build on older GNU/Linux systems without statx
|
||||
|
||||
* Fix line ending in --list output
|
||||
|
||||
* Print location of configuration file in --list output
|
||||
|
||||
* Fix alignment of profile listing
|
||||
|
||||
|
||||
|
||||
Changes since tio v3.0:
|
||||
|
||||
* Improve --list feature on non-linux platform
|
||||
|
||||
* List available profiles in --list output
|
||||
|
||||
* Always message when saving log file
|
||||
|
||||
* Add support for using TID as device in config file
|
||||
|
||||
* Fix use of invalid flag with regexec()
|
||||
|
||||
* Fix potential buffer overflow in match_and_replace()
|
||||
|
||||
* Fix profile autocompletion
|
||||
|
||||
* Remove inih dependency from CI builds
|
||||
|
||||
* Replace use of stat() with fstat()
|
||||
|
||||
For better security.
|
||||
|
||||
* Fix hexN output mode
|
||||
|
||||
* Update pattern matching example
|
||||
|
||||
* Fix submenu response when invalid key hit
|
||||
|
||||
* Replace inih with glib key file parser
|
||||
|
||||
After including the use of glib we might as well replace inih
|
||||
with the glib key file parser.
|
||||
|
||||
All configuration file parsing has been reworked and also the options
|
||||
parsing has been cleaned up, resulting in better and stricter
|
||||
configuration file and option value checks.
|
||||
|
||||
Compared to old, configuration files now requires any default
|
||||
configurations to be put in a group/section named [default].
|
||||
|
||||
Configuration file keywords such as "enable", "disable", "on",
|
||||
"off", "yes", "no", "0", "1" have been retired. Now only "true" and
|
||||
"false" apply to boolean configuration options. This is done to simplify
|
||||
things and avoid any confusion.
|
||||
|
||||
The pattern option feature has been reworked so now the user can now
|
||||
access the full match string and any matching subexpression using the
|
||||
%mN syntax.
|
||||
|
||||
For example:
|
||||
|
||||
[usb devices]
|
||||
pattern = usb([0-9]*)
|
||||
device = /dev/ttyUSB%m1
|
||||
|
||||
Then when using tio:
|
||||
$ tio usb12
|
||||
|
||||
%m0 = 'usb12' // Full match string
|
||||
%m1 = 12 // First match subexpression
|
||||
|
||||
Which results in device = /dev/ttyUSB12
|
||||
|
||||
* Remove CircleCI
|
||||
|
||||
Replaced with github workflow CI.
|
||||
|
||||
* Add github workflow for Ubuntu build
|
||||
|
||||
* Enable extended pattern matching
|
||||
|
||||
So that the exclude options can also work as include using special
|
||||
pattern syntax.
|
||||
|
||||
For example, to only include /dev/ttyUSB* devices simply do:
|
||||
|
||||
$ tio --exclude-devices=!(/dev/ttyUSB*) --list
|
||||
|
||||
See the man page of fnmatch() for all available extended pattern
|
||||
options.
|
||||
|
||||
* Update lua read() description
|
||||
|
||||
Rui Chen:
|
||||
|
||||
* fix: add build patch for `FNM_EXTMATCH`
|
||||
|
||||
* feat: add macOS workflow
|
||||
|
||||
* fix: add macOS build patch for `fs_get_creation_time`
|
||||
|
||||
|
||||
|
||||
Changes since tio v2.8:
|
||||
|
||||
* Simplify lua line manipulation API
|
||||
|
||||
Collapses lua high(), low(), toggle(), config_high(), config_low(),
|
||||
config_apply() into one simple function:
|
||||
|
||||
set{<line>=<state>, ...}
|
||||
|
||||
Line can be any of DTR, RTS, CTS, DSR, CD, RI.
|
||||
|
||||
State is high, low, or toggle.
|
||||
|
||||
Example:
|
||||
script = set{DTR=high, RTS=low}; msleep(100); set{DTR=low, RTS=high}; msleep(100); set{RTS=low}
|
||||
|
||||
Notice the use of {} instad of () when calling the set function. This is
|
||||
required to pass parameters by name in lua.
|
||||
|
||||
* Disable DEC Special Graphics at exit if vt100
|
||||
|
||||
If a vt100 terminal receives the Shift In character '\016' it will
|
||||
enable the 7 bit DEC Special Graphics character set used for line drawing.
|
||||
|
||||
For most users this can happen due to line noise from the tty device and
|
||||
will likely mess up your terminal even after tio exits.
|
||||
|
||||
To better handle this we want to make sure that tio disables this mode
|
||||
by sending the Shift Out character '\017' at exit.
|
||||
|
||||
This mechanism will only activate if environment variable TERM assumes
|
||||
value "vt100".
|
||||
|
||||
* Add hexN output mode
|
||||
|
||||
Adds support for hexN mode where N is a number in the range 1 to 4096
|
||||
which defines how many hex values will be printed before a line break.
|
||||
|
||||
In short, it defines the width of the hex output.
|
||||
|
||||
In this mode, if timestamps are enabled they will be added to each hex
|
||||
line.
|
||||
|
||||
* Rename sub-config to profile
|
||||
|
||||
Because better naming.
|
||||
|
||||
* Use lua io.write() instead of print()
|
||||
|
||||
io.write() gives better output control as print() is hardcoded to always
|
||||
print a newline.
|
||||
|
||||
* Add new ways to manage serial devices
|
||||
|
||||
* Rename --list-devices to --list
|
||||
|
||||
* Rename --no-autoconnect to --no-reconnect
|
||||
|
||||
* Switch -l and -L options
|
||||
|
||||
* -l now lists available serial devices
|
||||
|
||||
* -L enables log to file
|
||||
|
||||
* Add option --auto-connect <strategy>
|
||||
|
||||
* Supported strategies:
|
||||
|
||||
* "new" - Waits to connect first new appearing serial device
|
||||
|
||||
* "latest" - Connects to latest registered serial device
|
||||
|
||||
* "direct" - Connect directly to specified serial device (default)
|
||||
|
||||
* Add options to exclude serial devices from auto connect strategy by
|
||||
pattern
|
||||
|
||||
* Supported exclude options:
|
||||
|
||||
* --exclude-devices <pattern>
|
||||
|
||||
Example: '--exclude-devices "/dev/ttyUSB2,/dev/ttyS?"'
|
||||
|
||||
* --exclude-drivers <pattern>
|
||||
|
||||
Example: '--exclude-drivers "cdc_acm"'
|
||||
|
||||
* --exclude-tids <pattern>
|
||||
|
||||
Example: '--exclude-tids "yW07,bCC2"'
|
||||
|
||||
* Patterns support '*' and '?'
|
||||
|
||||
* Connect to same port/device combination via unique topology ID (TID)
|
||||
|
||||
* Topology ID is a 4 digit base62 encoded hash of a device topology
|
||||
string coming from the Linux kernel. This means that whenever you
|
||||
plug in the same e.g. USB serial port device to the same USB hub
|
||||
port connected via the exact same hub topology all the way to your
|
||||
computer, you will get the same unique TID.
|
||||
|
||||
* Useful for stable reconnections when serial device has no serial
|
||||
device by ID
|
||||
|
||||
* For now, only tested on Linux.
|
||||
|
||||
* Reworked and improved listing of serial devices to show serial devices:
|
||||
|
||||
* By device
|
||||
|
||||
* Including TID, uptime, driver, and description.
|
||||
|
||||
* Sorted by uptime (newest device listed last)
|
||||
|
||||
* By unique topology ID
|
||||
|
||||
* By ID
|
||||
|
||||
* By path
|
||||
|
||||
* Add script interface 'list = tty_search()' for searching for serial
|
||||
devices.
|
||||
|
||||
* Clean up timestamp enum definition
|
||||
|
||||
* Add missing options to show configuration
|
||||
|
||||
* Update description of mute option
|
||||
|
||||
* Add lua read_string() function
|
||||
|
||||
* Don't forget to log output in lua expect()
|
||||
|
||||
* Generalize automatic login example for Linux
|
||||
|
||||
* Fix log output in hex output mode
|
||||
|
||||
* Add timeout based timestamps in hex output mode
|
||||
|
||||
This change reintroduces timestamping in hex output mode but based on
|
||||
timeout instead of new lines which made no sense. This means that
|
||||
timestamps will only be printed when timeout time has elapsed with no
|
||||
output activity from serial device.
|
||||
|
||||
Adds option --timestamp-timeout <ms> for setting the timeout value in
|
||||
milliseconds.
|
||||
|
||||
Defaults to 200 ms.
|
||||
|
||||
* Improve switched messages
|
||||
|
||||
* Extend lua expect() to also return matched string
|
||||
|
||||
* Add automatic login script example
|
||||
|
||||
* Organize examples directory
|
||||
|
||||
* Introduce basic line input mode
|
||||
|
||||
* Cleanup global variable name shadowing
|
||||
|
||||
Davis C:
|
||||
|
||||
* Updated login example with new expect logic
|
||||
|
||||
* Reset buffer size at start of expect
|
||||
|
||||
* Return 1 when `expect` matches
|
||||
|
||||
|
||||
|
||||
Changes since tio v2.7:
|
||||
|
||||
* Rework resolve_config_file()
|
||||
|
||||
* Rework line_pulse_duration_option_parse()
|
||||
|
||||
Introduce proper sscanf() checks.
|
||||
|
||||
* Rework rs485_parse_config()
|
||||
|
||||
Introduce proper sscanf() checks.
|
||||
|
||||
* Clean up file descriptor name shadowing
|
||||
|
||||
* Add missing header guard
|
||||
|
||||
* Upgrade inih subproject
|
||||
|
||||
* Remove options --response-wait, --response-timeout
|
||||
|
||||
Remove options and rework input handling so it is possible to do the
|
||||
same thing but via script which is much more flexible.
|
||||
|
||||
These options were always a bit of a hardcoded solution. With the new
|
||||
script expect feature we can wait for any type of response.
|
||||
|
||||
For example, pipe command to serial device and wait for line response within 1 second:
|
||||
|
||||
$ echo "*IDN?" | tio /dev/ttyACM0 --script "expect('\r\n', 1000)" --mute
|
||||
|
||||
* Add lua exit(code)
|
||||
|
||||
* Add timeout feature to expect()
|
||||
|
||||
* Add lua expect(string)
|
||||
|
||||
Add simple expect functionality.
|
||||
|
||||
The expect(string) function will wait for input from the tty device and
|
||||
only return when there is a string match. Regular expressions are
|
||||
supported.
|
||||
|
||||
Example:
|
||||
|
||||
script = expect('password:'); send('my_password\n')
|
||||
|
||||
* Add lua send(string)
|
||||
|
||||
* Add lua modem_send(file,protocol)
|
||||
|
||||
* Fix xymodem error messages
|
||||
|
||||
* Rework x/y-modem transfer command
|
||||
|
||||
Remove ctrl-t X option and instead introduce submenu to ctrl-t x option
|
||||
for picking which xmodem protocol to use.
|
||||
|
||||
* Update README
|
||||
|
||||
* Cleanup options
|
||||
|
||||
* Add independent input and output mode
|
||||
|
||||
Replaces -x, --hexadecimal option with --input-mode and --output-mode
|
||||
so it is possible to select hex or normal mode for both input and output
|
||||
independently.
|
||||
|
||||
To obtain same behavior as -x, --hexadecimal use the following
|
||||
configuration:
|
||||
|
||||
input-mode = hex
|
||||
output-mode = hex
|
||||
|
||||
* Fix file descriptor handling on macOS
|
||||
|
||||
* Add tty line configuration script API
|
||||
|
||||
On some platforms calling high()/low() to switch line states result in
|
||||
costly system calls which makes it impossible to switch two or more tty
|
||||
lines simultaneously.
|
||||
|
||||
To help solve this timing issue we introduce a tty line state
|
||||
configuration API which can be used instead of using
|
||||
high()/low().
|
||||
|
||||
Using config_low(line) and config_high(line) one can set up a new line
|
||||
state configuration for multiple lines and then use config_apply() to
|
||||
finally apply the configuration. This will result in only one system
|
||||
call to instruct the serial port drive to switch all the configured line
|
||||
states which should help ensure that the lines are switched
|
||||
simultaneously.
|
||||
|
||||
Example:
|
||||
|
||||
script = config_high(DTR); config_low(RTS); config_apply()
|
||||
|
||||
* Add ONULBRK mapping flag
|
||||
|
||||
Add ONULBRK mapping to map nul (zero) to send break signal on output.
|
||||
|
||||
This is useful if one needs to e.g. send the break signal to the tty
|
||||
device when connected via socket.
|
||||
|
||||
* Add --log-directory option
|
||||
|
||||
For specifying directory path in which to save automatically named log
|
||||
files.
|
||||
|
||||
* Add Lua scripting feature
|
||||
|
||||
Add support for running Lua scripts that can manipulate the tty control
|
||||
lines. Script is activated automatically on connect or manually via in
|
||||
session key command.
|
||||
|
||||
The Lua scripting feature opens up for many possibilities in the future
|
||||
such as adding expect like functionality to easily and programatically
|
||||
interact with the connected device.
|
||||
|
||||
* Invert line states to reflect true electrical level
|
||||
|
||||
* Add support for disabling prefix key handling
|
||||
|
||||
To disable prefix key input handing simply set prefix-ctrl-key to
|
||||
'none'.
|
||||
|
||||
Based on original patch from Sebastian Krahmer.
|
||||
|
||||
* Add meson man pages install option
|
||||
|
||||
Defaults to installing man pages.
|
||||
|
||||
HiFiPhile:
|
||||
|
||||
* Poll on serial port read instead of delay.
|
||||
|
||||
* Add Xmodem-CRC support.
|
||||
|
||||
* CYGWIN: Fix port auto connection.
|
||||
|
||||
Mingjie Shen:
|
||||
|
||||
* Check return values of sscanf()
|
||||
|
||||
Failing to check that a call to 'sscanf' actually writes to an output
|
||||
variable can lead to unexpected behavior at reading time.
|
||||
|
||||
Jakob Haufe:
|
||||
|
||||
* Support NO_COLOR env variable as per no-color.org
|
||||
|
||||
* Fix troff warning
|
||||
|
||||
.eo/.ec sections seemingly need explicit empty lines using .sp
|
||||
|
||||
Otherwise, troff complains:
|
||||
|
||||
troff:<standard input>:535: warning: expected numeric expression, got '\'
|
||||
troff:<standard input>:538: warning: expected numeric expression, got '\'
|
||||
troff:<standard input>:541: warning: expected numeric expression, got '\'
|
||||
|
||||
Fredrik Svedberg:
|
||||
|
||||
* Add map FF to ESC-c on input
|
||||
|
||||
Added map of form feed to ESC-c on input for terminals that
|
||||
do not clear screen on ^L but do on ESC-c.
|
||||
|
||||
Brian:
|
||||
|
||||
* Add CodeQL Workflow for Code Security Analysis
|
||||
|
||||
Sylvain LAFRASSE:
|
||||
|
||||
* Fix double call of tty_disconnect() on macOS/Darwin.
|
||||
|
||||
|
||||
|
||||
Changes since tio v2.6:
|
||||
|
||||
Paul Ruizendaal:
|
||||
|
||||
* Add xmodem and ymodem file send support
|
||||
|
||||
HiFiPhile:
|
||||
|
||||
* tty_stdin_input_thread(): write to pipe only if byte_count > 0.
|
||||
|
||||
* Ignore EINTR error.
|
||||
|
||||
* CYGWIN: Add support for "COM*" naming.
|
||||
|
||||
Wes Koerber:
|
||||
|
||||
* chore: reorder log-strip and log-append
|
||||
|
||||
reorder to maintain consistency with documentation
|
||||
|
||||
* chore: update readme, bash completion, man page
|
||||
|
||||
* fix: support --log-append in cli options
|
||||
|
||||
|
||||
|
||||
Changes since tio v2.5:
|
||||
|
||||
* Remove warning when using pattern option
|
||||
|
||||
* Add --log-append option
|
||||
|
||||
Add --log-append option which makes tio append to any existing log file.
|
||||
|
||||
This also changes the default behavior of tio from appending to
|
||||
overwriting any existing log file. Now you have to use this new option
|
||||
to make tio append.
|
||||
|
||||
* Update man page
|
||||
|
||||
* Update README
|
||||
|
||||
* Fix line termination for response wait feature
|
||||
|
||||
The response wait feature waited for a line response, a string
|
||||
terminated with either CR or NL. However, some devices may send a CR and
|
||||
then their line content and then NL. This means tio will quit before
|
||||
receiving and printing the line response. To solve this we simply ignore
|
||||
the CR character and only consider lines terminated with a NL character.
|
||||
|
||||
This should work for all devices as lines are AFAIK always terminated
|
||||
with either CRNL or a NL.
|
||||
|
||||
* Update tty device listing configuration
|
||||
|
||||
Cleanup and add FreeBSD tty device listing support.
|
||||
|
||||
Braden Young:
|
||||
|
||||
* Move map variables to tty to keep them all in one spot
|
||||
|
||||
* Configure socket mapping flags from tty parsing logic. Remove duplicate parsing logic in socket
|
||||
|
||||
* Support input mapping modes for sockets
|
||||
|
||||
Josh Soref:
|
||||
|
||||
* Various spelling fixes
|
||||
|
||||
Peter van Dijk:
|
||||
|
||||
* avoid "warning: unused parameter" on setspeed stub
|
||||
|
||||
* use right /dev/ path on Haiku
|
||||
|
||||
Bill Hass:
|
||||
|
||||
* Update README with details on snap confinement
|
||||
|
||||
|
||||
|
||||
Changes since tio v2.4:
|
||||
|
||||
* Update configuration file documentation
|
||||
|
||||
Rename .tiorc to .tioconfig, tiorc to config, etc.
|
||||
|
||||
* Add support for $HOME/.tioconfig
|
||||
|
||||
Replaces what used to be $HOME/.tiorc
|
||||
|
||||
* Fix double prefix key regression
|
||||
|
||||
Vyacheslav Patkov:
|
||||
|
||||
* Better error checking in config file, rename the file
|
||||
|
||||
Accept "true", "enable", "on", "yes", "1" as true values, their
|
||||
counterparts as false ones. Check integer values for errors and range.
|
||||
Warn about ignored (e.g. misspelled) options.
|
||||
|
||||
Check getenv() return value for NULL.
|
||||
|
||||
Rename "tiorc" to "config", as it's a static INI file, not an executable
|
||||
"run commands".
|
||||
|
||||
|
||||
|
||||
Changes since tio v2.3:
|
||||
|
||||
* Add threaded input handling
|
||||
|
||||
To make tio more responsive to quit and I/O flush key command when main I/O
|
||||
thread is blocked on output.
|
||||
|
||||
* Fix so that is it possible to quit tio in tio etc.
|
||||
|
||||
Fix regression so that it is possible to send the prefix key code to the
|
||||
remote tio session without local tio session reacting to same key code
|
||||
(quitting etc.).
|
||||
|
||||
* Add key command to toggle log on/off
|
||||
|
||||
Add key command 'ctrl-t f' which will toggle log on/off.
|
||||
|
||||
If no log filename has been specified via the 'log-filename' option then
|
||||
tio will automatically generate a new log filename every time the log
|
||||
feature is toggled on. Meaning, when toggled multiple times, multiple
|
||||
log files will be generated.
|
||||
|
||||
However, if a log filename has been specified, tio will only write and
|
||||
append to that same file.
|
||||
|
||||
|
||||
|
||||
Changes since tio v2.2:
|
||||
|
||||
* Add mute feature
|
||||
|
||||
This will make tio go fully silent and not print anything.
|
||||
|
||||
* Rename config variable 'tty' to 'device'
|
||||
|
||||
* Deprecate tty config keyword but keep it around for now
|
||||
|
||||
* Update show config
|
||||
|
||||
* Update example tiorc
|
||||
|
||||
|
||||
|
||||
Changes since tio v2.1:
|
||||
|
||||
* Add shell completion of sub-configuration names
|
||||
|
||||
Does not work with sub configuration names that contains one or more
|
||||
white spaces.
|
||||
|
||||
* Beautify help
|
||||
|
||||
* Fix error message
|
||||
|
||||
* Simplify configfile implementation
|
||||
|
||||
=== tio v2.1 ===
|
||||
|
||||
|
||||
Changes since tio v2.0:
|
||||
|
|
@ -204,7 +1070,7 @@ Changes since tio v1.46:
|
|||
|
||||
Victor Oliveira
|
||||
|
||||
* add macports install instructions
|
||||
* add MacPorts install instructions
|
||||
|
||||
|
||||
|
||||
|
|
@ -438,7 +1304,7 @@ Changes since tio v1.39:
|
|||
pipe data to tio which then forwards the data to the connected serial
|
||||
device.
|
||||
|
||||
Non ineractive means that tio does not react to interactive key commands
|
||||
Non interactive means that tio does not react to interactive key commands
|
||||
in the incoming stream. This allows users to pipe binary data directly
|
||||
to the connected serial device.
|
||||
|
||||
|
|
@ -567,7 +1433,7 @@ Changes since tio v1.38:
|
|||
inherently inconsistent with how you define required arguments.
|
||||
|
||||
To avoid confusion we decide to avoid this inconsistency by replacing
|
||||
optional options with additional options with required argmuments.
|
||||
optional options with additional options with required arguments.
|
||||
|
||||
* Replace '1' with 'enable' in config files
|
||||
|
||||
|
|
@ -704,7 +1570,7 @@ Changes since tio v1.35:
|
|||
* Handle SIGHUP
|
||||
|
||||
Handle SIGHUP so that the registered exit handlers are called to restore
|
||||
the terminal back to its orignal state.
|
||||
the terminal back to its original state.
|
||||
|
||||
* Add color configuration support
|
||||
|
||||
|
|
@ -760,10 +1626,10 @@ Changes since tio v1.34:
|
|||
|
||||
* Add support for configurable timestamp format
|
||||
|
||||
Also changes default timestamp format from ISO8601 to classic 24-hour
|
||||
Also changes default timestamp format from ISO 8601 to classic 24-hour
|
||||
format as this is assumed to be the format that most users would prefer.
|
||||
|
||||
And reintroduces strict but optional ISO8601 format.
|
||||
And reintroduces strict but optional ISO 8601 format.
|
||||
|
||||
This feature allows to easily add more timestamp formats in the future.
|
||||
|
||||
|
|
@ -884,10 +1750,10 @@ Sylvain LAFRASSE:
|
|||
|
||||
attila-v:
|
||||
|
||||
* Refine timestamps with milliseconds and ISO-8601 format (#129).
|
||||
* Refine timestamps with milliseconds and ISO 8601 format (#129).
|
||||
|
||||
* Show milliseconds too in the timestamp (#114) and log file (#124)
|
||||
* Change timestamp format to ISO-8601.
|
||||
* Change timestamp format to ISO 8601.
|
||||
|
||||
Yin Fengwei:
|
||||
|
||||
|
|
@ -932,10 +1798,10 @@ Alban Bedel:
|
|||
* Fix out of tree builds
|
||||
|
||||
Out of tree builds are currently broken because $(top_srcdir)src/include
|
||||
is not in the search path. In tree builds are working because autconf add
|
||||
is not in the search path. In tree builds are working because autoconf adds
|
||||
$(top_builddir)/src/include to the search path for the generated config.h.
|
||||
As $(top_builddir) and $(top_srcdir) are identical during in tree builds
|
||||
the search path still end up beeing somehow correct.
|
||||
the search path still end up being somehow correct.
|
||||
|
||||
To fix this add -I$(srcdir)/include to the CPPFLAGS in Makefile.am.
|
||||
|
||||
|
|
@ -966,7 +1832,7 @@ Lars Kellogg-Stedman:
|
|||
|
||||
George Stark:
|
||||
|
||||
* dont show line state if ioctl failed
|
||||
* don't show line state if ioctl failed
|
||||
|
||||
* add serial lines manual control
|
||||
|
||||
|
|
@ -979,9 +1845,9 @@ arichi:
|
|||
|
||||
Mariusz Midor:
|
||||
|
||||
* Newline: handle booth NL and CR
|
||||
* Newline: handle both NL and CR
|
||||
|
||||
Flag ONLCRNL expects code \n after press Enter, but on some systems \r is send instead.
|
||||
Flag ONLCRNL expects code \n after press Enter, but on some systems \r is sent instead.
|
||||
|
||||
|
||||
|
||||
|
|
@ -1473,7 +2339,7 @@ Changes since tio v1.11:
|
|||
To display the total number of bytes transmitted/received simply perform the
|
||||
'ctrl-t s' command sequence.
|
||||
|
||||
This feature can be useful when eg. trying to detect non-printable
|
||||
This feature can be useful when e.g. trying to detect non-printable
|
||||
characters.
|
||||
|
||||
* Further simplification of key handling
|
||||
|
|
|
|||
441
README.md
441
README.md
|
|
@ -1,15 +1,20 @@
|
|||
# tio - a simple serial device I/O tool
|
||||
|
||||
[](https://circleci.com/gh/tio/tio/tree/master)
|
||||
[]()
|
||||
|
||||
# tio - a serial device I/O tool
|
||||
|
||||
[](https://github.com/tio/tio/actions/workflows/ubuntu.yml)
|
||||
[](https://github.com/tio/tio/actions/workflows/macos.yml)
|
||||
[](https://github.com/tio/tio/actions/workflows/codeql.yml)
|
||||
[](https://www.codefactor.io/repository/github/tio/tio)
|
||||
[](https://github.com/tio/tio/releases)
|
||||
[](https://github.com/tio/tio)
|
||||
[](https://repology.org/project/tio/versions)
|
||||
|
||||
## 1. Introduction
|
||||
|
||||
tio is a simple serial device tool which features a straightforward
|
||||
command-line and configuration file interface to easily connect to serial TTY
|
||||
devices for basic I/O operations.
|
||||
tio is a serial device tool which features a straightforward command-line and
|
||||
configuration file interface to easily connect to serial TTY devices for basic
|
||||
I/O operations.
|
||||
|
||||
<p align="center">
|
||||
<img src="images/tio-demo.gif">
|
||||
|
|
@ -17,45 +22,77 @@ devices for basic I/O operations.
|
|||
|
||||
### 1.1 Motivation
|
||||
|
||||
To make a simpler serial device tool for talking with serial TTY devices with
|
||||
To make a simpler serial device tool for working with serial TTY devices with
|
||||
less focus on classic terminal/modem features and more focus on the needs of
|
||||
embedded developers and hackers.
|
||||
|
||||
tio was originally created to replace
|
||||
tio was originally created as an alternative to
|
||||
[screen](https://www.gnu.org/software/screen) for connecting to serial devices
|
||||
when used in combination with [tmux](https://tmux.github.io).
|
||||
|
||||
## 2. Features
|
||||
|
||||
* Easily connect to serial TTY devices
|
||||
* Automatic connect and reconnect
|
||||
* Sensible defaults
|
||||
* Sensible defaults (115200 8n1)
|
||||
* Automatic connection management
|
||||
* Automatic detection of serial ports
|
||||
* Automatic reconnect
|
||||
* Automatically connect to first new appearing serial device
|
||||
* Automatically connect to latest registered serial device
|
||||
* Connect to same port/device combination via unique topology ID (TID)
|
||||
* Useful for reconnecting when serial device has no serial device by ID
|
||||
* Support for non-standard baud rates
|
||||
* Support for RS-485 mode
|
||||
* Support for mark and space parity
|
||||
* List available serial devices by ID
|
||||
* X-modem (1K/CRC) and Y-modem file upload
|
||||
* Support for RS-485 mode
|
||||
* List available serial devices
|
||||
* By device
|
||||
* Including topology ID, uptime, driver, description
|
||||
* Sorted by uptime (newest device listed last)
|
||||
* By ID
|
||||
* By path
|
||||
* Show RX/TX statistics
|
||||
* Toggle serial lines
|
||||
* Pulse serial lines with configurable pulse duration
|
||||
* Local echo support
|
||||
* Remapping of characters (nl, cr-nl, bs, lowercase to uppercase, etc.)
|
||||
* Line timestamps
|
||||
* Support for delayed output per character
|
||||
* Support for delayed output per line
|
||||
* Hexadecimal mode
|
||||
* Switchable independent input and output
|
||||
* Normal mode
|
||||
* Hex mode (output supports variable width)
|
||||
* Line mode (input only)
|
||||
* Timestamp support
|
||||
* Per line in normal output mode
|
||||
* Output timeout timestamps in hex output mode
|
||||
* Support for delayed output
|
||||
* Per character
|
||||
* Per line
|
||||
* Log to file
|
||||
* Autogeneration of log filename
|
||||
* Automatic naming of log file (default)
|
||||
* Configurable directory for saving automatic named log files
|
||||
* Manual naming of log file
|
||||
* Overwrite (default) or append to log file
|
||||
* Strip control characters and escape sequences
|
||||
* Configuration file support
|
||||
* Activate sub-configurations by name or pattern
|
||||
* Redirect I/O to UNIX socket or IPv4/v6 network socket for scripting or TTY sharing
|
||||
* Support for configuration profiles
|
||||
* Activate configuration profiles by name or pattern
|
||||
* Support for including other configuration files
|
||||
* Redirect I/O of shell command to serial device
|
||||
* Redirect I/O to UNIX socket or IPv4/v6 network socket
|
||||
* Useful for scripting or TTY sharing
|
||||
* Pipe input and/or output
|
||||
* Support for simple line request/response handling
|
||||
* Bash completion
|
||||
* Configurable text color
|
||||
* Bash completion on options, serial device names, and profile names
|
||||
* Configurable tio message text color
|
||||
* Supports NO_COLOR env variable as per [no-color.org](https://no-color.org)
|
||||
* Visual or audible alert on connect/disconnect
|
||||
* Remapping of prefix key
|
||||
* Lua scripting support for automation
|
||||
* Run script manually or automatically at connect (once/always/never)
|
||||
* Simple expect/send like functionality with support for regular expressions
|
||||
* Manipulate port modem lines (useful for microcontroller reset/boot etc.)
|
||||
* Send files via x/y-modem protocol
|
||||
* Search for serial devices
|
||||
* Man page documentation
|
||||
* Plays nicely with [tmux](https://tmux.github.io)
|
||||
* Plays nicely with [tmux](https://tmux.github.io) and similar terminal multiplexers
|
||||
|
||||
## 3. Usage
|
||||
|
||||
|
|
@ -65,13 +102,13 @@ For more usage details please see the man page documentation
|
|||
### 3.1 Command-line
|
||||
|
||||
The command-line interface is straightforward as reflected in the output from
|
||||
'tio --help':
|
||||
```tio --help```:
|
||||
```
|
||||
Usage: tio [<options>] <tty-device|sub-config>
|
||||
Usage: tio [<options>] <tty-device|profile|tid>
|
||||
|
||||
Connect to tty device directly or via sub-configuration.
|
||||
Connect to TTY device directly or via configuration profile or topology ID.
|
||||
|
||||
Options:
|
||||
Options:
|
||||
-b, --baudrate <bps> Baud rate (default: 115200)
|
||||
-d, --databits 5|6|7|8 Data bits (default: 8)
|
||||
-f, --flow hard|soft|none Flow control (default: none)
|
||||
|
|
@ -80,40 +117,50 @@ The command-line interface is straightforward as reflected in the output from
|
|||
-o, --output-delay <ms> Output character delay (default: 0)
|
||||
-O, --output-line-delay <ms> Output line delay (default: 0)
|
||||
--line-pulse-duration <duration> Set line pulse duration
|
||||
-n, --no-autoconnect Disable automatic connect
|
||||
-a, --auto-connect new|latest|direct Automatic connect strategy (default: direct)
|
||||
--exclude-devices <pattern> Exclude devices by pattern
|
||||
--exclude-drivers <pattern> Exclude drivers by pattern
|
||||
--exclude-tids <pattern> Exclude topology IDs by pattern
|
||||
-n, --no-reconnect Do not reconnect
|
||||
-e, --local-echo Enable local echo
|
||||
--input-mode normal|hex|line Select input mode (default: normal)
|
||||
--output-mode normal|hex|hexN Select output mode (default: normal)
|
||||
-t, --timestamp Enable line timestamp
|
||||
--timestamp-format <format> Set timestamp format (default: 24hour)
|
||||
-L, --list-devices List available serial devices
|
||||
-l, --log Enable log to file
|
||||
--timestamp-timeout <ms> Set timestamp timeout (default: 200)
|
||||
-l, --list List available serial devices, TIDs, and profiles
|
||||
-L, --log Enable log to file
|
||||
--log-file <filename> Set log filename
|
||||
--log-directory <path> Set log directory path for automatic named logs
|
||||
--log-append Append to log file
|
||||
--log-strip Strip control characters and escape sequences
|
||||
-m, --map <flags> Map characters
|
||||
-c, --color 0..255|bold|none|list Colorize tio text (default: bold)
|
||||
-S, --socket <socket> Redirect I/O to socket
|
||||
-x, --hexadecimal Enable hexadecimal mode
|
||||
-r, --response-wait Wait for line response then quit
|
||||
--response-timeout <ms> Response timeout (default: 100)
|
||||
--rs-485 Enable RS-485 mode
|
||||
--rs-485-config <config> Set RS-485 configuration
|
||||
--alert bell|blink|none Alert on connect/disconnect (default: none)
|
||||
--mute Mute tio messages
|
||||
--script <string> Run script from string
|
||||
--script-file <filename> Run script from file
|
||||
--script-run once|always|never Run script on connect (default: always)
|
||||
--exec <command> Execute shell command with I/O redirected to device
|
||||
-v, --version Display version
|
||||
-h, --help Display help
|
||||
|
||||
Options and sub-configurations may be set via configuration file.
|
||||
Options and profiles may be set via configuration file.
|
||||
|
||||
See the man page for more details.
|
||||
In session you can press ctrl-t ? to list available key commands.
|
||||
|
||||
See the man page for more details.
|
||||
```
|
||||
|
||||
By default tio automatically connects to the provided TTY device if present.
|
||||
If the device is not present, it will wait for it to appear and then connect.
|
||||
If the connection is lost (eg. device is unplugged), it will wait for the
|
||||
device to reappear and then reconnect. However, if the `--no-autoconnect`
|
||||
option is provided, tio will exit if the device is not present or an
|
||||
established connection is lost.
|
||||
|
||||
tio features full bash autocompletion.
|
||||
By default tio automatically connects to the provided TTY device. If the device
|
||||
is not present, tio will wait for it to appear and then connect. If the
|
||||
connection is lost (e.g. device is unplugged), it will wait for the device to
|
||||
reappear and then reconnect. However, if the `--no-reconnect` option is
|
||||
provided, tio will exit if the device is not present or an established
|
||||
connection is lost.
|
||||
|
||||
#### 3.1.1 Examples
|
||||
|
||||
|
|
@ -124,46 +171,129 @@ $ tio /dev/ttyUSB0
|
|||
|
||||
Which corresponds to the commonly used default options:
|
||||
```
|
||||
$ tio -b 115200 -d 8 -f none -s 1 -p none /dev/ttyUSB0
|
||||
$ tio --baudrate 115200 --databits 8 --flow none --stopbits 1 --parity none /dev/ttyUSB0
|
||||
```
|
||||
|
||||
It is recommended to connect serial tty devices by ID:
|
||||
List available serial devices:
|
||||
```
|
||||
$ tio /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
|
||||
```
|
||||
Using serial devices by ID ensures that tio automatically reconnects to the
|
||||
correct serial device if it is disconnected and then reconnected.
|
||||
$ tio --list
|
||||
Device TID Uptime [s] Driver Description
|
||||
----------------- ---- ------------- ---------------- --------------------------
|
||||
/dev/ttyS4 BaaB 19526.576 port 16550A UART
|
||||
/dev/ttyS5 eV0Z 19525.845 port 16550A UART
|
||||
/dev/ttyUSB1 bCC2 1023.274 ftdi_sio TTL232R-3V3
|
||||
/dev/ttyUSB0 SPpw 978.527 ftdi_sio TTL232RG-VREG3V3
|
||||
/dev/ttyACM0 i5q4 2.079 cdc_acm ST-Link VCP Ctrl
|
||||
|
||||
List available serial devices by ID:
|
||||
By-id
|
||||
--------------------------------------------------------------------------------
|
||||
/dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTCHUV56-if00-port0
|
||||
/dev/serial/by-id/usb-FTDI_TTL232RG-VREG3V3_FT1NELUB-if00-port0
|
||||
/dev/serial/by-id/usb-STMicroelectronics_STLINK-V3_004900343438510234313939-if02
|
||||
|
||||
By-path
|
||||
--------------------------------------------------------------------------------
|
||||
/dev/serial/by-path/pci-0000:00:14.0-usb-0:8.1.3.1.4:1.0-port0
|
||||
/dev/serial/by-path/pci-0000:00:14.0-usbv2-0:8.1.3.1.4:1.0-port0
|
||||
/dev/serial/by-path/pci-0000:00:14.0-usbv2-0:6.4:1.0-port0
|
||||
/dev/serial/by-path/pci-0000:00:14.0-usb-0:6.4:1.0-port0
|
||||
/dev/serial/by-path/pci-0000:00:14.0-usbv2-0:6.3:1.2
|
||||
/dev/serial/by-path/pci-0000:00:14.0-usb-0:6.3:1.2
|
||||
|
||||
Configuration profiles (/home/lundmar/.config/tio/config)
|
||||
--------------------------------------------------------------------------------
|
||||
rpi3 stm32 esp32 am64-evm
|
||||
imx8mp-evk nucleo-h743zi2 usb-devices
|
||||
```
|
||||
$ tio --list-devices
|
||||
|
||||
It is recommended to connect serial TTY devices by ID:
|
||||
```
|
||||
$ tio /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTCHUV56-if00-port0
|
||||
```
|
||||
Note: Using serial devices by ID helps ensure that tio automatically reconnects
|
||||
to the same serial device when reattached, even when it enumerates differently.
|
||||
|
||||
If no serial device by ID is available it is recommended to connect via
|
||||
topology ID (TID):
|
||||
```
|
||||
$ tio bCC2
|
||||
```
|
||||
Note: The TID is unique and will stay the same as long as your USB serial port
|
||||
device plugs into the same USB topology (same ports, same hubs, same
|
||||
connections, etc.). This way it is possible for tio to successfully reconnect
|
||||
to the same device.
|
||||
|
||||
Connect automatically to first new appearing serial device:
|
||||
```
|
||||
$ tio --auto-connect new
|
||||
```
|
||||
|
||||
Connect automatically to latest registered serial device:
|
||||
```
|
||||
$ tio --auto-connect latest
|
||||
```
|
||||
|
||||
It is possible to use exclude options to affect which serial devices are
|
||||
involved in the automatic connection strategy:
|
||||
```
|
||||
$ tio --auto-connect new --exclude-devices "/dev/ttyACM?,/dev/ttyUSB2"
|
||||
```
|
||||
|
||||
And to exclude drivers by pattern:
|
||||
```
|
||||
$ tio --auto-connect new --exclude-drivers "cdc_acm,ftdi_sio"
|
||||
```
|
||||
Note: Pattern matching supports '*' and '?'. Use comma separation to define
|
||||
multiple patterns.
|
||||
|
||||
To include drivers by specific pattern simply negate the exclude option:
|
||||
```
|
||||
$ tio --auto-connect new --exclude-drivers !("cp2102")
|
||||
```
|
||||
Note: One can also use tio shell completion on /dev which will automatically
|
||||
list all available serial tty devices.
|
||||
|
||||
Log to file with autogenerated filename:
|
||||
```
|
||||
$ tio --log /dev/ttyUSB0
|
||||
```
|
||||
|
||||
Log to file with specific filename:
|
||||
```
|
||||
$ tio --log --log-file my-log.txt
|
||||
```
|
||||
|
||||
Enable ISO8601 timestamps per line:
|
||||
```
|
||||
$ tio --timestamp --timestamp-format iso8601 /dev/ttyUSB0
|
||||
```
|
||||
|
||||
Output to hex with width 16:
|
||||
```
|
||||
$ tio --output-mode hex16 /dev/ttyUSB0
|
||||
```
|
||||
|
||||
Redirect I/O to IPv4 network socket on port 4242:
|
||||
```
|
||||
$ tio --socket inet:4242 /dev/ttyUSB0
|
||||
```
|
||||
|
||||
Inject data to the serial device:
|
||||
Map NL to CR-NL on input from device and DEL to BS on output to device:
|
||||
```
|
||||
$ tio --map INLCRNL,ODELBS /dev/ttyUSB0
|
||||
```
|
||||
|
||||
Pipe data to the serial device:
|
||||
```
|
||||
$ cat data.bin | tio /dev/ttyUSB0
|
||||
```
|
||||
|
||||
Send command to serial device and wait for line response:
|
||||
Manipulate modem lines on connect:
|
||||
```
|
||||
$ echo "*IDN?" | tio /dev/ttyACM0 --response-wait
|
||||
$ tio --script "tio.set{DTR=high,RTS=low}; tio.msleep(100); tio.set{DTR=toggle,RTS=toggle}" /dev/ttyUSB0
|
||||
```
|
||||
|
||||
Pipe command to serial device and wait for line response within 1 second:
|
||||
```
|
||||
$ echo "*IDN?" | tio /dev/ttyACM0 --script "tio.expect('\r\n', 1000)" --mute
|
||||
KORAD KD3305P V4.2 SN:32475045
|
||||
```
|
||||
|
||||
|
|
@ -173,22 +303,29 @@ Various in session key commands are supported. When tio is started, press
|
|||
ctrl-t ? to list the available key commands.
|
||||
|
||||
```
|
||||
[20:19:12.040] Key commands:
|
||||
[20:19:12.040] ctrl-t ? List available key commands
|
||||
[20:19:12.040] ctrl-t b Send break
|
||||
[20:19:12.040] ctrl-t c Show configuration
|
||||
[20:19:12.040] ctrl-t e Toggle local echo mode
|
||||
[20:19:12.040] ctrl-t g Toggle serial port line
|
||||
[20:19:12.040] ctrl-t h Toggle hexadecimal mode
|
||||
[20:19:12.040] ctrl-t l Clear screen
|
||||
[20:19:12.040] ctrl-t L Show line states
|
||||
[20:19:12.040] ctrl-t p Pulse serial port line
|
||||
[20:19:12.040] ctrl-t q Quit
|
||||
[20:19:12.041] ctrl-t s Show statistics
|
||||
[20:19:12.041] ctrl-t t Toggle line timestamp mode
|
||||
[20:19:12.041] ctrl-t U Toggle conversion to uppercase
|
||||
[20:19:12.041] ctrl-t v Show version
|
||||
[20:19:12.041] ctrl-t ctrl-t Send ctrl-t character
|
||||
[15:02:53.269] Key commands:
|
||||
[15:02:53.269] ctrl-t ? List available key commands
|
||||
[15:02:53.269] ctrl-t b Send break
|
||||
[15:02:53.269] ctrl-t c Show configuration
|
||||
[15:02:53.269] ctrl-t e Toggle local echo mode
|
||||
[15:02:53.269] ctrl-t f Toggle log to file
|
||||
[15:02:53.269] ctrl-t F Flush data I/O buffers
|
||||
[15:02:53.269] ctrl-t g Toggle serial port line
|
||||
[15:02:53.269] ctrl-t i Toggle input mode
|
||||
[15:02:53.269] ctrl-t l Clear screen
|
||||
[15:02:53.269] ctrl-t L Show line states
|
||||
[15:02:53.269] ctrl-t m Change mapping of characters on input or output
|
||||
[15:02:53.269] ctrl-t o Toggle output mode
|
||||
[15:02:53.269] ctrl-t p Pulse serial port line
|
||||
[15:02:53.269] ctrl-t q Quit
|
||||
[15:02:53.269] ctrl-t r Run script
|
||||
[15:02:53.269] ctrl-t R Execute shell command with I/O redirected to device
|
||||
[15:02:53.269] ctrl-t s Show statistics
|
||||
[15:02:53.269] ctrl-t t Toggle line timestamp mode
|
||||
[15:02:53.269] ctrl-t v Show version
|
||||
[15:02:53.269] ctrl-t x Send file via Xmodem
|
||||
[15:02:53.269] ctrl-t y Send file via Ymodem
|
||||
[15:02:53.269] ctrl-t ctrl-t Send ctrl-t character
|
||||
```
|
||||
|
||||
If needed, the prefix key (ctrl-t) can be remapped via configuration file.
|
||||
|
|
@ -197,40 +334,53 @@ If needed, the prefix key (ctrl-t) can be remapped via configuration file.
|
|||
|
||||
Options can be set via the configuration file first found in any of the
|
||||
following locations in the order listed:
|
||||
- $XDG_CONFIG_HOME/tio/tiorc
|
||||
- $HOME/.config/tio/tiorc
|
||||
- $HOME/.tiorc
|
||||
- $XDG_CONFIG_HOME/tio/config
|
||||
- $HOME/.config/tio/config
|
||||
- $HOME/.tioconfig
|
||||
|
||||
The configuration file supports sub-configurations using named sections which can
|
||||
be activated via the command-line by name or pattern. A sub-configuration
|
||||
specifies which tty to connect to and other options.
|
||||
The configuration file supports profiles using named sections which can be
|
||||
activated via the command-line by name or pattern. A profile specifies which
|
||||
TTY device to connect to and other options.
|
||||
|
||||
### 3.3.1 Example
|
||||
|
||||
Example configuration file:
|
||||
|
||||
```
|
||||
# Defaults
|
||||
baudrate = 9600
|
||||
[default]
|
||||
baudrate = 115200
|
||||
databits = 8
|
||||
parity = none
|
||||
stopbits = 1
|
||||
color = 10
|
||||
|
||||
[rpi3]
|
||||
tty = /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
|
||||
baudrate = 115200
|
||||
no-autoconnect = enable
|
||||
log = enable
|
||||
device = /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
|
||||
no-reconnect = true
|
||||
log = true
|
||||
log-file = rpi3.log
|
||||
line-pulse-duration = DTR=200,RTS=150
|
||||
color = 11
|
||||
|
||||
[svf2]
|
||||
device = /dev/ttyUSB0
|
||||
baudrate = 9600
|
||||
script = tio.expect("login: "); tio.write("root\n"); tio.expect("Password: "); tio.write("root\n")
|
||||
color = 12
|
||||
|
||||
[usb devices]
|
||||
pattern = usb([0-9]*)
|
||||
tty = /dev/ttyUSB%s
|
||||
[esp32]
|
||||
device = /dev/serial/by-id/usb-0403_6014-if00-port0
|
||||
script = tio.set{DTR=high,RTS=low}; tio.msleep(100); tio.set{DTR=low,RTS=high}; tio.msleep(100); tio.set{RTS=low}
|
||||
script-run = once
|
||||
color = 13
|
||||
|
||||
[usb-devices]
|
||||
pattern = ^usb([0-9]*)
|
||||
device = /dev/ttyUSB%m1
|
||||
color = 14
|
||||
```
|
||||
|
||||
To use a specific sub-configuration by name simply start tio like so:
|
||||
To use a specific profile by name simply start tio like so:
|
||||
```
|
||||
$ tio rpi3
|
||||
```
|
||||
|
|
@ -239,7 +389,86 @@ Or by pattern match:
|
|||
$ tio usb12
|
||||
```
|
||||
|
||||
Another more elaborate configuration file example is available [here](example/tiorc).
|
||||
Another more elaborate configuration file example is available [here](examples/config/config).
|
||||
|
||||
### 3.4 Lua script API
|
||||
|
||||
Tio suppots Lua scripting to easily automate interaction with the tty device.
|
||||
|
||||
In addition to the standard Lua API tio makes the following functions
|
||||
and variables available:
|
||||
|
||||
|
||||
#### `tio.expect(pattern, timeout)`
|
||||
|
||||
Waits for the Lua pattern to match or timeout before continuing.
|
||||
Timeout is in milliseconds, defaults to 0 meaning it will wait forever.
|
||||
|
||||
Returns the captures from the pattern or `nil` on timeout.
|
||||
|
||||
#### `tio.read(size, timeout)`
|
||||
|
||||
Read up to `size` bytes from serial device. If timeout is 0 or not provided it
|
||||
will wait forever until data is ready to read.
|
||||
|
||||
Returns a string up to `size` bytes long on success and `nil` on timeout.
|
||||
|
||||
#### `tio.readline(timeout)`
|
||||
|
||||
Read line from serial device. If timeout is 0 or not provided it will wait
|
||||
forever until data is ready to read.
|
||||
|
||||
Returns a string on success and `nil` on timeout. On timeout a partially read
|
||||
line may be returned as a second return value.
|
||||
|
||||
#### `tio.write(string)`
|
||||
|
||||
Write string to serial device.
|
||||
|
||||
Returns the `tio` table.
|
||||
|
||||
#### `tio.send(file, protocol)`
|
||||
|
||||
Send file using x/y-modem protocol.
|
||||
|
||||
Protocol can be any of `XMODEM_1K`, `XMODEM_CRC`, `YMODEM`.
|
||||
|
||||
#### `tio.ttysearch()`
|
||||
|
||||
Search for serial devices.
|
||||
|
||||
Returns a table of number indexed tables, one for each serial device found.
|
||||
Each of these tables contains the serial device information accessible via the
|
||||
following string indexed elements "path", "tid", "uptime", "driver",
|
||||
"description".
|
||||
|
||||
Returns `nil` if no serial devices are found.
|
||||
|
||||
#### `tio.set{line=state, ...}`
|
||||
Set state of one or multiple tty modem lines.
|
||||
|
||||
Line can be any of `DTR`, `RTS`, `CTS`, `DSR`, `CD`, `RI`
|
||||
|
||||
State is `high`, `low`, or `toggle`.
|
||||
|
||||
#### `tio.sleep(seconds)`
|
||||
|
||||
Sleep for seconds.
|
||||
|
||||
#### `tio.msleep(ms)`
|
||||
|
||||
Sleep for milliseconds.
|
||||
|
||||
#### `tio.alwaysecho`
|
||||
|
||||
A boolean value, defaults to `true`.
|
||||
|
||||
If `tio.alwaysecho` is `false`, the result of `tio.read`, `tio.readline` or
|
||||
`tio.expect` will only be returned from the function and not logged or printed.
|
||||
|
||||
If `tio.alwaysecho` is set to `true`, reading functions also emit a single
|
||||
timestamp to stdout and log file per `options.timestamp` and `options.log`.
|
||||
|
||||
|
||||
## 4. Installation
|
||||
|
||||
|
|
@ -255,9 +484,12 @@ reach out to its package maintainers team.
|
|||
|
||||
Install latest stable version:
|
||||
```
|
||||
$ snap install tio
|
||||
$ snap install tio --classic
|
||||
```
|
||||
|
||||
Note: Classic confinement is currently required due to limitations of the snapcraft framework.
|
||||
See [Issue #187](https://github.com/tio/tio/issues/187) for discussion.
|
||||
|
||||
### 4.3 Installation using brew (MacOS, Linux)
|
||||
|
||||
If you have [brew](http://brew.sh) installed:
|
||||
|
|
@ -276,9 +508,15 @@ $ pacman -S tio
|
|||
|
||||
The latest source releases can be found [here](https://github.com/tio/tio/releases).
|
||||
|
||||
Before running the install steps make sure you have glib and lua libraries installed. For example:
|
||||
|
||||
```
|
||||
$ sudo apt install libglib2.0-dev liblua5.2-dev
|
||||
```
|
||||
|
||||
Install steps:
|
||||
```
|
||||
$ meson build
|
||||
$ meson setup build
|
||||
$ meson compile -C build
|
||||
$ meson install -C build
|
||||
```
|
||||
|
|
@ -287,13 +525,24 @@ See meson\_options.txt for tio specific build options.
|
|||
|
||||
Note: The meson install steps may differ depending on your specific system.
|
||||
|
||||
### 4.6 Known issues
|
||||
|
||||
Getting permission access errors trying to open your serial device?
|
||||
|
||||
Add your user to the group which allows serial device access permanently. For example, to add your user to the 'dialout' group do:
|
||||
```bash
|
||||
sudo usermod -a -G dialout <username>
|
||||
```
|
||||
Switch to the "dialout" group, temporary but immediately for this session.
|
||||
```bash
|
||||
newgrp dialout
|
||||
```
|
||||
|
||||
|
||||
## 5. Contributing
|
||||
|
||||
tio is open source. If you want to help out with the project please feel free
|
||||
to join in.
|
||||
|
||||
All contributions (bug reports, code, doc, ideas, etc.) are welcome.
|
||||
This is an open source project - all contributions (bug reports, code, doc,
|
||||
ideas, etc.) are welcome.
|
||||
|
||||
Please use the github issue tracker and pull request features.
|
||||
|
||||
|
|
@ -320,6 +569,6 @@ tio is GPLv2+. See LICENSE file for more details.
|
|||
|
||||
## 9. Authors
|
||||
|
||||
Created by Martin Lund \<martin.lund@keep-it-simple.com>
|
||||
Maintained by Martin Lund \<martin.lund@keep-it-simple.com>
|
||||
|
||||
See the AUTHORS file for full list of contributors.
|
||||
|
|
|
|||
80
TODO
80
TODO
|
|
@ -1,3 +1,83 @@
|
|||
* Add release support for arm and x86 binary tarballs
|
||||
|
||||
* Support input and input mapping from lua scripts
|
||||
|
||||
* Add option to send file raw (no modem protocol)
|
||||
|
||||
* Add loopback option
|
||||
|
||||
Send received serial input back to output (for testing etc.)
|
||||
|
||||
* Add loopback support between two serial ports
|
||||
|
||||
Useful for traffic monitoring
|
||||
|
||||
* Add mapping feature for printing non-printable characters
|
||||
|
||||
* Porting layer to support native win32 builds.
|
||||
|
||||
Some of the work that needs to be done:
|
||||
|
||||
All posix functions need to be platform independent, go though file by file:
|
||||
|
||||
termios.h
|
||||
unistd.h has very limited functions
|
||||
ENV different in config_file_resolve
|
||||
errno
|
||||
sys/ioctl.h
|
||||
sys/poll.h
|
||||
socket, may need a new thread
|
||||
Serial, RS485, character mapping
|
||||
Communication pipe
|
||||
|
||||
Port enumerate, all devices of the same type have the same name (eg. USB
|
||||
Serial Device for ttyACM) -> which makes regex not meaningful (kind of a
|
||||
good thing since libtre in Mingw has too much dependencies makes binary too
|
||||
big)
|
||||
|
||||
* Support traditional hex output format such as:
|
||||
|
||||
00000000 74 65 73 74 20 74 65 73 74 20 74 65 73 74 20 74 |test test test t|
|
||||
00000010 65 73 74 64 66 0a 61 0a 66 61 0a 66 0a 61 73 66 |estdf.a.fa.f.asf|
|
||||
00000020 64 61 64 73 66 61 73 66 64 61 73 64 66 61 64 73 |dadsfasfdasdfads|
|
||||
00000030 66 0a 61 73 64 66 61 64 73 66 61 73 64 66 61 73 |f.asdfadsfasdfas|
|
||||
00000040 64 66 0a 61 73 64 66 61 64 73 66 61 73 64 66 61 |df.asdfadsfasdfa|
|
||||
00000050 73 64 66 66 64 61 73 64 66 0a 0a 31 32 33 31 0a |sdffdasdf..1231.|
|
||||
00000060 65 32 31 64 73 77 65 64 0a 0a |e21dswed..|
|
||||
0000006a
|
||||
|
||||
* Add support for activity based time stamping in normal output mode
|
||||
|
||||
Already supported in hex output mode.
|
||||
|
||||
* Allow tio to connect to socket
|
||||
|
||||
After some more consideration I think it makes sense to support connecting to a
|
||||
socket as that will make tio be able to both serve a serial port via a socket
|
||||
and connect to it - it will be an end to end solution. In short we will be able
|
||||
to do the following:
|
||||
|
||||
Host serial port on socket (existing feature):
|
||||
$ tio --socket unix:/tmp/tio-socket-0 /dev/ttyUSB0
|
||||
|
||||
Connect to same socket (new feature):
|
||||
$ tio unix:/tmp/tio-socket-0
|
||||
|
||||
Besides a bit of refactoring the following required changes spring to mind:
|
||||
|
||||
* Socket mode and type of socket should be activated via device name prefix. For example:
|
||||
* UNIX socket: tio unix:<filename>
|
||||
* TCPv4 socket: tio inet:<ip>:<port>
|
||||
* TCPv6 socket: tio inet6:<ip>:<port>
|
||||
* If no port number defined default to 3333
|
||||
* Mapping flags INLCR, IGNCR, ICRNL needs implementation for socket mode
|
||||
* Error messages should just say "device" instead of "tty device" etc.
|
||||
* Remove other tty'isms (tty_write() should be device_write() etc.)
|
||||
* In session key commands that do not work in socket mode should either not be listed or print an error messages if used.
|
||||
* All non-tty features should continue work (auto-connect etc.)
|
||||
* Shell completion script update
|
||||
* Man page update
|
||||
|
||||
|
||||
* Split I/O feature
|
||||
|
||||
|
|
|
|||
|
|
@ -1,59 +0,0 @@
|
|||
###############################
|
||||
# tio - https://tio.github.io #
|
||||
###############################
|
||||
|
||||
# Example configuration file
|
||||
|
||||
# Defaults
|
||||
baudrate = 115200
|
||||
databits = 8
|
||||
flow = none
|
||||
stopbits = 1
|
||||
parity = none
|
||||
prefix-ctrl-key = t
|
||||
output-delay = 0
|
||||
output-line-delay = 0
|
||||
no-autoconnect = disable
|
||||
hexadecimal = disable
|
||||
timestamp = disable
|
||||
log = disable
|
||||
log-strip = disable
|
||||
local-echo = disable
|
||||
color = bold
|
||||
rs-485 = disable
|
||||
response-wait = disable
|
||||
alert = none
|
||||
|
||||
# Sub-configuraions
|
||||
|
||||
[rpi3]
|
||||
baudrate = 115200
|
||||
tty = /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A6009HU3-if00-port0
|
||||
socket = unix:/tmp/tio-socket-0
|
||||
color = 9
|
||||
|
||||
[am64-evm]
|
||||
baudrate = 115200
|
||||
tty = /dev/serial/by-id/usb-Silicon_Labs_CP2105_Dual_USB_to_UART_Bridge_Controller_01093176-if01-port0
|
||||
line-pulse-duration = DTR=200,RTS=300,RI=50
|
||||
alert = bell
|
||||
color = 10
|
||||
|
||||
[tincan]
|
||||
baudrate = 9600
|
||||
tty = /dev/serial/by-id/usb-TinCanTools_Flyswatter2_FS20000-if00-port0
|
||||
log = enable
|
||||
log-file = tincan.log
|
||||
log-strip = enable
|
||||
color = 11
|
||||
|
||||
[usb devices]
|
||||
pattern = usb([0-9]*)
|
||||
tty = /dev/ttyUSB%s
|
||||
color = 12
|
||||
|
||||
[rs-485-device]
|
||||
tty = /dev/ttyUSB0
|
||||
rs-485 = enable
|
||||
rs-485-config = RTS_ON_SEND=1,RTS_AFTER_SEND=1,RTS_DELAY_BEFORE_SEND=60,RTS_DELAY_AFTER_SEND=80,RX_DURING_TX
|
||||
color = 13
|
||||
78
examples/config/config
Normal file
78
examples/config/config
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
###############################
|
||||
# tio - https://tio.github.io #
|
||||
###############################
|
||||
|
||||
# Example tio configuration file
|
||||
#
|
||||
# Place file in any of the following locations:
|
||||
# $XDG_CONFIG_HOME/tio/config
|
||||
# $HOME/.config/tio/config
|
||||
# $HOME/.tioconfig
|
||||
|
||||
[default]
|
||||
baudrate = 115200
|
||||
databits = 8
|
||||
flow = none
|
||||
stopbits = 1
|
||||
parity = none
|
||||
output-delay = 0
|
||||
output-line-delay = 0
|
||||
auto-connect = direct
|
||||
no-reconnect = false
|
||||
local-echo = false
|
||||
input-mode = normal
|
||||
output-mode = normal
|
||||
timestamp = false
|
||||
log = false
|
||||
log-append = false
|
||||
log-strip = false
|
||||
color = bold
|
||||
rs-485 = false
|
||||
alert = none
|
||||
script-run = always
|
||||
prefix-ctrl-key = t
|
||||
|
||||
# Configuration profiles
|
||||
|
||||
[rpi3]
|
||||
baudrate = 115200
|
||||
device = /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A6009HU3-if00-port0
|
||||
socket = unix:/tmp/tio-socket-0
|
||||
color = 9
|
||||
|
||||
[am64-evm]
|
||||
baudrate = 115200
|
||||
device = /dev/serial/by-id/usb-Silicon_Labs_CP2105_Dual_USB_to_UART_Bridge_Controller_01093176-if01-port0
|
||||
line-pulse-duration = DTR=200,RTS=300,RI=50
|
||||
alert = bell
|
||||
color = 10
|
||||
|
||||
[tincan]
|
||||
baudrate = 9600
|
||||
device = /dev/serial/by-id/usb-TinCanTools_Flyswatter2_FS20000-if00-port0
|
||||
log = true
|
||||
log-file = tincan.log
|
||||
log-strip = true
|
||||
color = 11
|
||||
|
||||
[usb-devices]
|
||||
pattern = ^usb([0-9]*)
|
||||
device = /dev/ttyUSB%m1
|
||||
color = 12
|
||||
|
||||
[rs-485-device]
|
||||
device = /dev/ttyUSB0
|
||||
rs-485 = true
|
||||
rs-485-config = RTS_ON_SEND=1,RTS_AFTER_SEND=1,RTS_DELAY_BEFORE_SEND=60,RTS_DELAY_AFTER_SEND=80,RX_DURING_TX
|
||||
color = 13
|
||||
|
||||
[esp32]
|
||||
device = /dev/ttyUSB0
|
||||
color = 14
|
||||
script = tio.set{DTR=high,RTS=low}; tio.msleep(100); tio.set{DTR=low,RTS=high}; tio.msleep(100); tio.set{RTS=low}
|
||||
script-run = always
|
||||
|
||||
[buspirate]
|
||||
device = /dev/ttyACM0
|
||||
map = INLCRNL,ODELBS
|
||||
color = 15
|
||||
28
examples/lua/automatic-linux-login.lua
Normal file
28
examples/lua/automatic-linux-login.lua
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
local logins = {
|
||||
["foo"] = {
|
||||
username = "foouser",
|
||||
password = "foopass",
|
||||
},
|
||||
["bar"] = {
|
||||
username = "baruser",
|
||||
password = "barpass",
|
||||
},
|
||||
["baz"] = {
|
||||
username = "bazuser",
|
||||
password = "bazpass",
|
||||
},
|
||||
}
|
||||
|
||||
local hostname = tio.expect("^(%g+) login:", 10)
|
||||
if hostname then
|
||||
local login = logins[hostname]
|
||||
if (nil ~= login) then
|
||||
tio.write(login.username .. "\n")
|
||||
tio.expect("Password:")
|
||||
tio.write(login.password .. "\n")
|
||||
else
|
||||
io.write("\r\nDon't know login info for " .. hostname .. "\r\n")
|
||||
end
|
||||
else
|
||||
io.write("\r\nDidn't find a login prompt\r\n")
|
||||
end
|
||||
5
examples/lua/control-lines-test.lua
Normal file
5
examples/lua/control-lines-test.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
tio.set{DTR=high, RTS=low}
|
||||
tio.msleep(100)
|
||||
tio.set{DTR=low, RTS=high}
|
||||
tio.msleep(100)
|
||||
tio.set{RTS=toggle}
|
||||
14
examples/lua/read.lua
Normal file
14
examples/lua/read.lua
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
tio.read(1000, 6000) -- initial config
|
||||
tio.write("\n")
|
||||
tio.msleep(100)
|
||||
tio.read(650, 60) -- main menu
|
||||
tio.write("S") -- S menu
|
||||
tio.msleep(30)
|
||||
tio.read(650, 60)
|
||||
tio.write("t") -- Parallel Value Table
|
||||
tio.read(650, 60)
|
||||
while true do
|
||||
tio.msleep(1000)
|
||||
tio.write("t")
|
||||
tio.read(650, 50) -- repeat PVT forever
|
||||
end
|
||||
15
examples/lua/read_line.lua
Normal file
15
examples/lua/read_line.lua
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
tio.read(1000, 8000) -- read initial config
|
||||
tio.write("\n")
|
||||
tio.read(650, 100) -- main menu
|
||||
tio.write("S") -- S menu
|
||||
repeat
|
||||
str = tio.readline(25)
|
||||
until str == nil
|
||||
while true do
|
||||
tio.write("t") -- query PV table
|
||||
tio.msleep(880)
|
||||
repeat
|
||||
str = tio.readline(60)
|
||||
tio.msleep(60)
|
||||
until str == nil
|
||||
end
|
||||
13
examples/lua/serial-device-search.lua
Normal file
13
examples/lua/serial-device-search.lua
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
io.write("Searching... ")
|
||||
|
||||
local device = tio.ttysearch()
|
||||
|
||||
io.write("done\r\n")
|
||||
|
||||
for i in ipairs(device) do
|
||||
io.write("\r\n" .. device[i]["path"] .. "\r\n")
|
||||
io.write(" tid = " .. device[i]["tid"] .. "\r\n")
|
||||
io.write(" uptime = " .. device[i]["uptime"] .. "\r\n")
|
||||
io.write(" driver = " .. device[i]["driver"] .. "\r\n")
|
||||
io.write(" description = " .. device[i]["description"] .. "\r\n")
|
||||
end
|
||||
BIN
images/tio-icon.png
Normal file
BIN
images/tio-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
408
man/tio.1.in
408
man/tio.1.in
|
|
@ -1,18 +1,18 @@
|
|||
.TH "tio" "1" "@version_date@" "tio @version@" "User Commands"
|
||||
|
||||
.SH "NAME"
|
||||
tio \- a simple serial device I/O tool
|
||||
tio \- a serial device I/O tool
|
||||
|
||||
.SH "SYNOPSIS"
|
||||
.PP
|
||||
.B tio
|
||||
.RI "[" <options> "] " "<tty-device|sub-config>"
|
||||
.RI "[" <options> "] " "<tty-device|profile|tid>"
|
||||
|
||||
.SH "DESCRIPTION"
|
||||
.PP
|
||||
\fBtio\fR is a simple serial device tool which features a straightforward
|
||||
command-line and configuration file interface to easily connect to serial TTY
|
||||
devices for basic I/O operations.
|
||||
\fBtio\fR is a serial device tool which features a straightforward command-line
|
||||
and configuration file interface to easily connect to serial TTY devices for
|
||||
basic I/O operations.
|
||||
|
||||
.SH "OPTIONS"
|
||||
|
||||
|
|
@ -21,19 +21,19 @@ devices for basic I/O operations.
|
|||
|
||||
Set baud rate [bps] (default: 115200).
|
||||
.TP
|
||||
.BR \-d ", " "\-\-databits 5" | 6 | 7 | 8
|
||||
.BR \-d ", " "\-\-databits " 5 | 6 | 7 | 8
|
||||
|
||||
Set data bits (default: 8).
|
||||
.TP
|
||||
.BR \-f ", " "\-\-flow hard" | soft | none
|
||||
.BR \-f ", " "\-\-flow " hard | soft | none
|
||||
|
||||
Set flow control (default: none).
|
||||
.TP
|
||||
.BR \-s ", " "\-\-stopbits 1" | 2
|
||||
.BR \-s ", " "\-\-stopbits " 1 | 2
|
||||
|
||||
Set stop bits (default: 1).
|
||||
.TP
|
||||
.BR \-p ", " "\-\-parity odd" | even | none | mark | space
|
||||
.BR \-p ", " "\-\-parity " odd | even | none | mark | space
|
||||
|
||||
Set parity (default: none).
|
||||
|
||||
|
|
@ -80,17 +80,48 @@ The default pulse duration for each line is 100 ms.
|
|||
.RE
|
||||
|
||||
.TP
|
||||
.BR \-n ", " \-\-no\-autoconnect
|
||||
.BR "\-a, \-\-auto\-connect new|latest|direct"
|
||||
|
||||
Disable automatic connect.
|
||||
Automatically connect to serial device according to one of the following
|
||||
strategies:
|
||||
|
||||
By default tio automatically connects to the provided device if present. If the
|
||||
device is not present, it will wait for it to appear and then connect. If the
|
||||
connection is lost (eg. device disconnects), it will wait for the device to
|
||||
reappear and then reconnect.
|
||||
.RS
|
||||
.TP 10n
|
||||
.IP "\fBnew"
|
||||
Automatically connect to first new appearing serial device.
|
||||
.IP "\fBlatest"
|
||||
Automatically connect to latest registered serial device.
|
||||
.IP "\fBdirect"
|
||||
Connect directly to specified TTY device.
|
||||
.P
|
||||
All the listed strategies automatically reconnects according to strategy if
|
||||
device is not available or connection is lost.
|
||||
.P
|
||||
Default value is "direct".
|
||||
.RE
|
||||
|
||||
However, if the \fB\-\-no\-autoconnect\fR option is provided, tio will exit if
|
||||
the device is not present or an established connection is lost.
|
||||
.TP
|
||||
.BR " \-\-exclude\-devices \fI<pattern>"
|
||||
|
||||
Exclude devices by pattern ('*' and '?' supported).
|
||||
|
||||
.TP
|
||||
.BR " \-\-exclude\-drivers \fI<pattern>"
|
||||
|
||||
Exclude drivers by pattern ('*' and '?' supported).
|
||||
|
||||
.TP
|
||||
.BR " \-\-exclude\-tids \fI<pattern>"
|
||||
|
||||
Exclude topology IDs by pattern ('*' and '?' supported).
|
||||
|
||||
.TP
|
||||
.BR \-n ", " \-\-no\-reconnect
|
||||
|
||||
Do not reconnect.
|
||||
|
||||
This means that tio will exit if it fails to connect to device or an
|
||||
established connection is lost.
|
||||
|
||||
.TP
|
||||
.BR \-e ", " "\-\-local\-echo
|
||||
|
|
@ -103,7 +134,7 @@ Enable local echo.
|
|||
Enable line timestamp.
|
||||
|
||||
.TP
|
||||
.BR " \-\-timestamp-format \fI<format>
|
||||
.BR " \-\-timestamp\-format \fI<format>"
|
||||
|
||||
Set timestamp format to any of the following timestamp formats:
|
||||
.RS
|
||||
|
|
@ -117,27 +148,55 @@ Set timestamp format to any of the following timestamp formats:
|
|||
24-hour format relative to previous timestamp
|
||||
.IP "\fBiso8601"
|
||||
ISO8601 format ("YYYY-MM-DDThh:mm:ss.sss")
|
||||
.IP "\fBepoch"
|
||||
Seconds since Unix epoch (1970-01-01)
|
||||
.IP "\fBepoch-usec"
|
||||
Seconds since Unix epoch (1970-01-01) with subdivision in microseconds
|
||||
.PP
|
||||
Default format is \fB24hour\fR
|
||||
.RE
|
||||
|
||||
.TP
|
||||
.BR \-L ", " \-\-list\-devices
|
||||
.BR " \-\-timestamp\-timeout \fI<ms>"
|
||||
|
||||
List available serial devices by ID.
|
||||
Set timestamp timeout value in milliseconds.
|
||||
|
||||
This value only takes effect in hex output mode where timestamps are only
|
||||
printed after elapsed timeout time of no output activity from tty device.
|
||||
|
||||
Default value is 200.
|
||||
|
||||
.TP
|
||||
.BR \-l ", " \-\-log
|
||||
.BR \-l ", " \-\-list
|
||||
|
||||
List available targets (serial devices, TIDs, configuration profiles).
|
||||
|
||||
.TP
|
||||
.BR \-L ", " \-\-log
|
||||
|
||||
Enable log to file.
|
||||
|
||||
If no filename is provided the filename will be automatically generated.
|
||||
The log file will be automatically named using the following format
|
||||
tio_TARGET_YYYY-MM-DDTHH:MM:SS.log. Target being the command line target such
|
||||
as tty-device, tid, or configuration profile.
|
||||
|
||||
The filename can be manually set using the \-\-log-file option.
|
||||
|
||||
.TP
|
||||
.BR " \-\-log-file \fI<filename>
|
||||
.BR " \-\-log\-file \fI<filename>
|
||||
|
||||
Set log filename.
|
||||
|
||||
.TP
|
||||
.BR " \-\-log\-directory \fI<path>
|
||||
|
||||
Set log directory path in which to save automatically named log files.
|
||||
|
||||
.TP
|
||||
.BR " \-\-log\-append
|
||||
|
||||
Append to log file.
|
||||
|
||||
.TP
|
||||
.BR " \-\-log-strip
|
||||
|
||||
|
|
@ -146,8 +205,8 @@ Strip control characters and escape sequences from log.
|
|||
.TP
|
||||
.BR \-m ", " "\-\-map " \fI<flags>
|
||||
|
||||
Map (replace, translate) characters on input or output. The following mapping
|
||||
flags are supported:
|
||||
Map (replace, translate) characters on input to the serial device or output
|
||||
from the serial device. The following mapping flags are supported:
|
||||
|
||||
.RS
|
||||
.TP 12n
|
||||
|
|
@ -155,10 +214,16 @@ flags are supported:
|
|||
Map CR to NL on input (unless IGNCR is set)
|
||||
.IP "\fBIGNCR"
|
||||
Ignore CR on input
|
||||
.IP "\fBIFFESCC"
|
||||
Map FF to ESC-c on input
|
||||
.IP "\fBINLCR"
|
||||
Map NL to CR on input
|
||||
.IP "\fBINLCRNL"
|
||||
Map NL to CR-NL on input
|
||||
.IP "\fBICRCRNL"
|
||||
Map CR to CR-NL on input
|
||||
.IP "\fBIMSB2LSB"
|
||||
Map MSB bit order to LSB on input
|
||||
.IP "\fBOCRNL"
|
||||
Map CR to NL on output
|
||||
.IP "\fBODELBS"
|
||||
|
|
@ -167,19 +232,44 @@ Map DEL to BS on output
|
|||
Map NL to CR-NL on output
|
||||
.IP "\fBOLTU"
|
||||
Map lowercase characters to uppercase on output
|
||||
.IP "\fBMSB2LSB"
|
||||
Map MSB bit order to LSB on output
|
||||
.IP "\fBONULBRK"
|
||||
Map nul (zero) to send break signal on output
|
||||
.IP "\fBOIGNCR"
|
||||
Ignore CR on output
|
||||
.P
|
||||
If defining more than one flag, the flags must be comma separated.
|
||||
.RE
|
||||
|
||||
.TP
|
||||
.BR \-x ", " \-\-hexadecimal
|
||||
.BR " \-\-input\-mode " normal|hex|line
|
||||
|
||||
Enable hexadecimal mode.
|
||||
Set input mode.
|
||||
|
||||
In normal mode input characters are sent immediately as they are typed.
|
||||
|
||||
In hex input mode bytes can be sent by typing the \fBtwo-character
|
||||
hexadecimal\fR representation of the 1 byte value, e.g.: to send \fI0xA\fR you
|
||||
must type \fI0a\fR or \fI0A\fR.
|
||||
|
||||
In line input mode input characters are sent when you press enter. The only
|
||||
editing feature supported in this mode is backspace.
|
||||
|
||||
Default value is "normal".
|
||||
|
||||
.TP
|
||||
.BR \-c ", " "\-\-color " \fI0..255|bold|none|list
|
||||
.BR " \-\-output\-mode " normal|hex|hexN
|
||||
|
||||
Set output mode.
|
||||
|
||||
In hex mode each incoming byte is printed out as a 1 byte hex value.
|
||||
|
||||
In hexN mode, N is a number less than or equal to 4096 which defines how many
|
||||
hex values will be printed before a line break.
|
||||
|
||||
Default value is "normal".
|
||||
|
||||
.TP
|
||||
.BR \-c ", " "\-\-color " 0..255|bold|none|list
|
||||
|
||||
Colorize tio text using ANSI color code value ranging from 0 to 255 or use
|
||||
"none" for no color or use "bold" to apply bold formatting to existing system
|
||||
|
|
@ -217,21 +307,6 @@ If port is 0 or no port is provided default port 3333 is used.
|
|||
At present there is a hardcoded limit of 16 clients connected at one time.
|
||||
.RE
|
||||
|
||||
.TP
|
||||
.BR \-r ", " \-\-response-wait
|
||||
|
||||
Wait for line response then quit. A line is considered any string ending with
|
||||
either CR or NL character. If no line is received tio will quit after response
|
||||
timeout.
|
||||
|
||||
Any tio text is automatically muted when piping a string to tio while in
|
||||
response mode to make it easy to parse the response.
|
||||
|
||||
.TP
|
||||
.BR " \-\-response\-timeout " \fI<ms>
|
||||
|
||||
Set timeout [ms] of line response (default: 100).
|
||||
|
||||
.TP
|
||||
.BR " \-\-rs\-485"
|
||||
|
||||
|
|
@ -269,6 +344,37 @@ will sound the bell twice or blink twice on disconnect.
|
|||
|
||||
Default value is "none".
|
||||
|
||||
.TP
|
||||
.BR "\-\-mute"
|
||||
|
||||
Mute tio messages.
|
||||
|
||||
.TP
|
||||
.BR "\-\-script \fI<string>
|
||||
|
||||
Run script from string.
|
||||
|
||||
.TP
|
||||
.BR "\-\-script\-file \fI<filename>
|
||||
|
||||
Run script from file with filename.
|
||||
|
||||
.TP
|
||||
.BR "\-\-script\-run once|always|never"
|
||||
|
||||
Run script on connect once, always, or never.
|
||||
|
||||
Default value is "always".
|
||||
|
||||
.TP
|
||||
.BR "\-\-exec \fI<command>
|
||||
|
||||
Execute shell command with I/O redirected to device
|
||||
|
||||
.TP
|
||||
.BR "\-\-complete-profiles
|
||||
|
||||
Prints profiles (for shell completion)
|
||||
.TP
|
||||
.BR \-v ", " \-\-version
|
||||
|
||||
|
|
@ -277,10 +383,10 @@ Display program version.
|
|||
.BR \-h ", " \-\-help
|
||||
|
||||
Display help.
|
||||
.SH "KEYS"
|
||||
.SH "KEY COMMANDS"
|
||||
.PP
|
||||
.TP 16n
|
||||
In session, the following key sequences, a prefix key (default: ctrl-t) followed by a command key, are intercepted as tio commands:
|
||||
In session, all key strokes are forwarded to the serial device except the following key sequence: a prefix key (default: ctrl-t) followed by a command key. These sequences are intercepted as key commands:
|
||||
.IP "\fBctrl-t ?"
|
||||
List available key commands
|
||||
.IP "\fBctrl-t b"
|
||||
|
|
@ -289,37 +395,111 @@ Send serial break (triggers SysRq on Linux, etc.)
|
|||
Show configuration (baudrate, databits, etc.)
|
||||
.IP "\fBctrl-t e"
|
||||
Toggle local echo mode
|
||||
.IP "\fBctrl-t f"
|
||||
Toggle log to file
|
||||
.IP "\fBctrl-t F"
|
||||
Flush data I/O buffers (discard data written but not transmitted and data received but not read)
|
||||
.IP "\fBctrl-t g"
|
||||
Toggle serial port line
|
||||
.IP "\fBctrl-t h"
|
||||
Toggle hexadecimal mode
|
||||
.IP "\fBctrl-t i"
|
||||
Toggle input mode
|
||||
.IP "\fBctrl-t l"
|
||||
Clear screen
|
||||
.IP "\fBctrl-t L"
|
||||
Show line states (DTR, RTS, CTS, DSR, DCD, RI)
|
||||
.IP "\fBctrl-t m"
|
||||
Change mapping of characters on input or output
|
||||
.IP "\fBctrl-t o"
|
||||
Toggle output mode
|
||||
.IP "\fBctrl-t p"
|
||||
Pulse serial port line
|
||||
.IP "\fBctrl-t q"
|
||||
Quit
|
||||
.IP "\fBctrl-t r"
|
||||
Run script
|
||||
.IP "\fBctrl-t R"
|
||||
Execute shell command with I/O redirected to device
|
||||
.IP "\fBctrl-t s"
|
||||
Show TX/RX statistics
|
||||
.IP "\fBctrl-t t"
|
||||
Toggle line timestamp mode
|
||||
.IP "\fBctrl-t U"
|
||||
Toggle conversion to uppercase on output
|
||||
.IP "\fBctrl-t v"
|
||||
Show version
|
||||
.IP "\fBctrl-t x"
|
||||
Send file using the XMODEM-1K or XMODEM-CRC protocol (prompts for file name and protocol)
|
||||
.IP "\fBctrl-t y"
|
||||
Send file using the YMODEM protocol (prompts for file name)
|
||||
.IP "\fBctrl-t ctrl-t"
|
||||
Send ctrl-t character
|
||||
|
||||
.SH "HEXADECIMAL MODE"
|
||||
.SH "SCRIPT API"
|
||||
.PP
|
||||
In hexadecimal mode each incoming byte is printed out as a hexadecimal value.
|
||||
Tio suppots Lua scripting to easily automate interaction with the tty device.
|
||||
|
||||
.PP
|
||||
Bytes can be sent in this mode by typing the \fBtwo-character hexadecimal\fR
|
||||
representation of the value, e.g.: to send \fI0xA\fR you must type \fI0a\fR or
|
||||
\fI0A\fR.
|
||||
In addition to the standard Lua API tio makes the following functions
|
||||
and variables available:
|
||||
|
||||
.TP 6n
|
||||
|
||||
.IP "\fBtio.expect(pattern, timeout)"
|
||||
Waits for the Lua pattern to match or timeout before continuing.
|
||||
Timeout is in milliseconds, defaults to 0 meaning it will wait forever.
|
||||
|
||||
Returns the captures from the pattern or nil on timeout.
|
||||
|
||||
.IP "\fBtio.read(size, timeout)"
|
||||
Read up to size bytes from serial device. If timeout is 0 or not provided it
|
||||
will wait forever until data is ready to read.
|
||||
|
||||
Returns a string up to size bytes long on success and nil on timeout.
|
||||
|
||||
.IP "\fBtio.readline(timeout)"
|
||||
Read line from serial device. If timeout is 0 or not provided it will wait
|
||||
forever until data is ready to read.
|
||||
|
||||
Returns a string on success and nil on timeout. On timeout a partially read
|
||||
line may be returned as a second return value.
|
||||
|
||||
.IP "\fBtio.write(string)"
|
||||
Write string to serial device.
|
||||
|
||||
Returns the tio table.
|
||||
|
||||
.IP "\fBtio.send(file, protocol)"
|
||||
Send file using x/y-modem protocol.
|
||||
|
||||
Protocol can be any of XMODEM_1K, XMODEM_CRC, YMODEM.
|
||||
|
||||
.IP "\fBtio.ttysearch()"
|
||||
Search for serial devices.
|
||||
|
||||
Returns a table of number indexed tables, one for each serial device found.
|
||||
Each of these tables contains the serial device information accessible via the
|
||||
following string indexed elements "path", "tid", "uptime", "driver",
|
||||
"description".
|
||||
|
||||
Returns nil if no serial devices are found.
|
||||
|
||||
.IP "\fBtio.set{line=state, ...}"
|
||||
Set state of one or multiple tty modem lines.
|
||||
|
||||
Line can be any of DTR, RTS, CTS, DSR, CD, RI
|
||||
|
||||
State is high, low, or toggle.
|
||||
|
||||
.IP "\fBtio.sleep(seconds)"
|
||||
Sleep for seconds.
|
||||
.IP "\fBtio.msleep(ms)"
|
||||
Sleep for milliseconds.
|
||||
|
||||
.IP "\fBtio.alwaysecho"
|
||||
A boolean value, defaults to true.
|
||||
|
||||
If tio.alwaysecho is false, the result of tio.read, tio.readline or tio.expect
|
||||
will only be returned from the function and not logged or printed.
|
||||
|
||||
If tio.alwaysecho is set to true, reading functions also emit a single
|
||||
timestamp to stdout and log file per options.timestamp and options.log.
|
||||
|
||||
.SH "CONFIGURATION FILE"
|
||||
.PP
|
||||
|
|
@ -328,19 +508,19 @@ the configuration file first found in the following locations in the order
|
|||
listed:
|
||||
|
||||
.PP
|
||||
.I $XDG_CONFIG_HOME/tio/tiorc
|
||||
.I $XDG_CONFIG_HOME/tio/config
|
||||
.PP
|
||||
.I $HOME/.config/tio/tiorc
|
||||
.I $HOME/.config/tio/config
|
||||
.PP
|
||||
.I $HOME/.tiorc
|
||||
.I $HOME/.tioconfig
|
||||
|
||||
.PP
|
||||
Labels can be used to group settings into named sub-configurations which can be
|
||||
activated from the command-line when starting tio.
|
||||
Labels can be used to group settings into named configuration profiles which
|
||||
can be activated from the command-line when starting tio.
|
||||
|
||||
.PP
|
||||
\fBtio\fR will try to match the user input to a sub-configuration by name or by
|
||||
pattern to get the tty and other options.
|
||||
\fBtio\fR will try to match the user input to a configuration profile by name or by
|
||||
pattern to get the TTY device and other options.
|
||||
|
||||
.PP
|
||||
Options without any label change the default options.
|
||||
|
|
@ -354,8 +534,8 @@ The following configuration file options are available:
|
|||
.TP 25n
|
||||
.IP "\fBpattern"
|
||||
Pattern matching user input. This pattern can be an extended regular expression with a single group.
|
||||
.IP "\fBtty"
|
||||
tty device to open. If it contains a "%s" it is substituted with the first group match.
|
||||
.IP "\fBdevice"
|
||||
TTY device to open. If it contains a "%s" it is substituted with the first group match.
|
||||
.IP "\fBbaudrate"
|
||||
Set baud rate
|
||||
.IP "\fBdatabits"
|
||||
|
|
@ -372,12 +552,16 @@ Set output character delay
|
|||
Set output line delay
|
||||
.IP "\fBline-pulse-duration"
|
||||
Set line pulse duration
|
||||
.IP "\fBno-autoconnect"
|
||||
Disable automatic connect
|
||||
.IP "\fBno-reconnect"
|
||||
Do not reconnect
|
||||
.IP "\fBlog"
|
||||
Enable log to file
|
||||
.IP "\fBlog-file"
|
||||
Set log filename
|
||||
.IP "\fBlog-directory"
|
||||
Set log directory path in which to save automatically named log files.
|
||||
.IP "\fBlog-append"
|
||||
Append to log file
|
||||
.IP "\fBlog-strip"
|
||||
Enable strip of control and escape sequences from log
|
||||
.IP "\fBlocal-echo"
|
||||
|
|
@ -386,26 +570,40 @@ Enable local echo
|
|||
Enable line timestamp
|
||||
.IP "\fBtimestamp-format"
|
||||
Set timestamp format
|
||||
.IP "\fBtimestamp-timeout"
|
||||
Set timestamp timeout
|
||||
.IP "\fBmap"
|
||||
Map characters on input or output
|
||||
.IP "\fBcolor"
|
||||
Colorize tio text using ANSI color code ranging from 0 to 255
|
||||
.IP "\fBhexadecimal"
|
||||
Enable hexadecimal mode
|
||||
.IP "\fBinput-mode"
|
||||
Set input mode
|
||||
.IP "\fBoutput-mode"
|
||||
Set output mode
|
||||
.IP "\fBsocket"
|
||||
Set socket to redirect I/O to
|
||||
.IP "\fBprefix-ctrl-key"
|
||||
Set prefix ctrl key (a..z, default: t)
|
||||
.IP "\fBresponse-wait"
|
||||
Enable wait for line response
|
||||
.IP "\fBresponse-timeout"
|
||||
Set line response timeout
|
||||
Set prefix ctrl key (a..z or 'none', default: t)
|
||||
.IP "\fBrs-485"
|
||||
Enable RS-485 mode
|
||||
.IP "\fBrs-485-config"
|
||||
Set RS-485 configuration
|
||||
.IP "\fBalert"
|
||||
Set alert action on connect/disconnect
|
||||
.IP "\fBmute"
|
||||
Mute tio messages
|
||||
.IP "\fBscript"
|
||||
Run script from string
|
||||
.IP "\fBscript-file"
|
||||
Run script from file
|
||||
.IP "\fBscript-run"
|
||||
Run script on connect
|
||||
.IP "\fBexec"
|
||||
Execute shell command with I/O redirected to device
|
||||
|
||||
.PP
|
||||
It is possible to include the content of other configuration files using the
|
||||
include directive like so: "[include <file>]".
|
||||
|
||||
.SH "CONFIGURATION FILE EXAMPLES"
|
||||
|
||||
|
|
@ -415,7 +613,7 @@ To change the default configuration simply set options like so:
|
|||
.RS
|
||||
.nf
|
||||
.eo
|
||||
# Defaults
|
||||
[default]
|
||||
baudrate = 9600
|
||||
databits = 8
|
||||
parity = none
|
||||
|
|
@ -427,13 +625,13 @@ line-pulse-duration = DTR=200,RTS=400
|
|||
.RE
|
||||
|
||||
.TP
|
||||
Named sub-configurations can be added via labels:
|
||||
Named configuration profiles can be added via labels:
|
||||
|
||||
.RS
|
||||
.nf
|
||||
.eo
|
||||
[rpi3]
|
||||
tty = /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
|
||||
device = /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
|
||||
baudrate = 115200
|
||||
color = 11
|
||||
.ec
|
||||
|
|
@ -441,7 +639,7 @@ color = 11
|
|||
.RE
|
||||
|
||||
.TP
|
||||
Activate the sub-configuration by name:
|
||||
Activate the configuration profile by name:
|
||||
|
||||
$ tio rpi3
|
||||
|
||||
|
|
@ -451,31 +649,31 @@ Which is equivalent to:
|
|||
$ tio -b 115200 -c 11 /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
|
||||
|
||||
.TP
|
||||
A sub-configuration can also be activated by its pattern which supports regular expressions:
|
||||
A configuration profile can also be activated by its pattern which supports regular expressions:
|
||||
|
||||
.RS
|
||||
.nf
|
||||
.eo
|
||||
[usb device]
|
||||
pattern = usb([0-9]*)
|
||||
tty = /dev/ttyUSB%s
|
||||
[usb-devices]
|
||||
pattern = ^usb([0-9]*)
|
||||
device = /dev/ttyUSB%m1
|
||||
baudrate = 115200
|
||||
.ec
|
||||
.fi
|
||||
.RE
|
||||
|
||||
.TP
|
||||
Activate the sub-configuration by pattern match:
|
||||
Activate the configuration profile by pattern match:
|
||||
|
||||
$ tio usb12
|
||||
|
||||
.TP
|
||||
Which is equivalent to:
|
||||
Which becomes equivalent to:
|
||||
|
||||
$ tio -b 115200 /dev/ttyUSB12
|
||||
|
||||
.TP
|
||||
It is also possible to combine use of sub-configuration and command-line options. For example:
|
||||
It is also possible to combine use of configuration profile and command-line options. For example:
|
||||
|
||||
$ tio -l -t usb12
|
||||
|
||||
|
|
@ -489,7 +687,7 @@ Which corresponds to the commonly used default options:
|
|||
|
||||
$ tio \-b 115200 \-d 8 \-f none \-s 1 \-p none /dev/ttyUSB0
|
||||
.TP
|
||||
It is recommended to connect serial tty devices by ID:
|
||||
It is recommended to connect serial TTY devices by ID:
|
||||
|
||||
$ tio /dev/serial/by\-id/usb\-FTDI_TTL232R-3V3_FTGQVXBL\-if00\-port0
|
||||
.PP
|
||||
|
|
@ -498,12 +696,12 @@ correct serial device if it is disconnected and then reconnected.
|
|||
.TP
|
||||
Redirect serial device I/O to Unix file socket for scripting:
|
||||
|
||||
$ tio -S unix:/tmp/tmux-socket0 /dev/ttyUSB0
|
||||
$ tio -S unix:/tmp/tio-socket0 /dev/ttyUSB0
|
||||
|
||||
.TP
|
||||
Then, to issue a command via the file socket simply do:
|
||||
|
||||
$ echo "ls -la" | nc -UN /tmp/tmux-socket0 > /dev/null
|
||||
$ echo "ls -la" | nc -UN /tmp/tio-socket0 > /dev/null
|
||||
|
||||
.TP
|
||||
Or use the expect command to script an interaction:
|
||||
|
|
@ -512,13 +710,13 @@ Or use the expect command to script an interaction:
|
|||
.nf
|
||||
.eo
|
||||
#!/usr/bin/expect -f
|
||||
|
||||
.sp
|
||||
set timeout -1
|
||||
log_user 0
|
||||
|
||||
.sp
|
||||
spawn nc -UN /tmp/tio-socket0
|
||||
set uart $spawn_id
|
||||
|
||||
.sp
|
||||
send -i $uart "date\n"
|
||||
expect -i $uart "prompt> "
|
||||
send -i $uart "ls -la\n"
|
||||
|
|
@ -528,13 +726,18 @@ expect -i $uart "prompt> "
|
|||
.RE
|
||||
|
||||
.TP
|
||||
Redirect device I/O to network file socket for remote tty sharing:
|
||||
It is also possible to use tio's own simpler expect/send script functionality to e.g. automate logins:
|
||||
|
||||
$ tio --script 'tio.expect("login: "); tio.write("root\\n"); tio.expect("Password: "); tio.write("root\\n")' /dev/ttyUSB0
|
||||
|
||||
.TP
|
||||
Redirect device I/O to network file socket for remote TTY sharing:
|
||||
|
||||
$ tio --socket inet:4444 /dev/ttyUSB0
|
||||
|
||||
.TP
|
||||
|
||||
Then, use netcat to connect to the shared tty session over network (assuming tio is hosted on IP 10.0.0.42):
|
||||
Then, use netcat to connect to the shared TTY session over network (assuming tio is hosted on IP 10.0.0.42):
|
||||
|
||||
$ nc -N 10.0.0.42 4444
|
||||
|
||||
|
|
@ -544,26 +747,35 @@ Pipe command to the serial device:
|
|||
$ echo "ls -la" | tio /dev/serial/by\-id/usb\-FTDI_TTL232R-3V3_FTGQVXBL\-if00\-port0
|
||||
|
||||
.TP
|
||||
Pipe command to the serial device and wait for line response (string ending with CR or NL):
|
||||
Pipe command to serial device and wait for line response within 1 second:
|
||||
|
||||
$ echo "*IDN?" | tio /dev/ttyACM0 --response-wait
|
||||
$ echo "*IDN?" | tio /dev/ttyACM0 --script "tio.expect('\\r\\n', 1000)" --mute
|
||||
.TP
|
||||
In this mode, only the response will be printed.
|
||||
|
||||
.TP
|
||||
Likewise, to pipe data from file to the serial device:
|
||||
|
||||
$ cat data.bin | tio /dev/serial/by\-id/usb\-FTDI_TTL232R-3V3_FTGQVXBL\-if00\-port0
|
||||
|
||||
.TP
|
||||
Map NL to CR-NL on input from device and DEL to BS on output to device:
|
||||
|
||||
$ tio --map INLCRNL,ODELBS /dev/ttyUSB0
|
||||
|
||||
.TP
|
||||
Enable RS-485 mode:
|
||||
|
||||
$ tio --rs-485 --rs-485-config=RTS_ON_SEND=1,RX_DURING_TX /dev/ttyUSB0
|
||||
|
||||
.TP
|
||||
Manipulate DTR and RTS lines upon first connect to reset connected microcontroller:
|
||||
|
||||
$ tio --script "tio.set{DTR=high,RTS=low}; tio.msleep(100); tio.set{RTS=toggle}" --script-run once /dev/ttyUSB0
|
||||
|
||||
.SH "WEBSITE"
|
||||
.PP
|
||||
Visit https://tio.github.io
|
||||
|
||||
.SH "AUTHOR"
|
||||
.PP
|
||||
Created by Martin Lund <martin.lund@keep\-it\-simple.com>.
|
||||
Maintained by Martin Lund <martin.lund@keep\-it\-simple.com>.
|
||||
|
|
|
|||
324
man/tio.1.txt
324
man/tio.1.txt
|
|
@ -1,13 +1,13 @@
|
|||
tio(1) User Commands tio(1)
|
||||
|
||||
NAME
|
||||
tio - a simple serial device I/O tool
|
||||
tio - a serial device I/O tool
|
||||
|
||||
SYNOPSIS
|
||||
tio [<options>] <tty-device|sub-config>
|
||||
tio [<options>] <tty-device|profile|tid>
|
||||
|
||||
DESCRIPTION
|
||||
tio is a simple serial device tool which features a straightforward command-line and configuration file interface to easily connect to serial TTY devices for basic I/O operations.
|
||||
tio is a serial device tool which features a straightforward command-line and configuration file interface to easily connect to serial TTY devices for basic I/O operations.
|
||||
|
||||
OPTIONS
|
||||
-b, --baudrate <bps>
|
||||
|
|
@ -62,14 +62,37 @@ OPTIONS
|
|||
|
||||
The default pulse duration for each line is 100 ms.
|
||||
|
||||
-n, --no-autoconnect
|
||||
-a, --auto-connect new|latest|direct
|
||||
|
||||
Disable automatic connect.
|
||||
Automatically connect to serial device according to one of the following strategies:
|
||||
|
||||
By default tio automatically connects to the provided device if present. If the device is not present, it will wait for it to appear and then connect. If the connection is lost
|
||||
(eg. device disconnects), it will wait for the device to reappear and then reconnect.
|
||||
new Automatically connect to first new appearing serial device.
|
||||
|
||||
However, if the --no-autoconnect option is provided, tio will exit if the device is not present or an established connection is lost.
|
||||
latest Automatically connect to latest registered serial device.
|
||||
|
||||
direct Connect directly to specified TTY device.
|
||||
|
||||
All the listed strategies automatically reconnects according to strategy if device is not available or connection is lost.
|
||||
|
||||
Default value is "direct".
|
||||
|
||||
--exclude-devices <pattern>
|
||||
|
||||
Exclude devices by pattern ('*' and '?' supported).
|
||||
|
||||
--exclude-drivers <pattern>
|
||||
|
||||
Exclude drivers by pattern ('*' and '?' supported).
|
||||
|
||||
--exclude-tids <pattern>
|
||||
|
||||
Exclude topology IDs by pattern ('*' and '?' supported).
|
||||
|
||||
-n, --no-reconnect
|
||||
|
||||
Do not reconnect.
|
||||
|
||||
This means that tio will exit if it fails to connect to device or an established connection is lost.
|
||||
|
||||
-e, --local-echo
|
||||
|
||||
|
|
@ -91,38 +114,66 @@ OPTIONS
|
|||
|
||||
iso8601 ISO8601 format ("YYYY-MM-DDThh:mm:ss.sss")
|
||||
|
||||
epoch Seconds since Unix epoch (1970-01-01)
|
||||
|
||||
epoch-usec Seconds since Unix epoch (1970-01-01) with subdivision microseconds
|
||||
|
||||
Default format is 24hour
|
||||
|
||||
-L, --list-devices
|
||||
--timestamp-timeout <ms>
|
||||
|
||||
List available serial devices by ID.
|
||||
Set timestamp timeout value in milliseconds.
|
||||
|
||||
-l, --log
|
||||
This value only takes effect in hex output mode where timestamps are only printed after elapsed timeout time of no output activity from tty device.
|
||||
|
||||
Default value is 200.
|
||||
|
||||
-l, --list
|
||||
|
||||
List available targets (serial devices, TIDs, configuration profiles).
|
||||
|
||||
-L, --log
|
||||
|
||||
Enable log to file.
|
||||
|
||||
If no filename is provided the filename will be automatically generated.
|
||||
The log file will be automatically named using the following format tio_TARGET_YYYY-MM-DDTHH:MM:SS.log. Target being the command line target such as tty-device, tid, or configuration profile.
|
||||
|
||||
The filename can be manually set using the --log-file option.
|
||||
|
||||
--log-file <filename>
|
||||
|
||||
Set log filename.
|
||||
|
||||
--log-directory <path>
|
||||
|
||||
Set log directory path in which to save automatically named log files.
|
||||
|
||||
--log-append
|
||||
|
||||
Append to log file.
|
||||
|
||||
--log-strip
|
||||
|
||||
Strip control characters and escape sequences from log.
|
||||
|
||||
-m, --map <flags>
|
||||
|
||||
Map (replace, translate) characters on input or output. The following mapping flags are supported:
|
||||
Map (replace, translate) characters on input to the serial device or output from the serial device. The following mapping flags are supported:
|
||||
|
||||
ICRNL Map CR to NL on input (unless IGNCR is set)
|
||||
|
||||
IGNCR Ignore CR on input
|
||||
|
||||
IFFESCC Map FF to ESC-c on input
|
||||
|
||||
INLCR Map NL to CR on input
|
||||
|
||||
INLCRNL Map NL to CR-NL on input
|
||||
|
||||
ICRCRNL Map CR to CR-NL on input
|
||||
|
||||
IMSB2LSB Map MSB bit order to LSB on input
|
||||
|
||||
OCRNL Map CR to NL on output
|
||||
|
||||
ODELBS Map DEL to BS on output
|
||||
|
|
@ -131,13 +182,33 @@ OPTIONS
|
|||
|
||||
OLTU Map lowercase characters to uppercase on output
|
||||
|
||||
MSB2LSB Map MSB bit order to LSB on output
|
||||
ONULBRK Map nul (zero) to send break signal on output
|
||||
|
||||
OIGNCR Ignore CR on output
|
||||
|
||||
If defining more than one flag, the flags must be comma separated.
|
||||
|
||||
-x, --hexadecimal
|
||||
--input-mode normal|hex|line
|
||||
|
||||
Enable hexadecimal mode.
|
||||
Set input mode.
|
||||
|
||||
In normal mode input characters are sent immediately as they are typed.
|
||||
|
||||
In hex input mode bytes can be sent by typing the two-character hexadecimal representation of the 1 byte value, e.g.: to send 0xA you must type 0a or 0A.
|
||||
|
||||
In line input mode input characters are sent when you press enter. The only editing feature supported in this mode is backspace.
|
||||
|
||||
Default value is "normal".
|
||||
|
||||
--output-mode normal|hex|hexN
|
||||
|
||||
Set output mode.
|
||||
|
||||
In hex mode each incoming byte is printed out as a 1 byte hex value.
|
||||
|
||||
In hexN mode, N is a number less than or equal to 4096 which defines how many hex values will be printed before a line break.
|
||||
|
||||
Default value is "normal".
|
||||
|
||||
-c, --color 0..255|bold|none|list
|
||||
|
||||
|
|
@ -151,8 +222,8 @@ OPTIONS
|
|||
|
||||
Redirect I/O to socket.
|
||||
|
||||
Any input from clients connected to the socket is sent on the serial port as if entered at the terminal where tio is running (except that ctrl-t sequences are not recognized), and
|
||||
any input from the serial port is multiplexed to the terminal and all connected clients.
|
||||
Any input from clients connected to the socket is sent on the serial port as if entered at the terminal where tio is running (except that ctrl-t sequences are not recognized), and any input from the serial port is multi‐
|
||||
plexed to the terminal and all connected clients.
|
||||
|
||||
Sockets remain open while the serial port is disconnected, and writes will block.
|
||||
|
||||
|
|
@ -168,16 +239,6 @@ OPTIONS
|
|||
|
||||
At present there is a hardcoded limit of 16 clients connected at one time.
|
||||
|
||||
-r, --response-wait
|
||||
|
||||
Wait for line response then quit. A line is considered any string ending with either CR or NL character. If no line is received tio will quit after response timeout.
|
||||
|
||||
Any tio text is automatically muted when piping a string to tio while in response mode to make it easy to parse the response.
|
||||
|
||||
--response-timeout <ms>
|
||||
|
||||
Set timeout [ms] of line response (default: 100).
|
||||
|
||||
--rs-485
|
||||
|
||||
Enable RS-485 mode.
|
||||
|
|
@ -206,6 +267,32 @@ OPTIONS
|
|||
|
||||
Default value is "none".
|
||||
|
||||
--mute
|
||||
|
||||
Mute tio messages.
|
||||
|
||||
--script <string>
|
||||
|
||||
Run script from string.
|
||||
|
||||
--script-file <filename>
|
||||
|
||||
Run script from file with filename.
|
||||
|
||||
--script-run once|always|never
|
||||
|
||||
Run script on connect once, always, or never.
|
||||
|
||||
Default value is "always".
|
||||
|
||||
--exec <command>
|
||||
|
||||
Execute shell command with I/O redirected to device
|
||||
|
||||
--complete-profiles
|
||||
|
||||
Prints profiles (for shell completion)
|
||||
|
||||
-v, --version
|
||||
|
||||
Display program version.
|
||||
|
|
@ -214,8 +301,8 @@ OPTIONS
|
|||
|
||||
Display help.
|
||||
|
||||
KEYS
|
||||
In session, the following key sequences, a prefix key (default: ctrl-t) followed by a command key, are intercepted as tio commands:
|
||||
KEY COMMANDS
|
||||
In session, all key strokes are forwarded to the serial device except the following key sequence: a prefix key (default: ctrl-t) followed by a command key. These sequences are intercepted as key commands:
|
||||
|
||||
ctrl-t ? List available key commands
|
||||
|
||||
|
|
@ -225,45 +312,114 @@ KEYS
|
|||
|
||||
ctrl-t e Toggle local echo mode
|
||||
|
||||
ctrl-t f Toggle log to file
|
||||
|
||||
ctrl-t F Flush data I/O buffers (discard data written but not transmitted and data received but not read)
|
||||
|
||||
ctrl-t g Toggle serial port line
|
||||
|
||||
ctrl-t h Toggle hexadecimal mode
|
||||
ctrl-t i Toggle input mode
|
||||
|
||||
ctrl-t l Clear screen
|
||||
|
||||
ctrl-t L Show line states (DTR, RTS, CTS, DSR, DCD, RI)
|
||||
|
||||
ctrl-t m Change mapping of characters on input or output
|
||||
|
||||
ctrl-t o Toggle output mode
|
||||
|
||||
ctrl-t p Pulse serial port line
|
||||
|
||||
ctrl-t q Quit
|
||||
|
||||
ctrl-t r Run script
|
||||
|
||||
ctrl-t R Execute shell command with I/O redirected to device
|
||||
|
||||
ctrl-t s Show TX/RX statistics
|
||||
|
||||
ctrl-t t Toggle line timestamp mode
|
||||
|
||||
ctrl-t U Toggle conversion to uppercase on output
|
||||
|
||||
ctrl-t v Show version
|
||||
|
||||
ctrl-t x Send file using the XMODEM-1K or XMODEM-CRC protocol (prompts for file name and protocol)
|
||||
|
||||
ctrl-t y Send file using the YMODEM protocol (prompts for file name)
|
||||
|
||||
ctrl-t ctrl-t Send ctrl-t character
|
||||
|
||||
HEXADECIMAL MODE
|
||||
In hexadecimal mode each incoming byte is printed out as a hexadecimal value.
|
||||
SCRIPT API
|
||||
Tio suppots Lua scripting to easily automate interaction with the tty device.
|
||||
|
||||
Bytes can be sent in this mode by typing the two-character hexadecimal representation of the value, e.g.: to send 0xA you must type 0a or 0A.
|
||||
In addition to the standard Lua API tio makes the following functions available:
|
||||
|
||||
expect(string, timeout)
|
||||
Expect string - waits for string to match or timeout before continuing. Supports regular expressions. Special characters must be escaped with '\\'. Timeout is in milliseconds, defaults to 0 meaning it will wait forever.
|
||||
|
||||
Returns 1 on successful match, 0 on timeout, or -1 on error.
|
||||
|
||||
On successful match it also returns the match string as second return value.
|
||||
|
||||
read(size, timeout)
|
||||
Read up to size bytes from serial device. If timeout is 0 or not provided it will wait forever until data is ready to read.
|
||||
|
||||
Returns number of bytes read on success, 0 on timeout, or -1 on error.
|
||||
|
||||
On success, returns read string as second return value. Also emits a single timestamp to stdout and log file per options.timestamp and options.log.
|
||||
|
||||
read_line(timeout)
|
||||
Read line from serial device. If timeout is 0 or not provided it will wait forever until data is ready to read.
|
||||
|
||||
Returns number of bytes read on success, 0 on timeout, or -1 on error.
|
||||
|
||||
On success, returns the string that was read as second return value. Also emits a single timestamp to stdout and log file per options.timestamp and options.log.
|
||||
|
||||
write(string)
|
||||
Write string to serial device.
|
||||
|
||||
Returns number of bytes written on success or -1 on error.
|
||||
|
||||
send(file, protocol)
|
||||
Send file using x/y-modem protocol.
|
||||
|
||||
Protocol can be any of XMODEM_1K, XMODEM_CRC, YMODEM.
|
||||
|
||||
tty_search()
|
||||
Search for serial devices.
|
||||
|
||||
Returns a table of number indexed tables, one for each serial device found. Each of these tables contains the serial device information accessible via the following string indexed elements "path", "tid", "uptime", "dri‐
|
||||
ver", "description".
|
||||
|
||||
Returns nil if no serial devices are found.
|
||||
|
||||
set{line=state, ...}
|
||||
Set state of one or multiple tty modem lines.
|
||||
|
||||
Line can be any of DTR, RTS, CTS, DSR, CD, RI
|
||||
|
||||
State is high, low, or toggle.
|
||||
|
||||
sleep(seconds)
|
||||
Sleep for seconds.
|
||||
|
||||
msleep(ms)
|
||||
Sleep for milliseconds.
|
||||
|
||||
exit(code)
|
||||
Exit with exit code.
|
||||
|
||||
CONFIGURATION FILE
|
||||
Options can be set via configuration file using the INI format. tio uses the configuration file first found in the following locations in the order listed:
|
||||
|
||||
$XDG_CONFIG_HOME/tio/tiorc
|
||||
$XDG_CONFIG_HOME/tio/config
|
||||
|
||||
$HOME/.config/tio/tiorc
|
||||
$HOME/.config/tio/config
|
||||
|
||||
$HOME/.tiorc
|
||||
$HOME/.tioconfig
|
||||
|
||||
Labels can be used to group settings into named sub-configurations which can be activated from the command-line when starting tio.
|
||||
Labels can be used to group settings into named configuration profiles which can be activated from the command-line when starting tio.
|
||||
|
||||
tio will try to match the user input to a sub-configuration by name or by pattern to get the tty and other options.
|
||||
tio will try to match the user input to a configuration profile by name or by pattern to get the TTY device and other options.
|
||||
|
||||
Options without any label change the default options.
|
||||
|
||||
|
|
@ -273,7 +429,7 @@ CONFIGURATION FILE
|
|||
|
||||
pattern Pattern matching user input. This pattern can be an extended regular expression with a single group.
|
||||
|
||||
tty tty device to open. If it contains a "%s" it is substituted with the first group match.
|
||||
device TTY device to open. If it contains a "%s" it is substituted with the first group match.
|
||||
|
||||
baudrate Set baud rate
|
||||
|
||||
|
|
@ -291,12 +447,16 @@ CONFIGURATION FILE
|
|||
|
||||
line-pulse-duration Set line pulse duration
|
||||
|
||||
no-autoconnect Disable automatic connect
|
||||
no-reconnect Do not reconnect
|
||||
|
||||
log Enable log to file
|
||||
|
||||
log-file Set log filename
|
||||
|
||||
log-directory Set log directory path in which to save automatically named log files.
|
||||
|
||||
log-append Append to log file
|
||||
|
||||
log-strip Enable strip of control and escape sequences from log
|
||||
|
||||
local-echo Enable local echo
|
||||
|
|
@ -305,19 +465,19 @@ CONFIGURATION FILE
|
|||
|
||||
timestamp-format Set timestamp format
|
||||
|
||||
timestamp-timeout Set timestamp timeout
|
||||
|
||||
map Map characters on input or output
|
||||
|
||||
color Colorize tio text using ANSI color code ranging from 0 to 255
|
||||
|
||||
hexadecimal Enable hexadecimal mode
|
||||
input-mode Set input mode
|
||||
|
||||
output-mode Set output mode
|
||||
|
||||
socket Set socket to redirect I/O to
|
||||
|
||||
prefix-ctrl-key Set prefix ctrl key (a..z, default: t)
|
||||
|
||||
response-wait Enable wait for line response
|
||||
|
||||
response-timeout Set line response timeout
|
||||
prefix-ctrl-key Set prefix ctrl key (a..z or 'none', default: t)
|
||||
|
||||
rs-485 Enable RS-485 mode
|
||||
|
||||
|
|
@ -325,10 +485,22 @@ CONFIGURATION FILE
|
|||
|
||||
alert Set alert action on connect/disconnect
|
||||
|
||||
mute Mute tio messages
|
||||
|
||||
script Run script from string
|
||||
|
||||
script-file Run script from file
|
||||
|
||||
script-run Run script on connect
|
||||
|
||||
exec Execute shell command with I/O redirected to device
|
||||
|
||||
It is possible to include the content of other configuration files using the include directive like so: "[include <file>]".
|
||||
|
||||
CONFIGURATION FILE EXAMPLES
|
||||
To change the default configuration simply set options like so:
|
||||
|
||||
# Defaults
|
||||
[default]
|
||||
baudrate = 9600
|
||||
databits = 8
|
||||
parity = none
|
||||
|
|
@ -336,14 +508,14 @@ CONFIGURATION FILE EXAMPLES
|
|||
color = 10
|
||||
line-pulse-duration = DTR=200,RTS=400
|
||||
|
||||
Named sub-configurations can be added via labels:
|
||||
Named configuration profiles can be added via labels:
|
||||
|
||||
[rpi3]
|
||||
tty = /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
|
||||
device = /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
|
||||
baudrate = 115200
|
||||
color = 11
|
||||
|
||||
Activate the sub-configuration by name:
|
||||
Activate the configuration profile by name:
|
||||
|
||||
$ tio rpi3
|
||||
|
||||
|
|
@ -351,22 +523,22 @@ CONFIGURATION FILE EXAMPLES
|
|||
|
||||
$ tio -b 115200 -c 11 /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
|
||||
|
||||
A sub-configuration can also be activated by its pattern which supports regular expressions:
|
||||
A configuration profile can also be activated by its pattern which supports regular expressions:
|
||||
|
||||
[usb device]
|
||||
pattern = usb([0-9]*)
|
||||
tty = /dev/ttyUSB%s
|
||||
[usb-devices]
|
||||
pattern = ^usb([0-9]*)
|
||||
device = /dev/ttyUSB%m1
|
||||
baudrate = 115200
|
||||
|
||||
Activate the sub-configuration by pattern match:
|
||||
Activate the configuration profile by pattern match:
|
||||
|
||||
$ tio usb12
|
||||
|
||||
Which is equivalent to:
|
||||
Which becomes equivalent to:
|
||||
|
||||
$ tio -b 115200 /dev/ttyUSB12
|
||||
|
||||
It is also possible to combine use of sub-configuration and command-line options. For example:
|
||||
It is also possible to combine use of configuration profile and command-line options. For example:
|
||||
|
||||
$ tio -l -t usb12
|
||||
|
||||
|
|
@ -379,7 +551,7 @@ EXAMPLES
|
|||
|
||||
$ tio -b 115200 -d 8 -f none -s 1 -p none /dev/ttyUSB0
|
||||
|
||||
It is recommended to connect serial tty devices by ID:
|
||||
It is recommended to connect serial TTY devices by ID:
|
||||
|
||||
$ tio /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
|
||||
|
||||
|
|
@ -387,11 +559,11 @@ EXAMPLES
|
|||
|
||||
Redirect serial device I/O to Unix file socket for scripting:
|
||||
|
||||
$ tio -S unix:/tmp/tmux-socket0 /dev/ttyUSB0
|
||||
$ tio -S unix:/tmp/tio-socket0 /dev/ttyUSB0
|
||||
|
||||
Then, to issue a command via the file socket simply do:
|
||||
|
||||
$ echo "ls -la" | nc -UN /tmp/tmux-socket0 > /dev/null
|
||||
$ echo "ls -la" | nc -UN /tmp/tio-socket0 > /dev/null
|
||||
|
||||
Or use the expect command to script an interaction:
|
||||
|
||||
|
|
@ -408,11 +580,15 @@ EXAMPLES
|
|||
send -i $uart "ls -la\n"
|
||||
expect -i $uart "prompt> "
|
||||
|
||||
Redirect device I/O to network file socket for remote tty sharing:
|
||||
It is also possible to use tio's own simpler expect/send script functionality to e.g. automate logins:
|
||||
|
||||
$ tio --script 'expect("login: "); write("root\n"); expect("Password: "); write("root\n")' /dev/ttyUSB0
|
||||
|
||||
Redirect device I/O to network file socket for remote TTY sharing:
|
||||
|
||||
$ tio --socket inet:4444 /dev/ttyUSB0
|
||||
|
||||
Then, use netcat to connect to the shared tty session over network (assuming tio is hosted on IP 10.0.0.42):
|
||||
Then, use netcat to connect to the shared TTY session over network (assuming tio is hosted on IP 10.0.0.42):
|
||||
|
||||
$ nc -N 10.0.0.42 4444
|
||||
|
||||
|
|
@ -420,24 +596,30 @@ EXAMPLES
|
|||
|
||||
$ echo "ls -la" | tio /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
|
||||
|
||||
Pipe command to the serial device and wait for line response (string ending with CR or NL):
|
||||
Pipe command to serial device and wait for line response within 1 second:
|
||||
|
||||
$ echo "*IDN?" | tio /dev/ttyACM0 --response-wait
|
||||
|
||||
In this mode, only the response will be printed.
|
||||
$ echo "*IDN?" | tio /dev/ttyACM0 --script "expect('\r\n', 1000)" --mute
|
||||
|
||||
Likewise, to pipe data from file to the serial device:
|
||||
|
||||
$ cat data.bin | tio /dev/serial/by-id/usb-FTDI_TTL232R-3V3_FTGQVXBL-if00-port0
|
||||
|
||||
Map NL to CR-NL on input from device and DEL to BS on output to device:
|
||||
|
||||
$ tio --map INLCRNL,ODELBS /dev/ttyUSB0
|
||||
|
||||
Enable RS-485 mode:
|
||||
|
||||
$ tio --rs-485 --rs-485-config=RTS_ON_SEND=1,RX_DURING_TX /dev/ttyUSB0
|
||||
|
||||
Manipulate DTR and RTS lines upon first connect to reset connected microcontroller:
|
||||
|
||||
$ tio --script "set{DTR=high,RTS=low}; msleep(100); set{RTS=toggle}" --script-run once /dev/ttyUSB0
|
||||
|
||||
WEBSITE
|
||||
Visit https://tio.github.io
|
||||
|
||||
AUTHOR
|
||||
Created by Martin Lund <martin.lund@keep-it-simple.com>.
|
||||
Maintained by Martin Lund <martin.lund@keep-it-simple.com>.
|
||||
|
||||
tio 2.1 2022-10-15 tio(1)
|
||||
tio 3.9 2025-04-13 tio(1)
|
||||
|
|
|
|||
12
meson.build
12
meson.build
|
|
@ -1,12 +1,12 @@
|
|||
project('tio', 'c',
|
||||
version : '2.1',
|
||||
license : [ 'GPL-2'],
|
||||
version : '3.9',
|
||||
license : 'GPL-2.0-or-later',
|
||||
meson_version : '>= 0.53.2',
|
||||
default_options : [ 'warning_level=2', 'buildtype=release', 'c_std=gnu99' ]
|
||||
)
|
||||
|
||||
# The tag date of the project_version(), update when the version bumps.
|
||||
version_date = '2022-10-15'
|
||||
version_date = '2025-04-13'
|
||||
|
||||
# Test for dynamic baudrate configuration interface
|
||||
compiler = meson.get_compiler('c')
|
||||
|
|
@ -80,4 +80,8 @@ if host_machine.system() == 'linux'
|
|||
endif
|
||||
|
||||
subdir('src')
|
||||
subdir('man')
|
||||
|
||||
install_man_pages = get_option('install_man_pages')
|
||||
if install_man_pages
|
||||
subdir('man')
|
||||
endif
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
option('bashcompletiondir',
|
||||
type : 'string',
|
||||
description : 'Directory for bash completion scripts ["no" disables]')
|
||||
option('install_man_pages',
|
||||
type : 'boolean', value: true,
|
||||
description : 'Install man pages')
|
||||
|
|
|
|||
31
src/alert.c
31
src/alert.c
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
*
|
||||
|
|
@ -19,37 +19,10 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include "error.h"
|
||||
#include "print.h"
|
||||
#include "options.h"
|
||||
|
||||
enum alert_t alert_option_parse(const char *arg)
|
||||
{
|
||||
enum alert_t alert = option.alert; // Default
|
||||
|
||||
if (arg != NULL)
|
||||
{
|
||||
if (strcmp(arg, "none") == 0)
|
||||
{
|
||||
return ALERT_NONE;
|
||||
}
|
||||
else if (strcmp(arg, "bell") == 0)
|
||||
{
|
||||
return ALERT_BELL;
|
||||
}
|
||||
else if (strcmp(arg, "blink") == 0)
|
||||
{
|
||||
return ALERT_BLINK;
|
||||
}
|
||||
}
|
||||
|
||||
return alert;
|
||||
}
|
||||
#include "alert.h"
|
||||
|
||||
void blink_background(void)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
*
|
||||
|
|
@ -21,14 +21,13 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
enum alert_t
|
||||
typedef enum
|
||||
{
|
||||
ALERT_NONE,
|
||||
ALERT_BELL,
|
||||
ALERT_BLINK,
|
||||
ALERT_END,
|
||||
};
|
||||
} alert_t;
|
||||
|
||||
enum alert_t alert_option_parse(const char *arg);
|
||||
void alert_connect(void);
|
||||
void alert_disconnect(void);
|
||||
|
|
|
|||
|
|
@ -18,23 +18,35 @@ _tio()
|
|||
-o --output-delay \
|
||||
-o --output-line-delay \
|
||||
--line-pulse-duration \
|
||||
-n --no-autoconnect \
|
||||
-a --auto-connect \
|
||||
--exclude-devices \
|
||||
--exclude-drivers \
|
||||
--exclude-tids \
|
||||
-n --no-reconnect \
|
||||
-e --local-echo \
|
||||
-l --log \
|
||||
--log-file \
|
||||
--log-directory \
|
||||
--log-append \
|
||||
--log-strip \
|
||||
-m --map \
|
||||
-t --timestamp \
|
||||
--timestamp-format \
|
||||
-L --list-devices \
|
||||
--timestamp-timeout \
|
||||
-L --list \
|
||||
-c --color \
|
||||
-S --socket \
|
||||
-x --hexadecimal \
|
||||
-r --response-wait \
|
||||
--response-timeout \
|
||||
--input-mode \
|
||||
--output-mode \
|
||||
--rs-485 \
|
||||
--rs-485-config \
|
||||
--alert \
|
||||
--mute \
|
||||
--script \
|
||||
--script-file \
|
||||
--script-run \
|
||||
--exec \
|
||||
--complete-profiles \
|
||||
-v --version \
|
||||
-h --help"
|
||||
|
||||
|
|
@ -69,44 +81,16 @@ _tio()
|
|||
COMPREPLY=( $(compgen -W "1 10 100" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
--line-pulse-duration)
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
-n | --no-autoconnect)
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
-e | --local-echo)
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
-l | --log)
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
--log-file)
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
--log-strip)
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
-a | --auto-connect)
|
||||
COMPREPLY=( $(compgen -W "new latest none" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
-m | --map)
|
||||
COMPREPLY=( $(compgen -W "ICRNL IGNCR INLCR INLCRNL OCRNL ODELBS ONLCRNL MSB2LSB" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
-t | --timestamp)
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
COMPREPLY=( $(compgen -W "ICRNL IGNCR INLCR IFFESCC INLCRNL ICRCRNL IMSB2LSB OCRNL ODELBS ONLCRNL OLTU ONULBRK OIGNCR" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
--timestamp-format)
|
||||
COMPREPLY=( $(compgen -W "24hour 24hour-start 24hour-delta iso8601" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
-L | --list-devices)
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
COMPREPLY=( $(compgen -W "24hour 24hour-start 24hour-delta iso8601 epoch epoch-usec" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
-c | --color)
|
||||
|
|
@ -117,20 +101,12 @@ _tio()
|
|||
COMPREPLY=( $(compgen -W "unix: inet: inet6:" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
-x | --hexadecimal)
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
--input-mode)
|
||||
COMPREPLY=( $(compgen -W "normal hex line" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
-r | --response-wait)
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
--response-timeout)
|
||||
COMPREPLY=( $(compgen -W "1 10 100" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
--rs-485)
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
--output-mode)
|
||||
COMPREPLY=( $(compgen -W "normal hex" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
--rs-485-config)
|
||||
|
|
@ -141,12 +117,8 @@ _tio()
|
|||
COMPREPLY=( $(compgen -W "none bell blink" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
-v | --version)
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
-h | --help)
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
--script-run)
|
||||
COMPREPLY=( $(compgen -W "once always never" -- ${cur}) )
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
|
|
@ -159,12 +131,14 @@ _tio()
|
|||
;;
|
||||
esac
|
||||
|
||||
profiles="`tio --complete-profiles`"
|
||||
|
||||
if [ -d /dev/serial/by-id ]; then
|
||||
ttys=$(printf '%s\n' /dev/tty* /dev/serial/by-id/*)
|
||||
else
|
||||
ttys=$(printf '%s\n' /dev/tty*)
|
||||
fi
|
||||
COMPREPLY=( $(compgen -W "${ttys}" -- ${cur}) )
|
||||
COMPREPLY=( $(compgen -W "${ttys} ${profiles}" -- ${cur}) )
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
|
|||
940
src/configfile.c
940
src/configfile.c
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2020 Liam Beguin
|
||||
* Copyright (c) 2022 Martin Lund
|
||||
|
|
@ -24,20 +24,15 @@
|
|||
|
||||
struct config_t
|
||||
{
|
||||
const char *user;
|
||||
|
||||
char *path;
|
||||
char *section_name;
|
||||
char *match;
|
||||
|
||||
char *tty;
|
||||
char *flow;
|
||||
char *parity;
|
||||
char *log_filename;
|
||||
char *socket;
|
||||
char *map;
|
||||
char *active_group;
|
||||
char *device;
|
||||
};
|
||||
|
||||
extern struct config_t config;
|
||||
|
||||
void config_file_print(void);
|
||||
void config_file_parse(void);
|
||||
void config_exit(void);
|
||||
void config_file_show_profiles(void);
|
||||
void config_list_targets(void);
|
||||
|
|
|
|||
22
src/error.c
22
src/error.c
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
*
|
||||
|
|
@ -19,22 +19,18 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#define __STDC_WANT_LIB_EXT2__ 1 // To access vasprintf
|
||||
|
||||
#include "config.h"
|
||||
#define _GNU_SOURCE // To access vasprintf
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "options.h"
|
||||
#include "print.h"
|
||||
#include "error.h"
|
||||
#include "timestamp.h"
|
||||
|
||||
static char error[2][1000];
|
||||
static bool in_session = false;
|
||||
bool error_normal = true;
|
||||
|
||||
void switch_error_output_mode(void)
|
||||
{
|
||||
error_normal = false;
|
||||
}
|
||||
|
||||
void error_enter_session_mode(void)
|
||||
{
|
||||
|
|
@ -93,7 +89,7 @@ void error_exit(void)
|
|||
/* Print error */
|
||||
error_printf_("Error: %s", error[0]);
|
||||
}
|
||||
else if ((error[1][0] != 0) && (option.no_autoconnect))
|
||||
else if ((error[1][0] != 0) && (option.no_reconnect))
|
||||
{
|
||||
/* Print silent error */
|
||||
error_printf_("Error: %s", error[1]);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
*
|
||||
|
|
@ -21,6 +21,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
extern bool error_normal;
|
||||
|
||||
#define TIO_SUCCESS 0
|
||||
#define TIO_ERROR 1
|
||||
|
||||
|
|
@ -28,3 +32,4 @@ void tio_error_printf(const char *format, ...);
|
|||
void tio_error_printf_silent(const char *format, ...);
|
||||
void error_exit(void);
|
||||
void error_enter_session_mode(void);
|
||||
void switch_error_output_mode(void);
|
||||
|
|
|
|||
226
src/fs.c
Normal file
226
src/fs.c
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
/*
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2024 Martin Lund
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE // For statx()
|
||||
#include "config.h"
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <regex.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <termios.h>
|
||||
#include "error.h"
|
||||
#include "print.h"
|
||||
#include "options.h"
|
||||
|
||||
bool fs_dir_exists(const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat(path, &st) != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!S_ISDIR(st.st_mode))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Function to read the content of a file but stripped of newline
|
||||
ssize_t fs_read_file_stripped(char *buf, size_t bufsiz, const char *format, ...)
|
||||
{
|
||||
char filename[PATH_MAX];
|
||||
int bytes_printed = 0;
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
bytes_printed = vsnprintf(filename, sizeof(filename), format, args);
|
||||
va_end(args);
|
||||
|
||||
if (bytes_printed < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
FILE *file = fopen(filename, "r");
|
||||
if (!file)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
ssize_t length = fread(buf, 1, bufsiz - 1, file);
|
||||
if (length == -1)
|
||||
{
|
||||
fclose(file);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Strip any newline
|
||||
buf[strcspn(buf, "\n")] = 0;
|
||||
buf[length] = '\0'; // Make sure to null-terminate the string
|
||||
|
||||
fclose(file);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
bool fs_file_exists(const char *format, ...)
|
||||
{
|
||||
char filename[PATH_MAX];
|
||||
int bytes_printed = 0;
|
||||
struct stat st;
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
bytes_printed = vsnprintf(filename, sizeof(filename), format, args);
|
||||
va_end(args);
|
||||
|
||||
if (bytes_printed < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return stat(filename, &st) == 0;
|
||||
}
|
||||
|
||||
char* fs_search_directory(const char *dir_path, const char *dirname)
|
||||
{
|
||||
struct dirent *entry;
|
||||
char path[PATH_MAX];
|
||||
struct stat st;
|
||||
DIR *dir;
|
||||
|
||||
if ((dir = opendir(dir_path)) == NULL)
|
||||
{
|
||||
// Error opening directory
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while ((entry = readdir(dir)) != NULL)
|
||||
{
|
||||
snprintf(path, PATH_MAX, "%s/%s", dir_path, entry->d_name);
|
||||
|
||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lstat(path, &st) == -1)
|
||||
{
|
||||
// Error getting directory status
|
||||
closedir(dir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (S_ISLNK(st.st_mode))
|
||||
{
|
||||
// Skip symbolic links
|
||||
continue;
|
||||
}
|
||||
|
||||
if (S_ISDIR(st.st_mode))
|
||||
{
|
||||
// If it's a directory, check if it's the one we're looking for
|
||||
if (strcmp(entry->d_name, dirname) == 0)
|
||||
{
|
||||
char *result = strndup(path, PATH_MAX);
|
||||
closedir(dir);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Recursively search within directories
|
||||
char* result = fs_search_directory(path, dirname);
|
||||
if (result != NULL)
|
||||
{
|
||||
closedir(dir);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if defined(__linux__) && defined(STATX_BTIME)
|
||||
|
||||
// Function to return creation time of file
|
||||
double fs_get_creation_time(const char *path)
|
||||
{
|
||||
struct statx stx;
|
||||
int fd = open(path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (statx(fd, "", AT_EMPTY_PATH, STATX_ALL, &stx) != 0)
|
||||
{
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Close the file
|
||||
close(fd);
|
||||
|
||||
return stx.stx_btime.tv_sec + stx.stx_btime.tv_nsec / 1e9;
|
||||
}
|
||||
|
||||
#elif defined(__APPLE__) || defined(__MACH__)
|
||||
|
||||
double fs_get_creation_time(const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat(path, &st) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return st.st_mtimespec.tv_sec + st.st_mtimespec.tv_nsec / 1e9;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
double fs_get_creation_time(const char *path)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat(path, &st) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (double) st.st_ctime;
|
||||
}
|
||||
|
||||
#endif
|
||||
31
src/fs.h
Normal file
31
src/fs.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2024 Martin Lund
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
bool fs_dir_exists(const char *path);
|
||||
bool fs_file_exists(const char *format, ...);
|
||||
char* fs_search_directory(const char *dir_path, const char *dirname);
|
||||
ssize_t fs_read_file_stripped(char *buf, size_t bufsiz, const char *format, ...);
|
||||
double fs_get_creation_time(const char *path);
|
||||
115
src/log.c
115
src/log.c
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
*
|
||||
|
|
@ -19,28 +19,20 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#define __STDC_WANT_LIB_EXT2__ 1 // To access vasprintf
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#define _GNU_SOURCE // To access vasprintf
|
||||
#include <sys/time.h>
|
||||
#include <libgen.h>
|
||||
#include "options.h"
|
||||
#include <errno.h>
|
||||
#include "print.h"
|
||||
#include "error.h"
|
||||
#include "fs.h"
|
||||
|
||||
#define IS_ESC_CSI_INTERMEDIATE_CHAR(c) ((c >= 0x20) && (c <= 0x3F))
|
||||
#define IS_ESC_END_CHAR(c) ((c >= 0x30) && (c <= 0x7E))
|
||||
#define IS_CTRL_CHAR(c) ((c >= 0x00) && (c <= 0x1F))
|
||||
|
||||
static FILE *fp;
|
||||
static bool log_error = false;
|
||||
static FILE *fp = NULL;
|
||||
static char file_buffer[BUFSIZ];
|
||||
static const char *log_filename = NULL;
|
||||
|
||||
static char *date_time(void)
|
||||
{
|
||||
|
|
@ -56,28 +48,68 @@ static char *date_time(void)
|
|||
return date_time_string;
|
||||
}
|
||||
|
||||
void log_open(const char *filename)
|
||||
int log_open(const char *filename)
|
||||
{
|
||||
static char automatic_filename[400];
|
||||
char *automatic_filename;
|
||||
char *dir_plus_automatic_filename;
|
||||
|
||||
if (filename == NULL)
|
||||
{
|
||||
// Generate filename if none provided ("tio_DEVICE_YYYY-MM-DDTHH:MM:SS.log")
|
||||
sprintf(automatic_filename, "tio_%s_%s.log", basename((char *)option.tty_device), date_time());
|
||||
filename = automatic_filename;
|
||||
option.log_filename = automatic_filename;
|
||||
// Generate filename if none provided
|
||||
if (option.auto_connect == AUTO_CONNECT_DIRECT)
|
||||
{
|
||||
// File name format ("tio_TARGET_YYYY-MM-DDTHH:MM:SS.log")
|
||||
asprintf(&automatic_filename, "tio_%s_%s.log", basename((char *)option.target), date_time());
|
||||
}
|
||||
else
|
||||
{
|
||||
// If using 'new' or 'latest' autoconnect strategy we simply use strategy
|
||||
// name to name autogenerated log name as device names may vary
|
||||
asprintf(&automatic_filename, "tio_%s_%s.log",
|
||||
option_auto_connect_state_to_string(option.auto_connect),
|
||||
date_time());
|
||||
}
|
||||
|
||||
// Open log file in append write mode
|
||||
if (option.log_directory != NULL)
|
||||
{
|
||||
if (fs_dir_exists(option.log_directory) == false)
|
||||
{
|
||||
tio_error_printf("Log directory not found");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
asprintf(&dir_plus_automatic_filename, "%s/%s", option.log_directory, automatic_filename);
|
||||
filename = dir_plus_automatic_filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
filename = automatic_filename;
|
||||
}
|
||||
}
|
||||
|
||||
log_filename = filename;
|
||||
|
||||
// Open log file
|
||||
if (option.log_append)
|
||||
{
|
||||
// Append to existing log file
|
||||
fp = fopen(filename, "a+");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Truncate existing log file
|
||||
fp = fopen(filename, "w+");
|
||||
}
|
||||
if (fp == NULL)
|
||||
{
|
||||
log_error = true;
|
||||
exit(EXIT_FAILURE);
|
||||
tio_warning_printf("Could not open log file %s (%s)", filename, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Enable line buffering
|
||||
setvbuf(fp, file_buffer, _IOLBF, BUFSIZ);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool log_strip(char c)
|
||||
|
|
@ -141,6 +173,11 @@ bool log_strip(char c)
|
|||
|
||||
void log_printf(const char *format, ...)
|
||||
{
|
||||
if (fp == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
char *line;
|
||||
|
||||
va_list(args);
|
||||
|
|
@ -155,11 +192,20 @@ void log_printf(const char *format, ...)
|
|||
|
||||
void log_putc(char c)
|
||||
{
|
||||
if (fp != NULL)
|
||||
if (fp == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (option.output_mode == OUTPUT_MODE_HEX)
|
||||
{
|
||||
fprintf(fp, "%02x ", (unsigned char) c);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (option.log_strip)
|
||||
{
|
||||
if (!log_strip(c))
|
||||
if (log_strip(c) == false)
|
||||
{
|
||||
fputc(c, fp);
|
||||
}
|
||||
|
|
@ -176,22 +222,21 @@ void log_close(void)
|
|||
if (fp != NULL)
|
||||
{
|
||||
fclose(fp);
|
||||
tio_printf("Saved log to file %s", log_filename);
|
||||
fp = NULL;
|
||||
log_filename = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void log_exit(void)
|
||||
{
|
||||
if (option.log)
|
||||
if ((option.log) && (log_filename != NULL))
|
||||
{
|
||||
log_close();
|
||||
}
|
||||
|
||||
if (log_error)
|
||||
{
|
||||
tio_error_printf("Could not open log file %s (%s)", option.log_filename, strerror(errno));
|
||||
}
|
||||
else if (option.log)
|
||||
{
|
||||
tio_printf("Saved log to file %s", option.log_filename);
|
||||
}
|
||||
}
|
||||
|
||||
const char *log_get_filename(void)
|
||||
{
|
||||
return log_filename;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
*
|
||||
|
|
@ -21,8 +21,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
void log_open(const char *filename);
|
||||
int log_open(const char *filename);
|
||||
void log_printf(const char *format, ...);
|
||||
void log_putc(char c);
|
||||
void log_close(void);
|
||||
void log_exit(void);
|
||||
const char * log_get_filename(void);
|
||||
|
|
|
|||
37
src/main.c
37
src/main.c
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
*
|
||||
|
|
@ -19,10 +19,11 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "version.h"
|
||||
#include "config.h"
|
||||
#include "options.h"
|
||||
#include "configfile.h"
|
||||
#include "tty.h"
|
||||
|
|
@ -45,6 +46,12 @@ int main(int argc, char *argv[])
|
|||
/* Parse command-line options (1st pass) */
|
||||
options_parse(argc, argv);
|
||||
|
||||
if (option.complete_profiles)
|
||||
{
|
||||
config_file_show_profiles();
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Parse configuration file */
|
||||
config_file_parse();
|
||||
|
||||
|
|
@ -54,6 +61,10 @@ int main(int argc, char *argv[])
|
|||
/* Configure tty device */
|
||||
tty_configure();
|
||||
|
||||
/* Disable line buffering in stdout. This is necessary if we
|
||||
* want things like local echo to work correctly. */
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
|
||||
/* Configure input terminal */
|
||||
if (isatty(fileno(stdin)))
|
||||
{
|
||||
|
|
@ -63,13 +74,10 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
// Enter non interactive mode
|
||||
interactive_mode = false;
|
||||
}
|
||||
|
||||
// Mute tio text in response mode
|
||||
if (option.response_wait)
|
||||
{
|
||||
option.mute = true;
|
||||
}
|
||||
}
|
||||
/* Switch error output format */
|
||||
switch_error_output_mode();
|
||||
|
||||
/* Configure output terminal */
|
||||
if (isatty(fileno(stdout)))
|
||||
|
|
@ -98,7 +106,7 @@ int main(int argc, char *argv[])
|
|||
error_enter_session_mode();
|
||||
|
||||
/* Print launch hints */
|
||||
tio_printf("tio v%s", VERSION);
|
||||
tio_printf("tio %s", VERSION);
|
||||
if (interactive_mode)
|
||||
{
|
||||
tio_printf("Press ctrl-%c q to quit", option.prefix_key);
|
||||
|
|
@ -114,9 +122,16 @@ int main(int argc, char *argv[])
|
|||
socket_configure();
|
||||
}
|
||||
|
||||
/* Spawn input handling into separate thread */
|
||||
tty_input_thread_create();
|
||||
|
||||
/* Wait for input to be ready */
|
||||
tty_input_thread_wait_ready();
|
||||
|
||||
/* Connect to tty device */
|
||||
if (option.no_autoconnect)
|
||||
if (option.no_reconnect)
|
||||
{
|
||||
tty_search();
|
||||
status = tty_connect();
|
||||
}
|
||||
else
|
||||
|
|
@ -125,7 +140,7 @@ int main(int argc, char *argv[])
|
|||
while (true)
|
||||
{
|
||||
tty_wait_for_device();
|
||||
status = tty_connect();
|
||||
tty_connect();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
# Generate version header
|
||||
version_h = vcs_tag(command : ['git', 'describe', '--tags', '--always', '--dirty'],
|
||||
input : 'version.h.in',
|
||||
output :'version.h',
|
||||
replace_string:'@VERSION@')
|
||||
|
||||
config_h = configuration_data()
|
||||
config_h.set_quoted('VERSION', meson.project_version())
|
||||
config_h.set('BAUDRATE_CASES', baudrate_cases)
|
||||
configure_file(output: 'config.h', configuration: config_h)
|
||||
|
||||
|
|
@ -17,14 +22,38 @@ tio_sources = [
|
|||
'setspeed.c',
|
||||
'rs485.c',
|
||||
'timestamp.c',
|
||||
'alert.c'
|
||||
'alert.c',
|
||||
'xymodem.c',
|
||||
'script.c',
|
||||
'fs.c',
|
||||
'readline.c',
|
||||
version_h
|
||||
]
|
||||
|
||||
tio_dep = dependency('inih', required: true,
|
||||
fallback : ['libinih', 'inih_dep'],
|
||||
default_options: ['default_library=static', 'distro_install=false'])
|
||||
|
||||
tio_c_args = ['-Wno-unused-result']
|
||||
foreach name: ['lua-5.4', 'lua-5.3', 'lua-5.2', 'lua-5.1', 'lua']
|
||||
lua_dep = dependency(name, version: '>=5.1', required: false)
|
||||
if lua_dep.found()
|
||||
break
|
||||
endif
|
||||
endforeach
|
||||
if not lua_dep.found()
|
||||
error('Lua could not be found!')
|
||||
endif
|
||||
|
||||
tio_dep = [
|
||||
dependency('threads', required: true),
|
||||
dependency('glib-2.0', required: true),
|
||||
lua_dep
|
||||
]
|
||||
|
||||
if host_machine.system() == 'darwin'
|
||||
iokit_dep = dependency('appleframeworks', modules: ['IOKit'], required: true)
|
||||
corefoundation_dep = dependency('appleframeworks', modules: ['CoreFoundation'], required: true)
|
||||
tio_dep += [iokit_dep, corefoundation_dep]
|
||||
endif
|
||||
|
||||
tio_c_args = ['-Wshadow','-Wno-unused-result']
|
||||
|
||||
if enable_setspeed2
|
||||
tio_c_args += '-DHAVE_TERMIOS2'
|
||||
|
|
|
|||
227
src/misc.c
227
src/misc.c
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
*
|
||||
|
|
@ -19,16 +19,15 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#define _GNU_SOURCE // For FNM_EXTMATCH
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <poll.h>
|
||||
#include <sys/wait.h>
|
||||
#include <fnmatch.h>
|
||||
#include <regex.h>
|
||||
#include <errno.h>
|
||||
#include "error.h"
|
||||
#include "print.h"
|
||||
#include "options.h"
|
||||
|
||||
void delay(long ms)
|
||||
{
|
||||
|
|
@ -45,22 +44,6 @@ void delay(long ms)
|
|||
nanosleep(&ts, NULL);
|
||||
}
|
||||
|
||||
long string_to_long(char *string)
|
||||
{
|
||||
long result;
|
||||
char *end_token;
|
||||
|
||||
errno = 0;
|
||||
result = strtol(string, &end_token, 10);
|
||||
if ((errno != 0) || (*end_token != 0))
|
||||
{
|
||||
printf("Error: Invalid digit\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int ctrl_key_code(unsigned char key)
|
||||
{
|
||||
if ((key >= 'a') && (key <= 'z'))
|
||||
|
|
@ -70,3 +53,201 @@ int ctrl_key_code(unsigned char key)
|
|||
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool regex_match(const char *string, const char *pattern)
|
||||
{
|
||||
regex_t regex;
|
||||
int status;
|
||||
|
||||
if (regcomp(®ex, pattern, REG_EXTENDED | REG_NOSUB) != 0)
|
||||
{
|
||||
// No match
|
||||
return false;
|
||||
}
|
||||
|
||||
status = regexec(®ex, string, (size_t) 0, NULL, 0);
|
||||
regfree(®ex);
|
||||
|
||||
if (status != 0)
|
||||
{
|
||||
// No match
|
||||
return false;
|
||||
}
|
||||
|
||||
// Match
|
||||
return true;
|
||||
}
|
||||
|
||||
int read_poll(int fd, void *data, size_t len, int timeout)
|
||||
{
|
||||
struct pollfd fds;
|
||||
int ret = 0;
|
||||
|
||||
fds.events = POLLIN;
|
||||
fds.fd = fd;
|
||||
|
||||
/* Wait data available */
|
||||
ret = poll(&fds, 1, timeout);
|
||||
if (ret < 0)
|
||||
{
|
||||
tio_error_print("%s", strerror(errno));
|
||||
return ret;
|
||||
}
|
||||
else if (ret > 0)
|
||||
{
|
||||
if (fds.revents & POLLIN)
|
||||
{
|
||||
// Read ready data
|
||||
return read(fd, data, len);
|
||||
}
|
||||
}
|
||||
|
||||
/* Timeout */
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Function to calculate djb2 hash of string
|
||||
unsigned long djb2_hash(const unsigned char *str)
|
||||
{
|
||||
unsigned long hash = 5381;
|
||||
int c;
|
||||
|
||||
while ((c = *str++))
|
||||
{
|
||||
hash = ((hash << 5) + hash) + c; // hash * 33 + c
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
// Function to encode a number to base62
|
||||
void *base62_encode(unsigned long num, char *output)
|
||||
{
|
||||
const char base62_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
if (output == NULL)
|
||||
{
|
||||
tio_error_print("Memory allocation failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
output[i] = base62_chars[num % 62];
|
||||
num /= 62;
|
||||
}
|
||||
output[4] = '\0';
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
// Function to return current time
|
||||
double get_current_time(void)
|
||||
{
|
||||
struct timespec current_time_ts;
|
||||
|
||||
if (clock_gettime(CLOCK_REALTIME, ¤t_time_ts) == -1)
|
||||
{
|
||||
// Error
|
||||
return -1;
|
||||
}
|
||||
|
||||
return current_time_ts.tv_sec + current_time_ts.tv_nsec / 1e9;
|
||||
}
|
||||
|
||||
bool match_patterns(const char *string, const char *patterns)
|
||||
{
|
||||
char *pattern;
|
||||
char *patterns_copy;
|
||||
|
||||
if ((string == NULL) || (patterns == NULL))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
patterns_copy = strdup(patterns);
|
||||
|
||||
// Tokenize the patterns string using strtok
|
||||
pattern = strtok(patterns_copy, ",");
|
||||
while (pattern != NULL)
|
||||
{
|
||||
// Check if the string matches the current pattern
|
||||
#ifdef FNM_EXTMATCH
|
||||
if (fnmatch(pattern, string, FNM_EXTMATCH) == 0)
|
||||
#else
|
||||
if (fnmatch(pattern, string, 0) == 0)
|
||||
#endif
|
||||
{
|
||||
free(patterns_copy);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Move to the next pattern
|
||||
pattern = strtok(NULL, ",");
|
||||
}
|
||||
|
||||
free(patterns_copy);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Function that forks subprocess, redirects its stdin and stdout to the
|
||||
// specified filedescriptor, and runs command.
|
||||
int execute_shell_command(int fd, const char *command)
|
||||
{
|
||||
pid_t pid;
|
||||
int status;
|
||||
|
||||
// Fork a child process
|
||||
pid = fork();
|
||||
if (pid == -1)
|
||||
{
|
||||
// Error occurred
|
||||
tio_error_print("fork() failed (%s)", strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else if (pid == 0)
|
||||
{
|
||||
// Child process
|
||||
|
||||
tio_printf("Executing shell command '%s'", command);
|
||||
|
||||
// Redirect stdout and stderr to the file descriptor
|
||||
if (dup2(fd, STDOUT_FILENO) == -1 || dup2(fd, STDERR_FILENO) == -1)
|
||||
{
|
||||
tio_error_print("dup2() failed (%s)", strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Execute the shell command
|
||||
execl("/bin/sh", "sh", "-c", command, (char *)NULL);
|
||||
|
||||
// If execlp() returns, it means an error occurred
|
||||
perror("execlp");
|
||||
tio_error_print("execlp() failed (%s)", strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Parent process
|
||||
|
||||
// Wait for the child process to finish
|
||||
waitpid(pid, &status, 0);
|
||||
|
||||
if (WIFEXITED(status))
|
||||
{
|
||||
tio_printf("Command exited with status %d", WEXITSTATUS(status));
|
||||
return WEXITSTATUS(status);
|
||||
}
|
||||
else
|
||||
{
|
||||
tio_error_printf("Child process exited abnormally\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void clear_line()
|
||||
{
|
||||
print("\r\033[K");
|
||||
}
|
||||
|
|
|
|||
17
src/misc.h
17
src/misc.h
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
*
|
||||
|
|
@ -21,11 +21,18 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define UNUSED(expr) do { (void)(expr); } while (0)
|
||||
|
||||
char * current_time(void);
|
||||
void delay(long ms);
|
||||
long string_to_long(char *string);
|
||||
int ctrl_key_code(unsigned char key);
|
||||
void alert_connect(void);
|
||||
void alert_disconnect(void);
|
||||
bool regex_match(const char *string, const char *pattern);
|
||||
unsigned long djb2_hash(const unsigned char *str);
|
||||
void *base62_encode(unsigned long num, char *output);
|
||||
int read_poll(int fd, void *data, size_t len, int timeout);
|
||||
double get_current_time(void);
|
||||
bool match_patterns(const char *string, const char *patterns);
|
||||
int execute_shell_command(int fd, const char *command);
|
||||
void clear_line();
|
||||
|
|
|
|||
969
src/options.c
969
src/options.c
File diff suppressed because it is too large
Load diff
110
src/options.h
110
src/options.h
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
*
|
||||
|
|
@ -23,49 +23,89 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <limits.h>
|
||||
#include <termios.h>
|
||||
#include <sys/param.h>
|
||||
#include "script.h"
|
||||
#include "timestamp.h"
|
||||
#include "alert.h"
|
||||
#include "tty.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
INPUT_MODE_NORMAL,
|
||||
INPUT_MODE_HEX,
|
||||
INPUT_MODE_LINE,
|
||||
INPUT_MODE_END,
|
||||
} input_mode_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
OUTPUT_MODE_NORMAL,
|
||||
OUTPUT_MODE_HEX,
|
||||
OUTPUT_MODE_END,
|
||||
} output_mode_t;
|
||||
|
||||
/* Options */
|
||||
struct option_t
|
||||
{
|
||||
const char *tty_device;
|
||||
unsigned int baudrate;
|
||||
char *target;
|
||||
int baudrate;
|
||||
int databits;
|
||||
char *flow;
|
||||
flow_t flow;
|
||||
int stopbits;
|
||||
char *parity;
|
||||
parity_t parity;
|
||||
int output_delay;
|
||||
int output_line_delay;
|
||||
unsigned int dtr_pulse_duration;
|
||||
unsigned int rts_pulse_duration;
|
||||
unsigned int cts_pulse_duration;
|
||||
unsigned int dsr_pulse_duration;
|
||||
unsigned int dcd_pulse_duration;
|
||||
unsigned int ri_pulse_duration;
|
||||
bool no_autoconnect;
|
||||
int dtr_pulse_duration;
|
||||
int rts_pulse_duration;
|
||||
int cts_pulse_duration;
|
||||
int dsr_pulse_duration;
|
||||
int dcd_pulse_duration;
|
||||
int ri_pulse_duration;
|
||||
bool no_reconnect;
|
||||
auto_connect_t auto_connect;
|
||||
bool log;
|
||||
bool log_append;
|
||||
bool log_strip;
|
||||
bool local_echo;
|
||||
enum timestamp_t timestamp;
|
||||
const char *log_filename;
|
||||
const char *map;
|
||||
const char *socket;
|
||||
timestamp_t timestamp;
|
||||
char *log_filename;
|
||||
char *log_directory;
|
||||
char *socket;
|
||||
int color;
|
||||
bool hex_mode;
|
||||
unsigned char prefix_code;
|
||||
unsigned char prefix_key;
|
||||
bool response_wait;
|
||||
int response_timeout;
|
||||
input_mode_t input_mode;
|
||||
output_mode_t output_mode;
|
||||
char prefix_code;
|
||||
char prefix_key;
|
||||
bool prefix_enabled;
|
||||
bool mute;
|
||||
bool rs485;
|
||||
uint32_t rs485_config_flags;
|
||||
int32_t rs485_delay_rts_before_send;
|
||||
int32_t rs485_delay_rts_after_send;
|
||||
enum alert_t alert;
|
||||
alert_t alert;
|
||||
bool complete_profiles;
|
||||
char *script;
|
||||
char *script_filename;
|
||||
script_run_t script_run;
|
||||
int timestamp_timeout;
|
||||
char *exclude_devices;
|
||||
char *exclude_drivers;
|
||||
char *exclude_tids;
|
||||
int hex_n_value;
|
||||
bool vt100;
|
||||
char *exec;
|
||||
bool map_i_nl_cr;
|
||||
bool map_i_cr_nl;
|
||||
bool map_ign_cr;
|
||||
bool map_i_ff_escc;
|
||||
bool map_i_nl_crnl;
|
||||
bool map_i_cr_crnl;
|
||||
bool map_o_cr_nl;
|
||||
bool map_o_nl_crnl;
|
||||
bool map_o_del_bs;
|
||||
bool map_o_ltu;
|
||||
bool map_o_nulbrk;
|
||||
bool map_i_msb2lsb;
|
||||
bool map_o_ign_cr;
|
||||
};
|
||||
|
||||
extern struct option_t option;
|
||||
|
|
@ -74,4 +114,22 @@ void options_print();
|
|||
void options_parse(int argc, char *argv[]);
|
||||
void options_parse_final(int argc, char *argv[]);
|
||||
|
||||
void line_pulse_duration_option_parse(const char *arg);
|
||||
int option_string_to_integer(const char *string, int *value, const char *desc, int min, int max);
|
||||
|
||||
void option_parse_flow(const char *arg, flow_t *flow);
|
||||
void option_parse_parity(const char *arg, parity_t *parity);
|
||||
|
||||
void option_parse_output_mode(const char *arg, output_mode_t *mode);
|
||||
void option_parse_input_mode(const char *arg, input_mode_t *mode);
|
||||
|
||||
void option_parse_line_pulse_duration(const char *arg);
|
||||
void option_parse_script_run(const char *arg, script_run_t *script_run);
|
||||
void option_parse_alert(const char *arg, alert_t *alert);
|
||||
|
||||
void option_parse_auto_connect(const char *arg, auto_connect_t *auto_connect);
|
||||
const char *option_auto_connect_state_to_string(auto_connect_t strategy);
|
||||
|
||||
void option_parse_timestamp(const char *arg, timestamp_t *timestamp);
|
||||
const char* option_timestamp_format_to_string(timestamp_t timestamp);
|
||||
|
||||
void option_parse_mappings(const char *map);
|
||||
|
|
|
|||
49
src/print.c
49
src/print.c
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
*
|
||||
|
|
@ -19,11 +19,6 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include "options.h"
|
||||
#include "print.h"
|
||||
|
||||
bool print_tainted = false;
|
||||
|
|
@ -31,11 +26,13 @@ char ansi_format[30];
|
|||
|
||||
void print_hex(char c)
|
||||
{
|
||||
print_tainted = true;
|
||||
printf("%02x ", (unsigned char) c);
|
||||
}
|
||||
|
||||
void print_normal(char c)
|
||||
{
|
||||
print_tainted = true;
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
|
|
@ -73,3 +70,43 @@ void tio_printf_array(const char *array)
|
|||
}
|
||||
tio_printf("");
|
||||
}
|
||||
|
||||
void print_tainted_set()
|
||||
{
|
||||
print_tainted = true;
|
||||
}
|
||||
|
||||
void print(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
vprintf(format, args);
|
||||
fflush(stdout);
|
||||
va_end(args);
|
||||
|
||||
print_tainted = true;
|
||||
}
|
||||
|
||||
void print_padded(char *string, size_t length, char pad_char)
|
||||
{
|
||||
size_t padding = 0;
|
||||
size_t string_length = 0;
|
||||
size_t i;
|
||||
|
||||
string_length = strlen(string);
|
||||
|
||||
if (string_length < length)
|
||||
{
|
||||
padding += length - string_length;
|
||||
printf("%s", string);
|
||||
for (i=0; i<padding; i++)
|
||||
{
|
||||
putchar(pad_char);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%s", string);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
29
src/print.h
29
src/print.h
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
*
|
||||
|
|
@ -23,7 +23,6 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "misc.h"
|
||||
#include "error.h"
|
||||
#include "options.h"
|
||||
#include "timestamp.h"
|
||||
|
|
@ -77,6 +76,29 @@ extern char ansi_format[];
|
|||
fprintf (stdout, "\r[%s] Warning: " format "\r\n", timestamp_current_time(), ## args); \
|
||||
else \
|
||||
ansi_printf("[%s] Warning: " format, timestamp_current_time(), ## args); \
|
||||
print_tainted = false; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define tio_error_print(format, args...) \
|
||||
{ \
|
||||
if (!option.mute) \
|
||||
{ \
|
||||
if (print_tainted) \
|
||||
putchar('\n'); \
|
||||
if (option.color < 0) { \
|
||||
if (error_normal) \
|
||||
fprintf (stderr, "Error: " format "\n", ## args); \
|
||||
else \
|
||||
fprintf (stderr, "\r[%s] Error: " format "\r\n", timestamp_current_time(), ## args); \
|
||||
} \
|
||||
else { \
|
||||
if (error_normal) \
|
||||
{ ansi_error_printf("Error: " format, ## args); }\
|
||||
else \
|
||||
{ ansi_error_printf("[%s] Error: " format, timestamp_current_time(), ## args); }\
|
||||
} \
|
||||
print_tainted = false; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +134,10 @@ extern char ansi_format[];
|
|||
#define tio_debug_printf_raw(format, args...)
|
||||
#endif
|
||||
|
||||
void print(const char *format, ...);
|
||||
void print_hex(char c);
|
||||
void print_normal(char c);
|
||||
void print_init_ansi_formatting(void);
|
||||
void tio_printf_array(const char *array);
|
||||
void print_tainted_set(void);
|
||||
void print_padded(char *string, size_t length, char pad_char);
|
||||
|
|
|
|||
276
src/readline.c
Normal file
276
src/readline.c
Normal file
|
|
@ -0,0 +1,276 @@
|
|||
/*
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2024 Martin Lund
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "print.h"
|
||||
#include "misc.h"
|
||||
|
||||
#define RL_LINE_LENGTH_MAX PATH_MAX
|
||||
#define RL_HISTORY_MAX 1000
|
||||
|
||||
static char rl_line[RL_LINE_LENGTH_MAX] = {};
|
||||
static char *rl_history[RL_HISTORY_MAX];
|
||||
static int rl_history_count = 0;
|
||||
static int rl_history_index = 0;
|
||||
static int rl_line_length = 0;
|
||||
static int rl_cursor_pos = 0;
|
||||
static int rl_escape = 0;
|
||||
|
||||
static void print_line(const char *string, int cursor_pos)
|
||||
{
|
||||
clear_line();
|
||||
print("%s", string);
|
||||
print("\r"); // Move the cursor back to the beginning
|
||||
for (int i = 0; i < cursor_pos; ++i)
|
||||
{
|
||||
print("\x1b[C"); // Move the cursor right
|
||||
}
|
||||
}
|
||||
|
||||
void readline_init(void)
|
||||
{
|
||||
rl_history_count = 0;
|
||||
rl_history_index = 0;
|
||||
|
||||
for (int i = 0; i < RL_HISTORY_MAX; ++i)
|
||||
{
|
||||
rl_history[i] = NULL;
|
||||
}
|
||||
|
||||
rl_line[0] = 0;
|
||||
rl_line_length = 0;
|
||||
rl_cursor_pos = 0;
|
||||
rl_escape = 0;
|
||||
}
|
||||
|
||||
char * readline_get(void)
|
||||
{
|
||||
return rl_line;
|
||||
}
|
||||
|
||||
static void readline_input_char(char input_char)
|
||||
{
|
||||
if (rl_line_length < RL_LINE_LENGTH_MAX - 1)
|
||||
{
|
||||
memmove(&rl_line[rl_cursor_pos + 1], &rl_line[rl_cursor_pos], rl_line_length - rl_cursor_pos);
|
||||
rl_line[rl_cursor_pos] = input_char;
|
||||
rl_line_length++;
|
||||
rl_cursor_pos++;
|
||||
rl_line[rl_line_length] = '\0';
|
||||
print_line(rl_line, rl_cursor_pos);
|
||||
}
|
||||
rl_escape = 0;
|
||||
}
|
||||
|
||||
static void readline_input_cr(void)
|
||||
{
|
||||
if (rl_line_length > 0)
|
||||
{
|
||||
// Save to history
|
||||
if (rl_history_count < RL_HISTORY_MAX)
|
||||
{
|
||||
rl_history[rl_history_count] = strndup(rl_line, rl_line_length);
|
||||
rl_history_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
free(rl_history[0]);
|
||||
memmove(&rl_history[0], &rl_history[1], (RL_HISTORY_MAX - 1) * sizeof(char*));
|
||||
rl_history[RL_HISTORY_MAX - 1] = strndup(rl_line, rl_line_length);
|
||||
}
|
||||
}
|
||||
|
||||
rl_line[rl_line_length] = '\0';
|
||||
if (option.local_echo == false)
|
||||
{
|
||||
clear_line();
|
||||
}
|
||||
else
|
||||
{
|
||||
print("\r\n");
|
||||
}
|
||||
|
||||
rl_line_length = 0;
|
||||
rl_cursor_pos = 0;
|
||||
rl_history_index = rl_history_count;
|
||||
rl_escape = 0;
|
||||
}
|
||||
|
||||
static void readline_input_bs(void)
|
||||
{
|
||||
if (rl_cursor_pos > 0)
|
||||
{
|
||||
memmove(&rl_line[rl_cursor_pos - 1], &rl_line[rl_cursor_pos], rl_line_length - rl_cursor_pos);
|
||||
rl_line_length--;
|
||||
rl_cursor_pos--;
|
||||
rl_line[rl_line_length] = '\0';
|
||||
print_line(rl_line, rl_cursor_pos);
|
||||
}
|
||||
rl_escape = 0;
|
||||
}
|
||||
|
||||
static void readline_input_escape(void)
|
||||
{
|
||||
rl_escape = 1;
|
||||
}
|
||||
|
||||
static void readline_input_left_bracket(void)
|
||||
{
|
||||
if (rl_escape == 1)
|
||||
{
|
||||
rl_escape = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
rl_escape = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void readline_input_A(void)
|
||||
{
|
||||
if (rl_escape == 2)
|
||||
{
|
||||
// Up arrow
|
||||
if (rl_history_index > 0)
|
||||
{
|
||||
rl_history_index--;
|
||||
strncpy(rl_line, rl_history[rl_history_index], RL_LINE_LENGTH_MAX-1);
|
||||
rl_line_length = strlen(rl_line);
|
||||
rl_cursor_pos = rl_line_length;
|
||||
print_line(rl_line, rl_cursor_pos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
readline_input_char('A');
|
||||
}
|
||||
|
||||
rl_escape = 0;
|
||||
}
|
||||
|
||||
static void readline_input_B(void)
|
||||
{
|
||||
if (rl_escape == 2)
|
||||
{
|
||||
// Down arrow
|
||||
if (rl_history_index < rl_history_count - 1)
|
||||
{
|
||||
rl_history_index++;
|
||||
strncpy(rl_line, rl_history[rl_history_index], RL_LINE_LENGTH_MAX-1);
|
||||
rl_line_length = strlen(rl_line);
|
||||
rl_cursor_pos = rl_line_length;
|
||||
print_line(rl_line, rl_cursor_pos);
|
||||
}
|
||||
else if (rl_history_index == rl_history_count - 1)
|
||||
{
|
||||
rl_history_index++;
|
||||
rl_line_length = 0;
|
||||
rl_cursor_pos = 0;
|
||||
rl_line[rl_line_length] = '\0';
|
||||
print_line(rl_line, rl_cursor_pos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
readline_input_char('B');
|
||||
}
|
||||
|
||||
rl_escape = 0;
|
||||
}
|
||||
|
||||
static void readline_input_C(void)
|
||||
{
|
||||
if (rl_escape == 2)
|
||||
{
|
||||
// Right arrow
|
||||
if (rl_cursor_pos < rl_line_length)
|
||||
{
|
||||
rl_cursor_pos++;
|
||||
print("\x1b[C");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
readline_input_char('C');
|
||||
}
|
||||
|
||||
rl_escape = 0;
|
||||
}
|
||||
|
||||
static void readline_input_D(void)
|
||||
{
|
||||
if (rl_escape == 2)
|
||||
{
|
||||
// Left arrow
|
||||
if (rl_cursor_pos > 0)
|
||||
{
|
||||
rl_cursor_pos--;
|
||||
print("\b");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
readline_input_char('D');
|
||||
}
|
||||
|
||||
rl_escape = 0;
|
||||
}
|
||||
|
||||
void readline_input(char input_char)
|
||||
{
|
||||
switch (input_char)
|
||||
{
|
||||
case '\r': // Carriage return
|
||||
readline_input_cr();
|
||||
break;
|
||||
|
||||
case 127: // Backspace
|
||||
readline_input_bs();
|
||||
break;
|
||||
|
||||
case 27: // Escape
|
||||
readline_input_escape();
|
||||
break;
|
||||
|
||||
case '[':
|
||||
readline_input_left_bracket();
|
||||
break;
|
||||
|
||||
case 'A':
|
||||
readline_input_A();
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
readline_input_B();
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
readline_input_C();
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
readline_input_D();
|
||||
break;
|
||||
|
||||
default:
|
||||
readline_input_char(input_char);
|
||||
break;
|
||||
}
|
||||
}
|
||||
26
src/readline.h
Normal file
26
src/readline.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2024 Martin Lund
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
void readline_init(void);
|
||||
void readline_input(char input_char);
|
||||
char * readline_get(void);
|
||||
28
src/rs485.c
28
src/rs485.c
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial device I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2022 Martin Lund
|
||||
*
|
||||
|
|
@ -19,14 +19,13 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdbool.h>
|
||||
#include "options.h"
|
||||
#include "print.h"
|
||||
#include "error.h"
|
||||
#include "misc.h"
|
||||
|
||||
#ifdef HAVE_RS485
|
||||
|
||||
|
|
@ -57,13 +56,16 @@ void rs485_parse_config(const char *arg)
|
|||
{
|
||||
char keyname[31];
|
||||
unsigned int value;
|
||||
sscanf(token, "%30[^=]=%d", keyname, &value);
|
||||
int match_count;
|
||||
|
||||
match_count = sscanf(token, "%30[^=]=%d", keyname, &value);
|
||||
|
||||
if (match_count == 2)
|
||||
{
|
||||
if (!strcmp(keyname, "RTS_ON_SEND"))
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
|
||||
/* Set logical level for RTS pin equal to 1 when sending */
|
||||
option.rs485_config_flags |= SER_RS485_RTS_ON_SEND;
|
||||
}
|
||||
|
|
@ -96,7 +98,10 @@ void rs485_parse_config(const char *arg)
|
|||
/* Set RTS delay after send */
|
||||
option.rs485_delay_rts_after_send = value;
|
||||
}
|
||||
else if (!strcmp(keyname, "RX_DURING_TX"))
|
||||
}
|
||||
else if (match_count == 1)
|
||||
{
|
||||
if (!strcmp(keyname, "RX_DURING_TX"))
|
||||
{
|
||||
/* Receive data even while sending data */
|
||||
option.rs485_config_flags |= SER_RS485_RX_DURING_TX;
|
||||
|
|
@ -107,6 +112,11 @@ void rs485_parse_config(const char *arg)
|
|||
token_found = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
token_found = false;
|
||||
}
|
||||
}
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
|
|
@ -117,7 +127,7 @@ void rs485_print_config(void)
|
|||
tio_printf(" RTS_AFTER_SEND: %s", (rs485_config.flags & SER_RS485_RTS_AFTER_SEND) ? "high" : "low");
|
||||
tio_printf(" RTS_DELAY_BEFORE_SEND = %d", rs485_config.delay_rts_before_send);
|
||||
tio_printf(" RTS_DELAY_AFTER_SEND = %d", rs485_config.delay_rts_after_send);
|
||||
tio_printf(" RX_DURING_TX: %s", (rs485_config.flags & SER_RS485_RX_DURING_TX) ? "enabled" : "disabled");
|
||||
tio_printf(" RX_DURING_TX: %s", (rs485_config.flags & SER_RS485_RX_DURING_TX) ? "true" : "false");
|
||||
}
|
||||
|
||||
int rs485_mode_enable(int fd)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial device I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2022 Martin Lund
|
||||
*
|
||||
|
|
|
|||
547
src/script.c
Normal file
547
src/script.c
Normal file
|
|
@ -0,0 +1,547 @@
|
|||
/*
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2024 Martin Lund
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <lauxlib.h>
|
||||
#include <lualib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <ctype.h>
|
||||
#include "misc.h"
|
||||
#include "print.h"
|
||||
#include "options.h"
|
||||
#include "tty.h"
|
||||
#include "xymodem.h"
|
||||
#include "log.h"
|
||||
#include "script.h"
|
||||
#include "fs.h"
|
||||
#include "timestamp.h"
|
||||
#include "termios.h"
|
||||
|
||||
#define MAX_BUFFER_SIZE 2000 // Maximum size of circular buffer
|
||||
#define READ_LINE_SIZE 4096 // read_line buffer length
|
||||
|
||||
static int device_fd;
|
||||
|
||||
static char script_init[] =
|
||||
"tio.set = function(arg)\n"
|
||||
" local dtr = arg.DTR or -1\n"
|
||||
" local rts = arg.RTS or -1\n"
|
||||
" local cts = arg.CTS or -1\n"
|
||||
" local dsr = arg.DSR or -1\n"
|
||||
" local cd = arg.CD or -1\n"
|
||||
" local ri = arg.RI or -1\n"
|
||||
" tio.line_set(dtr, rts, cts, dsr, cd, ri)\n"
|
||||
"end\n"
|
||||
"tio.expect = function(pattern, timeout)\n"
|
||||
" local str = ''\n"
|
||||
" while true do\n"
|
||||
" local c = tio.read(1, timeout)\n"
|
||||
" if c then\n"
|
||||
" str = str .. c\n"
|
||||
" if string.match(str, pattern) then\n"
|
||||
" return string.match(str, pattern)\n"
|
||||
" end\n"
|
||||
" else\n"
|
||||
" return nil, str\n"
|
||||
" end\n"
|
||||
" end\n"
|
||||
"end\n"
|
||||
"tio.alwaysecho = true\n"
|
||||
"setmetatable(tio, tio)\n";
|
||||
|
||||
static bool alwaysecho(lua_State *L)
|
||||
{
|
||||
bool b;
|
||||
|
||||
lua_getglobal(L, "tio");
|
||||
lua_getfield(L, -1, "alwaysecho");
|
||||
b = lua_toboolean(L, -1);
|
||||
lua_pop(L, 2);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
static int api_echo(lua_State *L)
|
||||
{
|
||||
size_t len = 0;
|
||||
const char *str = luaL_checklstring(L, 1, &len);
|
||||
|
||||
if (option.timestamp)
|
||||
{
|
||||
char *pTimeStampNow = timestamp_current_time();
|
||||
if (pTimeStampNow)
|
||||
{
|
||||
tio_printf("%s", str);
|
||||
if (option.log)
|
||||
{
|
||||
log_printf("\n[%s] %s", pTimeStampNow, str);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (size_t i=0; i<len; i++)
|
||||
{
|
||||
putchar(str[i]);
|
||||
|
||||
if (option.log)
|
||||
log_putc(str[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void maybe_echo(lua_State *L)
|
||||
{
|
||||
if (alwaysecho(L))
|
||||
{
|
||||
lua_pushcfunction(L, api_echo);
|
||||
lua_pushvalue(L, -2);
|
||||
lua_call(L, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// lua: tio.sleep(seconds)
|
||||
static int api_sleep(lua_State *L)
|
||||
{
|
||||
long seconds = lua_tointeger(L, 1);
|
||||
|
||||
if (seconds < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
tio_printf("Sleeping %ld seconds", seconds);
|
||||
|
||||
sleep(seconds);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// lua: tio.msleep(miliseconds)
|
||||
static int api_msleep(lua_State *L)
|
||||
{
|
||||
long mseconds = lua_tointeger(L, 1);
|
||||
long useconds = mseconds * 1000;
|
||||
|
||||
if (useconds < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
tio_printf("Sleeping %ld ms", mseconds);
|
||||
usleep(useconds);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// lua: tio.line_set(dtr,rts,cts,dsr,cd,ri)
|
||||
static int line_set(lua_State *L)
|
||||
{
|
||||
tty_line_config_t line_config[6] = { };
|
||||
|
||||
int dtr = lua_tointeger(L, 1);
|
||||
int rts = lua_tointeger(L, 2);
|
||||
int cts = lua_tointeger(L, 3);
|
||||
int dsr = lua_tointeger(L, 4);
|
||||
int cd = lua_tointeger(L, 5);
|
||||
int ri = lua_tointeger(L, 6);
|
||||
|
||||
if (dtr != -1)
|
||||
{
|
||||
line_config[0].mask = TIOCM_DTR;
|
||||
line_config[0].value = dtr;
|
||||
line_config[0].reserved = true;
|
||||
}
|
||||
if (rts != -1)
|
||||
{
|
||||
line_config[1].mask = TIOCM_RTS;
|
||||
line_config[1].value = rts;
|
||||
line_config[1].reserved = true;
|
||||
}
|
||||
if (cts != -1)
|
||||
{
|
||||
line_config[2].mask = TIOCM_CTS;
|
||||
line_config[2].value = cts;
|
||||
line_config[2].reserved = true;
|
||||
}
|
||||
if (dsr != -1)
|
||||
{
|
||||
line_config[3].mask = TIOCM_DSR;
|
||||
line_config[3].value = dsr;
|
||||
line_config[3].reserved = true;
|
||||
}
|
||||
if (cd != -1)
|
||||
{
|
||||
line_config[4].mask = TIOCM_CD;
|
||||
line_config[4].value = cd;
|
||||
line_config[4].reserved = true;
|
||||
}
|
||||
if (ri != -1)
|
||||
{
|
||||
line_config[5].mask = TIOCM_RI;
|
||||
line_config[5].value = ri;
|
||||
line_config[5].reserved = true;
|
||||
}
|
||||
|
||||
tty_line_set(device_fd, line_config);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// lua: tio.send(file, protocol)
|
||||
static int api_send(lua_State *L)
|
||||
{
|
||||
const char *file = luaL_checkstring(L, 1);
|
||||
int protocol = luaL_checkinteger(L, 2);
|
||||
int ret;
|
||||
|
||||
if (file == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (protocol)
|
||||
{
|
||||
case XMODEM_1K:
|
||||
tio_printf("Sending file '%s' using XMODEM-1K", file);
|
||||
ret = xymodem_send(device_fd, file, XMODEM_1K);
|
||||
tio_printf("%s", ret < 0 ? "Aborted" : "Done");
|
||||
break;
|
||||
|
||||
case XMODEM_CRC:
|
||||
tio_printf("Sending file '%s' using XMODEM-CRC", file);
|
||||
ret = xymodem_send(device_fd, file, XMODEM_CRC);
|
||||
tio_printf("%s", ret < 0 ? "Aborted" : "Done");
|
||||
break;
|
||||
|
||||
case YMODEM:
|
||||
tio_printf("Sending file '%s' using YMODEM", file);
|
||||
ret = xymodem_send(device_fd, file, YMODEM);
|
||||
tio_printf("%s", ret < 0 ? "Aborted" : "Done");
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// lua: tio.write(string)
|
||||
static int api_write(lua_State *L)
|
||||
{
|
||||
size_t len = 0;
|
||||
const char *string = luaL_checklstring(L, 1, &len);
|
||||
ssize_t ret;
|
||||
int attempts = 100;
|
||||
|
||||
do {
|
||||
ret = write(device_fd, string, len);
|
||||
if (ret < 0)
|
||||
return luaL_error(L, "%s", strerror(errno));
|
||||
|
||||
len -= ret;
|
||||
string += ret;
|
||||
} while (len > 0 && --attempts);
|
||||
|
||||
if (len > 0)
|
||||
return luaL_error(L, "partial write");
|
||||
|
||||
fsync(device_fd); // flush these characters now
|
||||
tcdrain(device_fd); //ensure we flushed characters to our device
|
||||
|
||||
lua_getglobal(L, "tio");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// lua: tio.read(size, timeout)
|
||||
static int api_read(lua_State *L)
|
||||
{
|
||||
int size = luaL_checkinteger(L, 1);
|
||||
int timeout = lua_tointeger(L, 2);
|
||||
|
||||
if (timeout == 0)
|
||||
{
|
||||
timeout = -1; // Wait forever
|
||||
}
|
||||
|
||||
luaL_Buffer buffer;
|
||||
luaL_buffinit(L, &buffer);
|
||||
|
||||
#if LUA_VERSION_NUM >= 502
|
||||
char *p = luaL_prepbuffsize(&buffer, size);
|
||||
#else
|
||||
if (size > LUAL_BUFFERSIZE)
|
||||
return luaL_error(L, "buffer overflow, max size is: %d", LUAL_BUFFERSIZE);
|
||||
char *p = luaL_prepbuffer(&buffer);
|
||||
#endif
|
||||
|
||||
ssize_t ret = read_poll(device_fd, p, size, timeout);
|
||||
if (ret < 0)
|
||||
return luaL_error(L, "%s", strerror(errno));
|
||||
|
||||
luaL_addsize(&buffer, ret);
|
||||
luaL_pushresult(&buffer);
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
// On timeout return nil instead of an empty string
|
||||
lua_pop(L, 1);
|
||||
lua_pushnil(L);
|
||||
}
|
||||
else
|
||||
{
|
||||
maybe_echo(L);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// lua: string = tio.readline(timeout)
|
||||
static int api_readline(lua_State *L) {
|
||||
int timeout = lua_tointeger(L, 1); //ms
|
||||
luaL_Buffer b;
|
||||
char ch;
|
||||
|
||||
if (timeout == 0)
|
||||
{
|
||||
timeout = -1; // Wait forever
|
||||
}
|
||||
|
||||
luaL_buffinit(L, &b);
|
||||
luaL_prepbuffer(&b);
|
||||
while (true) {
|
||||
int ret = read_poll(device_fd, &ch, 1, timeout);
|
||||
|
||||
if (ret < 0)
|
||||
return luaL_error(L, "%s", strerror(errno));
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
luaL_pushresult(&b);
|
||||
maybe_echo(L);
|
||||
lua_pushnil(L);
|
||||
lua_insert(L, -2);
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (ch == '\n')
|
||||
{
|
||||
luaL_pushresult(&b);
|
||||
maybe_echo(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
luaL_addchar(&b, ch);
|
||||
}
|
||||
}
|
||||
|
||||
// lua: table = tio.ttysearch()
|
||||
static int api_ttysearch(lua_State *L)
|
||||
{
|
||||
UNUSED(L);
|
||||
GList *iter;
|
||||
int i = 1;
|
||||
|
||||
GList *device_list = tty_search_for_serial_devices();
|
||||
|
||||
if (device_list == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Create a new table
|
||||
lua_newtable(L);
|
||||
|
||||
// Iterate through found devices
|
||||
for (iter = device_list; iter != NULL; iter = g_list_next(iter))
|
||||
{
|
||||
device_t *device = (device_t *) iter->data;
|
||||
|
||||
// Create a new sub-table for each serial device
|
||||
lua_newtable(L);
|
||||
|
||||
// Add elements to the table
|
||||
lua_pushstring(L, "path");
|
||||
lua_pushstring(L, device->path);
|
||||
lua_settable(L, -3);
|
||||
|
||||
lua_pushstring(L, "tid");
|
||||
lua_pushstring(L, device->tid);
|
||||
lua_settable(L, -3);
|
||||
|
||||
lua_pushstring(L, "uptime");
|
||||
lua_pushnumber(L, device->uptime);
|
||||
lua_settable(L, -3);
|
||||
|
||||
lua_pushstring(L, "driver");
|
||||
lua_pushstring(L, device->driver);
|
||||
lua_settable(L, -3);
|
||||
|
||||
lua_pushstring(L, "description");
|
||||
lua_pushstring(L, device->description);
|
||||
lua_settable(L, -3);
|
||||
|
||||
// Set the sub-table as a row in the main table
|
||||
lua_rawseti(L, -2, i++);
|
||||
}
|
||||
|
||||
// Return table
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void script_buffer_run(lua_State *L, const char *script_buffer)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = luaL_loadbuffer(L, script_buffer, strlen(script_buffer), "tio") ||
|
||||
lua_pcall(L, 0, 0, 0);
|
||||
if (error)
|
||||
{
|
||||
tio_warning_printf("lua: %s\n", lua_tostring(L, -1));
|
||||
lua_pop(L, 1); /* Pop error message from the stack */
|
||||
}
|
||||
}
|
||||
|
||||
static void script_file_run(lua_State *L, const char *filename)
|
||||
{
|
||||
if (strlen(filename) == 0)
|
||||
{
|
||||
tio_warning_printf("Missing script filename\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (luaL_dofile(L, filename))
|
||||
{
|
||||
tio_warning_printf("lua: %s", lua_tostring(L, -1));
|
||||
lua_pop(L, 1); /* pop error message from the stack */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static const struct luaL_Reg tio_lib[] =
|
||||
{
|
||||
{ "echo", api_echo},
|
||||
{ "sleep", api_sleep},
|
||||
{ "msleep", api_msleep},
|
||||
{ "line_set", line_set},
|
||||
{ "send", api_send},
|
||||
{ "write", api_write},
|
||||
{ "read", api_read},
|
||||
{ "readline", api_readline},
|
||||
{ "ttysearch", api_ttysearch},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static void script_load(lua_State *L)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = luaL_loadbuffer(L, script_init, strlen(script_init), "tio") || lua_pcall(L, 0, 0, 0);
|
||||
if (error)
|
||||
{
|
||||
tio_error_print("%s\n", lua_tostring(L, -1));
|
||||
lua_pop(L, 1); // Pop error message from the stack
|
||||
}
|
||||
}
|
||||
|
||||
static void script_set_global(lua_State *L, const char *name, long value)
|
||||
{
|
||||
lua_pushnumber(L, value);
|
||||
lua_setglobal(L, name);
|
||||
}
|
||||
|
||||
static void script_set_globals(lua_State *L)
|
||||
{
|
||||
script_set_global(L, "toggle", 2);
|
||||
script_set_global(L, "high", 1);
|
||||
script_set_global(L, "low", 0);
|
||||
script_set_global(L, "XMODEM_CRC", XMODEM_CRC);
|
||||
script_set_global(L, "XMODEM_1K", XMODEM_1K);
|
||||
script_set_global(L, "YMODEM", YMODEM);
|
||||
}
|
||||
|
||||
#if LUA_VERSION_NUM >= 502
|
||||
static int luaopen_tio(lua_State *L)
|
||||
{
|
||||
luaL_newlib(L, tio_lib);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
void script_run(int fd, const char *script_filename)
|
||||
{
|
||||
lua_State *L;
|
||||
|
||||
device_fd = fd;
|
||||
|
||||
L = luaL_newstate();
|
||||
luaL_openlibs(L);
|
||||
|
||||
#if LUA_VERSION_NUM >= 502
|
||||
luaL_requiref(L, "tio", luaopen_tio, 1);
|
||||
#else
|
||||
luaL_register(L, "tio", tio_lib);
|
||||
#endif
|
||||
lua_pop(L, 1);
|
||||
|
||||
// Load lua init script
|
||||
script_load(L);
|
||||
|
||||
// Initialize globals
|
||||
script_set_globals(L);
|
||||
|
||||
if (script_filename != NULL)
|
||||
{
|
||||
tio_printf("Running script %s", script_filename);
|
||||
script_file_run(L, script_filename);
|
||||
}
|
||||
else if (option.script_filename != NULL)
|
||||
{
|
||||
tio_printf("Running script %s", option.script_filename);
|
||||
script_file_run(L, option.script_filename);
|
||||
}
|
||||
else if (option.script != NULL)
|
||||
{
|
||||
tio_printf("Running script");
|
||||
script_buffer_run(L, option.script);
|
||||
}
|
||||
|
||||
lua_close(L);
|
||||
}
|
||||
|
||||
const char *script_run_state_to_string(script_run_t state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case SCRIPT_RUN_ONCE:
|
||||
return "once";
|
||||
case SCRIPT_RUN_ALWAYS:
|
||||
return "always";
|
||||
case SCRIPT_RUN_NEVER:
|
||||
return "never";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
33
src/script.h
Normal file
33
src/script.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2024 Martin Lund
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SCRIPT_RUN_ONCE,
|
||||
SCRIPT_RUN_ALWAYS,
|
||||
SCRIPT_RUN_NEVER,
|
||||
SCRIPT_RUN_END,
|
||||
} script_run_t;
|
||||
|
||||
void script_run(int fd, const char *script_filename);
|
||||
const char *script_run_state_to_string(script_run_t state);
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2017-2022 Martin Lund
|
||||
*
|
||||
|
|
@ -33,6 +33,7 @@
|
|||
#include <IOKit/serial/ioss.h>
|
||||
#endif
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
#ifdef HAVE_TERMIOS2
|
||||
int setspeed(int fd, int baudrate)
|
||||
|
|
@ -62,6 +63,9 @@ int setspeed(int fd, int baudrate)
|
|||
#else
|
||||
int setspeed(int fd, int baudrate)
|
||||
{
|
||||
UNUSED(fd);
|
||||
UNUSED(baudrate);
|
||||
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2022 Martin Lund
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2022 Martin Lund
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2022 Martin Lund
|
||||
*
|
||||
|
|
|
|||
62
src/socket.c
62
src/socket.c
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
* Copyright (c) 2022 Google LLC
|
||||
|
|
@ -33,6 +33,7 @@
|
|||
#include "socket.h"
|
||||
#include "options.h"
|
||||
#include "print.h"
|
||||
#include "tty.h"
|
||||
|
||||
#define MAX_SOCKET_CLIENTS 16
|
||||
#define SOCKET_PORT_DEFAULT 3333
|
||||
|
|
@ -51,23 +52,23 @@ static const char *socket_filename(void)
|
|||
static int socket_inet_port(void)
|
||||
{
|
||||
/* skip 'inet:' */
|
||||
int port_number = atoi(option.socket + 5);
|
||||
if (port_number == 0)
|
||||
int port = atoi(option.socket + 5);
|
||||
if (port == 0)
|
||||
{
|
||||
port_number = SOCKET_PORT_DEFAULT;
|
||||
port = SOCKET_PORT_DEFAULT;
|
||||
}
|
||||
return port_number;
|
||||
return port;
|
||||
}
|
||||
|
||||
static int socket_inet6_port(void)
|
||||
{
|
||||
/* skip 'inet6:' */
|
||||
int port_number = atoi(option.socket + 6);
|
||||
if (port_number == 0)
|
||||
int port = atoi(option.socket + 6);
|
||||
if (port == 0)
|
||||
{
|
||||
port_number = SOCKET_PORT_DEFAULT;
|
||||
port = SOCKET_PORT_DEFAULT;
|
||||
}
|
||||
return port_number;
|
||||
return port;
|
||||
}
|
||||
|
||||
static void socket_exit(void)
|
||||
|
|
@ -82,14 +83,14 @@ static bool socket_stale(const char *path)
|
|||
{
|
||||
struct sockaddr_un addr;
|
||||
bool stale = false;
|
||||
int sockfd;
|
||||
int sfd;
|
||||
|
||||
/* Test if socket file exists */
|
||||
if (access(path, F_OK) == 0)
|
||||
{
|
||||
/* Create test socket */
|
||||
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (sockfd < 0)
|
||||
sfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (sfd < 0)
|
||||
{
|
||||
tio_warning_printf("Failure opening socket (%s)", strerror(errno));
|
||||
return false;
|
||||
|
|
@ -123,6 +124,7 @@ void socket_configure(void)
|
|||
struct sockaddr_in6 sockaddr_inet6 = {};
|
||||
struct sockaddr *sockaddr_p;
|
||||
socklen_t socklen;
|
||||
int optval;
|
||||
|
||||
/* Parse socket string */
|
||||
|
||||
|
|
@ -224,6 +226,16 @@ void socket_configure(void)
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
#if defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL)
|
||||
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR | SO_NOSIGPIPE, &optval, sizeof(optval)))
|
||||
#else
|
||||
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)))
|
||||
#endif
|
||||
{
|
||||
tio_error_printf("Failed to set socket options (%s)", strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Bind */
|
||||
if (bind(sockfd, sockaddr_p, socklen) < 0)
|
||||
{
|
||||
|
|
@ -262,7 +274,12 @@ void socket_write(char input_char)
|
|||
{
|
||||
if (clientfds[i] != -1)
|
||||
{
|
||||
if (write(clientfds[i], &input_char, 1) <= 0)
|
||||
|
||||
#if defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL)
|
||||
if (send(clientfds[i], &input_char, 1, 0) <= 0)
|
||||
#else
|
||||
if (send(clientfds[i], &input_char, 1, MSG_NOSIGNAL) <= 0)
|
||||
#endif
|
||||
{
|
||||
tio_error_printf_silent("Failed to write to socket (%s)", strerror(errno));
|
||||
close(clientfds[i]);
|
||||
|
|
@ -340,11 +357,26 @@ bool socket_handle_input(fd_set *rdfs, char *output_char)
|
|||
clientfds[i] = -1;
|
||||
continue;
|
||||
}
|
||||
/* match the behavior of a terminal in raw mode */
|
||||
if (*output_char == '\n')
|
||||
|
||||
/* If INLCR is set, a received NL character shall be translated into a CR character */
|
||||
if (*output_char == '\n' && option.map_i_nl_cr)
|
||||
{
|
||||
*output_char = '\r';
|
||||
}
|
||||
else if (*output_char == '\r')
|
||||
{
|
||||
/* If IGNCR is set, a received CR character shall be ignored (not read). */
|
||||
if (option.map_ign_cr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/* If IGNCR is not set and ICRNL is set, a received CR character shall be translated into an NL character. */
|
||||
if (option.map_i_cr_nl)
|
||||
{
|
||||
*output_char = '\n';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
* Copyright (c) 2022 Google LLC
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
*
|
||||
|
|
@ -22,8 +22,6 @@
|
|||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include "error.h"
|
||||
|
|
@ -31,8 +29,6 @@
|
|||
#include "options.h"
|
||||
#include "timestamp.h"
|
||||
|
||||
#define TIME_STRING_SIZE_MAX 24
|
||||
|
||||
char *timestamp_current_time(void)
|
||||
{
|
||||
static char time_string[TIME_STRING_SIZE_MAX];
|
||||
|
|
@ -50,7 +46,7 @@ char *timestamp_current_time(void)
|
|||
first = false;
|
||||
}
|
||||
|
||||
// Add formatted timestap
|
||||
// Add formatted timestamp
|
||||
switch (option.timestamp)
|
||||
{
|
||||
case TIMESTAMP_NONE:
|
||||
|
|
@ -78,75 +74,31 @@ char *timestamp_current_time(void)
|
|||
tm = localtime(&tv.tv_sec);
|
||||
len = strftime(time_string, sizeof(time_string), "%Y-%m-%dT%H:%M:%S", tm);
|
||||
break;
|
||||
case TIMESTAMP_EPOCH:
|
||||
case TIMESTAMP_EPOCH_USEC:
|
||||
// "N.sss" (seconds since Unix epoch, 1970-01-01 00:00:00Z)
|
||||
tv = tv_now;
|
||||
tm = localtime(&tv.tv_sec);
|
||||
len = strftime(time_string, sizeof(time_string), "%s", tm);
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Append milliseconds to all timestamps
|
||||
// Append millis-/microseconds to all timestamps
|
||||
if (len)
|
||||
{
|
||||
if ( option.timestamp == TIMESTAMP_EPOCH_USEC )
|
||||
{
|
||||
len = snprintf(time_string + len, TIME_STRING_SIZE_MAX - len, ".%06ld", (long)tv.tv_usec);
|
||||
}
|
||||
else
|
||||
{
|
||||
len = snprintf(time_string + len, TIME_STRING_SIZE_MAX - len, ".%03ld", (long)tv.tv_usec / 1000);
|
||||
}
|
||||
|
||||
}
|
||||
// Save previous time value for next run
|
||||
tv_previous = tv_now;
|
||||
|
||||
return (len < TIME_STRING_SIZE_MAX) ? time_string : NULL;
|
||||
}
|
||||
|
||||
const char* timestamp_state_to_string(enum timestamp_t timestamp)
|
||||
{
|
||||
switch (timestamp)
|
||||
{
|
||||
case TIMESTAMP_NONE:
|
||||
return "disabled";
|
||||
break;
|
||||
|
||||
case TIMESTAMP_24HOUR:
|
||||
return "24hour";
|
||||
break;
|
||||
|
||||
case TIMESTAMP_24HOUR_START:
|
||||
return "24hour-start";
|
||||
break;
|
||||
|
||||
case TIMESTAMP_24HOUR_DELTA:
|
||||
return "24hour-delta";
|
||||
break;
|
||||
|
||||
case TIMESTAMP_ISO8601:
|
||||
return "iso8601";
|
||||
break;
|
||||
|
||||
default:
|
||||
return "unknown";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
enum timestamp_t timestamp_option_parse(const char *arg)
|
||||
{
|
||||
enum timestamp_t timestamp = TIMESTAMP_24HOUR; // Default
|
||||
|
||||
if (arg != NULL)
|
||||
{
|
||||
if (strcmp(arg, "24hour") == 0)
|
||||
{
|
||||
return TIMESTAMP_24HOUR;
|
||||
}
|
||||
else if (strcmp(arg, "24hour-start") == 0)
|
||||
{
|
||||
return TIMESTAMP_24HOUR_START;
|
||||
}
|
||||
else if (strcmp(arg, "24hour-delta") == 0)
|
||||
{
|
||||
return TIMESTAMP_24HOUR_DELTA;
|
||||
}
|
||||
else if (strcmp(arg, "iso8601") == 0)
|
||||
{
|
||||
return TIMESTAMP_ISO8601;
|
||||
}
|
||||
}
|
||||
|
||||
return timestamp;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
*
|
||||
|
|
@ -21,16 +21,19 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
enum timestamp_t
|
||||
typedef enum
|
||||
{
|
||||
TIMESTAMP_NONE,
|
||||
TIMESTAMP_24HOUR,
|
||||
TIMESTAMP_24HOUR_START,
|
||||
TIMESTAMP_24HOUR_DELTA,
|
||||
TIMESTAMP_ISO8601,
|
||||
TIMESTAMP_EPOCH,
|
||||
TIMESTAMP_EPOCH_USEC,
|
||||
TIMESTAMP_END,
|
||||
};
|
||||
} timestamp_t;
|
||||
|
||||
#define TIME_STRING_SIZE_MAX 24
|
||||
|
||||
char *timestamp_current_time(void);
|
||||
const char* timestamp_state_to_string(enum timestamp_t timestamp);
|
||||
enum timestamp_t timestamp_option_parse(const char *arg);
|
||||
|
||||
|
|
|
|||
55
src/tty.h
55
src/tty.h
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* tio - a simple serial terminal I/O tool
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2022 Martin Lund
|
||||
*
|
||||
|
|
@ -22,12 +22,65 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <glib.h>
|
||||
|
||||
#define LINE_HIGH true
|
||||
#define LINE_LOW false
|
||||
|
||||
#define TOPOLOGY_ID_SIZE 4
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FLOW_NONE,
|
||||
FLOW_HARD,
|
||||
FLOW_SOFT,
|
||||
} flow_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PARITY_NONE,
|
||||
PARITY_ODD,
|
||||
PARITY_EVEN,
|
||||
PARITY_MARK,
|
||||
PARITY_SPACE,
|
||||
} parity_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
AUTO_CONNECT_DIRECT,
|
||||
AUTO_CONNECT_NEW,
|
||||
AUTO_CONNECT_LATEST,
|
||||
AUTO_CONNECT_END,
|
||||
} auto_connect_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *tid;
|
||||
double uptime;
|
||||
char *path;
|
||||
char *driver;
|
||||
char *description;
|
||||
} device_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int mask;
|
||||
int value;
|
||||
bool reserved;
|
||||
} tty_line_config_t;
|
||||
|
||||
extern const char *device_name;
|
||||
extern bool interactive_mode;
|
||||
|
||||
void stdout_configure(void);
|
||||
void stdin_configure(void);
|
||||
void tty_configure(void);
|
||||
void tty_reconfigure(void);
|
||||
int tty_connect(void);
|
||||
void tty_wait_for_device(void);
|
||||
void list_serial_devices(void);
|
||||
void tty_input_thread_create(void);
|
||||
void tty_input_thread_wait_ready(void);
|
||||
void tty_line_set(int fd, tty_line_config_t line_config[]);
|
||||
void tty_search(void);
|
||||
GList *tty_search_for_serial_devices(void);
|
||||
|
|
|
|||
3
src/version.h.in
Normal file
3
src/version.h.in
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
#define VERSION "@VERSION@"
|
||||
739
src/xymodem.c
Normal file
739
src/xymodem.c
Normal file
|
|
@ -0,0 +1,739 @@
|
|||
/*
|
||||
* Minimalistic implementation of the xmodem-1k and ymodem sender protocol.
|
||||
* https://en.wikipedia.org/wiki/XMODEM
|
||||
* https://en.wikipedia.org/wiki/YMODEM
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later OR MIT-0
|
||||
*
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <poll.h>
|
||||
#include "xymodem.h"
|
||||
#include "print.h"
|
||||
#include "misc.h"
|
||||
|
||||
#define SOH 0x01
|
||||
#define STX 0x02
|
||||
#define ACK 0x06
|
||||
#define NAK 0x15
|
||||
#define CAN 0x18
|
||||
#define EOT 0x04
|
||||
|
||||
#define SOH_STR "\001"
|
||||
#define ACK_STR "\006"
|
||||
#define NAK_STR "\025"
|
||||
#define CAN_STR "\030"
|
||||
#define EOT_STR "\004"
|
||||
|
||||
#define OK 0
|
||||
#define ERR (-1)
|
||||
#define ERR_FATAL (-2)
|
||||
#define USER_CAN (-5)
|
||||
|
||||
#define RX_IGNORE 5
|
||||
|
||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
struct xpacket_1k {
|
||||
uint8_t type;
|
||||
uint8_t seq;
|
||||
uint8_t nseq;
|
||||
uint8_t data[1024];
|
||||
uint8_t crc_hi;
|
||||
uint8_t crc_lo;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct xpacket {
|
||||
uint8_t type;
|
||||
uint8_t seq;
|
||||
uint8_t nseq;
|
||||
uint8_t data[128];
|
||||
uint8_t crc_hi;
|
||||
uint8_t crc_lo;
|
||||
} __attribute__((packed));
|
||||
|
||||
/* See https://en.wikipedia.org/wiki/Computation_of_cyclic_redundancy_checks */
|
||||
static uint16_t crc16(const uint8_t *data, uint16_t size)
|
||||
{
|
||||
uint16_t crc, s;
|
||||
|
||||
for (crc = 0; size > 0; size--) {
|
||||
s = *data++ ^ (crc >> 8);
|
||||
s ^= (s >> 4);
|
||||
crc = (crc << 8) ^ s ^ (s << 5) ^ (s << 12);
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
static int xmodem_1k(int sio, const void *data, size_t len, int seq)
|
||||
{
|
||||
struct xpacket_1k packet;
|
||||
const uint8_t *buf = data;
|
||||
char resp = 0;
|
||||
int rc, crc;
|
||||
|
||||
/* Drain pending characters from serial line. Insist on the
|
||||
* last drained character being 'C'.
|
||||
*/
|
||||
while(1) {
|
||||
if (key_hit)
|
||||
return -1;
|
||||
rc = read_poll(sio, &resp, 1, 50);
|
||||
if (rc == 0) {
|
||||
if (resp == 'C') break;
|
||||
if (resp == CAN) return ERR;
|
||||
continue;
|
||||
}
|
||||
else if (rc < 0) {
|
||||
tio_error_print("Read sync from serial failed");
|
||||
return ERR;
|
||||
}
|
||||
}
|
||||
|
||||
/* Always work with 1K packets */
|
||||
packet.seq = seq;
|
||||
packet.type = STX;
|
||||
|
||||
while (len) {
|
||||
size_t sz, z = 0;
|
||||
char *from, status;
|
||||
|
||||
/* Build next packet, pad with 0 to full seq */
|
||||
z = min(len, sizeof(packet.data));
|
||||
memcpy(packet.data, buf, z);
|
||||
memset(packet.data + z, 0, sizeof(packet.data) - z);
|
||||
crc = crc16(packet.data, sizeof(packet.data));
|
||||
packet.crc_hi = crc >> 8;
|
||||
packet.crc_lo = crc;
|
||||
packet.nseq = 0xff - packet.seq;
|
||||
|
||||
/* Send packet */
|
||||
from = (char *) &packet;
|
||||
sz = sizeof(packet);
|
||||
while (sz) {
|
||||
if (key_hit)
|
||||
return ERR;
|
||||
if ((rc = write(sio, from, sz)) < 0 ) {
|
||||
if (errno == EWOULDBLOCK) {
|
||||
usleep(1000);
|
||||
continue;
|
||||
}
|
||||
tio_error_print("Write packet to serial failed");
|
||||
return ERR;
|
||||
}
|
||||
from += rc;
|
||||
sz -= rc;
|
||||
}
|
||||
|
||||
/* Clear response */
|
||||
resp = 0;
|
||||
|
||||
/* 'lrzsz' does not ACK ymodem's fin packet */
|
||||
if (seq == 0 && packet.data[0] == 0) resp = ACK;
|
||||
|
||||
/* Read receiver response, timeout 1 s */
|
||||
for(int n=0; n < 20; n++) {
|
||||
if (key_hit)
|
||||
return ERR;
|
||||
rc = read_poll(sio, &resp, 1, 50);
|
||||
if (rc < 0) {
|
||||
tio_error_print("Read ack/nak from serial failed");
|
||||
return ERR;
|
||||
} else if(rc > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update "progress bar" */
|
||||
switch (resp) {
|
||||
case NAK: status = 'N'; break;
|
||||
case ACK: status = '.'; break;
|
||||
case 'C': status = 'C'; break;
|
||||
case CAN: status = '!'; return ERR;
|
||||
default: status = '?';
|
||||
}
|
||||
write(STDOUT_FILENO, &status, 1);
|
||||
|
||||
/* Move to next block after ACK */
|
||||
if (resp == ACK) {
|
||||
packet.seq++;
|
||||
len -= z;
|
||||
buf += z;
|
||||
}
|
||||
}
|
||||
|
||||
/* Send EOT at 1 Hz until ACK or CAN received */
|
||||
while (seq) {
|
||||
if (key_hit)
|
||||
return ERR;
|
||||
if (write(sio, EOT_STR, 1) < 0) {
|
||||
tio_error_print("Write EOT to serial failed");
|
||||
return ERR;
|
||||
}
|
||||
write(STDOUT_FILENO, "|", 1);
|
||||
/* 1s timeout */
|
||||
rc = read_poll(sio, &resp, 1, 1000);
|
||||
if (rc < 0) {
|
||||
tio_error_print("Read from serial failed");
|
||||
return ERR;
|
||||
} else if(rc == 0) {
|
||||
continue;
|
||||
}
|
||||
if (resp == ACK || resp == CAN) {
|
||||
write(STDOUT_FILENO, "\r\n", 2);
|
||||
return (resp == ACK) ? OK : ERR;
|
||||
}
|
||||
}
|
||||
return 0; /* not reached */
|
||||
}
|
||||
|
||||
static int xmodem(int sio, const void *data, size_t len)
|
||||
{
|
||||
struct xpacket packet;
|
||||
const uint8_t *buf = data;
|
||||
char resp = 0;
|
||||
int rc, crc;
|
||||
|
||||
/* Drain pending characters from serial line. Insist on the
|
||||
* last drained character being 'C'.
|
||||
*/
|
||||
while(1) {
|
||||
if (key_hit)
|
||||
return -1;
|
||||
rc = read_poll(sio, &resp, 1, 50);
|
||||
if (rc == 0) {
|
||||
if (resp == 'C') break;
|
||||
if (resp == CAN) return ERR;
|
||||
continue;
|
||||
}
|
||||
else if (rc < 0) {
|
||||
tio_error_print("Read sync from serial failed");
|
||||
return ERR;
|
||||
}
|
||||
}
|
||||
|
||||
/* Always work with 128b packets */
|
||||
packet.seq = 1;
|
||||
packet.type = SOH;
|
||||
|
||||
while (len) {
|
||||
size_t sz, z = 0;
|
||||
char *from, status;
|
||||
|
||||
/* Build next packet, pad with 0 to full seq */
|
||||
z = min(len, sizeof(packet.data));
|
||||
memcpy(packet.data, buf, z);
|
||||
memset(packet.data + z, 0, sizeof(packet.data) - z);
|
||||
crc = crc16(packet.data, sizeof(packet.data));
|
||||
packet.crc_hi = crc >> 8;
|
||||
packet.crc_lo = crc;
|
||||
packet.nseq = 0xff - packet.seq;
|
||||
|
||||
/* Send packet */
|
||||
from = (char *) &packet;
|
||||
sz = sizeof(packet);
|
||||
while (sz) {
|
||||
if (key_hit)
|
||||
return ERR;
|
||||
if ((rc = write(sio, from, sz)) < 0 ) {
|
||||
if (errno == EWOULDBLOCK) {
|
||||
usleep(1000);
|
||||
continue;
|
||||
}
|
||||
tio_error_print("Write packet to serial failed");
|
||||
return ERR;
|
||||
}
|
||||
from += rc;
|
||||
sz -= rc;
|
||||
}
|
||||
|
||||
/* Clear response */
|
||||
resp = 0;
|
||||
|
||||
/* Read receiver response, timeout 1 s */
|
||||
for(int n=0; n < 20; n++) {
|
||||
if (key_hit)
|
||||
return ERR;
|
||||
rc = read_poll(sio, &resp, 1, 50);
|
||||
if (rc < 0) {
|
||||
tio_error_print("Read ack/nak from serial failed");
|
||||
return ERR;
|
||||
} else if(rc > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update "progress bar" */
|
||||
switch (resp) {
|
||||
case NAK: status = 'N'; break;
|
||||
case ACK: status = '.'; break;
|
||||
case 'C': status = 'C'; break;
|
||||
case CAN: status = '!'; return ERR;
|
||||
default: status = '?';
|
||||
}
|
||||
write(STDOUT_FILENO, &status, 1);
|
||||
|
||||
/* Move to next block after ACK */
|
||||
if (resp == ACK) {
|
||||
packet.seq++;
|
||||
len -= z;
|
||||
buf += z;
|
||||
}
|
||||
}
|
||||
|
||||
/* Send EOT at 1 Hz until ACK or CAN received */
|
||||
while (1) {
|
||||
if (key_hit)
|
||||
return ERR;
|
||||
if (write(sio, EOT_STR, 1) < 0) {
|
||||
tio_error_print("Write EOT to serial failed");
|
||||
return ERR;
|
||||
}
|
||||
write(STDOUT_FILENO, "|", 1);
|
||||
/* 1s timeout */
|
||||
rc = read_poll(sio, &resp, 1, 1000);
|
||||
if (rc < 0) {
|
||||
tio_error_print("Read from serial failed");
|
||||
return ERR;
|
||||
} else if(rc == 0) {
|
||||
continue;
|
||||
}
|
||||
if (resp == ACK || resp == CAN) {
|
||||
write(STDOUT_FILENO, "\r\n", 2);
|
||||
return (resp == ACK) ? OK : ERR;
|
||||
}
|
||||
}
|
||||
return 0; /* not reached */
|
||||
}
|
||||
|
||||
int start_receive(int sio)
|
||||
{
|
||||
int rc;
|
||||
struct pollfd fds;
|
||||
fds.events = POLLIN;
|
||||
fds.fd = sio;
|
||||
for (int n = 0; n < 20; n++)
|
||||
{
|
||||
/* Send the 'C' byte until the sender of the file responds with
|
||||
something. The start character will be sent once a second for a number of
|
||||
seconds. If nothing is received in that time then return false to indicate
|
||||
that the transfer did not start. */
|
||||
rc = write(sio, "C", 1);
|
||||
if (rc < 0) {
|
||||
if (errno == EWOULDBLOCK) {
|
||||
usleep(1000);
|
||||
continue;
|
||||
}
|
||||
tio_error_print("Write packet to serial failed");
|
||||
return ERR;
|
||||
}
|
||||
/* Wait until data is available */
|
||||
rc = poll(&fds, 1, 3000);
|
||||
if (rc < 0)
|
||||
{
|
||||
tio_error_print("%s", strerror(errno));
|
||||
return rc;
|
||||
}
|
||||
else if (rc > 0)
|
||||
{
|
||||
if (fds.revents & POLLIN)
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
if (key_hit)
|
||||
return USER_CAN;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
uint16_t update_CRC(uint16_t crc, char data_char)
|
||||
{
|
||||
uint8_t data = data_char;
|
||||
crc = crc ^ ((uint16_t)data << 8);
|
||||
for (int ix = 0; (ix < 8); ix++)
|
||||
{
|
||||
if (crc & 0x8000)
|
||||
{
|
||||
crc = (crc << 1) ^ 0x1021;
|
||||
}
|
||||
else
|
||||
{
|
||||
crc <<= 1;
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
int receive_packet(int sio, struct xpacket packet, int fd)
|
||||
{
|
||||
char rxSeq1, rxSeq2 = 0;
|
||||
char resp = 0;
|
||||
uint16_t calcCrc = 0;
|
||||
uint16_t rxCrc = 0;
|
||||
int rc;
|
||||
|
||||
struct pollfd fds;
|
||||
fds.events = POLLIN;
|
||||
fds.fd = sio;
|
||||
|
||||
/* Read seq bytes*/
|
||||
rc = read_poll(sio, &rxSeq1, 1, 3000);
|
||||
if (rc == 0) {
|
||||
tio_error_print("Timeout waiting for first seq byte");
|
||||
return ERR;
|
||||
} else if (rc < 0) {
|
||||
tio_error_print("Error reading first seq byte")
|
||||
return ERR_FATAL;
|
||||
}
|
||||
rc = read_poll(sio, &rxSeq2, 1, 3000);
|
||||
if (rc == 0) {
|
||||
tio_error_print("Timeout waiting for second seq byte");
|
||||
return ERR;
|
||||
} else if (rc < 0) {
|
||||
tio_error_print("Error reading second seq byte")
|
||||
return ERR_FATAL;
|
||||
}
|
||||
if (key_hit)
|
||||
return USER_CAN;
|
||||
|
||||
/* Read packet Data */
|
||||
for (unsigned ix = 0; (ix < sizeof(packet.data)); ix++)
|
||||
{
|
||||
rc = read_poll(sio, &resp, 1, 3000);
|
||||
/* If the read times out or fails then fail this packet. */
|
||||
if (rc == 0)
|
||||
{
|
||||
tio_error_print("Timeout waiting for next packet char");
|
||||
rc = write(sio, CAN_STR, 1);
|
||||
if (rc < 0) {
|
||||
tio_error_print("Write cancel packet to serial failed");
|
||||
return ERR_FATAL;
|
||||
}
|
||||
return ERR;
|
||||
} else if (rc < 0) {
|
||||
tio_error_print("Error reading next packet char")
|
||||
rc = write(sio, CAN_STR, 1);
|
||||
if (rc < 0) {
|
||||
tio_error_print("Write cancel packet to serial failed");
|
||||
}
|
||||
return ERR_FATAL;
|
||||
}
|
||||
packet.data[ix] = (uint8_t) resp;
|
||||
calcCrc = update_CRC(calcCrc, resp);
|
||||
if (key_hit)
|
||||
return USER_CAN;
|
||||
}
|
||||
|
||||
/* Read CRC */
|
||||
rc = read_poll(sio, &resp, 1, 3000);
|
||||
if (rc == 0) {
|
||||
tio_error_print("Timeout waiting for first CRC byte");
|
||||
return ERR;
|
||||
} else if (rc < 0) {
|
||||
tio_error_print("Error reading first CRC byte")
|
||||
return ERR_FATAL;
|
||||
}
|
||||
|
||||
uint8_t uresp = resp;
|
||||
uint16_t uresp16 = uresp;
|
||||
rxCrc = uresp16 << 8;
|
||||
|
||||
rc = read_poll(sio, &resp, 1, 3000);
|
||||
if (rc == 0) {
|
||||
tio_error_print("Timeout waiting for second CRC byte");
|
||||
return ERR;
|
||||
} else if (rc < 0) {
|
||||
tio_error_print("Error reading second CRC byte")
|
||||
return ERR_FATAL;
|
||||
}
|
||||
|
||||
uresp = resp;
|
||||
uresp16 = uresp;
|
||||
rxCrc |= uresp16;
|
||||
|
||||
if (key_hit)
|
||||
return USER_CAN;
|
||||
|
||||
/* At this point in the code, there should not be anything in the receive buffer
|
||||
because the sender has just sent a complete packet and is waiting on a response. */
|
||||
rc = poll(&fds, 1, 10);
|
||||
if (rc < 0)
|
||||
{
|
||||
tio_error_print("%s", strerror(errno));
|
||||
tio_error_print("Poll check error after packet finish");
|
||||
rc = write(sio, CAN_STR, 1);
|
||||
if (rc < 0) {
|
||||
tio_error_print("Write cancel packet to serial failed");
|
||||
}
|
||||
return ERR_FATAL;
|
||||
}
|
||||
else if (rc > 0)
|
||||
{
|
||||
if (fds.revents & POLLIN)
|
||||
{
|
||||
tio_error_print("RX sync error");
|
||||
char dummy = 0;
|
||||
/* Drain buffer */
|
||||
while (read_poll(sio, &dummy, 1, 100) > 0) {}
|
||||
return ERR;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t tester = 0xff;
|
||||
uint8_t seq1 = rxSeq1;
|
||||
uint8_t seq2 = rxSeq2;
|
||||
|
||||
if ((calcCrc == rxCrc) && (seq1 == packet.seq - 1) && ((seq1 ^ seq2) == tester))
|
||||
{
|
||||
/* Resend of previously processed packet. */
|
||||
rc = write(sio, ACK_STR, 1);
|
||||
if (rc < 0) {
|
||||
tio_error_print("Write acknowlegdement packet to serial failed");
|
||||
return ERR_FATAL;
|
||||
}
|
||||
return RX_IGNORE;
|
||||
}
|
||||
else if ((calcCrc != rxCrc) || (seq1 != packet.seq) || ((seq1 ^ seq2) != tester))
|
||||
{
|
||||
/* Fail if the CRC or sequence number is not correct or if the two received
|
||||
sequence numbers are not the complement of one another. */
|
||||
tio_error_print("Bad CRC or sequence number");
|
||||
tio_debug_printf("CRC read: %u", rxCrc);
|
||||
tio_debug_printf("CRC calculated: %u", calcCrc);
|
||||
tio_debug_printf("Seq read: %hhu", rxSeq1);
|
||||
tio_debug_printf("Seq should be: %hhu", packet.seq);
|
||||
tio_debug_printf("inv seq: %hhu", rxSeq2);
|
||||
return ERR;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The data is good. Process the packet then ACK it to the sender. */
|
||||
rc = write(fd, packet.data, sizeof(packet.data));
|
||||
if (rc < 0)
|
||||
{
|
||||
tio_error_print("Problem writing to file");
|
||||
rc = write(sio, CAN_STR, 1);
|
||||
if (rc < 0) {
|
||||
tio_error_print("Write cancel packet to serial failed");
|
||||
}
|
||||
return ERR_FATAL;
|
||||
}
|
||||
rc = write(sio, ACK_STR, 1);
|
||||
if (rc < 0)
|
||||
{
|
||||
tio_error_print("Write acknowlegdement packet to serial failed");
|
||||
return ERR_FATAL;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int xmodem_receive(int sio, int fd)
|
||||
{
|
||||
struct xpacket packet;
|
||||
char resp = 0;
|
||||
int rc;
|
||||
bool complete = false;
|
||||
char status;
|
||||
|
||||
/* Drain pending characters from serial line.*/
|
||||
while(1) {
|
||||
if (key_hit)
|
||||
return -1;
|
||||
rc = read_poll(sio, &resp, 1, 50);
|
||||
if (rc == 0) {
|
||||
if (resp == CAN) return ERR;
|
||||
break;
|
||||
}
|
||||
else if (rc < 0) {
|
||||
if (rc != USER_CAN) {
|
||||
tio_error_print("Read sync from serial failed");
|
||||
}
|
||||
return ERR;
|
||||
}
|
||||
}
|
||||
|
||||
/* Always work with 128b packets */
|
||||
packet.seq = 1;
|
||||
packet.type = SOH;
|
||||
|
||||
/* Start Receive*/
|
||||
rc = start_receive(sio);
|
||||
if (rc == 0)
|
||||
{
|
||||
tio_error_print("Timeout waiting for transfer to start");
|
||||
return ERR;
|
||||
} else if (rc < 0) {
|
||||
tio_error_print("Error starting XMODEM receive");
|
||||
return ERR;
|
||||
}
|
||||
|
||||
while (!complete) {
|
||||
/* Poll for 1 new byte for 3 seconds */
|
||||
rc = read_poll(sio, &resp, 1, 3000);
|
||||
if (rc == 0) {
|
||||
tio_error_print("Timeout waiting for start of next packet");
|
||||
return ERR;
|
||||
} else if (rc < 0) {
|
||||
tio_error_print("Error reading start of next packet")
|
||||
return ERR;
|
||||
}
|
||||
if (key_hit)
|
||||
return USER_CAN;
|
||||
|
||||
switch(resp)
|
||||
{
|
||||
case SOH:
|
||||
/* Start of a packet */
|
||||
rc = receive_packet(sio, packet, fd);
|
||||
if (rc == OK) {
|
||||
packet.seq++;
|
||||
status = '.';
|
||||
} else if (rc == ERR) {
|
||||
rc = write(sio, NAK_STR, 1);
|
||||
if (rc < 0) {
|
||||
tio_error_print("Writing not acknowledge packet to serial failed");
|
||||
return ERR;
|
||||
}
|
||||
status = 'N';
|
||||
} else if (rc == ERR_FATAL) {
|
||||
tio_error_print("Receive cancelled due to fatal error");
|
||||
return ERR;
|
||||
} else if (rc == USER_CAN) {
|
||||
rc = write(sio, CAN_STR, 1);
|
||||
if (rc < 0) {
|
||||
tio_error_print("Writing cancel to serial failed");
|
||||
return ERR;
|
||||
}
|
||||
return USER_CAN;
|
||||
} else if (rc == RX_IGNORE) {
|
||||
status = ':';
|
||||
}
|
||||
break;
|
||||
|
||||
case EOT:
|
||||
/* End of Transfer */
|
||||
rc = write(sio, ACK_STR, 1);
|
||||
if (rc < 0)
|
||||
{
|
||||
tio_error_print("Write acknowlegdement packet to serial failed");
|
||||
return ERR;
|
||||
}
|
||||
complete = true;
|
||||
status = '\0';
|
||||
write(STDOUT_FILENO, "|\r\n", 3);
|
||||
break;
|
||||
|
||||
case CAN:
|
||||
/* Cancel from sender */
|
||||
tio_error_print("Transmission cancelled from sender");
|
||||
return ERR;
|
||||
break;
|
||||
|
||||
default:
|
||||
tio_error_print("Unexpected character received waiting for next packet");
|
||||
return ERR;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
/* Update "progress bar" */
|
||||
write(STDOUT_FILENO, &status, 1);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
int xymodem_send(int sio, const char *filename, modem_mode_t mode)
|
||||
{
|
||||
size_t len;
|
||||
int rc, fd;
|
||||
struct stat stat;
|
||||
const uint8_t *buf;
|
||||
|
||||
/* Open file, map into memory */
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
tio_error_print("Could not open file");
|
||||
return ERR;
|
||||
}
|
||||
fstat(fd, &stat);
|
||||
len = stat.st_size;
|
||||
buf = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (!buf) {
|
||||
close(fd);
|
||||
tio_error_print("Could not mmap file");
|
||||
return ERR;
|
||||
}
|
||||
|
||||
/* Do transfer */
|
||||
key_hit = 0;
|
||||
if (mode == XMODEM_1K) {
|
||||
rc = xmodem_1k(sio, buf, len, 1);
|
||||
}
|
||||
else if (mode == XMODEM_CRC) {
|
||||
rc = xmodem(sio, buf, len);
|
||||
}
|
||||
else {
|
||||
/* Ymodem: hdr + file + fin */
|
||||
while(1) {
|
||||
char hdr[1024], *p;
|
||||
|
||||
rc = -1;
|
||||
if (strlen(filename) > 977) break; /* hdr block overrun */
|
||||
p = stpncpy(hdr, filename, 1024) + 1;
|
||||
p += sprintf(p, "%ld %lo %o", len, stat.st_mtime, stat.st_mode);
|
||||
|
||||
if (xmodem_1k(sio, hdr, p - hdr, 0) < 0) break; /* hdr with metadata */
|
||||
if (xmodem_1k(sio, buf, len, 1) < 0) break; /* xmodem file */
|
||||
if (xmodem_1k(sio, "", 1, 0) < 0) break; /* empty hdr = fin */
|
||||
rc = 0; break;
|
||||
}
|
||||
}
|
||||
key_hit = 0xff;
|
||||
|
||||
/* Flush serial and release resources */
|
||||
tcflush(sio, TCIOFLUSH);
|
||||
munmap((void *)buf, len);
|
||||
close(fd);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int xymodem_receive(int sio, const char *filename, modem_mode_t mode)
|
||||
{
|
||||
int rc, fd;
|
||||
|
||||
/* Create new file */
|
||||
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0664);
|
||||
if (fd < 0) {
|
||||
tio_error_print("Could not open file");
|
||||
return ERR;
|
||||
}
|
||||
|
||||
/* Do transfer */
|
||||
key_hit = 0;
|
||||
if (mode == XMODEM_1K) {
|
||||
tio_error_print("Not supported");
|
||||
rc = -1;
|
||||
}
|
||||
else if (mode == XMODEM_CRC) {
|
||||
rc = xmodem_receive(sio, fd);
|
||||
}
|
||||
else {
|
||||
tio_error_print("Not supported");
|
||||
rc = -1;
|
||||
}
|
||||
key_hit = 0xff;
|
||||
|
||||
/* Flush serial and release resources */
|
||||
tcflush(sio, TCIOFLUSH);
|
||||
close(fd);
|
||||
return rc;
|
||||
}
|
||||
34
src/xymodem.h
Normal file
34
src/xymodem.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* tio - a serial device I/O tool
|
||||
*
|
||||
* Copyright (c) 2014-2024 Martin Lund
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef enum {
|
||||
XMODEM_1K,
|
||||
XMODEM_CRC,
|
||||
YMODEM,
|
||||
} modem_mode_t;
|
||||
|
||||
extern char key_hit;
|
||||
|
||||
int xymodem_send(int sio, const char *filename, modem_mode_t mode);
|
||||
|
||||
int xymodem_receive(int sio, const char *filename, modem_mode_t mode);
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
[wrap-git]
|
||||
directory=libinih
|
||||
url=https://github.com/benhoyt/inih.git
|
||||
revision=r56
|
||||
Loading…
Add table
Add a link
Reference in a new issue