Skip to content

Commit e4c0e36

Browse files
committed
inlined system functions
1 parent d28f08b commit e4c0e36

File tree

4 files changed

+61
-76
lines changed

4 files changed

+61
-76
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
all: fmt
22

33
fmt:
4-
clang-format -i src/*.cpp src/*.h -style="{BasedOnStyle: Google, ColumnLimit: 120}"
4+
clang-format -i src/*.h -style="{BasedOnStyle: Google, ColumnLimit: 120}"
55

66
update:
77
rm -rf ./lwmqtt

src/MQTTClient.h

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,66 @@
55
#include <Client.h>
66
#include <Stream.h>
77

8-
#include "system.h"
8+
extern "C" {
9+
#include "lwmqtt/lwmqtt.h"
10+
};
11+
12+
typedef struct {
13+
uint32_t end;
14+
} lwmqtt_arduino_timer_t;
15+
16+
void lwmqtt_arduino_timer_set(void *ref, uint32_t timeout);
17+
18+
int32_t lwmqtt_arduino_timer_get(void *ref);
19+
20+
typedef struct {
21+
Client *client;
22+
} lwmqtt_arduino_network_t;
23+
24+
void lwmqtt_arduino_timer_set(void *ref, uint32_t timeout) {
25+
// cast timer reference
26+
auto t = (lwmqtt_arduino_timer_t *)ref;
27+
28+
// set future end time
29+
t->end = (uint32_t)(millis() + timeout);
30+
}
31+
32+
int32_t lwmqtt_arduino_timer_get(void *ref) {
33+
// cast timer reference
34+
auto t = (lwmqtt_arduino_timer_t *)ref;
35+
36+
// get difference to end time
37+
return (int32_t)t->end - (int32_t)millis();
38+
}
39+
40+
lwmqtt_err_t lwmqtt_arduino_network_read(void *ref, uint8_t *buffer, size_t len, size_t *read, uint32_t timeout) {
41+
// cast network reference
42+
auto n = (lwmqtt_arduino_network_t *)ref;
43+
44+
// set timeout
45+
n->client->setTimeout(timeout);
46+
47+
// read bytes
48+
*read = n->client->readBytes(buffer, len);
49+
if (*read <= 0) {
50+
return LWMQTT_NETWORK_FAILED_READ;
51+
}
52+
53+
return LWMQTT_SUCCESS;
54+
}
55+
56+
lwmqtt_err_t lwmqtt_arduino_network_write(void *ref, uint8_t *buffer, size_t len, size_t *sent, uint32_t /*timeout*/) {
57+
// cast network reference
58+
auto n = (lwmqtt_arduino_network_t *)ref;
59+
60+
// write bytes
61+
*sent = n->client->write(buffer, len);
62+
if (*sent <= 0) {
63+
return LWMQTT_NETWORK_FAILED_WRITE;
64+
};
65+
66+
return LWMQTT_SUCCESS;
67+
}
968

1069
class MQTTClient;
1170

src/system.cpp

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/system.h

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)