To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 7540814f authored by remartin's avatar remartin
Browse files

Added dynamical detection of the correct /dev/ttyACM* file path.

parent 04edea33
......@@ -13,6 +13,7 @@
#include <string>
#include <vector>
#include <ctime>
#include <fstream>
//SERIAL COMMUNICATION PARAMETERS
......@@ -44,9 +45,9 @@ class SerialLight
public:
SerialLight();
void init();
int startConnection(const char* port);
void closeConnection();
bool isConnected(const char* port = "");
//bool isConnected(const char* port = "");
bool isConnected();
bool writeSerialLight(const char* buffer);
......@@ -54,6 +55,9 @@ public:
std::string readSerialLight();
private:
int startConnection(const char* port);
int tty_fd;
struct termios tio;
......
......@@ -3,6 +3,8 @@
// Michael Rogenmoser michaero @ee.ethz.ch
// Tiago Salzmann tiagos @ee.ethz.ch
//
// Modified by remartin to allow distinction between ACM* files.
//
// This file is part of D-FaLL-System.
//
// D-FaLL-System is free software: you can redistribute it and/or modify
......@@ -49,15 +51,17 @@
#include <string>
#include <vector>
#include <ctime>
#include <fstream>
class Serial
{
public:
Serial();
void init();
int startConnection(const char* port);
void closeConnection();
bool isConnected(const char* port = "");
//bool isConnected(const char* port = "");
bool isConnected();
bool writeSerial(const char* buffer);
......@@ -65,6 +69,8 @@ public:
std::string readSerial();
private:
int startConnection(const char* port);
int tty_fd;
struct termios tio;
......
......@@ -244,7 +244,9 @@ void DataListener::_resetLocalisation()
bool DataListener::_startSerialCommunication()
{
if (!serial.startConnection("/dev/ttyACM0")) return false;
//if (!serial.startConnection("/dev/ttyACM0")) return false;
serial.init();
if (!serial.writeSerial("loc100\r")) return false;
locTimer = std::chrono::high_resolution_clock::now();
......
#include "SerialLight.h"
SerialLight::SerialLight(){
_isConnected = false;
_port = "";
......@@ -10,8 +9,40 @@ SerialLight::SerialLight(){
}
void SerialLight::init(){
startConnection("/dev/ttyACM0");
// The Device could be located at ttyACM0 or ttyACM1.
// Need to determine which. Or just hard-code the path.
printf("Searching for the /dev file linked to the Arduino.\n");
// the command: get device infos, suppress error stream, filter for arduino, count lines.
char command[] = "udevadm info /dev/ttyACM0 2> /dev/null | grep arduino | wc -l > rubbishBin.txt";
char path[] = "/dev/ttyACM0";
std::ifstream reader; // use a pipe instead?
int response = 0;
bool foundDevice = false;
for(int gg = 0; gg<10 && !foundDevice; gg++){
command[24] = '0' + gg ; // ACM1 etc.
system(command);
// get the result of the command
reader.open("rubbishBin.txt");
reader >> response;
reader.close();
remove("rubbishBin.txt");
if(response > 0){
path[11] = '0' + gg;
printf("Found Arduino /dev file port at %s. \n", path);
foundDevice = true;
}
}
if(!foundDevice){printf("Can't find the Arduino. Is it plugged in? \n");return;}
startConnection(path);
usleep(500000);
}
......@@ -77,12 +108,17 @@ void SerialLight::closeConnection(){
close(tty_fd); // Port release
}
/*
bool SerialLight::isConnected(const char* port){
if (port != ""){
return (_isConnected && _port == port);
}
return _isConnected;
}
*/
bool SerialLight::isConnected(){
return _isConnected;
}
std::string SerialLight::readSerialLight(){
if (_commands.empty())
......
......@@ -3,6 +3,8 @@
// Michael Rogenmoser michaero @ee.ethz.ch
// Tiago Salzmann tiagos @ee.ethz.ch
//
// Modified by remartin to allow distinction between ACM* files.
//
// This file is part of D-FaLL-System.
//
// D-FaLL-System is free software: you can redistribute it and/or modify
......@@ -45,7 +47,37 @@ Serial::Serial()
void Serial::init()
{
startConnection("/dev/ttyACM0");
// The Device could be located at ttyACM0 or ttyACM1.
// Need to determine which.
printf("Searching for the /dev file linked to the base station.\n");
// the command: get device infos, suppress error stream, filter, count lines.
char command[] = "udevadm info /dev/ttyACM0 2> /dev/null | grep STMicroelectronics | wc -l > rubbishBin.txt";
char path[] = "/dev/ttyACM0";
std::ifstream reader;
int response = 0;
bool foundDevice = false;
for(int gg = 0; gg<10 && !foundDevice; gg++){
command[24] = '0' + gg ; // ACM1 etc.
system(command);
// get the result of the command
reader.open("rubbishBin.txt");
reader >> response;
reader.close();
remove("rubbishBin.txt");
if(response > 0){
path[11] = '0' + gg;
printf("Found base station /dev file port at %s. \n", path);
foundDevice = true;
}
}
if(!foundDevice){printf("Can't find the base station. Is it plugged in? \n");return;}
usleep(500000);
}
......@@ -95,12 +127,17 @@ void Serial::closeConnection()
close(tty_fd); // Port release
}
/*
bool Serial::isConnected(const char* port)
{
if (port != "")
return (_isConnected && _port == port);
return _isConnected;
}
*/
bool Serial::isConnected(){
return _isConnected;
}
std::string Serial::readSerial()
{
......
......@@ -61,14 +61,14 @@ int main(int argc, char* argv[]){
ros::Subscriber enableUWBSubscriber = nodeHandle.subscribe("/my_GUI/enableUWB", 1, anchorArrangementChangedCallback);
// subscribe to the UWB data publisher, which provides info on the target = crazyflie.
ros::Subscriber targetSubscriber = namespaceNodeHandle.subscribe("UWBDataPublisher/UWBData", 100, updateTargetPositionCallback);
ros::Subscriber targetSubscriber = namespaceNodeHandle.subscribe("UWBDataPublisher/UWBData", 1, updateTargetPositionCallback);
ROS_INFO_STREAM("[UWBSpotlight_main] subscribed to target UWB stuff. ");
ROS_INFO_STREAM("[UWBSpotlight_main] started. ");
// Just for testing!
slM.calibrateOrientation();
ros::spin(); // spinning 'till it goes out -> need initialisation procedure on first call?
ROS_WARN("[UWBSpotlight_main] stopped. ");
......
......@@ -18,8 +18,6 @@ using namespace std;
spotlightManager::spotlightManager(){
const char portLocation[] = "/dev/ttyACM0";
defaultChannel = 10; // value between 0 and 255...
messageLength = 14;
......@@ -29,8 +27,8 @@ spotlightManager::spotlightManager(){
dmxValues[hans] = 0;
}
sL.startConnection(portLocation);
if(sL.isConnected(portLocation)){
sL.init();
if(sL.isConnected()){
printf("Could connect to the serial stuff.\n");
}else{
printf("There's no connection.\n");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment