Skip to content

Commit

Permalink
AP_HAL_SITL: sim: namespace for specifying SITL devices from cmdline
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker authored and rmackay9 committed Mar 27, 2018
1 parent a5a36c0 commit 1151d76
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libraries/AP_HAL_SITL/SITL_State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ void SITL_State::wait_clock(uint64_t wait_time_usec)
}
}

#define streq(a, b) (!strcmp(a, b))
int SITL_State::sim_fd(const char *name, const char *arg)
{
AP_HAL::panic("unknown simulated device: %s", name);
}

#ifndef HIL_MODE
/*
check for a SITL RC input packet
Expand Down
4 changes: 4 additions & 0 deletions libraries/AP_HAL_SITL/SITL_State.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class HALSITL::SITL_State {
return _base_port;
}

// create a file desciptor attached to a virtual device; type of
// device is given by name parameter
int sim_fd(const char *name, const char *arg);

bool use_rtscts(void) const {
return _use_rtscts;
}
Expand Down
7 changes: 7 additions & 0 deletions libraries/AP_HAL_SITL/UARTDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void UARTDriver::begin(uint32_t baud, uint16_t rxSpace, uint16_t txSpace)
tcp:0:wait // tcp listen on use base_port + 0
tcpclient:192.168.2.15:5762
uart:/dev/ttyUSB0:57600
sim:ParticleSensor_SDS021:
*/
char *saveptr = nullptr;
char *s = strdup(path);
Expand All @@ -89,6 +90,12 @@ void UARTDriver::begin(uint32_t baud, uint16_t rxSpace, uint16_t txSpace)
_uart_path = strdup(args1);
_uart_baudrate = baudrate;
_uart_start_connection();
} else if (strcmp(devtype, "sim") == 0) {
::printf("SIM connection %s:%s\n", args1, args2);
if (!_connected) {
_connected = true;
_fd = _sitlState->sim_fd(args1, args2);
}
} else {
AP_HAL::panic("Invalid device path: %s", path);
}
Expand Down

0 comments on commit 1151d76

Please sign in to comment.