Use defined mcast addr for device groups instead of sharing emuation's, Code size reductions

This commit is contained in:
Paul C Diem 2020-04-24 09:12:43 -05:00
parent 56e756602e
commit 81a874ec72
9 changed files with 362 additions and 412 deletions

View File

@ -421,10 +421,12 @@
#define USE_EXS_DIMMER // Add support for ES-Store WiFi Dimmer (+1k5 code)
// #define EXS_MCU_CMNDS // Add command to send MCU commands (+0k8 code)
//#define USE_HOTPLUG // Add support for sensor HotPlug
#define USE_DEVICE_GROUPS // Add support for device groups (+5k6 code)
#define USE_DEVICE_GROUPS_SEND // Add support for the DevGroupSend command (+0k5 code)
#define USE_PWM_DIMMER // Add support for MJ-SD01/acenx/NTONPOWER PWM dimmers (+2k5 code)
#define USE_PWM_DIMMER_REMOTE // Add support for remote switches to PWM Dimmer, also adds device groups support (+1k code plus device groups size)
#define USE_DEVICE_GROUPS // Add support for device groups (+5k5 code)
#define DEVICE_GROUPS_ADDRESS 239,255,250,250 // Device groups multicast address
#define DEVICE_GROUPS_PORT 4447 // Device groups multicast port
#define USE_DEVICE_GROUPS_SEND // Add support for the DevGroupSend command (+0k6 code)
#define USE_PWM_DIMMER // Add support for MJ-SD01/acenx/NTONPOWER PWM dimmers (+2k2 code, DGR=0k4)
#define USE_PWM_DIMMER_REMOTE // Add support for remote switches to PWM Dimmer, also adds device groups support (+0k9 code plus device groups size)
//#define USE_KEELOQ // Add support for Jarolift rollers by Keeloq algorithm (+4k5 code)
#define USE_SONOFF_D1 // Add support for Sonoff D1 Dimmer (+0k7 code)

View File

@ -876,6 +876,7 @@ void CmndSetoption(void)
else if (4 == ptype) { // SetOption82 .. 113
bitWrite(Settings.flag4.data, pindex, XdrvMailbox.payload);
switch (pindex) {
case 3: // SetOption85 - Enable Device Groups
case 6: // SetOption88 - PWM Dimmer Buttons control remote devices
restart_flag = 2;
break;
@ -1798,8 +1799,9 @@ void CmndDevGroupSend(void)
{
uint8_t device_group_index = (XdrvMailbox.usridx ? XdrvMailbox.index - 1 : 0);
if (device_group_index < device_group_count) {
_SendDeviceGroupMessage(device_group_index, DGR_MSGTYPE_UPDATE_COMMAND);
ResponseCmndChar(XdrvMailbox.data);
if (!_SendDeviceGroupMessage(device_group_index, DGR_MSGTYPE_UPDATE_COMMAND)) {
ResponseCmndChar(XdrvMailbox.data);
}
}
}
#endif // USE_DEVICE_GROUPS_SEND

File diff suppressed because it is too large Load Diff

View File

@ -49,7 +49,11 @@ bool UdpDisconnect(void)
{
if (udp_connected) {
PortUdp.flush();
#ifdef USE_DEVICE_GROUPS
PortUdp.stop();
#else // USE_DEVICE_GROUPS
WiFiUDP::stopAll();
#endif // !USE_DEVICE_GROUPS
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPNP D_MULTICAST_DISABLED));
udp_connected = false;
}
@ -135,12 +139,6 @@ void PollUdp(void)
continue;
}
}
#ifdef USE_DEVICE_GROUPS
if (Settings.flag4.device_groups_enabled && !strncmp_P(packet_buffer, kDeviceGroupMessage, sizeof(DEVICE_GROUP_MESSAGE) - 1)) {
ProcessDeviceGroupMessage(packet_buffer, len);
}
#endif // USE_DEVICE_GROUPS
}
optimistic_yield(100);
}

View File

@ -573,14 +573,12 @@ void WifiCheck(uint8_t param)
StopWebserver();
}
#ifdef USE_EMULATION
#ifdef USE_DEVICE_GROUPS
if (Settings.flag2.emulation || Settings.flag4.device_groups_enabled) { UdpConnect(); }
#else // USE_DEVICE_GROUPS
if (Settings.flag2.emulation) { UdpConnect(); }
#endif // USE_DEVICE_GROUPS
#endif // USE_EMULATION
#endif // USE_WEBSERVER
#ifdef USE_DEVICE_GROUPS
DeviceGroupsStart();
#endif // USE_DEVICE_GROUPS
#ifdef USE_KNX
if (!knx_started && Settings.flag.knx_enabled) { // CMND_KNX_ENABLED
KNXStart();
@ -593,6 +591,9 @@ void WifiCheck(uint8_t param)
#ifdef USE_EMULATION
UdpDisconnect();
#endif // USE_EMULATION
#ifdef USE_DEVICE_GROUPS_SSDP
DeviceGroupsStop();
#endif // USE_DEVICE_GROUPS_SSDP
Wifi.mdns_begun = 0;
#ifdef USE_KNX
knx_started = false;

View File

@ -304,7 +304,7 @@ enum DevGroupMessageType { DGR_MSGTYP_FULL_STATUS, DGR_MSGTYP_PARTIAL_UPDATE, DG
enum DevGroupMessageFlag { DGR_FLAG_RESET = 1, DGR_FLAG_STATUS_REQUEST = 2, DGR_FLAG_FULL_STATUS = 4, DGR_FLAG_ACK = 8, DGR_FLAG_MORE_TO_COME = 16, DGR_FLAG_DIRECT = 32, DGR_FLAG_ANNOUNCEMENT = 64 };
enum DevGroupItem { DGR_ITEM_EOL, DGR_ITEM_STATUS,
enum DevGroupItem { DGR_ITEM_EOL, DGR_ITEM_STATUS, DGR_ITEM_FLAGS,
DGR_ITEM_LIGHT_FADE, DGR_ITEM_LIGHT_SPEED, DGR_ITEM_LIGHT_BRI, DGR_ITEM_LIGHT_SCHEME, DGR_ITEM_LIGHT_FIXED_COLOR,
DGR_ITEM_BRI_PRESET_LOW, DGR_ITEM_BRI_PRESET_HIGH, DGR_ITEM_BRI_POWER_ON,
// Add new 8-bit items before this line
@ -312,7 +312,7 @@ enum DevGroupItem { DGR_ITEM_EOL, DGR_ITEM_STATUS,
//DGR_ITEM_ANALOG1, DGR_ITEM_ANALOG2, DGR_ITEM_ANALOG3, DGR_ITEM_ANALOG4, DGR_ITEM_ANALOG5,
// Add new 16-bit items before this line
DGR_ITEM_LAST_16BIT, DGR_ITEM_MAX_16BIT = 127,
DGR_ITEM_POWER, DGR_ITEM_DIMMER_RANGE,
DGR_ITEM_POWER,
// Add new 32-bit items before this line
DGR_ITEM_LAST_32BIT, DGR_ITEM_MAX_32BIT = 191,
DGR_ITEM_EVENT, DGR_ITEM_COMMAND,

View File

@ -62,9 +62,6 @@ extern "C" void resetPins();
#endif
#ifdef USE_EMULATION_WEMO
#define USE_EMULATION
#endif
#ifdef USE_DEVICE_GROUPS
#define USE_EMULATION
#endif
// See https://github.com/esp8266/Arduino/pull/4889
#undef NO_EXTRA_4K_HEAP // Allocate 4k heap for WPS in ESP8166/Arduino core v2.4.2 (was always allocated in previous versions)
@ -329,8 +326,6 @@ const char kWebColors[] PROGMEM =
#ifdef USE_DEVICE_GROUPS
#define SendDeviceGroupMessage(DEVICE_INDEX, REQUEST_TYPE, ...) _SendDeviceGroupMessage(DEVICE_INDEX, REQUEST_TYPE, __VA_ARGS__, 0)
#define SendLocalDeviceGroupMessage(REQUEST_TYPE, ...) _SendDeviceGroupMessage(0, REQUEST_TYPE, __VA_ARGS__, 0)
#define DEVICE_GROUP_MESSAGE "M-TASMOTA_DGR/"
const char kDeviceGroupMessage[] PROGMEM = DEVICE_GROUP_MESSAGE;
uint8_t device_group_count = 1;
#endif // USE_DEVICE_GROUPS

View File

@ -3058,11 +3058,7 @@ bool Xdrv01(uint8_t function)
case FUNC_LOOP:
PollDnsWebserver();
#ifdef USE_EMULATION
#ifdef USE_DEVICE_GROUPS
if (Settings.flag2.emulation || Settings.flag4.device_groups_enabled) { PollUdp(); }
#else // USE_DEVICE_GROUPS
if (Settings.flag2.emulation) { PollUdp(); }
#endif // USE_DEVICE_GROUPS
#endif // USE_EMULATION
break;
case FUNC_COMMAND:

View File

@ -276,7 +276,7 @@ void PWMDimmerHandleButton(void)
}
bool state_updated = false;
int8_t bri_offset = 0;
int32_t bri_offset = 0;
uint8_t power_on_bri = 0;
uint8_t dgr_item = 0;
uint8_t dgr_value;
@ -550,7 +550,7 @@ void PWMDimmerHandleButton(void)
// If the button was not held, adjust the brightness. Set the direction based on which
// button is pressed. The new brightness will be calculated below.
if (button_hold_time[button_index] >= now) {
bri_offset = (is_down_button ? -10 : 10);
bri_offset = (is_down_button ? -1 : 1);
dgr_item = 255;
}
@ -591,9 +591,8 @@ void PWMDimmerHandleButton(void)
else
#endif // USE_PWM_DIMMER_REMOTE
bri = light_state.getBri();
int32_t new_bri;
bri_offset *= (Settings.light_correction ? 4 : bri / 16 + 1);
new_bri = bri + bri_offset;
int32_t new_bri = bri + bri_offset * ((dgr_item ? 16 : Settings.light_correction ? 4 : bri / 16 + 1));
if (bri_offset > 0) {
if (new_bri > 255) new_bri = 255;
}
@ -602,7 +601,7 @@ void PWMDimmerHandleButton(void)
}
if (new_bri != bri) {
#ifdef USE_DEVICE_GROUPS
SendDeviceGroupMessage(power_button_index, (dgr_item ? DGR_MSGTYP_PARTIAL_UPDATE : DGR_MSGTYP_UPDATE_MORE_TO_COME), DGR_ITEM_LIGHT_BRI, new_bri);
SendDeviceGroupMessage(power_button_index, (dgr_item ? DGR_MSGTYP_UPDATE : DGR_MSGTYP_UPDATE_MORE_TO_COME), DGR_ITEM_LIGHT_BRI, new_bri);
#endif // USE_DEVICE_GROUPS
#ifdef USE_PWM_DIMMER_REMOTE
if (!active_device_is_local)