Skip to content

Commit

Permalink
to: test build other platform
Browse files Browse the repository at this point in the history
  • Loading branch information
fishros committed Apr 2, 2024
1 parent 343af3b commit a9f5458
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 49 deletions.
50 changes: 32 additions & 18 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build-Release
name: Build-Release-Linux

on:
push:
Expand All @@ -9,41 +9,55 @@ jobs:
build-docker:
runs-on: ubuntu-latest
steps:
- name: Docker login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Checkout repository
uses: actions/checkout@v2
- name: Build the Docker image
run: docker build -f Dockerfile.build -t ${{ secrets.DOCKERHUB_USERNAME }}/fishbot_tool:build_ubuntu22 .
- name: Docker image push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/fishbot_tool:build_ubuntu22
- name: Docker login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Checkout repository
uses: actions/checkout@v2
- name: Build the Docker image
run: docker build -f Dockerfile.build -t ${{ secrets.DOCKERHUB_USERNAME }}/fishbot_tool:${{ env.REF_NAME }} .
- name: Docker image push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/fishbot_tool:${{ env.REF_NAME }}

build-linux-x64:
runs-on: ubuntu-latest
needs: build-docker # Wait for the completion of the 'build-docker' job
container: fishros2/fishbot_tool:build_ubuntu22
build-linux-amd64:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build firmware

- name: Set up Python 3.10
uses: actions/setup-python@master
with:
python-version: 3.10

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pyinstaller
pip install pyserial requests
- name: Build with PyInstaller
run: pyinstaller release_linux.spec

- name: Generate file list for bin directory
id: file_list
run: |
file_list=$(ls -1 dist/*) # Only list .bin files in the bin directory
echo "FILES=$file_list" >> $GITHUB_ENV
echo "REF_NAME=$GITHUB_REF_NAME" >> $GITHUB_ENV
- name: Create Release and Upload Release Asset
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
tag_name: ${{ github.ref }}
name: ${{ env.REF_NAME }}
body: Linux版本及Docker版本配置助手。
body_path: release-notes.md
token: ${{ secrets.ACCESS_TOKEN }}
draft: false
prerelease: false
files: |
${{ env.FILES }}
fishbot_tool_cli.py
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ubuntu:jammy

RUN echo "chooses:\n" > fish_install.yaml \
&& echo "- {choose: 5, desc: '一键安装:ROS(支持ROS和ROS2,树莓派Jetson)'}\n" >> fish_install.yaml \
&& echo "- {choose: 2, desc: 更换源继续安装}\n" >> fish_install.yaml \
&& echo "- {choose: 1, desc: 清理三方源}\n" >> fish_install.yaml \
&& apt update && apt install wget python3 python3-distro python3-yaml -y \
&& wget http://fishros.com/install -O fishros && /bin/bash fishros \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& apt-get clean && apt autoclean \
&& rm -rf fish_install.yaml

# RUN DEBIAN_FRONTEND=noninteractive apt install -y tzdata


RUN apt-get update && apt-get install -y \
fonts-wqy-zenhei \
libgl1 \
libegl1 \
&& apt-get clean && apt-get autoclean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

COPY "dist/f1.alpha_linux_x64" /fishbot
RUN chmod +x /fishbot
ENTRYPOINT ["/fishbot"]

# docker run -it --rm --privileged -v /dev:/dev -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY fishbot-tool
50 changes: 30 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
# 配置工具
# FishBot配置工具

支持设备:
- FishBot二驱板
- FishBot四驱动板
- FishBot_Camera无线摄像头

## 源码使用

首先克隆代码到本地,接着安装 PyQt6,PySide6,pyserial,esptool
## 使用方法(可视化版)

### 1.直接下载(推荐)

[release](https://github.com/fishros/fishbot_tool/releases)页面下载构好的二进制文件(Linux需要下载后右击勾选可执行)双击运行即可。

### 2.Docker使用

首先确保你的电脑安装了Docker,然后直接运行以下命令(注意,最新版本需要到release页面查看):

```
xhost + && sudo docker run -it --rm --privileged -v /dev:/dev -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY fishros2/fishbot-tool:v1.0.0.20240219 python3 main.py
```

### 3.源码使用
首先克隆代码到本地,接着安装 PyQt6,pyserial,esptool,requests
```
sudo apt install python3-pip
sudo pip3 install PyQt6 PySide6 pyserial esptool -i https://pypi.tuna.tsinghua.edu.cn/simple
sudo pip3 install PyQt6 requests pyserial esptool -i https://pypi.tuna.tsinghua.edu.cn/simple
```

接着执行
接着执行(注意Linux下要给串口设备权限)

```
cd fishbot_tool/fishbot_tool/
sudo DISPLAY=unix$DISPLAY python3 main.py
python3 main.py
```


## 快速使用
## 使用方法(无界面版本)

安装好Docker,在你的终端输入下面代码,既可使用
安装好Python3.8+,到release页面下载fishbot_tool_cli.py,接着执行:

```
docker run -it --rm --privileged -v /dev:/dev fishros2/fishbot-tool python main.py
python fishbot_tool_cli.py
```

最后根据提示使用即可。

## 设计思考

```
功能列表
固件相关
1.烧录fishbot固件(手动选择软件版本)
2.烧录雷达转接板固件(只做一个固件即可)
配置相关
1.配置雷达转接板波特率等(wifi&ip&port&baut)
2.配置运动控制板相关内容(wifi&ip&port&reduce&pid)
```

- Autor: [fishros](https://github.com/fishros)
Binary file added esptool/esptool_arm64
Binary file not shown.
Binary file added esptool/esptool_linux_amd64
Binary file not shown.
Binary file added esptool/esptool_macos
Binary file not shown.
Binary file added esptool/esptool_win64.exe
Binary file not shown.
155 changes: 155 additions & 0 deletions fishbot_tool_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import os
import sys

def check_installation(package_name,install_pkg):
try:
__import__(package_name)
return True
except ImportError:
print(f'{package_name} 未安装,尝试安装')
os.system(f'pip install {install_pkg}')
return False

check_installation('serial',"pyserial")
check_installation('esptool','esptool')
check_installation('requests','requests')

import serial #导入模块
import serial.tools.list_ports
import requests
import time


def list_serial_ports():
port_list = list(serial.tools.list_ports.comports())
if len(port_list) == 0:
print('无可用串口,请插入串口设备')
return False
else:
print('当前可用串口有:')
for i in range(0,len(port_list)):
print(port_list[i].name)
return True

def download_firmware(firmware_path):
print('将测到固件在HTTP路径上,开始下载')
response = requests.get(firmware_path, stream=True)
response.raise_for_status()

filename = os.path.basename(firmware_path)
with open(filename, 'wb') as file:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
file.write(chunk)

print(f'下载完成:{filename}')
return filename

def flash_firmware():
firmware_path = 'firmware.bin'
while not os.path.exists(firmware_path):
print(f"提示:{firmware_path}固件文件不存在,请重新输入")
firmware_path = input("请输入固件文件路径(可以是网址): ")
if firmware_path.startswith('http'):
firmware_path = download_firmware(firmware_path)


while list_serial_ports()==False:
time.sleep(1)
port = input("请输入要烧录的串口设备名称: ")

flash_command = f'esptool.py --port {port} write_flash 0x00000 {firmware_path}'
os.system(flash_command)



def config_board(key: str, value: str, port='/dev/ttyUSB0', baudrate=115200):
try:
ser = serial.Serial(port, baudrate)
except:
return {"error": "串口打开异常,请检查设备是否被占用"}

config_str = f"${key}={value}\n".encode()
print(f"发送 {str(config_str)}{ser.port}")
ser.write(config_str)
start_time_timeout = time.time()
recv_avaliable_data = False
while (time.time()-start_time_timeout < 5) and (not recv_avaliable_data):
print("开始接收...")
try:
recv = ser.read_all().decode()
print(f"尝试接收..{recv}")
time.sleep(0.5)
if len(recv) > 0:
print(f"接收到有效数据 :{recv}")
recv_avaliable_data = True
except Exception as e:
print(e)

if len(recv) == 0:
return {"error": "串口数据异常,请确认设备在配置模式"}

result = {}
lines = recv.splitlines()
for line in lines:
if len(line) > 0 and line[0] == '$':
split_result = line[1:].split("=")
if len(split_result) == 2:
result[split_result[0]] = split_result[1]
ser.close()
if len(result) == 0:
return {"error": "串口数据异常,请确认设备在配置模式"}
return result


def restart_device_bt_rst(port):
try:
ser = serial.Serial(port, baudrate=74880)
ser.setRTS(False)
ser.setDTR(False)
time.sleep(0.2)
ser.setRTS(True)
ser.setDTR(True)
time.sleep(0.2)
time.sleep(0.1)
return "[提示]发送RTS成功!"
except Exception as e:
ser.close()
print(e)
return {"error": "串口打开异常,请检查设备是否被占用"}


def print_help():
print("使用方法:")
print(" python fishbot_tool_cli.py list_port - 列出可用的串口")
print(" python fishbot_tool_cli.py flash - 下载固件")
print(" python fishbot_tool_cli.py read_config COMX - 读取配置,COMX替换为设备编号")
print(" python fishbot_tool_cli.py config name value - 设置配置项")
print(" python fishbot_tool_cli.py - 打印帮助信息")


def main():
if len(sys.argv) == 1:
print_help()
elif sys.argv[1] == 'list_port':
list_serial_ports()
elif sys.argv[1] == 'flash':
flash_firmware()
elif sys.argv[1] == 'read_config':
if len(sys.argv)!=3:
print('请在read_config后添加你要读取的设备串口号')
return
all_configs = config_board("command", "read_config", port=sys.argv[2], baudrate=115200)
print(all_configs)
elif sys.argv[1] == 'config':
if len(sys.argv)!=5:
print('请在config后添加你的:设备号 配置项 配置值')
return
result = config_board(sys.argv[3], sys.argv[4], port=sys.argv[2], baudrate=115200)
print(result)
else:
print("未知的命令")
print_help()

if __name__ == "__main__":
main()
1 change: 0 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import os
CURRENT_DIR = os.path.dirname(__file__)
# os.system(f"code {CURRENT_DIR}")

class FishBotTool():
def __init__(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
- [feat]发布Linux可执行文件(下载后给可执行权限双击运行)
- [feat]改用docker发布模式
- [feat]添加无界面版本fishbot_tool_cli.py

版本说明:
- alpha:内部测试版本(不建议使用)
- beta:新功能测试版本(可以尝试)
- release:最终测试版本(推荐)

使用说明:
- 国内用户可以使用[代理工具](http://github.fishros.org)下载
17 changes: 14 additions & 3 deletions release_linux.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# -*- mode: python ; coding: utf-8 -*-
import os
import platform

def get_platform_name():
system = platform.system()
if system == "Linux":
if platform.machine() == "x86_64":
return "linux_amd64"
elif platform.machine() == "aarch64":
return "linux_arm64"


# 从环境变量中获取版本号
version_name = os.getenv('GITHUB_REF_NAME', 'v1.0.0.alpha') # 如果环境变量中没有设置版本号,则使用默认值'1.0.0'
Expand All @@ -18,11 +28,12 @@ replace("ui/main.ui", "VCODE", version_name)

block_cipher = None


a = Analysis(
['main.py'],
pathex=['/home/fishros/github/fishbot_tool/'],
pathex=[''],
binaries=[],
datas=[('./ui/about.ui', 'ui'), ('./ui/main.ui', 'ui'), ('./ui/taobao.ui', 'ui'), ('./ui/assert/fishros.jpg', 'ui/assert'),('./ui/assert/taobao.jpeg', 'ui/assert')],
datas=[('./esptool/esptool_linux_amd64', '.'),('./ui/about.ui', 'ui'), ('./ui/main.ui', 'ui'), ('./ui/taobao.ui', 'ui'), ('./ui/assert/fishros.jpg', 'ui/assert'),('./ui/assert/taobao.jpeg', 'ui/assert')],
hiddenimports=[],
hookspath=[],
hooksconfig={},
Expand All @@ -43,7 +54,7 @@ exe = EXE(
a.zipfiles,
a.datas,
[],
name=f'FishBot配置工具{version_name}_linux_x64',
name=f'FishBotTool.{version_name}.{get_platform_name()}',
debug=True,
bootloader_ignore_signals=False,
strip=False,
Expand Down
Loading

0 comments on commit a9f5458

Please sign in to comment.