Merge changes I2721cdc6,Ibb04affb,Ib350b16c,I27b37c9c,I29496ce7, ...
* changes:
Fix message_bridge_server buffer size
Point message_bridge_{client,server} to config.json
Quiet down log_namer when there is no disk
7971 now uses the new IMU plugged in directly
Remove starter dependency on core.
Convert core to use glog
diff --git a/aos/BUILD b/aos/BUILD
index 47de872..2bd49c1 100644
--- a/aos/BUILD
+++ b/aos/BUILD
@@ -5,7 +5,6 @@
name = "prime_binaries",
srcs = [
"//aos:aos_dump",
- "//aos:core",
"//aos/starter",
],
visibility = ["//visibility:public"],
@@ -23,7 +22,6 @@
name = "prime_binaries_stripped",
srcs = [
# starter is hard coded to look for a non-stripped core...
- "//aos:core",
"//aos:aos_dump.stripped",
"//aos/starter",
],
diff --git a/aos/logging/log_namer.cc b/aos/logging/log_namer.cc
index 22db82a..83a39c8 100644
--- a/aos/logging/log_namer.cc
+++ b/aos/logging/log_namer.cc
@@ -101,7 +101,7 @@
char test_device[10];
for (char i = 'a'; i < 'z'; ++i) {
snprintf(test_device, sizeof(test_device), "/dev/sd%c", i);
- LOG(INFO) << "Trying to access" << test_device;
+ VLOG(1) << "Trying to access" << test_device;
if (access(test_device, F_OK) != -1) {
snprintf(device, device_size, "sd%c", i);
return true;
diff --git a/aos/network/message_bridge_client.cc b/aos/network/message_bridge_client.cc
index c44eee0..891a8a1 100644
--- a/aos/network/message_bridge_client.cc
+++ b/aos/network/message_bridge_client.cc
@@ -3,7 +3,7 @@
#include "aos/events/shm_event_loop.h"
#include "aos/init.h"
-DEFINE_string(config, "multinode_pingpong_config.json", "Path to the config.");
+DEFINE_string(config, "config.json", "Path to the config.");
namespace aos {
namespace message_bridge {
diff --git a/aos/network/message_bridge_server.cc b/aos/network/message_bridge_server.cc
index fa5e7c1..ee276d6 100644
--- a/aos/network/message_bridge_server.cc
+++ b/aos/network/message_bridge_server.cc
@@ -4,7 +4,7 @@
#include "gflags/gflags.h"
#include "glog/logging.h"
-DEFINE_string(config, "multinode_pingpong_config.json", "Path to the config.");
+DEFINE_string(config, "config.json", "Path to the config.");
namespace aos {
namespace message_bridge {
diff --git a/aos/network/message_bridge_server_lib.cc b/aos/network/message_bridge_server_lib.cc
index f54e2bf..53afe84 100644
--- a/aos/network/message_bridge_server_lib.cc
+++ b/aos/network/message_bridge_server_lib.cc
@@ -227,17 +227,24 @@
server_connection_.resize(event_loop->configuration()->nodes()->size());
// Seed up all the per-node connection state.
+ // We are making the assumption here that every connection is bidirectional
+ // (data is being sent both ways). This is pretty safe because we are
+ // forwarding timestamps between nodes.
for (std::string_view destination_node_name :
configuration::DestinationNodeNames(event_loop->configuration(),
event_loop->node())) {
// Find the largest connection message so we can size our buffers big enough
- // to receive a connection message.
- max_size = std::max(
- max_size,
- static_cast<int32_t>(MakeConnectMessage(event_loop->configuration(),
- event_loop->node(),
- destination_node_name)
- .size()));
+ // to receive a connection message. The connect message comes from the
+ // client to the server, so swap the node arguments.
+ const int32_t connect_size = static_cast<int32_t>(
+ MakeConnectMessage(event_loop->configuration(),
+ configuration::GetNode(event_loop->configuration(),
+ destination_node_name),
+ event_loop->node()->name()->string_view())
+ .size());
+ VLOG(1) << "Connection to " << destination_node_name << " has size "
+ << connect_size;
+ max_size = std::max(max_size, connect_size);
const Node *destination_node = configuration::GetNode(
event_loop->configuration(), destination_node_name);
@@ -315,6 +322,7 @@
}
// Buffer up the max size a bit so everything fits nicely.
+ LOG(INFO) << "Max message size for all clients is " << max_size;
server_.SetMaxSize(max_size + 100);
statistics_timer_ = event_loop_->AddTimer([this]() { Tick(); });
diff --git a/aos/starter/starter.cc b/aos/starter/starter.cc
index 6860cc4..5d78b5a 100644
--- a/aos/starter/starter.cc
+++ b/aos/starter/starter.cc
@@ -73,7 +73,7 @@
void operator()(event *evt) {
if (evt == NULL) return;
if (event_del(evt) != 0) {
- AOS_LOG(WARNING, "event_del(%p) failed\n", evt);
+ LOG(WARNING) << "event_del(" << evt << ") failed";
}
}
};
@@ -140,16 +140,16 @@
void RemoveWatchFromMap() {
int watch = watch_to_remove_;
if (watch == -1) {
- AOS_CHECK_NE(watch_, -1);
+ CHECK_NE(watch_, -1);
watch = watch_;
}
if (watchers[watch] != this) {
- AOS_LOG(WARNING, "watcher for %s (%p) didn't find itself in the map\n",
- filename_.c_str(), this);
+ LOG(WARNING) << "watcher for " << filename_ << " (" << this
+ << ") didn't find itself in the map";
} else {
watchers.erase(watch);
}
- AOS_LOG(DEBUG, "removed watch ID %d\n", watch);
+ VLOG(1) << "removed watch ID " << watch;
if (watch_to_remove_ == -1) {
watch_ = -1;
} else {
@@ -158,20 +158,19 @@
}
void CreateWatch() {
- AOS_CHECK_EQ(watch_, -1);
+ CHECK_EQ(watch_, -1);
watch_ = inotify_add_watch(notify_fd, filename_.c_str(),
create_ ? IN_CREATE : (IN_ATTRIB |
IN_MODIFY |
IN_DELETE_SELF |
IN_MOVE_SELF));
if (watch_ == -1) {
- AOS_PLOG(FATAL,
- "inotify_add_watch(%d, %s,"
- " %s ? IN_CREATE : (IN_ATTRIB | IN_MODIFY)) failed",
- notify_fd, filename_.c_str(), create_ ? "true" : "false");
+ PLOG(FATAL) << "inotify_add_watch(" << notify_fd << ", " << filename_
+ << ", " << (create_ ? "true" : "false")
+ << " ? IN_CREATE : (IN_ATTRIB | IN_MODIFY)) failed";
}
watchers[watch_] = this;
- AOS_LOG(DEBUG, "watch for %s is %d\n", filename_.c_str(), watch_);
+ VLOG(1) << "watch for " << filename_ << " is " << watch_;
}
// This gets set up as the callback for EV_READ on the inotify file
@@ -180,7 +179,7 @@
unsigned int to_read;
// Use FIONREAD to figure out how many bytes there are to read.
if (ioctl(notify_fd, FIONREAD, &to_read) < 0) {
- AOS_PLOG(FATAL, "FIONREAD(%d, %p) failed", notify_fd, &to_read);
+ PLOG(FATAL) << "FIONREAD(" << notify_fd << ", " << &to_read << ") failed";
}
inotify_event *notifyevt = static_cast<inotify_event *>(malloc(to_read));
const char *end = reinterpret_cast<char *>(notifyevt) + to_read;
@@ -191,8 +190,8 @@
AOS_PLOG(FATAL, "read(%d, %p, %u) failed", notify_fd, notifyevt, to_read);
}
if (static_cast<size_t>(ret) != to_read) {
- AOS_LOG(ERROR, "read(%d, %p, %u) returned %zd instead of %u\n", notify_fd,
- notifyevt, to_read, ret, to_read);
+ LOG(ERROR) << "read(" << notify_fd << ", " << notifyevt << ", " << to_read
+ << ") returned " << ret << " instead of " << to_read;
return;
}
@@ -200,9 +199,10 @@
// multiple events at once.
while (reinterpret_cast<char *>(notifyevt) < end) {
if (watchers.count(notifyevt->wd) != 1) {
- AOS_LOG(WARNING, "couldn't find whose watch ID %d is\n", notifyevt->wd);
+ LOG(WARNING) << "couldn't find whose watch ID " << notifyevt->wd
+ << " is";
} else {
- AOS_LOG(DEBUG, "mask=%" PRIu32 "\n", notifyevt->mask);
+ VLOG(1) << "mask=" << notifyevt->mask;
// If the watch was removed.
if (notifyevt->mask & IN_IGNORED) {
watchers[notifyevt->wd]->WatchDeleted();
@@ -222,7 +222,7 @@
// INotifyReadable calls this method whenever the watch for our file gets
// removed somehow.
void WatchDeleted() {
- AOS_LOG(DEBUG, "watch for %s deleted\n", filename_.c_str());
+ VLOG(1) << "watch for " << filename_ << " deleted";
RemoveWatchFromMap();
CreateWatch();
}
@@ -230,7 +230,7 @@
// INotifyReadable calls this method whenever the watch for our file triggers.
void FileNotified(const char *filename) {
AOS_CHECK_NE(watch_, -1);
- AOS_LOG(DEBUG, "got a notification for %s\n", filename_.c_str());
+ VLOG(1) << "got a notification for " << filename_;
if (!check_filename_.empty()) {
if (filename == NULL) {
@@ -315,8 +315,7 @@
}
if (feof(pipe)) {
- AOS_LOG(FATAL, "`%s` failed. didn't print a whole line\n",
- command.c_str());
+ LOG(FATAL) << "`" << command << "` failed. didn't print a whole line";
}
}
@@ -329,7 +328,7 @@
}
if (child_status != 0) {
- AOS_LOG(FATAL, "`%s` failed. return %d\n", command.c_str(), child_status);
+ LOG(FATAL) << "`" << command << "` failed. return " << child_status;
}
return std::string(result.get());
@@ -349,16 +348,14 @@
time_timeval.tv_usec = usec.count();
}
if (evtimer_add(timeout.release(), &time_timeval) != 0) {
- AOS_LOG(FATAL, "evtimer_add(%p, %p) failed\n", timeout.release(),
- &time_timeval);
+ LOG(FATAL) << "evtimer_add(" << timeout.release() << ", " << &time_timeval
+ << ") failed";
}
}
class Child;
-// This is where all of the Child instances except core live.
+// This is where all of the Child instances live.
std::vector<unique_ptr<Child>> children;
-// A global place to hold on to which child is core.
-unique_ptr<Child> core;
// Represents a child process. It will take care of restarting itself etc.
class Child {
@@ -401,7 +398,7 @@
monotonic_clock::time_point oldest = restarts_.front();
restarts_.pop();
if (monotonic_clock::now() <= kMaxRestartsTime + oldest) {
- AOS_LOG(WARNING, "process %s getting restarted too often\n", name());
+ LOG(WARNING) << "process " << name() << " getting restarted too often";
Timeout(kResumeWait, StaticStart, this);
return;
}
@@ -441,7 +438,7 @@
}
void FileModified() {
- AOS_LOG(DEBUG, "file for %s modified\n", name());
+ LOG(INFO) << "file for " << name() << " modified";
struct timeval restart_time_timeval;
{
::std::chrono::seconds sec =
@@ -455,18 +452,14 @@
}
// This will reset the timeout again if it hasn't run yet.
if (evtimer_add(restart_timeout.get(), &restart_time_timeval) != 0) {
- AOS_LOG(FATAL, "evtimer_add(%p, %p) failed\n", restart_timeout.get(),
- &restart_time_timeval);
+ LOG(FATAL) << "evtimer_add(" << restart_timeout.get() << ", "
+ << &restart_time_timeval << ") failed";
}
waiting_to_restart.insert(this);
}
static void StaticDoRestart(int, short, void *) {
- AOS_LOG(DEBUG, "restarting everything that needs it\n");
- if (waiting_to_restart.find(core.get()) != waiting_to_restart.end()) {
- core->DoRestart();
- waiting_to_restart.erase(core.get());
- }
+ LOG(INFO) << "restarting everything that needs it";
for (auto c : waiting_to_restart) {
c->DoRestart();
}
@@ -483,18 +476,14 @@
¤t_stat);
}
if (current_stat.st_mtime == stat_at_start_.st_mtime) {
- AOS_LOG(DEBUG, "ignoring trigger for %s because mtime didn't change\n",
- name());
+ LOG(INFO) << "ignoring trigger for " << name()
+ << " because mtime didn't change";
return;
}
}
- if (this == core.get()) {
- fprintf(stderr, "Restarting core -> exiting now.\n");
- exit(0);
- }
if (pid_ != -1) {
- AOS_LOG(DEBUG, "sending SIGTERM to child %d to restart it\n", pid_);
+ LOG(INFO) << "sending SIGTERM to child " << pid_ << " to restart it";
if (kill(pid_, SIGTERM) == -1) {
AOS_PLOG(WARNING, "kill(%d, SIGTERM) failed", pid_);
}
@@ -503,7 +492,7 @@
status->old_pid = pid_;
Timeout(kProcessDieTime, StaticCheckDied, status);
} else {
- AOS_LOG(WARNING, "%s restart attempted but not running\n", name());
+ LOG(WARNING) << name() << " restart attempted but not running";
}
}
@@ -516,9 +505,9 @@
// Checks to see if the child using the PID old_pid is still running.
void CheckDied(pid_t old_pid) {
if (pid_ == old_pid) {
- AOS_LOG(WARNING, "child %d refused to die\n", old_pid);
+ LOG(WARNING) << "child " << old_pid << " refused to die";
if (kill(old_pid, SIGKILL) == -1) {
- AOS_PLOG(WARNING, "kill(%d, SIGKILL) failed", old_pid);
+ LOG(WARNING) << "kill(" << old_pid << ", SIGKILL) failed";
}
}
}
@@ -530,8 +519,8 @@
// Actually starts the child.
void Start() {
if (pid_ != -1) {
- AOS_LOG(WARNING, "calling Start() but already have child %d running\n",
- pid_);
+ LOG(WARNING) << "calling Start() but already have child " << pid_
+ << " running";
if (kill(pid_, SIGKILL) == -1) {
AOS_PLOG(WARNING, "kill(%d, SIGKILL) failed", pid_);
return;
@@ -571,7 +560,7 @@
if (pid_ == -1) {
AOS_PLOG(FATAL, "forking to run \"%s\" failed", binary_.c_str());
}
- AOS_LOG(DEBUG, "started \"%s\" successfully\n", binary_.c_str());
+ LOG(INFO) << "started \"" << binary_ << "\" successfully";
}
// A history of the times that this process has been restarted.
@@ -658,10 +647,6 @@
}
}
- if (pid == core->pid()) {
- return core;
- }
-
static const unique_ptr<Child> kNothing;
return kNothing;
}
@@ -688,44 +673,40 @@
if (child) {
switch (infop.si_code) {
case CLD_EXITED:
- AOS_LOG(WARNING, "child %d (%s) exited with status %d\n", pid,
- child->name(), status);
+ LOG(WARNING) << "child " << pid << " (" << child->name()
+ << ") exited with status " << status;
break;
case CLD_DUMPED:
- AOS_LOG(INFO,
- "child %d actually dumped core. "
- "falling through to killed by signal case\n",
- pid);
+ LOG(INFO) << "child " << pid
+ << " actually dumped core. falling through to killed by "
+ "signal case";
[[fallthrough]];
/* FALLTHRU */
case CLD_KILLED:
// If somebody (possibly us) sent it SIGTERM that means that they just
// want it to stop, so it stopping isn't a WARNING.
- AOS_LOG((status == SIGTERM) ? DEBUG : WARNING,
- "child %d (%s) was killed by signal %d (%s)\n", pid,
- child->name(), status, aos_strsignal(status));
+ ((status == SIGTERM) ? LOG(INFO) : LOG(WARNING))
+ << "child " << pid << " (" << child->name()
+ << ") was killed by signal " << status << " ("
+ << aos_strsignal(status) << ")";
break;
case CLD_STOPPED:
- AOS_LOG(WARNING,
- "child %d (%s) was stopped by signal %d "
- "(giving it a SIGCONT(%d))\n",
- pid, child->name(), status, SIGCONT);
+ LOG(WARNING) << "child " << pid << " (" << child->name()
+ << ") was stopped by signal " << status
+ << " (giving it a SIGCONT(" << SIGCONT << "))";
kill(pid, SIGCONT);
continue;
default:
- AOS_LOG(WARNING, "something happened to child %d (%s) (killing it)\n",
- pid, child->name());
+ LOG(WARNING) << "something happened to child " << pid << " ("
+ << child->name() << ") (killing it)";
kill(pid, SIGKILL);
continue;
}
} else {
- AOS_LOG(WARNING, "couldn't find a Child for pid %d\n", pid);
+ LOG(WARNING) << "couldn't find a Child for pid " << pid;
return;
}
- if (child == core) {
- AOS_LOG(FATAL, "core died\n");
- }
child->ProcessDied();
}
}
@@ -734,7 +715,7 @@
// start from main to Run.
const char *child_list_file;
-void Run(void *watch);
+void Run();
void Main() {
logging::Init();
@@ -777,44 +758,15 @@
libevent_base = EventBaseUniquePtr(event_base_new());
- std::string core_touch_file = "/tmp/starter.";
- core_touch_file += std::to_string(static_cast<intmax_t>(getpid()));
- core_touch_file += ".core_touch_file";
- const int result =
- ::aos::util::RunCommand(("touch '" + core_touch_file + "'").c_str());
- if (result == -1) {
- AOS_PLOG(FATAL, "running `touch '%s'` failed\n", core_touch_file.c_str());
- } else if (!WIFEXITED(result) || WEXITSTATUS(result) != 0) {
- AOS_LOG(FATAL, "`touch '%s'` gave result %x\n", core_touch_file.c_str(),
- result);
- }
- FileWatch core_touch_file_watch(core_touch_file, Run, NULL);
- core = unique_ptr<Child>(
- new Child("core " + core_touch_file));
-
- FILE *pid_file = fopen("/tmp/starter.pid", "w");
- if (pid_file == NULL) {
- AOS_PLOG(FATAL, "fopen(\"/tmp/starter.pid\", \"w\") failed");
- } else {
- if (fprintf(pid_file, "%d", core->pid()) == -1) {
- AOS_PLOG(WARNING, "fprintf(%p, \"%%d\", %d) failed", pid_file,
- core->pid());
- }
- fclose(pid_file);
- }
-
- AOS_LOG(INFO, "waiting for %s to appear\n", core_touch_file.c_str());
+ Run();
event_base_dispatch(libevent_base.get());
- AOS_LOG(FATAL, "event_base_dispatch(%p) returned\n", libevent_base.get());
+ LOG(FATAL) << "event_base_dispatch(" << libevent_base.get() << ") returned";
}
// This is the callback for when core creates the file indicating that it has
// started.
-void Run(void *watch) {
- // Make it so it doesn't keep on seeing random changes in /tmp.
- static_cast<FileWatch *>(watch)->RemoveWatch();
-
+void Run() {
// It's safe now because core is up.
aos::InitNRT();
@@ -827,7 +779,7 @@
break;
}
if (list_file.rdstate() != 0) {
- AOS_LOG(FATAL, "reading input file %s failed\n", child_list_file);
+ LOG(FATAL) << "reading input file " << child_list_file << " failed";
}
children.push_back(unique_ptr<Child>(new Child(child_name)));
}
diff --git a/y2020/constants.cc b/y2020/constants.cc
index a35798f..90129dd 100644
--- a/y2020/constants.cc
+++ b/y2020/constants.cc
@@ -26,7 +26,6 @@
const uint16_t kCompTeamNumber = 971;
const uint16_t kPracticeTeamNumber = 9971;
-const uint16_t kCodingRobotTeamNumber = 7971;
const Values *DoGetValuesForTeam(uint16_t team) {
Values *const r = new Values();
@@ -120,7 +119,7 @@
turret_params->zeroing_constants.measured_absolute_position = 0.0;
break;
- case kCodingRobotTeamNumber:
+ case Values::kCodingRobotTeamNumber:
hood->zeroing_constants.measured_absolute_position = 0.0;
intake->zeroing_constants.measured_absolute_position = 0.0;
diff --git a/y2020/constants.h b/y2020/constants.h
index 39f6e36..7fbb704 100644
--- a/y2020/constants.h
+++ b/y2020/constants.h
@@ -20,6 +20,8 @@
namespace constants {
struct Values {
+ static const uint16_t kCodingRobotTeamNumber = 7971;
+
static const int kZeroingSampleSize = 200;
static constexpr double kDrivetrainCyclesPerRevolution() { return 512.0; }
diff --git a/y2020/wpilib_interface.cc b/y2020/wpilib_interface.cc
index a1083eb..b336fd7 100644
--- a/y2020/wpilib_interface.cc
+++ b/y2020/wpilib_interface.cc
@@ -25,6 +25,7 @@
#include "aos/init.h"
#include "aos/logging/logging.h"
#include "aos/make_unique.h"
+#include "aos/network/team_number.h"
#include "aos/realtime.h"
#include "aos/robot_state/robot_state_generated.h"
#include "aos/time/time.h"
@@ -504,9 +505,19 @@
// Note: If ADIS16470 is plugged in directly to the roboRIO SPI port without
// the Spartan Board, then trigger is on 26, reset 27, and chip select is
// CS0.
- auto imu_trigger = make_unique<frc::DigitalInput>(0);
- auto imu_reset = make_unique<frc::DigitalOutput>(1);
- auto spi = make_unique<frc::SPI>(frc::SPI::Port::kOnboardCS2);
+ frc::SPI::Port spi_port = frc::SPI::Port::kOnboardCS2;
+ std::unique_ptr<frc::DigitalInput> imu_trigger;
+ std::unique_ptr<frc::DigitalOutput> imu_reset;
+ if (::aos::network::GetTeamNumber() ==
+ constants::Values::kCodingRobotTeamNumber) {
+ imu_trigger = make_unique<frc::DigitalInput>(26);
+ imu_reset = make_unique<frc::DigitalOutput>(27);
+ spi_port = frc::SPI::Port::kOnboardCS0;
+ } else {
+ imu_trigger = make_unique<frc::DigitalInput>(0);
+ imu_reset = make_unique<frc::DigitalOutput>(1);
+ }
+ auto spi = make_unique<frc::SPI>(spi_port);
frc971::wpilib::ADIS16470 imu(&sensor_reader_event_loop, spi.get(),
imu_trigger.get(), imu_reset.get());
sensor_reader.set_imu(&imu);