Skip to content

Commit 787d448

Browse files
authored
Merge branch 'openshwprojects:main' into tuyamcu
2 parents 0f7c96a + c49a934 commit 787d448

File tree

12 files changed

+2957
-3
lines changed

12 files changed

+2957
-3
lines changed

platforms/obk_main.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ set(OBKM_SRC
133133
${OBK_SRCS}driver/drv_spiLED.c
134134
${OBK_SRCS}driver/drv_spi_flash.c
135135
${OBK_SRCS}driver/drv_spidma.c
136+
${OBK_SRCS}driver/drv_mdns.c
136137
${OBK_SRCS}driver/drv_ssdp.c
137138
${OBK_SRCS}driver/drv_ssd1306.c
138139
${OBK_SRCS}driver/drv_tasmotaDeviceGroups.c

platforms/obk_main.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ OBKM_SRC += $(OBK_SRCS)driver/drv_spi.c
152152
OBKM_SRC += $(OBK_SRCS)driver/drv_spiLED.c
153153
OBKM_SRC += $(OBK_SRCS)driver/drv_spi_flash.c
154154
OBKM_SRC += $(OBK_SRCS)driver/drv_spidma.c
155+
OBKM_SRC += $(OBK_SRCS)driver/drv_mdns.c
155156
OBKM_SRC += $(OBK_SRCS)driver/drv_ssdp.c
156157
OBKM_SRC += $(OBK_SRCS)driver/drv_shutters.c
157158
OBKM_SRC += $(OBK_SRCS)driver/drv_ssd1306.c

src/driver/drv_local.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ void Bridge_driver_QuickFrame();
303303
void Bridge_driver_OnChannelChanged(int ch, int value);
304304
/*************************************************************/
305305

306+
/* Roomba driver *********************************************/
307+
void Roomba_AppendInformationToHTTPIndexPage(http_request_t *request, int bPreState);
308+
/*************************************************************/
306309
void LTR_Init();
307310
void LTR_OnEverySecond();
308311
void LTR_AppendInformationToHTTPIndexPage(http_request_t* request, int bPreState);

src/driver/drv_main.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "drv_ntp.h"
1212
#include "drv_deviceclock.h"
1313
#include "drv_public.h"
14+
#include "drv_mdns.h"
1415
#include "drv_ssdp.h"
1516
#include "drv_test_drivers.h"
1617
#include "drv_tuyaMCU.h"
@@ -77,6 +78,22 @@ static driver_t g_drivers[] = {
7778
false, // loaded
7879
},
7980
#endif
81+
#if ENABLE_DRIVER_ROOMBA
82+
//drvdetail:{"name":"Roomba",
83+
//drvdetail:"title":"Roomba",
84+
//drvdetail:"descr":"Roomba OI Driver",
85+
//drvdetail:"requires":""}
86+
{ "Roomba", // Driver Name
87+
Roomba_Init, // Init
88+
Roomba_RunEverySecond, // onEverySecond
89+
Roomba_AppendInformationToHTTPIndexPage, // appendInformationToHTTPIndexPage
90+
Roomba_OnQuickTick, // runQuickTick
91+
NULL, // stopFunction
92+
NULL, // onChannelChanged
93+
Roomba_OnHassDiscovery, // onHassDiscovery
94+
false, // loaded
95+
},
96+
#endif
8097
#ifdef ENABLE_DRIVER_GIRIERMCU
8198
//drvdetail:{"name":"GirierMCU",
8299
//drvdetail:"title":"GirierMCU",
@@ -829,6 +846,22 @@ static driver_t g_drivers[] = {
829846
false, // loaded
830847
},
831848
#endif
849+
#if ENABLE_DRIVER_MDNS
850+
//drvdetail:{"name":"MDNS",
851+
//drvdetail:"title":"TODO",
852+
//drvdetail:"descr":"mDNS/DNS-SD discovery service. Publishes the device hostname and HTTP service on local network.",
853+
//drvdetail:"requires":""}
854+
{ "MDNS", // Driver Name
855+
DRV_MDNS_Init, // Init
856+
DRV_MDNS_RunEverySecond, // onEverySecond
857+
NULL, // appendInformationToHTTPIndexPage
858+
DRV_MDNS_RunQuickTick, // runQuickTick
859+
DRV_MDNS_Shutdown, // stopFunction
860+
NULL, // onChannelChanged
861+
NULL, // onHassDiscovery
862+
false, // loaded
863+
},
864+
#endif
832865
#if ENABLE_DRIVER_SSDP
833866
//drvdetail:{"name":"SSDP",
834867
//drvdetail:"title":"TODO",

src/driver/drv_mdns.c

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#include "../new_common.h"
2+
#include "../new_cfg.h"
3+
#include "../logging/logging.h"
4+
#include "../obk_config.h"
5+
#include "drv_mdns.h"
6+
7+
#if (PLATFORM_BK7231N || PLATFORM_BK7231T) && ENABLE_DRIVER_MDNS
8+
9+
#include "lwip/apps/mdns_opts.h"
10+
11+
#if LWIP_MDNS_RESPONDER
12+
13+
#include "lwip/apps/mdns.h"
14+
#include "lwip/err.h"
15+
#include "lwip/init.h"
16+
#include "lwip/netif.h"
17+
#include "net.h"
18+
#include "tcpip.h"
19+
20+
#ifndef LOCK_TCPIP_CORE
21+
#define LOCK_TCPIP_CORE()
22+
#endif
23+
24+
#ifndef UNLOCK_TCPIP_CORE
25+
#define UNLOCK_TCPIP_CORE()
26+
#endif
27+
28+
extern int Main_IsConnectedToWiFi();
29+
extern int DRV_MDNS_Active;
30+
31+
static int g_mdnsInitDone = 0;
32+
static int g_mdnsNetifAdded = 0;
33+
static s8_t g_mdnsServiceSlot = -1;
34+
35+
#if (LWIP_VERSION_MAJOR > 2) || (LWIP_VERSION_MAJOR == 2 && LWIP_VERSION_MINOR >= 1)
36+
#define DRV_MDNS_HAS_RESTART_API 1
37+
#else
38+
#define DRV_MDNS_HAS_RESTART_API 0
39+
#endif
40+
41+
static struct netif *DRV_MDNS_GetStaNetif(void) {
42+
return (struct netif *)net_get_sta_handle();
43+
}
44+
45+
static void DRV_MDNS_StartOrRestart(void) {
46+
struct netif *netif;
47+
const char *hostName;
48+
err_t err;
49+
50+
netif = DRV_MDNS_GetStaNetif();
51+
if (netif == 0) {
52+
addLogAdv(LOG_ERROR, LOG_FEATURE_HTTP, "DRV_MDNS: no STA netif handle");
53+
return;
54+
}
55+
56+
hostName = CFG_GetShortDeviceName();
57+
if (hostName == 0 || *hostName == 0) {
58+
hostName = "openbeken";
59+
}
60+
61+
LOCK_TCPIP_CORE();
62+
63+
if (!g_mdnsInitDone) {
64+
mdns_resp_init();
65+
g_mdnsInitDone = 1;
66+
}
67+
68+
if (!g_mdnsNetifAdded) {
69+
err = mdns_resp_add_netif(netif, hostName, 120);
70+
if (err == ERR_OK) {
71+
g_mdnsNetifAdded = 1;
72+
g_mdnsServiceSlot = mdns_resp_add_service(netif, hostName, "_http", DNSSD_PROTO_TCP, 80, 120, 0, 0);
73+
if (g_mdnsServiceSlot < 0) {
74+
addLogAdv(LOG_ERROR, LOG_FEATURE_HTTP, "DRV_MDNS: mdns_resp_add_service failed");
75+
}
76+
#if DRV_MDNS_HAS_RESTART_API
77+
mdns_resp_announce(netif);
78+
#else
79+
mdns_resp_netif_settings_changed(netif);
80+
#endif
81+
addLogAdv(LOG_INFO, LOG_FEATURE_HTTP, "DRV_MDNS: responder started (%s.local)", hostName);
82+
} else {
83+
addLogAdv(LOG_ERROR, LOG_FEATURE_HTTP, "DRV_MDNS: mdns_resp_add_netif failed %d", (int)err);
84+
}
85+
} else {
86+
#if DRV_MDNS_HAS_RESTART_API
87+
mdns_resp_restart(netif);
88+
mdns_resp_announce(netif);
89+
#else
90+
mdns_resp_netif_settings_changed(netif);
91+
#endif
92+
addLogAdv(LOG_INFO, LOG_FEATURE_HTTP, "DRV_MDNS: responder restarted");
93+
}
94+
95+
UNLOCK_TCPIP_CORE();
96+
}
97+
98+
void DRV_MDNS_Init(void) {
99+
DRV_MDNS_Active = 1;
100+
101+
if (!Main_IsConnectedToWiFi()) {
102+
addLogAdv(LOG_INFO, LOG_FEATURE_HTTP, "DRV_MDNS_Init - no wifi, await connection");
103+
return;
104+
}
105+
106+
DRV_MDNS_StartOrRestart();
107+
}
108+
109+
void DRV_MDNS_RunEverySecond(void) {
110+
}
111+
112+
void DRV_MDNS_RunQuickTick(void) {
113+
}
114+
115+
void DRV_MDNS_Shutdown(void) {
116+
struct netif *netif;
117+
118+
addLogAdv(LOG_INFO, LOG_FEATURE_HTTP, "DRV_MDNS_Shutdown");
119+
120+
if (g_mdnsNetifAdded) {
121+
netif = DRV_MDNS_GetStaNetif();
122+
if (netif != 0) {
123+
LOCK_TCPIP_CORE();
124+
mdns_resp_remove_netif(netif);
125+
UNLOCK_TCPIP_CORE();
126+
}
127+
g_mdnsNetifAdded = 0;
128+
g_mdnsServiceSlot = -1;
129+
}
130+
131+
DRV_MDNS_Active = 0;
132+
}
133+
134+
#else
135+
136+
extern int DRV_MDNS_Active;
137+
138+
void DRV_MDNS_Init(void) {
139+
addLogAdv(LOG_INFO, LOG_FEATURE_HTTP, "DRV_MDNS unavailable in this SDK build");
140+
DRV_MDNS_Active = 0;
141+
}
142+
143+
void DRV_MDNS_RunEverySecond(void) {
144+
}
145+
146+
void DRV_MDNS_RunQuickTick(void) {
147+
}
148+
149+
void DRV_MDNS_Shutdown(void) {
150+
DRV_MDNS_Active = 0;
151+
}
152+
153+
#endif
154+
155+
#else
156+
157+
extern int DRV_MDNS_Active;
158+
159+
void DRV_MDNS_Init(void) {
160+
DRV_MDNS_Active = 0;
161+
}
162+
163+
void DRV_MDNS_RunEverySecond(void) {
164+
}
165+
166+
void DRV_MDNS_RunQuickTick(void) {
167+
}
168+
169+
void DRV_MDNS_Shutdown(void) {
170+
DRV_MDNS_Active = 0;
171+
}
172+
173+
#endif

src/driver/drv_mdns.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extern int DRV_MDNS_Active;
2+
3+
void DRV_MDNS_Init();
4+
void DRV_MDNS_RunEverySecond();
5+
void DRV_MDNS_RunQuickTick();
6+
void DRV_MDNS_Shutdown();

0 commit comments

Comments
 (0)