initial
This commit is contained in:
24
vnproglib/c/examples/firmware_update/CMakeLists.txt
Normal file
24
vnproglib/c/examples/firmware_update/CMakeLists.txt
Normal file
@ -0,0 +1,24 @@
|
||||
cmake_minimum_required(VERSION 2.8.4)
|
||||
project(firmware_update)
|
||||
|
||||
add_subdirectory(../.. libvnc)
|
||||
|
||||
set(CMAKE_SUPPRESS_REGENERATION TRUE)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
|
||||
if (CMAKE_COMPILER_IS_GNUCC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpedantic -std=c90")
|
||||
endif()
|
||||
|
||||
set(SOURCE_FILES
|
||||
main.c)
|
||||
|
||||
include_directories("../../include")
|
||||
|
||||
add_executable(sensor ${SOURCE_FILES})
|
||||
|
||||
target_link_libraries(sensor LINK_PUBLIC libvnc)
|
||||
|
||||
if (UNIX OR APPLE)
|
||||
target_link_libraries(sensor LINK_PUBLIC pthread)
|
||||
endif()
|
||||
20
vnproglib/c/examples/firmware_update/Makefile
Normal file
20
vnproglib/c/examples/firmware_update/Makefile
Normal file
@ -0,0 +1,20 @@
|
||||
CC = gcc
|
||||
INCLUDES = -I ../../include
|
||||
CFLAGS = -Wall
|
||||
|
||||
all: firmware_update
|
||||
|
||||
clean:
|
||||
rm -f main.o
|
||||
rm -f firmware_update
|
||||
cd ../.. && make clean
|
||||
|
||||
firmware_update: main.o proglib
|
||||
$(CC) -o firmware_update main.o -L ../../build -lvnc -lpthread
|
||||
|
||||
proglib:
|
||||
cd ../.. && make
|
||||
|
||||
main.o: main.c
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
|
||||
|
||||
@ -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 Example", "Firmware Update Example.vcxproj", "{615ED95B-A8FD-44D7-A8BF-3879D236C3FE}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libvnc", "..\..\..\..\projects\vs2017\libvnc.vcxproj", "{E237AE2C-CE1B-39F5-B931-3C0E53353E53}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{615ED95B-A8FD-44D7-A8BF-3879D236C3FE}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{615ED95B-A8FD-44D7-A8BF-3879D236C3FE}.Debug|x86.Build.0 = Debug|Win32
|
||||
{615ED95B-A8FD-44D7-A8BF-3879D236C3FE}.Release|x86.ActiveCfg = Release|Win32
|
||||
{615ED95B-A8FD-44D7-A8BF-3879D236C3FE}.Release|x86.Build.0 = Release|Win32
|
||||
{E237AE2C-CE1B-39F5-B931-3C0E53353E53}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{E237AE2C-CE1B-39F5-B931-3C0E53353E53}.Debug|x86.Build.0 = Debug|Win32
|
||||
{E237AE2C-CE1B-39F5-B931-3C0E53353E53}.Release|x86.ActiveCfg = Release|Win32
|
||||
{E237AE2C-CE1B-39F5-B931-3C0E53353E53}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {7AEE4A97-D29B-418A-A35F-75821820433A}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@ -0,0 +1,112 @@
|
||||
<?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>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{615ed95b-a8fd-44d7-a8bf-3879d236c3fe}</ProjectGuid>
|
||||
<RootNamespace>FirmwareUpdateExample</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>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</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>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<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|x64'">
|
||||
<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>C:\Workspace\customer-source-code-tools\Programming Library\c\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.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\projects\vs2017\libvnc.vcxproj">
|
||||
<Project>{e237ae2c-ce1b-39f5-b931-3c0e53353e53}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
||||
@ -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.
|
||||
|
||||
|
||||
|
||||
340
vnproglib/c/examples/firmware_update/main.c
Normal file
340
vnproglib/c/examples/firmware_update/main.c
Normal file
@ -0,0 +1,340 @@
|
||||
#include <stdio.h>
|
||||
|
||||
/* Include files needed to do firmware updates. */
|
||||
#include "vn/sensors.h"
|
||||
|
||||
int processErrorReceived(char* errorMessage, VnError errorCode);
|
||||
|
||||
/*
|
||||
Firmware Update Protocol
|
||||
1. Switch to target processor
|
||||
2. Enter Update Mode in Bootloader
|
||||
3. Set Baud Rate
|
||||
4. Verify Acknowledgement
|
||||
5. Send firmware update one record at a time
|
||||
6. Wait for Acknowledgement before sending next record
|
||||
7. Exit Update Mode in Bootloader
|
||||
8. Switch to next target processor or return back to the NAV processor
|
||||
*/
|
||||
|
||||
int one_call_method_for_the_VN300(void)
|
||||
{
|
||||
|
||||
VnSensor vs;
|
||||
char modelNumber[30];
|
||||
char firmwareVersion[30];
|
||||
VnError error;
|
||||
|
||||
/* 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 char SENSOR_PORT[] = "COM4"; /* Windows format for physical and virtual (USB) serial port. */
|
||||
/*const char SENSOR_PORT[] = "/dev/ttyS1"; */ /* Linux format for physical serial port. */
|
||||
/*const char SENSOR_PORT[] = "/dev/ttyUSB0"; */ /* Linux format for virtual (USB) serial port. */
|
||||
/*const char SENSOR_PORT[] = "/dev/tty.usbserial-FTXXXXXX"; */ /* Mac OS X format for virtual (USB) serial port. */
|
||||
/*const char SENSOR_PORT[] = "/dev/ttyS0"; */ /* CYGWIN format. Usually the Windows COM port number minus 1. This would connect to COM1. */
|
||||
const uint32_t SENSOR_BAUDRATE = 115200;
|
||||
const uint32_t FIRMWARE_UPDATE_BAUDRATE = 115200; /* This can be different than the sensor baudrate, recommend 115200 or slower for reliability */
|
||||
const char VN300_NAVFirmwareUpdate[] = "../../FirmwareUpdates/VN300_NAV_v0.5.0.0.vnx";
|
||||
const char VN300_GPSFirmwareUpdate[] = "../../FirmwareUpdates/VN300_GPS_v0.5.0.0.vnx";
|
||||
|
||||
|
||||
/* We first need to initialize our VnSensor structure. */
|
||||
printf("Initialize VN Sensor.\n");
|
||||
VnSensor_initialize(&vs);
|
||||
|
||||
/* Now connect to our sensor. */
|
||||
printf("Connect to VN Sensor.\n");
|
||||
if ((error = VnSensor_connect(&vs, SENSOR_PORT, SENSOR_BAUDRATE)) != E_NONE)
|
||||
return processErrorReceived("Error connecting to sensor.", error);
|
||||
|
||||
/* Let's query the sensor's model number. */
|
||||
printf("Query VN Sensor Model.\n");
|
||||
if ((error = VnSensor_readModelNumber(&vs, modelNumber, sizeof(modelNumber))) != E_NONE)
|
||||
return processErrorReceived("Error reading model number.", error);
|
||||
printf("Model Number: %s\n", modelNumber);
|
||||
|
||||
/* Let's query the sensor's firmware version. */
|
||||
printf("Query VN Sensor Firmware Version.\n");
|
||||
if ((error = VnSensor_readFirmwareVersion(&vs, firmwareVersion, sizeof(firmwareVersion))) != E_NONE)
|
||||
return processErrorReceived("Error reading firmware version.", error);
|
||||
printf("Firmware Version: %s\n", firmwareVersion);
|
||||
|
||||
/* Let's update the firmware on the NAV processor. */
|
||||
printf("NAV Firmware Update VN Sensor with %s.\n", VN300_NAVFirmwareUpdate);
|
||||
if ((error = VnSensor_firmwareUpdate(&vs, FIRMWARE_UPDATE_BAUDRATE, VN300_NAVFirmwareUpdate)) != E_NONE)
|
||||
return processErrorReceived("Error updating firmware.", error);
|
||||
|
||||
/* Let's switch to the target processor to update. */
|
||||
printf("Switch processors on VN Sensor.\n");
|
||||
if ((error = VnSensor_switchProcessors(&vs, VNPROCESSOR_GPS, modelNumber, firmwareVersion)) != E_NONE)
|
||||
return processErrorReceived("Error switching processors.", error);
|
||||
|
||||
/* Let's update the firmware on the GPS processor. */
|
||||
printf("GPS Firmware Update VN Sensor with %s.\n", VN300_GPSFirmwareUpdate);
|
||||
if ((error = VnSensor_firmwareUpdate(&vs, FIRMWARE_UPDATE_BAUDRATE, VN300_GPSFirmwareUpdate)) != E_NONE)
|
||||
return processErrorReceived("Error updating firmware.", error);
|
||||
|
||||
/* Now disconnect from the sensor since we are finished. */
|
||||
printf("Disconnect from VN Sensor.\n");
|
||||
if ((error = VnSensor_disconnect(&vs)) != E_NONE)
|
||||
return processErrorReceived("Error disconnecting from sensor.", error);
|
||||
|
||||
/* Depending on the sensor, a power cycle may be needed instead of a reset. */
|
||||
printf("Power Cycle the sensor.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int manage_each_step_for_the_VN200(void)
|
||||
{
|
||||
VnSensor vs;
|
||||
char modelNumber[30];
|
||||
char firmwareVersion[30];
|
||||
VnError error;
|
||||
int RecordSize = MAXFIRMWAREUPDATERECORDSIZE;
|
||||
char record[MAXFIRMWAREUPDATERECORDSIZE];
|
||||
bool stillGoing = true;
|
||||
|
||||
/* This example walks through using the VectorNav C Library to connect to
|
||||
* and interact with a VectorNav sensor using the VnSensor structure. */
|
||||
|
||||
/* 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 char SENSOR_PORT[] = "COM3"; /* Windows format for physical and virtual (USB) serial port. */
|
||||
/*const char SENSOR_PORT[] = "/dev/ttyS1"; */ /* Linux format for physical serial port. */
|
||||
/*const char SENSOR_PORT[] = "/dev/ttyUSB0"; */ /* Linux format for virtual (USB) serial port. */
|
||||
/*const char SENSOR_PORT[] = "/dev/tty.usbserial-FTXXXXXX"; */ /* Mac OS X format for virtual (USB) serial port. */
|
||||
/*const char SENSOR_PORT[] = "/dev/ttyS0"; */ /* CYGWIN format. Usually the Windows COM port number minus 1. This would connect to COM1. */
|
||||
const uint32_t SENSOR_BAUDRATE = 115200;
|
||||
const uint32_t FIRMWARE_UPDATE_BAUDRATE = 115200; /* This can be different than the sensor baudrate, recommend 115200 or slower for reliability */
|
||||
const char VN200FirmwareUpdate[] = "../../FirmwareUpdates/VN200_NAV_v2.0.0.1.vnx";
|
||||
|
||||
/* We first need to initialize our VnSensor structure. */
|
||||
printf("Initialize VN Sensor.\n");
|
||||
VnSensor_initialize(&vs);
|
||||
|
||||
/* Now connect to our sensor. */
|
||||
printf("Connect to VN Sensor.\n");
|
||||
if ((error = VnSensor_connect(&vs, SENSOR_PORT, SENSOR_BAUDRATE)) != E_NONE)
|
||||
return processErrorReceived("Error connecting to sensor.", error);
|
||||
|
||||
/* Let's query the sensor's model number. */
|
||||
printf("Query VN Sensor Model.\n");
|
||||
if ((error = VnSensor_readModelNumber(&vs, modelNumber, sizeof(modelNumber))) != E_NONE)
|
||||
return processErrorReceived("Error reading model number.", error);
|
||||
printf("Model Number: %s\n", modelNumber);
|
||||
|
||||
/* Let's query the sensor's firmware version. */
|
||||
printf("Query VN Sensor Firmware Version.\n");
|
||||
if ((error = VnSensor_readFirmwareVersion(&vs, firmwareVersion, sizeof(firmwareVersion))) != E_NONE)
|
||||
return processErrorReceived("Error reading firmware version.", error);
|
||||
printf("Firmware Version: %s\n", firmwareVersion);
|
||||
|
||||
/* Open Firmware Update File*/
|
||||
FILE* firmwareUpdateFile = VnSensor_openFirmwareUpdateFile(VN200FirmwareUpdate);
|
||||
|
||||
/* Enter the bootloader */
|
||||
if((error = VnSensor_firmwareUpdateMode(&vs, true)) != E_NONE)
|
||||
return processErrorReceived("Failed to enter firmware update mode.", error);
|
||||
|
||||
/* Give the processor some time to reboot */
|
||||
VnThread_sleepMs(1000);
|
||||
|
||||
/* Change the baud rate for updating the firmware */
|
||||
if((error = VnSerialPort_changeBaudrate(&(vs.serialPort), FIRMWARE_UPDATE_BAUDRATE)) != E_NONE)
|
||||
return processErrorReceived("Failed to change the firmware update baud rate.", error);
|
||||
|
||||
/* Calibrate the Bootloader before sending records */
|
||||
VnSensor_calibrateBootloader(&vs);
|
||||
|
||||
/* Write the firmware update file to the sensor, one record at a time */
|
||||
while (stillGoing)
|
||||
{
|
||||
stillGoing = VnSensor_getNextFirmwareUpdateRecord(firmwareUpdateFile, record, RecordSize);
|
||||
if (stillGoing)
|
||||
{
|
||||
//printf("Send: %s\n", record);
|
||||
printf(".");
|
||||
if((error = VnSensor_writeFirmwareUpdateRecord(&vs, record)) != E_BOOTLOADER_NONE)
|
||||
{
|
||||
processErrorReceived("Failed to write record to firmware.", error);
|
||||
stillGoing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
/* Switch the baud rate back to the original setting */
|
||||
if((error = VnSerialPort_changeBaudrate(&(vs.serialPort), SENSOR_BAUDRATE)) != E_NONE)
|
||||
return processErrorReceived("Failed to change baud rate back.", error);
|
||||
|
||||
/* Close the firmware update file */
|
||||
VnSensor_closeFirmwareUpdateFile(firmwareUpdateFile);
|
||||
|
||||
/* Exit Bootloader mode. Just sleep for 10 seconds */
|
||||
VnThread_sleepMs(10000);
|
||||
|
||||
/* Do a reset */
|
||||
VnSensor_reset(&vs, true);
|
||||
|
||||
/* Wait 2 seconds for the reset to finish */
|
||||
VnThread_sleepMs(2000);
|
||||
|
||||
/* Now disconnect from the sensor since we are finished. */
|
||||
printf("Disconnect from VN Sensor.\n");
|
||||
if ((error = VnSensor_disconnect(&vs)) != E_NONE)
|
||||
return processErrorReceived("Error disconnecting from sensor.", error);
|
||||
|
||||
/* Depending on the sensor, a power cycle may be needed instead of a reset. */
|
||||
printf("Power Cycle the sensor.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int one_call_method_for_the_VN310(void)
|
||||
{
|
||||
|
||||
VnSensor vs;
|
||||
char modelNumber[30];
|
||||
char firmwareVersion[30];
|
||||
VnError error;
|
||||
int RecordSize = MAXFIRMWAREUPDATERECORDSIZE;
|
||||
char record[MAXFIRMWAREUPDATERECORDSIZE];
|
||||
bool stillGoing = true;
|
||||
|
||||
/* This example walks through using the VectorNav C Library to connect to
|
||||
* and interact with a VectorNav sensor using the VnSensor structure. */
|
||||
|
||||
/* 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 char SENSOR_PORT[] = "COM6"; /* Windows format for physical and virtual (USB) serial port. */
|
||||
/*const char SENSOR_PORT[] = "/dev/ttyS1"; */ /* Linux format for physical serial port. */
|
||||
/*const char SENSOR_PORT[] = "/dev/ttyUSB0"; */ /* Linux format for virtual (USB) serial port. */
|
||||
/*const char SENSOR_PORT[] = "/dev/tty.usbserial-FTXXXXXX"; */ /* Mac OS X format for virtual (USB) serial port. */
|
||||
/*const char SENSOR_PORT[] = "/dev/ttyS0"; */ /* CYGWIN format. Usually the Windows COM port number minus 1. This would connect to COM1. */
|
||||
const uint32_t SENSOR_BAUDRATE = 115200;
|
||||
const uint32_t FIRMWARE_UPDATE_BAUDRATE = 115200; /* This can be different than the sensor baudrate, recommend 115200 or slower for reliability */
|
||||
const char VN310_NAVFirmwareUpdate[] = "../../FirmwareUpdates/VN310_NAV_v0.8.1.0.vnx";
|
||||
const char VN310_GPSFirmwareUpdate[] = "../../FirmwareUpdates/VN310_GPS_v0.8.1.0.vnx";
|
||||
const char VN310_IMUFirmwareUpdate[] = "../../FirmwareUpdates/VN310_IMU_v2.5.1.0.vnx";
|
||||
|
||||
bool updateNAV = true;
|
||||
bool updateGPS = true;
|
||||
bool updateIMU = true;
|
||||
|
||||
|
||||
/* We first need to initialize our VnSensor structure. */
|
||||
printf("Initialize VN Sensor.\n");
|
||||
VnSensor_initialize(&vs);
|
||||
|
||||
/* Now connect to our sensor. */
|
||||
printf("Connect to VN Sensor.\n");
|
||||
if ((error = VnSensor_connect(&vs, SENSOR_PORT, SENSOR_BAUDRATE)) != E_NONE)
|
||||
return processErrorReceived("Error connecting to sensor.", error);
|
||||
|
||||
/* Let's query the sensor's model number. */
|
||||
printf("Query VN Sensor Model.\n");
|
||||
if ((error = VnSensor_readModelNumber(&vs, modelNumber, sizeof(modelNumber))) != E_NONE)
|
||||
return processErrorReceived("Error reading model number.", error);
|
||||
printf("Model Number: %s\n", modelNumber);
|
||||
|
||||
/* Let's query the sensor's firmware version. */
|
||||
printf("Query VN Sensor Firmware Version.\n");
|
||||
if ((error = VnSensor_readFirmwareVersion(&vs, firmwareVersion, sizeof(firmwareVersion))) != E_NONE)
|
||||
return processErrorReceived("Error reading firmware version.", error);
|
||||
printf("Firmware Version: %s\n", firmwareVersion);
|
||||
|
||||
if (updateNAV)
|
||||
{
|
||||
/* Let's update the firmware on the NAV processor. */
|
||||
printf("NAV Firmware Update VN Sensor with %s.\n", VN310_NAVFirmwareUpdate);
|
||||
if ((error = VnSensor_firmwareUpdate(&vs, FIRMWARE_UPDATE_BAUDRATE, VN310_NAVFirmwareUpdate)) != E_NONE)
|
||||
return processErrorReceived("Error updating firmware.", error);
|
||||
|
||||
/* Need to switch back to NAV befor we leave*/
|
||||
printf("Switch to NAV processor.\n");
|
||||
if ((error = VnSensor_switchProcessors(&vs, VNPROCESSOR_NAV, modelNumber, firmwareVersion)) != E_NONE)
|
||||
return processErrorReceived("Error switching processors.", error);
|
||||
}
|
||||
|
||||
if (updateGPS)
|
||||
{
|
||||
/* Let's switch to the target processor to update. */
|
||||
printf("Switch to GPS processor.\n");
|
||||
if ((error = VnSensor_switchProcessors(&vs, VNPROCESSOR_GPS, modelNumber, firmwareVersion)) != E_NONE)
|
||||
return processErrorReceived("Error switching processors.", error);
|
||||
|
||||
/* Let's update the firmware on the GPS processor. */
|
||||
printf("GPS Firmware Update VN Sensor with %s.\n", VN310_GPSFirmwareUpdate);
|
||||
if ((error = VnSensor_firmwareUpdate(&vs, FIRMWARE_UPDATE_BAUDRATE, VN310_GPSFirmwareUpdate)) != E_NONE)
|
||||
return processErrorReceived("Error updating firmware.", error);
|
||||
|
||||
/* Need to switch back to NAV since we cannot switch directly to IMU from GPS. */
|
||||
printf("Switch to NAV processor.\n");
|
||||
if ((error = VnSensor_switchProcessors(&vs, VNPROCESSOR_NAV, modelNumber, firmwareVersion)) != E_NONE)
|
||||
return processErrorReceived("Error switching processors.", error);
|
||||
}
|
||||
|
||||
if (updateIMU)
|
||||
{
|
||||
/* Let's switch to the target processor to update. */
|
||||
printf("Switch to IMU processor.\n");
|
||||
if ((error = VnSensor_switchProcessors(&vs, VNPROCESSOR_IMU, modelNumber, firmwareVersion)) != E_NONE)
|
||||
return processErrorReceived("Error switching processors.", error);
|
||||
|
||||
/* Let's update the firmware on the GPS processor. */
|
||||
printf("IMU Firmware Update VN Sensor with %s.\n", VN310_IMUFirmwareUpdate);
|
||||
if ((error = VnSensor_firmwareUpdate(&vs, FIRMWARE_UPDATE_BAUDRATE, VN310_IMUFirmwareUpdate)) != E_NONE)
|
||||
return processErrorReceived("Error updating firmware.", error);
|
||||
|
||||
/* Need to switch back to NAV befor we leave*/
|
||||
printf("Switch to NAV processor.\n");
|
||||
if ((error = VnSensor_switchProcessors(&vs, VNPROCESSOR_NAV, modelNumber, firmwareVersion)) != E_NONE)
|
||||
return processErrorReceived("Error switching processors.", error);
|
||||
}
|
||||
/* Now disconnect from the sensor since we are finished. */
|
||||
printf("Disconnect from VN Sensor.\n");
|
||||
if ((error = VnSensor_disconnect(&vs)) != E_NONE)
|
||||
return processErrorReceived("Error disconnecting from sensor.", error);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int processErrorReceived(char* errorMessage, VnError errorCode)
|
||||
{
|
||||
char errorCodeStr[100];
|
||||
strFromVnError(errorCodeStr, errorCode);
|
||||
printf("%s\nERROR: %s\n", errorMessage, errorCodeStr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
printf("********************************************************************************\n");
|
||||
printf("Updating the firmware on a VN200.\n");
|
||||
printf("********************************************************************************\n");
|
||||
retval = manage_each_step_for_the_VN200();
|
||||
|
||||
printf("********************************************************************************\n");
|
||||
printf("Updating the firmware on a VN300.\n");
|
||||
printf("********************************************************************************\n");
|
||||
retval = one_call_method_for_the_VN300();
|
||||
|
||||
printf("********************************************************************************\n");
|
||||
printf("Updating the firmware on a VN310.\n");
|
||||
printf("********************************************************************************\n");
|
||||
retval = one_call_method_for_the_VN310();
|
||||
|
||||
return retval;
|
||||
}
|
||||
Reference in New Issue
Block a user