Skip to content

Commit

Permalink
Merge branch 'master' into openmrnlite
Browse files Browse the repository at this point in the history
# By Balazs Racz (146) and others
# Via Balazs Racz (14) and GitHub (3)
* master: (171 commits)
  Fix os_thread_create_helper for arduino esp32 (#525)
  Broadcast Time Server Detection (#521)
  Fix test. (#522)
  Update the descriptions in the User Info Segment. (#518)
  Adds support for write to the memoryconfig utils application. (#515)
  Adds a parseblink method to turn a blinker code into a numeric display. (#516)
  Fixes broken build of DCC driver instantiation. (#514)
  Allow applib.mk SRCDIR to be overridden. (#512)
  Flip the order of operations for resetting the callback flag and calling the actual callback. This allows for rearming the callback from the callback itself. (#510)
  limit timer cleanup (#509)
  Adds a generalized shift operation to the Fixed16 class. (#508)
  Adds ability to remove an event handler from the callbacks. (#507)
  Limit Timer (#506)
  Adds support for a random jitter in the DCC signal timing. (#505)
  Tune DCC end of packet behavior (#504)
  Adds support for DCC function 29-68. (#503)
  Adds helper functions to generate different DCC packet types: (#502)
  Fixes library.a dependencies and other makefile cleanup. (#501)
  Adds functions to generate paged-mode programming packets. (#500)
  fix eepromemu tests.
  ...

# Conflicts:
#	src/freertos_drivers/esp32/Esp32WiFiManager.cxx
  • Loading branch information
balazsracz committed Apr 5, 2021
2 parents 6f82751 + c09a153 commit 7e7a509
Show file tree
Hide file tree
Showing 257 changed files with 12,093 additions and 1,309 deletions.
2 changes: 2 additions & 0 deletions applications/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ SUBDIRS = \
train \
tcp_blink_client \
usb_can \
time_client \
time_server


include $(OPENMRNPATH)/etc/recurse.mk
3 changes: 2 additions & 1 deletion applications/async_blink/targets/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
SUBDIRS = linux.x86 \
linux.armv7a \
linux.llvm \
mach.x86 \
mach.x86_64 \
freertos.armv7m.ek-lm4f120xl \
freertos.armv7m.ek-tm4c123gxl \
Expand All @@ -13,6 +12,8 @@ SUBDIRS = linux.x86 \
freertos.armv6m.st-stm32f072b-discovery \
freertos.armv7m.st-stm32f103rb-olimexino \
freertos.armv7m.st-stm32f303-discovery \
freertos.armv7m.st-stm32f303re-nucleo-dev-board \
freertos.armv7m.st-stm32l432kc-nucleo \
freertos.armv7m.st-maple-cmsis \
freertos.armv4t.panda2 \
freertos.mips4k.pic32mx-duinomitemega \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "openlcb/If.hxx"

extern const openlcb::NodeID NODE_ID;
const openlcb::NodeID NODE_ID = 0x050101011410ULL;
const openlcb::NodeID NODE_ID = 0x050101011869ULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "openlcb/If.hxx"

extern const openlcb::NodeID NODE_ID;
const openlcb::NodeID NODE_ID = 0x050101011867ULL;
2 changes: 0 additions & 2 deletions applications/async_blink/targets/mach.x86/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions applications/async_blink/targets/mach.x86_64/Makefile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
-include ../../config.mk
include $(OPENMRNPATH)/etc/prog.mk
10 changes: 5 additions & 5 deletions applications/clinic_app/targets/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
SUBDIRS = \
freertos.armv7m.ek-tm4c123gxl \
freertos.armv7m.ek-tm4c1294xl \
freertos.armv6m.st-stm32f072b-discovery \
freertos.armv7m.st-stm32f303-discovery \
freertos.armv7m.ek-tm4c123gxl \
freertos.armv7m.ek-tm4c1294xl \
freertos.armv6m.st-stm32f072b-discovery \
freertos.armv7m.st-stm32f303-discovery \
linux.armv7a \
linux.x86 \
mach.x86
mach.x86_64


# freertos.armv7m.lpc1768-mbed \
Expand Down
64 changes: 49 additions & 15 deletions applications/hub/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@

#include <memory>

#include "os/os.h"
#include "utils/constants.hxx"
#include "utils/Hub.hxx"
#include "utils/GcTcpHub.hxx"
#include "utils/ClientConnection.hxx"
#include "executor/Executor.hxx"
#include "executor/Service.hxx"
#include "os/os.h"
#include "utils/ClientConnection.hxx"
#include "utils/GcTcpHub.hxx"
#include "utils/Hub.hxx"
#include "utils/HubDeviceSelect.hxx"
#include "utils/SocketCan.hxx"
#include "utils/constants.hxx"

Executor<1> g_executor("g_executor", 0, 1024);
Service g_service(&g_executor);
Expand All @@ -58,6 +60,7 @@ OVERRIDE_CONST(gridconnect_buffer_delay_usec, 2000);

int port = 12021;
const char *device_path = nullptr;
const char *socket_can_path = nullptr;
int upstream_port = 12021;
const char *upstream_host = nullptr;
bool timestamped = false;
Expand All @@ -67,18 +70,28 @@ bool printpackets = false;

void usage(const char *e)
{
fprintf(stderr, "Usage: %s [-p port] [-d device_path] [-u upstream_host] "
"[-q upstream_port] [-m] [-n mdns_name] [-t] [-l]\n\n",
e);
fprintf(stderr, "GridConnect CAN HUB.\nListens to a specific TCP port, "
"reads CAN packets from the incoming connections using "
"the GridConnect protocol, and forwards all incoming "
"packets to all other participants.\n\nArguments:\n");
fprintf(stderr,
"Usage: %s [-p port] [-d device_path] [-u upstream_host] "
"[-q upstream_port] [-m] [-n mdns_name] "
#if defined(__linux__)
"[-s socketcan_interface] "
#endif
"[-t] [-l]\n\n",
e);
fprintf(stderr,
"GridConnect CAN HUB.\nListens to a specific TCP port, "
"reads CAN packets from the incoming connections using "
"the GridConnect protocol, and forwards all incoming "
"packets to all other participants.\n\nArguments:\n");
fprintf(stderr, "\t-p port specifies the port number to listen on, "
"default is 12021.\n");
fprintf(stderr, "\t-d device is a path to a physical device doing "
"serial-CAN or USB-CAN. If specified, opens device and "
"adds it to the hub.\n");
#if defined(__linux__)
fprintf(stderr, "\t-s socketcan_interface is a socketcan device (e.g. 'can0'). "
"If specified, opens device and adds it to the hub.\n");
#endif
fprintf(stderr, "\t-u upstream_host is the host name for an upstream "
"hub. If specified, this hub will connect to an upstream "
"hub.\n");
Expand All @@ -100,7 +113,7 @@ void usage(const char *e)
void parse_args(int argc, char *argv[])
{
int opt;
while ((opt = getopt(argc, argv, "hp:d:u:q:tlmn:")) >= 0)
while ((opt = getopt(argc, argv, "hp:d:s:u:q:tlmn:")) >= 0)
{
switch (opt)
{
Expand All @@ -110,6 +123,11 @@ void parse_args(int argc, char *argv[])
case 'd':
device_path = optarg;
break;
#if defined(__linux__)
case 's':
socket_can_path = optarg;
break;
#endif
case 'p':
port = atoi(optarg);
break;
Expand Down Expand Up @@ -160,12 +178,28 @@ int appl_main(int argc, char *argv[])
void mdns_client_start();
void mdns_publish(const char *name, uint16_t port);

if (export_mdns) {
if (export_mdns)
{
mdns_client_start();
mdns_publish(mdns_name, port);
}
#endif

#if defined(__linux__)
if (socket_can_path)
{
int s = socketcan_open(socket_can_path, 1);
if (s >= 0)
{
new HubDeviceSelect<CanHubFlow>(&can_hub0, s);
fprintf(stderr, "Opened SocketCan %s: fd %d\n", socket_can_path, s);
}
else
{
fprintf(stderr, "Failed to open SocketCan %s.\n", socket_can_path);
}
}
#endif

if (upstream_host)
{
connections.emplace_back(new UpstreamConnectionClient(
Expand Down
2 changes: 1 addition & 1 deletion applications/hub/targets/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SUBDIRS = linux.x86 \
linux.armv7a \
mach.x86
mach.x86_64

include $(OPENMRNPATH)/etc/recurse.mk
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
-include ../../config.mk
include $(OPENMRNPATH)/etc/prog.mk

1 change: 1 addition & 0 deletions applications/hub/targets/linux.rpi1/AvaHiMDNS.cxx
36 changes: 36 additions & 0 deletions applications/hub/targets/linux.rpi1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Adding SocketCAN support on the Raspberry Pi 4

These are my notes from adding SocketCAN support and building the **hub** application in a Raspberry Pi.

- Start with the pre-built JMRI - RPI disk image from: [M Steve Todd's - JMRI RaspberryPi as Access Point](https://mstevetodd.com/rpi)

- Install the MCP2517 CAN interface hardware from: [2-Channel CAN-BUS(FD) Shield for Raspberry Pi](https://www.seeedstudio.com/2-Channel-CAN-BUS-FD-Shield-for-Raspberry-Pi-p-4072.html) and followed their instructions for building the MCP2517 kernel device driver on their [Support Wiki](http://wiki.seeedstudio.com/2-Channel-CAN-BUS-FD-Shield-for-Raspberry-Pi/#software) page.

- Install some needed packages on the RPi:

`sudo apt install git doxygen libavahi-client-dev`

- Download the OpenMRN source code to the RPi:

`cd ~`

`git clone https://github.com/bakerstu/openmrn.git`

- Build the **hub** application:

`cd openmrn/applications/hub/targets/linux.rpi1/`

`make`

- Configure the **can0** interface for 125,000 bps and run the **hub** application at system at start-up by creating the file: `/etc/network/interfaces.d/can0` with the following lines:
```
allow-hotplug can0
iface can0 can static
bitrate 125000
up /home/pi/openmrn/applications/hub/targets/linux.rpi1/hub -s $IFACE &
```

- Configure the LCC Layout Connection in JMRI to use
- System Connection: `CAN via GridConnect Network Interface`
- IP Address/Host Name: `localhost`
- TCP/UDP Port: `12021`
1 change: 0 additions & 1 deletion applications/hub/targets/mach.x86/lib/Makefile

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,40 @@ openlcb::ConfiguredProducer producer_sw2(
openlcb::RefreshLoop loop(
stack.node(), {producer_sw1.polling(), producer_sw2.polling()});

/// This timer checks the eeprom once a second and if the user has written
/// something, executes a reload of the configuration via the OpenLCB config
/// service.
class AutoUpdateTimer : public ::Timer
{
public:
AutoUpdateTimer()
: ::Timer(stack.executor()->active_timers())
{
start(SEC_TO_NSEC(1));
}

long long timeout() override
{
extern uint8_t eeprom_updated;
if (eeprom_updated)
{
needUpdate_ = true;
eeprom_updated = 0;
}
else
{
if (needUpdate_)
{
stack.config_service()->trigger_update();
needUpdate_ = false;
}
}
return RESTART;
}

bool needUpdate_ {false};
} update_timer;

/** Entry point to application.
* @param argc number of command line arguments
* @param argv array of command line arguments
Expand Down
Loading

0 comments on commit 7e7a509

Please sign in to comment.