Library-ish layout

This commit is contained in:
Midgard 2020-08-20 21:51:33 +02:00
parent 9dc7c399f2
commit 589a0f691d
Signed by: midgard
GPG key ID: 511C112F1331BBB4
4 changed files with 20 additions and 25 deletions

View file

@ -1,6 +1,6 @@
#include <mcp2515.h> #include <mcp2515.h>
#include "obus_can.hpp" #include "obus_can.h"
MCP2515 mcp2515(10); MCP2515 mcp2515(10);

View file

@ -1,5 +1,4 @@
#include "shared.hpp" #include <obus_can.h>
#include "obus_can.hpp"
#define STATE_INACTIVE 0 #define STATE_INACTIVE 0
@ -9,8 +8,12 @@
#define OBUS_MAX_STRIKES 3 // Number of strikes allowed until game over #define OBUS_MAX_STRIKES 3 // Number of strikes allowed until game over
#define OBUS_GAME_DURATION 10 // Duration of the game in seconds #define OBUS_GAME_DURATION 10 // Duration of the game in seconds
#define OBUS_MAX_MODULES 16
#define OBUS_DISC_DURATION 5 // Duration of discovery round in seconds
#define OBUS_UPDATE_INTERVAL 500 // Number of milliseconds between game updates
#define OBUS_GAME_DURATION_MS ((uint32_t) OBUS_GAME_DURATION*1000) #define OBUS_GAME_DURATION_MS ((uint32_t) OBUS_GAME_DURATION*1000)
#define OBUS_DISC_DURATION_MS ((uint32_t) OBUS_DISC_DURATION*1000)
#define DIVIDE_CEIL(dividend, divisor) ((dividend + (divisor - 1)) / divisor) #define DIVIDE_CEIL(dividend, divisor) ((dividend + (divisor - 1)) / divisor)
#define MAX_AMOUNT_PUZZLES 256 // The ID of a puzzle is uint8 #define MAX_AMOUNT_PUZZLES 256 // The ID of a puzzle is uint8
@ -85,6 +88,13 @@ void start_hello() {
} }
uint16_t full_module_id(struct module mod) {
return \
((uint16_t) mod.type << 8) | \
(uint16_t) mod.id;
}
void receive_hello() { void receive_hello() {
struct obus_message msg; struct obus_message msg;
uint32_t current_time = millis(); uint32_t current_time = millis();
@ -93,12 +103,15 @@ void receive_hello() {
if (msg.msg_type == OBUS_MSGTYPE_M_HELLO) { if (msg.msg_type == OBUS_MSGTYPE_M_HELLO) {
Serial.print(" Registered module "); Serial.print(" Registered module ");
Serial.println(full_module_id(msg.from)); Serial.println(full_module_id(msg.from));
if (nr_connected_modules < OBUS_MAX_MODULES) {
connected_modules_ids[nr_connected_modules] = msg.from; connected_modules_ids[nr_connected_modules] = msg.from;
nr_connected_modules++; nr_connected_modules++;
if (msg.from.type == OBUS_TYPE_PUZZLE) { if (msg.from.type == OBUS_TYPE_PUZZLE) {
add_module_to_bit_vector(full_module_id(msg.from)); add_module_to_bit_vector(full_module_id(msg.from));
} }
}
obuscan_send_c_ack(this_module); obuscan_send_c_ack(this_module);
Serial.println(" ACK"); Serial.println(" ACK");

View file

@ -1,18 +0,0 @@
#ifndef OBUS_SHARED_H
#define OBUS_SHARED_H
#include "obus_can.hpp"
#define OBUS_MAX_MODULES 16
#define OBUS_DISC_DURATION 5 // Duration of discovery round in seconds
#define OBUS_UPDATE_INTERVAL 500 // Number of milliseconds between game updates
#define OBUS_DISC_DURATION_MS ((uint32_t) OBUS_DISC_DURATION*1000)
uint16_t full_module_id(struct module mod) {
return \
((uint16_t) mod.type << 8) | \
(uint16_t) mod.id;
}
#endif /* end of include guard: OBUS_DEFS_H */