#include "main_emit.h"
/**
- * Communcation overview:
+ * Communication overview:
*
* Initialization:
* bbb --init1--> mbed1
* Initialization:
* Each mbed is initialized by the BBB by receiving an initialization
* message. The Device ID must be non-zero, and is saved for future
- * messages. If the device is already initialized and a recevied Device ID
+ * messages. If the device is already initialized and a received Device ID
* does not match the configured Device ID, the messages is relayed to the
* second mbed.
*
*/
void comm_send_event(uint16_t event, uint64_t local)
{
- //time_printf("event received", local);
+ time_printf("event received", local);
// Convert timestamp
uint64_t world = time_to_world(local);
body->control & MSG_CTL_VALID_START ? "START" : "start",
body->control & MSG_CTL_VALID_PERIOD ? "PERIOD" : "period",
body->control & MSG_CTL_VALID_WORLD ? "WORLD" : "world",
- body->control & MSG_CTL_VALID_SYNC ? "SYNC" : "sync");
+ body->control & MSG_CTL_RELAY_MODE ? "RELAY" : "relay",
+ body->control & MSG_CTL_BEGIN_SYNC ? "SYNC" : "sync");
sirq_printf(" dev -- %d\r\n", body->device);
time_printf(" start ", comm_read_time(body->start));
time_printf(" period", comm_read_time(body->period));
if (body->control & MSG_CTL_VALID_DEVICE)
comm_device_id = body->device;
- if (body->control & MSG_CTL_VALID_START ||
- body->control & MSG_CTL_VALID_PERIOD) {
- uint64_t start = comm_read_time(body->start);
- uint64_t period = comm_read_time(body->period);
- emit_enable(start, period);
- }
-
- if (body->control & MSG_CTL_VALID_WORLD) {
- uint64_t world = comm_read_time(body->world);
- uint64_t local = tdma_time();
- time_ext_init(local, world);
- }
+ if (body->control & MSG_CTL_VALID_WORLD)
+ time_ext_init(tdma_time(), comm_read_time(body->world));
if (body->control & MSG_CTL_RELAY_MODE)
comm_relay_mode = 1;
else
comm_relay_mode = 0;
- if (body->control & MSG_CTL_VALID_SYNC)
+ if (body->control & MSG_CTL_BEGIN_SYNC)
comm_sync_due = tdma_time() + comm_sync_delay;
+
+ // Run these after world time is valid
+ if (body->control & MSG_CTL_VALID_START)
+ emit_set_start(comm_read_time(body->start));
+
+ if (body->control & MSG_CTL_VALID_PERIOD)
+ emit_set_period(comm_read_time(body->period));
}
/**