This commit is contained in:
r.koeppe
2024-05-14 02:14:13 +02:00
parent 0052d3984b
commit 2d22ccd2d6
1423 changed files with 354055 additions and 7 deletions

View File

@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 2.8.4)
project(firmware_update)
set(CMAKE_SUPPRESS_REGENERATION TRUE)
add_subdirectory(../.. libvncxx)
if(CMAKE_COMPILER_ID MATCHES "GNU|Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
set(SOURCE_FILES
main.cpp)
include_directories(../../include)
add_executable(getting_started ${SOURCE_FILES})
target_link_libraries(getting_started PRIVATE libvncxx)
if (UNIX OR APPLE)
target_link_libraries(getting_started LINK_PUBLIC pthread)
else()
target_link_libraries(getting_started LINK_PUBLIC Advapi32 SetupAPI)
endif()

View File

@ -0,0 +1,22 @@
CXX = g++
INCLUDES = -I ../../include
CPPFLAGS = -Wall
SOURCES = main.cpp
all: firmware_update
clean:
rm -f main.o
rm -f firmware_update
cd ../.. && make clean
firmware_update: main.o ../../build/bin/libvncxx.a
$(CXX) -o firmware_update main.o -L ../../build/bin -lvncxx -lpthread
../../build/bin/libvncxx.a:
cd ../.. && make
main.o: main.cpp
$(CXX) $(CPPFLAGS) $(INCLUDES) -c $< -o $@

View File

@ -0,0 +1,24 @@
When opening the vs2019 example Project, Visual Studio will pop up a dialog asking to retarget Projects to the latest Windows SDK Version and Platform Toolset. DO NOT update the projects because it will break building the libvncxx library. The latest Platform Toolset that can be used to build the libvncxx library is Visual Studio 2017.
Also, the library currently only supports x86 builds.
If you do not have the Visual Studio 2017 Build Tools, you will get the following error:
Error MSB8020 The build tools for Visual Studio 2017 (Platform Toolset = 'v141') cannot be found. To build using the v141 build tools, please install Visual Studio 2017 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution".
The following link will walk you through how to add the Visual Studio 2017 platform toolset to your environment.
https://docs.microsoft.com/en-us/visualstudio/install/modify-visual-studio?view=vs-2019
Run C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe
Select C++/CLI support for v141 build tools (14.16) under Compilers, build tools, and runtimes from the Individual components tab of modifying Visual Studio 2019
MSVC v141 - VS 2017 C++ x64/x86 build tools (v14.16)
Also select Windows 10 SDK 10.0.18362.0 for the needed make tools.
After adding support for Visual Studio 2017 build toolset, if the projects are marked as unusable, have Visual Studio install the missing components.

View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30717.126
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "firmware_update", "firmware_update.vcxproj", "{04D3924A-69D8-433A-8B5A-04646A2C40D6}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libvncxx", "..\..\..\..\projects\vs2019\libvncxx.vcxproj", "{72FA8039-B6D8-37DF-8FC0-CDE71377C512}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{04D3924A-69D8-433A-8B5A-04646A2C40D6}.Debug|x86.ActiveCfg = Debug|Win32
{04D3924A-69D8-433A-8B5A-04646A2C40D6}.Debug|x86.Build.0 = Debug|Win32
{04D3924A-69D8-433A-8B5A-04646A2C40D6}.Release|x86.ActiveCfg = Release|Win32
{04D3924A-69D8-433A-8B5A-04646A2C40D6}.Release|x86.Build.0 = Release|Win32
{72FA8039-B6D8-37DF-8FC0-CDE71377C512}.Debug|x86.ActiveCfg = Debug|Win32
{72FA8039-B6D8-37DF-8FC0-CDE71377C512}.Debug|x86.Build.0 = Debug|Win32
{72FA8039-B6D8-37DF-8FC0-CDE71377C512}.Release|x86.ActiveCfg = Release|Win32
{72FA8039-B6D8-37DF-8FC0-CDE71377C512}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8FA300D7-9E17-4CD7-AF70-0EDB3ABE57FB}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,101 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{04d3924a-69d8-433a-8b5a-04646a2c40d6}</ProjectGuid>
<RootNamespace>firmwareupdate</RootNamespace>
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>..\..\..\..\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>..\..\..\..\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\main.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\projects\vs2019\libvncxx.vcxproj">
<Project>{72fa8039-b6d8-37df-8fc0-cde71377c512}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

View File

@ -0,0 +1,378 @@
// firmware_update.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
// Include this header file to get access to VectorNav sensors.
#include "vn/sensors.h"
// We need this file for our sleep function.
#include "vn/thread.h"
using namespace std;
using namespace vn::math;
using namespace vn::sensors;
using namespace vn::protocol::uart;
using namespace vn::xplat;
void one_call_method_for_the_VN300()
{
// This example walks through using the VectorNav C++ Library to do a firmware update on the different processors of the VN300 using the firmwareUpdate method
// First determine which COM port your sensor is attached to and update the constant below. Also, if you have changed your sensor from the factory
// default baudrate of 115200, you will need to update the baudrate constant below as well.
const string SensorPort = "COM4"; // Windows format for physical and virtual (USB) serial port.
// const string SensorPort = "/dev/ttyS1"; // Linux format for physical serial port.
// const string SensorPort = "/dev/ttyUSB0"; // Linux format for virtual (USB) serial port.
// const string SensorPort = "/dev/tty.usbserial-FTXXXXXX"; // Mac OS X format for virtual (USB) serial port.
// const string SensorPort = "/dev/ttyS0"; // CYGWIN format. Usually the Windows COM port number minus 1. This would connect to COM1.
const uint32_t SensorBaudrate = 115200;
const uint32_t FirmwareUpdateBaudrate = 115200; // This can be different than the sensor baudrate, recommend 115200 or slower for reliability
std::string VN300_NAVFirmwareUpdate("../../FirmwareUpdates/VN300_NAV_v0.5.0.0.vnx");
std::string VN300_GPSFirmwareUpdate("../../FirmwareUpdates/VN300_GPS_v0.5.0.0.vnx");
// Now let's create a VnSensor object and use it to connect to our sensor.
cout << "Connecting to sensor" << endl;
VnSensor vs;
vs.connect(SensorPort, SensorBaudrate);
// Let's query the sensor's model number.
string mn = vs.readModelNumber();
cout << "Model Number: " << mn << endl;
// Let's query the sensor's firmware version.
string fwv = vs.readFirmwareVersion();
cout << "Firmware Version: " << fwv << endl;
// Let's update the NAV firmware first.
cout << "Updating NAV processor" << endl;
vs.firmwareUpdate(FirmwareUpdateBaudrate, VN300_NAVFirmwareUpdate);
// Let's switch to the target processor to update.
cout << "Switching to the GPS processor to update" << endl;
vs.switchProcessors(vs.VNPROCESSOR_GPS, mn, fwv);
// Let's update the GPS firmware Second.
cout << "Updating GPS processor" << endl;
vs.firmwareUpdate(FirmwareUpdateBaudrate, VN300_GPSFirmwareUpdate);
// Now disconnect from the sensor since we are finished.
cout << "Disconnecting from sensor" << endl;
vs.disconnect();
// Depending on the sensor, a power cycle may be needed instead of a reset.
cout << "Power Cycle the sensor" << endl;
}
void manage_each_step_method_for_the_VN200()
{
// This example walks through using the VectorNav C++ Library to do a firmware update of the VN200 using the firmwareUpdate method
// First determine which COM port your sensor is attached to and update the
// constant below. Also, if you have changed your sensor from the factory
// default baudrate of 115200, you will need to update the baudrate
// constant below as well.
const string SensorPort = "COM3"; // Windows format for physical and virtual (USB) serial port.
// const string SensorPort = "/dev/ttyS1"; // Linux format for physical serial port.
// const string SensorPort = "/dev/ttyUSB0"; // Linux format for virtual (USB) serial port.
// const string SensorPort = "/dev/tty.usbserial-FTXXXXXX"; // Mac OS X format for virtual (USB) serial port.
// const string SensorPort = "/dev/ttyS0"; // CYGWIN format. Usually the Windows COM port number minus 1. This would connect to COM1.
const uint32_t SensorBaudrate = 115200;
const uint32_t FirmwareUpdateBaudrate = 115200; // This can be different than the sensor baudrate, recommend 115200 or slower for reliability
std::string VN200FirmwareUpdate("../../FirmwareUpdates/VN200_NAV_v2.0.0.1.vnx");
// Now let's create a VnSensor object and use it to connect to our sensor.
cout << "Connecting to sensor" << endl;
VnSensor vs;
vs.connect(SensorPort, SensorBaudrate);
// Let's query the sensor's model number.
string mn = vs.readModelNumber();
cout << "Model Number: " << mn << endl;
// Let's query the sensor's firmware version.
string fwv = vs.readFirmwareVersion();
cout << "Firmware Version: " << fwv << endl;
// Let's update the firmware on the target processor.
cout << "Updating processor" << endl;
std::string record = "";
// Open firmware update file
vs.openFirmwareUpdateFile(VN200FirmwareUpdate);
// Enter bootloader mode
vs.firmwareUpdateMode(true);
// Give the sensor time to reboot into bootloader mode
Thread::sleepSec(1);
// Configure baudrate for firmware update
uint32_t navBaudRate = vs.baudrate();
vs.setFirmwareUpdateBaudRate(FirmwareUpdateBaudrate);
// Calibrate the bootloader by letting it calculate the current baudrate.
std::string bootloaderVersion = vs.calibrateBootloader();
cout << bootloaderVersion << endl;
// Send each record from the firmware update file one at a time
do
{
record = vs.getNextFirwareUpdateRecord();
if (!record.empty())
{
cout << ".";
record.erase(0, 1); // Remove the ':' from the beginning of the line.
vs.writeFirmwareUpdateRecord(record, true);
}
} while (!record.empty());
cout << endl;
// Close firmware update file
vs.closeFirmwareUpdateFile();
// Reset baudrate
vs.setFirmwareUpdateBaudRate(navBaudRate);
// Exit bootloader mode. Sleep for 10 seconds
Thread::sleepSec(10);
// Do a reset
vs.reset();
// Wait 2 seconds after a reset
Thread::sleepSec(2);
// Now disconnect from the sensor since we are finished.
cout << "Disconnecting from sensor" << endl;
vs.disconnect();
// Depending on the sensor, a power cycle may be needed instead of a reset.
cout << "Power Cycle the sensor" << endl;
}
void manage_each_step_method_for_the_VN310()
{
const string SensorPort = "COM6";
const uint32_t SensorBaudrate = 115200;
const uint32_t FirmwareUpdateBaudrate = 115200; // This can be different than the sensor baudrate, recommend 115200 or slower for reliability
std::string VN310_NAVFirmwareUpdate("../../FirmwareUpdates/VN310_NAV_v0.8.1.0.vnx");
std::string VN310_GPSFirmwareUpdate("../../FirmwareUpdates/VN310_GPS_v0.8.1.0.vnx");
std::string VN310_IMUFirmwareUpdate("../../FirmwareUpdates/VN310_IMU_v2.5.1.0.vnx");
bool updateNAV = true;
bool updateGPS = true;
bool updateIMU = true;
// Now let's create a VnSensor object and use it to connect to our sensor.
cout << "Connecting to sensor" << endl;
VnSensor vs;
vs.connect(SensorPort, SensorBaudrate);
// Let's query the sensor's model number.
string mn = vs.readModelNumber();
cout << "Model Number: " << mn << endl;
// Let's query the sensor's firmware version.
string fwv = vs.readFirmwareVersion();
cout << "Firmware Version: " << fwv << endl;
// Let's update the firmware on the target processor.
cout << "Updating processor" << endl;
std::string record = "";
// ******************** Update NAV ********************
if (updateNAV)
{
cout << "********************************************************************************" << endl;
cout << "Updating the NAV firmware on a VN310" << endl;
cout << "********************************************************************************" << endl;
// Open firmware update file
vs.openFirmwareUpdateFile(VN310_NAVFirmwareUpdate);
// Enter bootloader mode
vs.firmwareUpdateMode(true);
// Give the sensor time to reboot into bootloader mode
Thread::sleepSec(1);
// Configure baudrate for firmware update
uint32_t navBaudRate = vs.baudrate();
vs.setFirmwareUpdateBaudRate(FirmwareUpdateBaudrate);
// Calibrate the bootloader by letting it calculate the current baudrate.
std::string bootloaderVersion = vs.calibrateBootloader();
cout << bootloaderVersion << endl;
// Send each record from the firmware update file one at a time
do
{
record = vs.getNextFirwareUpdateRecord();
if (!record.empty())
{
cout << ".";
record.erase(0, 1); // Remove the ':' from the beginning of the line.
vs.writeFirmwareUpdateRecord(record, true);
}
} while (!record.empty());
// Close firmware update file
vs.closeFirmwareUpdateFile();
// Reset baudrate
vs.setFirmwareUpdateBaudRate(navBaudRate);
// Exit bootloader mode. Sleep for 10 seconds
Thread::sleepSec(10);
// Do a reset
vs.reset();
// Wait 2 seconds after a reset
Thread::sleepSec(2);
// Let's switch back to the main processor
cout << "Switching to the NAV processor" << endl;
vs.switchProcessors(vs.VNPROCESSOR_NAV, mn, fwv);
}
// ******************** Update GPS ********************
if (updateGPS)
{
cout << "********************************************************************************" << endl;
cout << "Updating the GPS firmware on a VN310" << endl;
cout << "********************************************************************************" << endl;
// Let's switch to the target processor to update.
cout << "Switching to the GPS processor to update" << endl;
vs.switchProcessors(vs.VNPROCESSOR_GPS, mn, fwv);
// Open firmware update file
vs.openFirmwareUpdateFile(VN310_GPSFirmwareUpdate);
// Enter bootloader mode
vs.firmwareUpdateMode(true);
// Give the sensor time to reboot into bootloader mode
Thread::sleepSec(1);
// Configure baudrate for firmware update
uint32_t navBaudRate = vs.baudrate();
vs.setFirmwareUpdateBaudRate(FirmwareUpdateBaudrate);
// Calibrate the bootloader by letting it calculate the current baudrate.
std::string bootloaderVersion = vs.calibrateBootloader();
cout << bootloaderVersion << endl;
// Send each record from the firmware update file one at a time
do
{
record = vs.getNextFirwareUpdateRecord();
if (!record.empty())
{
cout << ".";
record.erase(0, 1); // Remove the ':' from the beginning of the line.
vs.writeFirmwareUpdateRecord(record, true);
}
} while (!record.empty());
// Close firmware update file
vs.closeFirmwareUpdateFile();
// Reset baudrate
vs.setFirmwareUpdateBaudRate(navBaudRate);
// Exit bootloader mode. Sleep for 10 seconds
Thread::sleepSec(10);
// Do a reset
vs.reset();
// Wait 2 seconds after a reset
Thread::sleepSec(2);
// Let's switch back to the main processor
cout << "Switching to the NAV processor" << endl;
vs.switchProcessors(vs.VNPROCESSOR_NAV, mn, fwv);
}
// ******************** Update IMU ********************
if (updateIMU)
{
cout << "********************************************************************************" << endl;
cout << "Updating the IMU firmware on a VN310" << endl;
cout << "********************************************************************************" << endl;
// Let's switch to the target processor to update.
cout << "Switching to the IMU processor to update" << endl;
vs.switchProcessors(vs.VNPROCESSOR_IMU, mn, fwv);
// Open firmware update file
vs.openFirmwareUpdateFile(VN310_IMUFirmwareUpdate);
// Enter bootloader mode
vs.firmwareUpdateMode(true);
// Give the sensor time to reboot into bootloader mode
Thread::sleepSec(1);
// Configure baudrate for firmware update
uint32_t navBaudRate = vs.baudrate();
vs.setFirmwareUpdateBaudRate(FirmwareUpdateBaudrate);
// Calibrate the bootloader by letting it calculate the current baudrate.
std::string bootloaderVersion = vs.calibrateBootloader();
cout << bootloaderVersion << endl;
// Send each record from the firmware update file one at a time
do
{
record = vs.getNextFirwareUpdateRecord();
if (!record.empty())
{
cout << ".";
record.erase(0, 1); // Remove the ':' from the beginning of the line.
vs.writeFirmwareUpdateRecord(record, true);
}
} while (!record.empty());
// Close firmware update file
vs.closeFirmwareUpdateFile();
// Reset baudrate
vs.setFirmwareUpdateBaudRate(navBaudRate);
// Exit bootloader mode. Sleep for 10 seconds
Thread::sleepSec(10);
// Do a reset
vs.reset();
// Wait 2 seconds after a reset
Thread::sleepSec(2);
// Let's switch back to the main processor
cout << "Switching to the NAV processor" << endl;
vs.switchProcessors(vs.VNPROCESSOR_NAV, mn, fwv);
}
// Now disconnect from the sensor since we are finished.
cout << "Disconnecting from sensor" << endl;
vs.disconnect();
}
int main()
{
cout << "Updating the firmware on a VN200" << endl;
manage_each_step_method_for_the_VN200();
cout << "Updating the firmware on a VN300" << endl;
one_call_method_for_the_VN300();
cout << "Updating the firmware on a VN310" << endl;
manage_each_step_method_for_the_VN310();
return 0;
}