init upload + readme + error handling
This commit is contained in:
25
ReadMe.md
Normal file
25
ReadMe.md
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# Upload Tec Script
|
||||||
|
|
||||||
|
This Code is for uploading the [TECware](https://gitlab.psi.ch/coldbox/tec/tecware) to the TEC in the Coldbox environemen via the CAN Bus.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
- Please install python 3.6 on you PC / Raspberry PI
|
||||||
|
- then go to you terminal, jump to this directory
|
||||||
|
- go into the python directory: `cd python`
|
||||||
|
- install python library: `python setup.py install`
|
||||||
|
- then go back to the home directory
|
||||||
|
- copy the srec file from the [TECware](https://gitlab.psi.ch/coldbox/tec/tecware) reop to this directory
|
||||||
|
- (If you are on windows, please change you CAN Interface in the uploadtec.py script) [here](https://www.feaser.com/en/blog/2018/07/libopenblt-python-bindings-tutorial/) some infos
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
to use this script the libopenblt.(so on linux)(dll on windows) library should be in the same directory.
|
||||||
|
|
||||||
|
on linux first reset the canbus with `./resetCAN.sh`.
|
||||||
|
|
||||||
|
the use the script to upload the code:
|
||||||
|
`python uploadtec.py [all/1-8] [filename]`
|
||||||
|
|
||||||
|
if the upload gets interrupted, the should restart the upload because th code on the TEC is now corrupted.
|
||||||
|
The Bootloader itself should not corrupt itself, so everything is save. These are 2 completly different and independent programms.
|
BIN
libopenblt.dll
Normal file
BIN
libopenblt.dll
Normal file
Binary file not shown.
BIN
libopenblt.so
Normal file
BIN
libopenblt.so
Normal file
Binary file not shown.
47
python/README.rst
Normal file
47
python/README.rst
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
Python wrapper for LibOpenBLT
|
||||||
|
=============================
|
||||||
|
The OpenBLT Host Library (`LibOpenBLT <https://www.feaser.com/openblt/doku.php?id=manual:libopenblt>`_) contains an application programming interface (API) for communicating with a microcontroller target, running the OpenBLT bootloader, for making firmware updates on the target. The goal of the OpenBLT Host Library is to empower you to quickly and efficiently create your own firmware update tool, in case you don’t prefer the standard MicroBoot and BootCommander tools that are included in the OpenBLT bootloader package.
|
||||||
|
|
||||||
|
This package contains the python wrapper for LibOpenBLT, which enables you to quickly develop your own firmware update tool in the Python programming language.
|
||||||
|
|
||||||
|
Install the package
|
||||||
|
-------------------
|
||||||
|
Run the following command from the directory that contains the **setup.py** file (assuming setuptools is installed):
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
python setup.py install
|
||||||
|
|
||||||
|
Alternatively, you can use **pip** by running this command from the directory that contains the **setup.py** file:
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
pip install .
|
||||||
|
|
||||||
|
|
||||||
|
Using the package
|
||||||
|
-----------------
|
||||||
|
Basic code snippet to call the BltVersionGetString()-function which displays the version of LibOpenBLT:
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
import openblt
|
||||||
|
|
||||||
|
print('LibOpenBLT version:', openblt.version_get_string())
|
||||||
|
|
||||||
|
Have a look at the function headers inside openblt.lib for details on how to call the functions, including examples. A video tutorial about getting started with the Python bindings is available in this `blog article <https://www.feaser.com/en/blog/?p=208>`_.
|
||||||
|
|
||||||
|
|
||||||
|
Run-time libraries
|
||||||
|
------------------
|
||||||
|
Copy the LibOpenBLT related run-time libraries into your python program's directory. Refer to the following section on the OpenBLT Wiki for a overview of these run-time libraries:
|
||||||
|
|
||||||
|
https://www.feaser.com/openblt/doku.php?id=manual:libopenblt#run-time_libraries.
|
||||||
|
|
||||||
|
These run-time libraries can be found in the ./Host directory of the OpenBLT bootloader package. These run-time libraries should also be included, when distributing your program.
|
||||||
|
|
||||||
|
Specific on Windows
|
||||||
|
------------------
|
||||||
|
Under Microsoft Windows, the LibOpenBLT shared library (libopenblt.dll) is 64-bit ever since OpenBLT version 1.14. Therefore you need to run your Python application, that makes use of LibOpenBLT, using the 64-bit Python interpreter.
|
||||||
|
|
||||||
|
If you use the LibOpenBLT shared library from before OpenBLT version 1.14 or if you rebuilt it yourself as 32-bit, you need to run your Python application using the 32-bit Python interpreter.
|
94
python/build/lib/openblt/__init__.py
Normal file
94
python/build/lib/openblt/__init__.py
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
"""
|
||||||
|
Package **openblt** is a python wrapper for the OpenBLT Host Library (`LibOpenBLT <https://www.feaser.com/openblt/doku.php?id=manual:libopenblt>`_).
|
||||||
|
|
||||||
|
Have a look at the function headers inside openblt.lib for details on how to call the functions, including examples.
|
||||||
|
"""
|
||||||
|
__docformat__ = 'reStructuredText'
|
||||||
|
# ***************************************************************************************
|
||||||
|
# File Name: __init__.py
|
||||||
|
#
|
||||||
|
# ---------------------------------------------------------------------------------------
|
||||||
|
# C O P Y R I G H T
|
||||||
|
# ---------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2018 by Feaser http://www.feaser.com All rights reserved
|
||||||
|
#
|
||||||
|
# ---------------------------------------------------------------------------------------
|
||||||
|
# L I C E N S E
|
||||||
|
# ---------------------------------------------------------------------------------------
|
||||||
|
# This file is part of OpenBLT. OpenBLT 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 3 of the License, or (at your option) any later
|
||||||
|
# version.
|
||||||
|
#
|
||||||
|
# OpenBLT 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 have received a copy of the GNU General Public License along with OpenBLT. It
|
||||||
|
# should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
||||||
|
#
|
||||||
|
# ***************************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
# ***************************************************************************************
|
||||||
|
# Imports
|
||||||
|
# ***************************************************************************************
|
||||||
|
from openblt.lib import BLT_RESULT_OK
|
||||||
|
from openblt.lib import BLT_RESULT_ERROR_GENERIC
|
||||||
|
|
||||||
|
|
||||||
|
# ***************************************************************************************
|
||||||
|
# V E R S I O N I N F O R M A T I O N
|
||||||
|
# ***************************************************************************************
|
||||||
|
from openblt.lib import version_get_number
|
||||||
|
from openblt.lib import version_get_string
|
||||||
|
|
||||||
|
|
||||||
|
# ***************************************************************************************
|
||||||
|
# S E S S I O N / T R A N S P O R T L A Y E R S
|
||||||
|
# ***************************************************************************************
|
||||||
|
from openblt.lib import BLT_SESSION_XCP_V10
|
||||||
|
from openblt.lib import BLT_TRANSPORT_XCP_V10_RS232
|
||||||
|
from openblt.lib import BLT_TRANSPORT_XCP_V10_CAN
|
||||||
|
from openblt.lib import BLT_TRANSPORT_XCP_V10_USB
|
||||||
|
from openblt.lib import BLT_TRANSPORT_XCP_V10_NET
|
||||||
|
from openblt.lib import BltSessionSettingsXcpV10
|
||||||
|
from openblt.lib import BltTransportSettingsXcpV10Rs232
|
||||||
|
from openblt.lib import BltTransportSettingsXcpV10Can
|
||||||
|
from openblt.lib import BltTransportSettingsXcpV10Net
|
||||||
|
from openblt.lib import session_init
|
||||||
|
from openblt.lib import session_terminate
|
||||||
|
from openblt.lib import session_start
|
||||||
|
from openblt.lib import session_stop
|
||||||
|
from openblt.lib import session_clear_memory
|
||||||
|
from openblt.lib import session_write_data
|
||||||
|
from openblt.lib import session_read_data
|
||||||
|
|
||||||
|
|
||||||
|
# ***************************************************************************************
|
||||||
|
# F I R M W A R E D A T A
|
||||||
|
# ***************************************************************************************
|
||||||
|
from openblt.lib import BLT_FIRMWARE_PARSER_SRECORD
|
||||||
|
from openblt.lib import firmware_terminate
|
||||||
|
from openblt.lib import firmware_init
|
||||||
|
from openblt.lib import firmware_load_from_file
|
||||||
|
from openblt.lib import firmware_save_to_file
|
||||||
|
from openblt.lib import firmware_get_segment_count
|
||||||
|
from openblt.lib import firmware_get_segment
|
||||||
|
from openblt.lib import firmware_add_data
|
||||||
|
from openblt.lib import firmware_remove_data
|
||||||
|
from openblt.lib import firmware_clear_data
|
||||||
|
|
||||||
|
|
||||||
|
# ***************************************************************************************
|
||||||
|
# G E N E R I C U T I L I T I E S
|
||||||
|
# ***************************************************************************************
|
||||||
|
from openblt.lib import util_crc16_calculate
|
||||||
|
from openblt.lib import util_crc32_calculate
|
||||||
|
from openblt.lib import util_time_get_system_time
|
||||||
|
from openblt.lib import util_time_delay_ms
|
||||||
|
from openblt.lib import util_crypto_aes256_encrypt
|
||||||
|
from openblt.lib import util_crypto_aes256_decrypt
|
||||||
|
|
||||||
|
|
||||||
|
# ********************************* end of __init__.py **********************************
|
1215
python/build/lib/openblt/lib.py
Normal file
1215
python/build/lib/openblt/lib.py
Normal file
File diff suppressed because it is too large
Load Diff
BIN
python/dist/openblt-1.3.7-py3.9.egg
vendored
Normal file
BIN
python/dist/openblt-1.3.7-py3.9.egg
vendored
Normal file
Binary file not shown.
57
python/openblt.egg-info/PKG-INFO
Normal file
57
python/openblt.egg-info/PKG-INFO
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
Metadata-Version: 1.0
|
||||||
|
Name: openblt
|
||||||
|
Version: 1.3.7
|
||||||
|
Summary: Python wrapper for the OpenBLT host library (LibOpenBLT).
|
||||||
|
Home-page: https://www.feaser.com/openblt/doku.php?id=manual:libopenblt
|
||||||
|
Author: Frank Voorburg
|
||||||
|
Author-email: voorburg@feaser.com
|
||||||
|
License: UNKNOWN
|
||||||
|
Description: Python wrapper for LibOpenBLT
|
||||||
|
=============================
|
||||||
|
The OpenBLT Host Library (`LibOpenBLT <https://www.feaser.com/openblt/doku.php?id=manual:libopenblt>`_) contains an application programming interface (API) for communicating with a microcontroller target, running the OpenBLT bootloader, for making firmware updates on the target. The goal of the OpenBLT Host Library is to empower you to quickly and efficiently create your own firmware update tool, in case you don’t prefer the standard MicroBoot and BootCommander tools that are included in the OpenBLT bootloader package.
|
||||||
|
|
||||||
|
This package contains the python wrapper for LibOpenBLT, which enables you to quickly develop your own firmware update tool in the Python programming language.
|
||||||
|
|
||||||
|
Install the package
|
||||||
|
-------------------
|
||||||
|
Run the following command from the directory that contains the **setup.py** file (assuming setuptools is installed):
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
python setup.py install
|
||||||
|
|
||||||
|
Alternatively, you can use **pip** by running this command from the directory that contains the **setup.py** file:
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
pip install .
|
||||||
|
|
||||||
|
|
||||||
|
Using the package
|
||||||
|
-----------------
|
||||||
|
Basic code snippet to call the BltVersionGetString()-function which displays the version of LibOpenBLT:
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
import openblt
|
||||||
|
|
||||||
|
print('LibOpenBLT version:', openblt.version_get_string())
|
||||||
|
|
||||||
|
Have a look at the function headers inside openblt.lib for details on how to call the functions, including examples. A video tutorial about getting started with the Python bindings is available in this `blog article <https://www.feaser.com/en/blog/?p=208>`_.
|
||||||
|
|
||||||
|
|
||||||
|
Run-time libraries
|
||||||
|
------------------
|
||||||
|
Copy the LibOpenBLT related run-time libraries into your python program's directory. Refer to the following section on the OpenBLT Wiki for a overview of these run-time libraries:
|
||||||
|
|
||||||
|
https://www.feaser.com/openblt/doku.php?id=manual:libopenblt#run-time_libraries.
|
||||||
|
|
||||||
|
These run-time libraries can be found in the ./Host directory of the OpenBLT bootloader package. These run-time libraries should also be included, when distributing your program.
|
||||||
|
|
||||||
|
Specific on Windows
|
||||||
|
------------------
|
||||||
|
Under Microsoft Windows, the LibOpenBLT shared library (libopenblt.dll) is 64-bit ever since OpenBLT version 1.14. Therefore you need to run your Python application, that makes use of LibOpenBLT, using the 64-bit Python interpreter.
|
||||||
|
|
||||||
|
If you use the LibOpenBLT shared library from before OpenBLT version 1.14 or if you rebuilt it yourself as 32-bit, you need to run your Python application using the 32-bit Python interpreter.
|
||||||
|
|
||||||
|
Platform: UNKNOWN
|
8
python/openblt.egg-info/SOURCES.txt
Normal file
8
python/openblt.egg-info/SOURCES.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
README.rst
|
||||||
|
setup.py
|
||||||
|
openblt/__init__.py
|
||||||
|
openblt/lib.py
|
||||||
|
openblt.egg-info/PKG-INFO
|
||||||
|
openblt.egg-info/SOURCES.txt
|
||||||
|
openblt.egg-info/dependency_links.txt
|
||||||
|
openblt.egg-info/top_level.txt
|
1
python/openblt.egg-info/dependency_links.txt
Normal file
1
python/openblt.egg-info/dependency_links.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
1
python/openblt.egg-info/top_level.txt
Normal file
1
python/openblt.egg-info/top_level.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
openblt
|
94
python/openblt/__init__.py
Normal file
94
python/openblt/__init__.py
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
"""
|
||||||
|
Package **openblt** is a python wrapper for the OpenBLT Host Library (`LibOpenBLT <https://www.feaser.com/openblt/doku.php?id=manual:libopenblt>`_).
|
||||||
|
|
||||||
|
Have a look at the function headers inside openblt.lib for details on how to call the functions, including examples.
|
||||||
|
"""
|
||||||
|
__docformat__ = 'reStructuredText'
|
||||||
|
# ***************************************************************************************
|
||||||
|
# File Name: __init__.py
|
||||||
|
#
|
||||||
|
# ---------------------------------------------------------------------------------------
|
||||||
|
# C O P Y R I G H T
|
||||||
|
# ---------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2018 by Feaser http://www.feaser.com All rights reserved
|
||||||
|
#
|
||||||
|
# ---------------------------------------------------------------------------------------
|
||||||
|
# L I C E N S E
|
||||||
|
# ---------------------------------------------------------------------------------------
|
||||||
|
# This file is part of OpenBLT. OpenBLT 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 3 of the License, or (at your option) any later
|
||||||
|
# version.
|
||||||
|
#
|
||||||
|
# OpenBLT 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 have received a copy of the GNU General Public License along with OpenBLT. It
|
||||||
|
# should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
||||||
|
#
|
||||||
|
# ***************************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
# ***************************************************************************************
|
||||||
|
# Imports
|
||||||
|
# ***************************************************************************************
|
||||||
|
from openblt.lib import BLT_RESULT_OK
|
||||||
|
from openblt.lib import BLT_RESULT_ERROR_GENERIC
|
||||||
|
|
||||||
|
|
||||||
|
# ***************************************************************************************
|
||||||
|
# V E R S I O N I N F O R M A T I O N
|
||||||
|
# ***************************************************************************************
|
||||||
|
from openblt.lib import version_get_number
|
||||||
|
from openblt.lib import version_get_string
|
||||||
|
|
||||||
|
|
||||||
|
# ***************************************************************************************
|
||||||
|
# S E S S I O N / T R A N S P O R T L A Y E R S
|
||||||
|
# ***************************************************************************************
|
||||||
|
from openblt.lib import BLT_SESSION_XCP_V10
|
||||||
|
from openblt.lib import BLT_TRANSPORT_XCP_V10_RS232
|
||||||
|
from openblt.lib import BLT_TRANSPORT_XCP_V10_CAN
|
||||||
|
from openblt.lib import BLT_TRANSPORT_XCP_V10_USB
|
||||||
|
from openblt.lib import BLT_TRANSPORT_XCP_V10_NET
|
||||||
|
from openblt.lib import BltSessionSettingsXcpV10
|
||||||
|
from openblt.lib import BltTransportSettingsXcpV10Rs232
|
||||||
|
from openblt.lib import BltTransportSettingsXcpV10Can
|
||||||
|
from openblt.lib import BltTransportSettingsXcpV10Net
|
||||||
|
from openblt.lib import session_init
|
||||||
|
from openblt.lib import session_terminate
|
||||||
|
from openblt.lib import session_start
|
||||||
|
from openblt.lib import session_stop
|
||||||
|
from openblt.lib import session_clear_memory
|
||||||
|
from openblt.lib import session_write_data
|
||||||
|
from openblt.lib import session_read_data
|
||||||
|
|
||||||
|
|
||||||
|
# ***************************************************************************************
|
||||||
|
# F I R M W A R E D A T A
|
||||||
|
# ***************************************************************************************
|
||||||
|
from openblt.lib import BLT_FIRMWARE_PARSER_SRECORD
|
||||||
|
from openblt.lib import firmware_terminate
|
||||||
|
from openblt.lib import firmware_init
|
||||||
|
from openblt.lib import firmware_load_from_file
|
||||||
|
from openblt.lib import firmware_save_to_file
|
||||||
|
from openblt.lib import firmware_get_segment_count
|
||||||
|
from openblt.lib import firmware_get_segment
|
||||||
|
from openblt.lib import firmware_add_data
|
||||||
|
from openblt.lib import firmware_remove_data
|
||||||
|
from openblt.lib import firmware_clear_data
|
||||||
|
|
||||||
|
|
||||||
|
# ***************************************************************************************
|
||||||
|
# G E N E R I C U T I L I T I E S
|
||||||
|
# ***************************************************************************************
|
||||||
|
from openblt.lib import util_crc16_calculate
|
||||||
|
from openblt.lib import util_crc32_calculate
|
||||||
|
from openblt.lib import util_time_get_system_time
|
||||||
|
from openblt.lib import util_time_delay_ms
|
||||||
|
from openblt.lib import util_crypto_aes256_encrypt
|
||||||
|
from openblt.lib import util_crypto_aes256_decrypt
|
||||||
|
|
||||||
|
|
||||||
|
# ********************************* end of __init__.py **********************************
|
1215
python/openblt/lib.py
Normal file
1215
python/openblt/lib.py
Normal file
File diff suppressed because it is too large
Load Diff
53
python/setup.py
Normal file
53
python/setup.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
Setuptools setup specification for package 'openblt'.
|
||||||
|
"""
|
||||||
|
__docformat__ = 'reStructuredText'
|
||||||
|
# ***************************************************************************************
|
||||||
|
# File Name: setup.py
|
||||||
|
#
|
||||||
|
# ---------------------------------------------------------------------------------------
|
||||||
|
# C O P Y R I G H T
|
||||||
|
# ---------------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2018 by Feaser http://www.feaser.com All rights reserved
|
||||||
|
#
|
||||||
|
# ---------------------------------------------------------------------------------------
|
||||||
|
# L I C E N S E
|
||||||
|
# ---------------------------------------------------------------------------------------
|
||||||
|
# This file is part of OpenBLT. OpenBLT 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 3 of the License, or (at your option) any later
|
||||||
|
# version.
|
||||||
|
#
|
||||||
|
# OpenBLT 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 have received a copy of the GNU General Public License along with OpenBLT. It
|
||||||
|
# should be located in ".\Doc\license.html". If not, contact Feaser to obtain a copy.
|
||||||
|
#
|
||||||
|
# ***************************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
# ***************************************************************************************
|
||||||
|
# Imports
|
||||||
|
# ***************************************************************************************
|
||||||
|
from setuptools import setup
|
||||||
|
|
||||||
|
|
||||||
|
# ***************************************************************************************
|
||||||
|
# Implementation
|
||||||
|
# ***************************************************************************************
|
||||||
|
setup ( \
|
||||||
|
name = 'openblt',
|
||||||
|
version = '1.3.7',
|
||||||
|
description = 'Python wrapper for the OpenBLT host library (LibOpenBLT).',
|
||||||
|
long_description = open('README.rst', 'r').read(),
|
||||||
|
author = 'Frank Voorburg',
|
||||||
|
author_email = 'voorburg@feaser.com',
|
||||||
|
url = 'https://www.feaser.com/openblt/doku.php?id=manual:libopenblt',
|
||||||
|
packages = ['openblt'],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# ********************************* end of setup.py *************************************
|
2
resetCAN.sh
Normal file
2
resetCAN.sh
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
sudo ip link set can0 down; sudo ip link set can0 type can bitrate 125000; sudo ip link set can0 up
|
97
uploadtec.py
Normal file
97
uploadtec.py
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
# This is a sample Python script.
|
||||||
|
|
||||||
|
import openblt as blt
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
LINE_UP = '\033[1A'
|
||||||
|
LINE_CLEAR = '\x1b[2K'
|
||||||
|
|
||||||
|
def print_del(txt:str):
|
||||||
|
"""print and delete line before"""
|
||||||
|
print(LINE_UP, end=LINE_CLEAR)
|
||||||
|
print(txt)
|
||||||
|
|
||||||
|
|
||||||
|
def upload_code(tec_id, filename):
|
||||||
|
blt.firmware_init(blt.BLT_FIRMWARE_PARSER_SRECORD)
|
||||||
|
session_type = blt.BLT_SESSION_XCP_V10
|
||||||
|
session_settings = blt.BltSessionSettingsXcpV10()
|
||||||
|
transport_type = blt.BLT_TRANSPORT_XCP_V10_CAN
|
||||||
|
transport_settings = blt.BltTransportSettingsXcpV10Can()
|
||||||
|
transport_settings.baudrate = 125000
|
||||||
|
transport_settings.receiveId = 0x340 | tec_id
|
||||||
|
transport_settings.transmitId = 0x300 | tec_id
|
||||||
|
transport_settings.deviceName = 'can0'
|
||||||
|
|
||||||
|
blt.session_init(session_type, session_settings,transport_type, transport_settings)
|
||||||
|
|
||||||
|
print('tec: ' + str(tec_id))
|
||||||
|
print('connecting to the bootloader')
|
||||||
|
|
||||||
|
while blt.session_start() != blt.BLT_RESULT_OK:
|
||||||
|
pass
|
||||||
|
|
||||||
|
print('connected')
|
||||||
|
print('clearing [0/0]')
|
||||||
|
|
||||||
|
if blt.firmware_load_from_file(filename) != blt.BLT_RESULT_OK:
|
||||||
|
print('error reading file')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
segment_count = blt.firmware_get_segment_count()
|
||||||
|
for segment_idx in range(0, segment_count):
|
||||||
|
print_del(f"clearing [{segment_idx+1}/{segment_count}]")
|
||||||
|
segment_data, segment_address, segment_len = blt.firmware_get_segment((segment_idx))
|
||||||
|
res = blt.session_clear_memory(segment_address, segment_len)
|
||||||
|
if res != blt.BLT_RESULT_OK:
|
||||||
|
print('error clearing data')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
print("uploading [0/0]")
|
||||||
|
|
||||||
|
for segment_idx in range(0, segment_count):
|
||||||
|
print_del(f"uploading [{segment_idx+1}/{segment_count}]")
|
||||||
|
segment_data, segment_address, segment_len = blt.firmware_get_segment((segment_idx))
|
||||||
|
res = blt.session_write_data(segment_address, segment_len, segment_data)
|
||||||
|
if res != blt.BLT_RESULT_OK:
|
||||||
|
print('error writing data')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
print("finished upoading")
|
||||||
|
|
||||||
|
blt.session_stop()
|
||||||
|
|
||||||
|
blt.session_terminate()
|
||||||
|
blt.firmware_terminate()
|
||||||
|
|
||||||
|
print("disconnected")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
if len(sys.argv) != 3:
|
||||||
|
print('check parameters: [1-8/all] [filename]')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if sys.argv[1] == 'all':
|
||||||
|
for i in range(8):
|
||||||
|
upload_code(i+1, sys.argv[2])
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
try:
|
||||||
|
tec_id = int(sys.argv[1])
|
||||||
|
except:
|
||||||
|
print("error: illegal command (tecid)")
|
||||||
|
print('check parameters: [1-8/all] [filename]')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if( 1 < tec_id > 8):
|
||||||
|
print("wrong tec id")
|
||||||
|
print('check parameters: [1-8/all] [filename]')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
upload_code(tec_id, sys.argv[2])
|
||||||
|
|
Reference in New Issue
Block a user