determine_baud_node.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (Apache 2.0)
3  *
4  * Copyright (c) 2019, The MITRE Corporation.
5  * All rights reserved.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * https://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Sections of this project contains content developed by The MITRE Corporation.
20  * If this code is used in a deployment or embedded within another project,
21  * it is requested that you send an email to opensource@mitre.org in order to
22  * let us know where this software is being used.
23  *********************************************************************/
24 
34 // STD
35 #include <iostream>
36 #include <algorithm>
37 
38 // KVH GEO FOG
41 #include "spatial_packets.h"
42 
43 // ROS
44 #include "ros/ros.h"
45 
46 int main(int argc, char **argv)
47 {
48  ros::init(argc, argv, "kvh_geo_fog_3d_driver");
49 
50  ros::NodeHandle node("~");
51 
52  std::set<int> baudRates = {
53  1200, 1800, 2400, 4800, 9600,
54  19200, 57600, 115200, 230400,
55  460800, 500000, 576000, 921600, 1000000};
56 
57  std::string kvhPort("/dev/ttyUSB0");
58  int startingBaud = 1200;
59  // Check if the port has been set on the ros param server
60  if (node.getParam("port", kvhPort))
61  {
62  ROS_INFO_STREAM("Connecting to KVH on port " << kvhPort);
63  }
64  else
65  {
66  ROS_WARN("No port specified by param, defaulting to USB0!");
67  }
68 
69  if (node.getParam("starting_baud", startingBaud))
70  {
71  ROS_INFO_STREAM("Starting baud check at " << startingBaud);
72  }
73  else
74  {
75  ROS_WARN("No starting baud specified. Defaulting to 1200.");
76  }
77 
78 
79 
80  int curBaudRate = kvh::KvhDeviceConfig::FindCurrentBaudRate(kvhPort, startingBaud);
81 
82  if (curBaudRate > 0)
83  {
84  int newBaudRate = 0;
85  std::string possibleRates = "";
86 
87  for(int rate : baudRates)
88  {
89  possibleRates += std::to_string(rate) + "\n";
90  }
91 
92  while (true)
93  {
94  printf("If you wish to modify the baud rate, please input a new rate.\n%s", possibleRates.c_str());
95  printf("********************************\n");
96  printf("Keep in mind that if your port runs on hyper mode, divide your baud rate\n");
97  printf("by a factor of 8. Example, if you wish to enter 921600, enter 115200 (921600/115200)\n");
98  printf("********************************\n");
99  printf("If you wish to exit, please enter a negative number.\n");
100 
101 
102  std::cin >> newBaudRate;
103 
104  if (baudRates.count(newBaudRate) > 0)
105  {
106  if (kvh::KvhDeviceConfig::SetBaudRate(kvhPort, curBaudRate, newBaudRate) != 0)
107  {
108  printf("Unable to set baud rate, please try again or exit.\n");
109  continue;
110  }
111  else
112  {
113  printf("Baud Rate successfully set. Exiting.\n");
114  break;
115  }
116 
117  }
118  else if (newBaudRate > 0)
119  {
120  printf("Please enter a value from the list provided.\n");
121  }
122  else
123  {
124  printf("Exiting program.\n");
125  break;
126  }
127  }
128  }
129  else
130  {
131  printf("Unable to find baud rate. Try a different port.");
132  }
133 
134  printf("Reached the end successfully.\n");
135 }
static int SetBaudRate(std::string _port, int _curBaudRate, int _primaryBaudRate, int _gpioBaudRate=115200, int _auxBaudRate=115200)
This function can be used to set the buad rate independent of the other functions of the driver...
KVH Geo Fog 3D driver class header.
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define ROS_WARN(...)
Helper functions for configuring the hardware.
static int FindCurrentBaudRate(std::string, int)
This function tries each possible setting of baudrates until it either finds one that is receiving pa...
#define ROS_INFO_STREAM(args)
int main(int argc, char **argv)
bool getParam(const std::string &key, std::string &s) const


kvh_geo_fog_3d_driver
Author(s): Trevor Bostic , Zach LaCelle
autogenerated on Fri Jan 24 2020 03:18:17