Update TTN_decoder.txt #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Convert TTN Decoder to ChirpStack | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'UV254-LB/TTN_decoder.txt' # 只在 TTN_decoder.txt 文件更改时触发 | |
workflow_dispatch: # 允许手动触发 | |
jobs: | |
convert: | |
runs-on: ubuntu-latest # 使用 ubuntu-latest 作为运行环境 | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' # 使用 Python 3.9 | |
- name: Run conversion script | |
run: | | |
cd UV254-LB | |
# 创建 Python 脚本 | |
cat <<EOF > convert_decoder.py | |
import re | |
def convert_ttn_to_chirpstack(ttn_js_content): | |
# 替换函数名称 Decoder -> decodeUplink | |
chirpstack_js_content = re.sub( | |
r'function\s+Decoder\s*\(([^)]+)\)', | |
r'function decodeUplink(\1)', | |
ttn_js_content | |
) | |
# 替换返回值格式 | |
chirpstack_js_content = re.sub( | |
r'return\s+({[^}]*});', | |
r'return {\n data: \1,\n warnings: [],\n errors: []\n };', | |
chirpstack_js_content | |
) | |
return chirpstack_js_content | |
# 读取 TTN_decoder.txt | |
with open('TTN_decoder.txt', 'r') as file: | |
ttn_js_content = file.read() | |
# 转换为 ChirpStack 格式 | |
chirpstack_js_content = convert_ttn_to_chirpstack(ttn_js_content) | |
# 保存为 ChirpStack_decoder.js | |
with open('ChirpStack_decoder.js', 'w') as file: | |
file.write(chirpstack_js_content) | |
EOF | |
# 运行 Python 脚本 | |
python convert_decoder.py | |
- name: Commit and push changes | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add UV254-LB/ChirpStack_decoder.js | |
git commit -m "Automated conversion of TTN decoder to ChirpStack for UV254-LB" | |
git push |