Skip to content

Commit

Permalink
Made UART code fully core compliant, fix for MQTT compilation error.
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeio committed May 9, 2024
1 parent 6190bdf commit 7225c90
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
16 changes: 12 additions & 4 deletions main/mqtt.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// mqtt.c - MQTT client API for grblHAL, ESP32 version
//
// v0.1 / 2023-02-09 / Io Engineering / Terje
// v0.2 / 2024-05-08 / Io Engineering / Terje
//

/*
Copyright (c) 2023, Terje Io
Copyright (c) 2023-2024, Terje Io
All rights reserved.
Expand Down Expand Up @@ -82,8 +82,16 @@ static void event_handler_callback (void *arg, esp_event_base_t event_base, int3
case MQTT_EVENT_DATA:
/* if(arg != NULL)
((on_mqtt_message_received_ptr)arg)(mqtt_message.topic, (void *)mqtt_message.payload, mqtt_message.payload_length);
else*/ if(mqtt_events.on_message_received)
mqtt_events.on_message_received(event->topic, (void *)event->data, (size_t)event->topic_len);
else*/
if(mqtt_events.on_message_received) {
char *topic;
if((topic = malloc(event->topic_len + 1))) {
strncpy(topic, event->topic, event->topic_len);
topic[event->topic_len] = '\0';
mqtt_events.on_message_received(topic, (void *)event->data, (size_t)event->data_len);
free(topic);
}
}
break;

default:
Expand Down
17 changes: 7 additions & 10 deletions main/uart_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
Copyright (c) 2023-2024 Terje Io
Grbl is free software: you can redistribute it and/or modify
grblHAL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Grbl is distributed in the hope that it will be useful,
grblHAL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
along with grblHAL. If not, see <http://www.gnu.org/licenses/>.
*/

Expand Down Expand Up @@ -125,7 +125,6 @@ static io_stream_properties_t serial[] = {
.instance = 0,
.flags.claimable = On,
.flags.claimed = Off,
.flags.connected = On,
.flags.can_set_baud = On,
.flags.modbus_ready = On,
.claim = serialInit
Expand All @@ -136,7 +135,6 @@ static io_stream_properties_t serial[] = {
.instance = 1,
.flags.claimable = On,
.flags.claimed = Off,
.flags.connected = On,
.flags.can_set_baud = On,
#ifdef UART2_TX_PIN
.flags.modbus_ready = On,
Expand All @@ -152,7 +150,6 @@ static io_stream_properties_t serial[] = {
.instance = 2,
.flags.claimable = On,
.flags.claimed = Off,
.flags.connected = On,
.flags.can_set_baud = On,
#ifdef UART3_TX_PIN
.flags.modbus_ready = On,
Expand Down Expand Up @@ -575,7 +572,7 @@ static const io_stream_t *serialInit (uint32_t baud_rate)
{
static const io_stream_t stream = {
.type = StreamType_Serial,
.state.connected = true,
.is_connected = stream_connected,
.read = serialRead,
.write = serialWriteS,
.write_n = serialWrite,
Expand Down Expand Up @@ -803,7 +800,7 @@ static const io_stream_t *serial2Init (uint32_t baud_rate)
static const io_stream_t stream = {
.type = StreamType_Serial,
.instance = 1,
.state.connected = true,
.is_connected = stream_connected,
.read = serial2Read,
.write = serial2WriteS,
.write_n = serial2Write,
Expand Down Expand Up @@ -1037,7 +1034,7 @@ static const io_stream_t *serial3Init (uint32_t baud_rate)
static const io_stream_t stream = {
.type = StreamType_Serial,
.instance = 2,
.state.connected = true,
.is_connected = stream_connected,
.read = serial3Read,
.write = serial3WriteS,
.write_n = serial3Write,
Expand Down

0 comments on commit 7225c90

Please sign in to comment.