Skip to content

Accept wildcards in mqtt subscription prefix #1497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: development
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Revert "Bug fix for GPIO under recent Linux kernel versions"
This reverts commit 2cfe833.
cvdenzen committed Feb 4, 2025
commit 76beb1f39daeb4819bd992783df67c9f52a4587e
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ $(ARDUINO): $(ARDUINO_LIB_OBJS)

# Gateway Build
$(GATEWAY): $(GATEWAY_OBJECTS) $(ARDUINO_LIB_OBJS)
$(CXX) $(LDFLAGS) -o $@ $(GATEWAY_OBJECTS) $(ARDUINO_LIB_OBJS) $(LATE_LDFLAGS)
$(CXX) $(LDFLAGS) -o $@ $(GATEWAY_OBJECTS) $(ARDUINO_LIB_OBJS)

# Include all .d files
-include $(DEPS)
2 changes: 1 addition & 1 deletion MyConfig.h
Original file line number Diff line number Diff line change
@@ -442,7 +442,7 @@
* - RF24_PA_MAX = 0dBm
*/
#ifndef MY_RF24_PA_LEVEL
#define MY_RF24_PA_LEVEL (RF24_PA_MAX)
#define MY_RF24_PA_LEVEL (RF24_PA_HIGH)
#endif

/**
3 changes: 1 addition & 2 deletions configure
Original file line number Diff line number Diff line change
@@ -318,7 +318,7 @@ signing=none
signing_request_signatures=false
encryption=false

params="SOC CFLAGS CXXFLAGS CPPFLAGS LDFLAGS LATE_LDFLAGS PREFIX CC CXX ARDUINO_LIB_DIR BUILDDIR BINDIR GATEWAY_DIR INIT_SYSTEM SPI_DRIVER TYPE"
params="SOC CFLAGS CXXFLAGS CPPFLAGS LDFLAGS PREFIX CC CXX ARDUINO_LIB_DIR BUILDDIR BINDIR GATEWAY_DIR INIT_SYSTEM SPI_DRIVER TYPE"

for opt do
if [ "$opt" = "-h" ] || [ "$opt" = "--help" ]; then
@@ -706,7 +706,6 @@ fi

LDFLAGS="-pthread $LDFLAGS"
CPPFLAGS="$CPUFLAGS $CPPFLAGS"
LATE_LDFLAGS="-Wl,-Bstatic -lgpiod -Wl,-Bdynamic"

printf " ${OK} CPPFLAGS: $CPPFLAGS\n"
printf " ${OK} CXXFLAGS: $CXXFLAGS\n"
102 changes: 60 additions & 42 deletions hal/architecture/Linux/drivers/core/interrupt.cpp
Original file line number Diff line number Diff line change
@@ -37,7 +37,6 @@
struct ThreadArgs {
void (*func)();
int gpioPin;
struct gpiod_line *line;
};

volatile bool interruptsEnabled = true;
@@ -88,10 +87,10 @@ int piHiPri(const int pri)
void *interruptHandler(void *args)
{
int fd;
struct pollfd polls;
char c;
struct ThreadArgs *arguments = (struct ThreadArgs *)args;
int gpioPin = arguments->gpioPin;
struct gpiod_line *line = arguments->line;
void (*func)() = arguments->func;
delete arguments;

@@ -102,26 +101,28 @@ void *interruptHandler(void *args)
return NULL;
}

// Setup poll structure
polls.fd = fd;
polls.events = POLLPRI | POLLERR;

while (1) {
// Wait for it ...
// New version
int ret = gpiod_line_event_wait(line, NULL);
int ret = poll(&polls, 1, -1);
if (ret < 0) {
logError("Error waiting for interrupt: %s\n", strerror(errno));
break;
}
struct gpiod_line_event event;
if (gpiod_line_event_read(line, &event) == 0) {
if (event.event_type == GPIOD_LINE_EVENT_RISING_EDGE) {
logInfo("RISING Edge\n");
} else {
logInfo("FALLING Edge\n");
}
// Do a dummy read to clear the interrupt
// A one character read appars to be enough.
if (lseek (fd, 0, SEEK_SET) < 0) {
logError("Interrupt handler error: %s\n", strerror(errno));
break;
}
if (read (fd, &c, 1) < 0) {
logError("Interrupt handler error: %s\n", strerror(errno));
break;
}

// Call user function.
logError("Calling user function\n");

pthread_mutex_lock(&intMutex);
if (interruptsEnabled) {
pthread_mutex_unlock(&intMutex);
@@ -130,8 +131,6 @@ void *interruptHandler(void *args)
pthread_mutex_unlock(&intMutex);
}
}
// Adding gpiod closing instructions
gpiod_line_release(line);

close(fd);

@@ -154,53 +153,72 @@ void attachInterrupt(uint8_t gpioPin, void (*func)(), uint8_t mode)
usleep(1000);
}

char *chipname = "gpiochip0";
unsigned int line_num = gpioPin;
struct gpiod_line_event event;
struct gpiod_chip *chip;
struct gpiod_line *line;


chip = gpiod_chip_open_by_name(chipname);
if (!chip) {
logError("Open chip failed\n");
// Export pin for interrupt
if ((fd = fopen("/sys/class/gpio/export", "w")) == NULL) {
logError("attachInterrupt: Unable to export pin %d for interrupt: %s\n", gpioPin, strerror(errno));
exit(1);
}
fprintf(fd, "%d\n", gpioPin);
fclose(fd);

line = gpiod_chip_get_line(chip, line_num);
if (!line) {
logError("Get line failed\n");
exit(1);
// Wait a bit the system to create /sys/class/gpio/gpio<GPIO number>
usleep(1000);

snprintf(fName, sizeof(fName), "/sys/class/gpio/gpio%d/direction", gpioPin) ;
if ((fd = fopen (fName, "w")) == NULL) {
logError("attachInterrupt: Unable to open GPIO direction interface for pin %d: %s\n",
gpioPin, strerror(errno));
exit(1) ;
}
fprintf(fd, "in\n") ;
fclose(fd) ;

snprintf(fName, sizeof(fName), "/sys/class/gpio/gpio%d/edge", gpioPin) ;
if ((fd = fopen(fName, "w")) == NULL) {
logError("attachInterrupt: Unable to open GPIO edge interface for pin %d: %s\n", gpioPin,
strerror(errno));
exit(1) ;
}

switch (mode) {
case CHANGE:
gpiod_line_request_both_edges_events(line, "gpiointerrupt");
fprintf(fd, "both\n");
break;
case FALLING:
gpiod_line_request_falling_edge_events(line, "gpiointerrupt");
fprintf(fd, "falling\n");
break;
case RISING:
gpiod_line_request_rising_edge_events(line, "gpiointerrupt");
fprintf(fd, "rising\n");
break;
case NONE:
fprintf(fd, "none\n");
break;
default:
logError("attachInterrupt: Invalid mode\n");
fclose(fd);
return;
}
fclose(fd);

if (sysFds[gpioPin] == -1) {
if ((sysFds[gpioPin] = gpiod_line_event_get_fd(line)) < 0) {
snprintf(fName, sizeof(fName), "/sys/class/gpio/gpio%d/value", gpioPin);
if ((sysFds[gpioPin] = open(fName, O_RDONLY)) < 0) {
logError("Error reading pin %d: %s\n", gpioPin, strerror(errno));
exit(1);
}
}

// Clear any initial pending interrupt
ioctl(sysFds[gpioPin], FIONREAD, &count);
for (int i = 0; i < count; ++i) {
if (read(sysFds[gpioPin], &c, 1) == -1) {
logError("attachInterrupt: failed to read pin status: %s\n", strerror(errno));
}
}

struct ThreadArgs *threadArgs = new struct ThreadArgs;
threadArgs->func = func;
threadArgs->gpioPin = gpioPin;
threadArgs->line = line;

// Create a thread passing the pin and function
pthread_create(threadIds[gpioPin], NULL, interruptHandler, (void *)threadArgs);
@@ -221,13 +239,13 @@ void detachInterrupt(uint8_t gpioPin)
sysFds[gpioPin] = -1;
}

// FILE *fp = fopen("/sys/class/gpio/unexport", "w");
// if (fp == NULL) {
// logError("Unable to unexport pin %d for interrupt\n", gpioPin);
// exit(1);
// }
// fprintf(fp, "%d", gpioPin);
// fclose(fp);
FILE *fp = fopen("/sys/class/gpio/unexport", "w");
if (fp == NULL) {
logError("Unable to unexport pin %d for interrupt\n", gpioPin);
exit(1);
}
fprintf(fp, "%d", gpioPin);
fclose(fp);
}

void interrupts()
3 changes: 0 additions & 3 deletions hal/architecture/Linux/drivers/core/interrupt.h
Original file line number Diff line number Diff line change
@@ -24,9 +24,6 @@

#include <stdint.h>

// Ajout RRO
#include <gpiod.h>

#define CHANGE 1
#define FALLING 2
#define RISING 3