tried to make sensor_receiver restart cleanly
diff --git a/aos/config/configure-prime.txt b/aos/config/configure-prime.txt
index 87b2818..1adaccd 100644
--- a/aos/config/configure-prime.txt
+++ b/aos/config/configure-prime.txt
@@ -67,10 +67,7 @@
11. Set the correct date.
`date` to check if date is correct.
`date -s <date string>` to set it if it isn't.
-12. Make it export UART1 on boot.
- Add the following to /boot/uboot/uenv.txt:
- "optargs=capemgr.enable_partno=BB-UART1"
-13. Fix the locale setup for SSHing in.
+12. Fix the locale setup for SSHing in.
`dpkg-reconfigure locales`, leave it with "en_US.UTF-8" only being
enabled, and then select "None" instead of that for the default in
the second screen.
diff --git a/aos/config/starter b/aos/config/starter
index f7a9c18..1fc05a0 100755
--- a/aos/config/starter
+++ b/aos/config/starter
@@ -69,6 +69,7 @@
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
+ killall starter_loop.sh
start-stop-daemon --stop --quiet --retry=INT/10/KILL/5 --pidfile $PIDFILE
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
@@ -80,7 +81,7 @@
# sleep for some time.
#start-stop-daemon --stop --quiet --oknodo --retry=INT/10/KILL/5
#[ "$?" = 2 ] && return 2
- sleep 10
+ sleep 5
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
diff --git a/aos/linux_code/starter/starter.sh b/aos/linux_code/starter/starter.sh
index 62338af..9d7cc13 100755
--- a/aos/linux_code/starter/starter.sh
+++ b/aos/linux_code/starter/starter.sh
@@ -1,5 +1,7 @@
#!/bin/bash
+echo $$ > /tmp/starter.pid
+
echo '/home/driver/tmp/robot_logs/%e-%s-%p-%t.coredump' > /proc/sys/kernel/core_pattern
#echo $$ > /var/run/`basename $0`.pid IT FORKS AFTER THIS!!!!
diff --git a/bbb_cape/src/bbb/sensor_reader.cc b/bbb_cape/src/bbb/sensor_reader.cc
index f9395c2..312633f 100644
--- a/bbb_cape/src/bbb/sensor_reader.cc
+++ b/bbb_cape/src/bbb/sensor_reader.cc
@@ -39,7 +39,7 @@
const DataStruct *SensorReader::ReadPacket() {
static constexpr ::aos::time::Time kResetTimeout =
- ::aos::time::Time::InSeconds(2.5);
+ ::aos::time::Time::InSeconds(5);
while (true) {
::aos::time::Time next_timeout = last_received_time_ + kResetTimeout;
diff --git a/bbb_cape/src/bbb/uart_reader.cc b/bbb_cape/src/bbb/uart_reader.cc
index a82faa1..9ed0c39 100644
--- a/bbb_cape/src/bbb/uart_reader.cc
+++ b/bbb_cape/src/bbb/uart_reader.cc
@@ -8,7 +8,6 @@
#include "aos/common/logging/logging.h"
// This is the code for receiving data from the cape via UART.
-// NOTE: In order for this to work, you must have the BB-UART1 device tree
// fragment active.
// `su -c "echo BB-UART1 > /sys/devices/bone_capemgr.*/slots"` works, but
// you have to do it every time. It is also possible to set it up to do that
@@ -16,9 +15,49 @@
namespace bbb {
namespace {
+
// TODO(brians): Determine this in some way that allows easy switching for
// testing with /dev/ttyUSB0 for example.
const char *device = "/dev/ttyO1";
+
+bool easy_access(const char *path) {
+ if (access(path, R_OK | W_OK) == 0) return true;
+ if (errno == EACCES || errno == ENOENT) return false;
+ LOG(FATAL, "access(%s, F_OK) failed with %d: %s\n", path, errno,
+ strerror(errno));
+}
+
+int open_device() {
+ if (easy_access(device)) {
+ LOG(INFO, "unexporting BB-UART1\n");
+ if (system("bash -c 'echo -$(cat /sys/devices/bone_capemgr.*/slots"
+ " | fgrep BB-UART1"
+ " | cut -c 2) > /sys/devices/bone_capemgr.*/slots'") ==
+ -1) {
+ LOG(FATAL, "system([disable OMAP UART]) failed with %d: %s\n", errno,
+ strerror(errno));
+ }
+ while (easy_access(device)) {
+ ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.1));
+ }
+ }
+
+ LOG(INFO, "exporting BB-UART1\n");
+ // 2 strings to work around a VIM bug where the indenter locks up when they're
+ // combined as 1...
+ if (system("bash -c 'echo BB-UART1 > /sys/devices/bone_capemgr.*"
+ "/slots'") ==
+ -1) {
+ LOG(FATAL, "system([enable OMAP UART]) failed with %d: %s\n", errno,
+ strerror(errno));
+ }
+ while (!easy_access(device)) {
+ ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.1));
+ }
+
+ return open(device, O_RDWR | O_NOCTTY | O_NONBLOCK);
+}
+
} // namespace
extern "C" {
@@ -32,7 +71,7 @@
} // extern "C"
UartReader::UartReader(int32_t baud_rate)
- : fd_(open(device, O_RDWR | O_NOCTTY | O_NONBLOCK)) {
+ : fd_(open_device()) {
if (fd_ < 0) {
LOG(FATAL, "open(%s, O_RDWR | O_NOCTTY | O_NOBLOCK) failed with %d: %s."