From 4ecaf87e5e7695df40eff8ca221f6a860df61fda Mon Sep 17 00:00:00 2001 From: Tester23 Date: Wed, 29 Nov 2023 11:02:28 +0100 Subject: [PATCH] cosmetic-only cleanup of DGR code --- src/driver/drv_tasmotaDeviceGroups.c | 125 +-------------------------- 1 file changed, 1 insertion(+), 124 deletions(-) diff --git a/src/driver/drv_tasmotaDeviceGroups.c b/src/driver/drv_tasmotaDeviceGroups.c index 9eb52e6b6..739406d3d 100644 --- a/src/driver/drv_tasmotaDeviceGroups.c +++ b/src/driver/drv_tasmotaDeviceGroups.c @@ -141,38 +141,6 @@ void DGR_FlushSendQueue() { xSemaphoreGive(g_mutex); } - -// DGR send can be called from MQTT LED driver, but doing a DGR send -// directly from there may cause crashes. -// This is a temporary solution to avoid this problem. -//bool g_dgr_ledDimmerPendingSend = false; -//int g_dgr_ledDimmerPendingSend_value; -//bool g_dgr_ledPowerPendingSend = false; -//int g_dgr_ledPowerPendingSend_value; - -// -//int DRV_DGR_CreateSocket_Send() { -// -// struct sockaddr_in addr; -// int flag = 1; -// int fd; -// -// // create what looks like an ordinary UDP socket -// // -// fd = socket(AF_INET, SOCK_DGRAM, 0); -// if (fd < 0) { -// return 1; -// } -// -// memset(&addr, 0, sizeof(addr)); -// addr.sin_family = AF_INET; -// addr.sin_addr.s_addr = inet_addr(dgr_group); -// addr.sin_port = htons(dgr_port); -// -// -// return 0; -//} - byte Val255ToVal100(byte v){ float fr; // convert to our 0-100 range @@ -188,70 +156,26 @@ byte Val100ToVal255(byte v){ } void DRV_DGR_CreateSocket_Send() { // create what looks like an ordinary UDP socket - // g_dgr_socket_send = socket(AF_INET, SOCK_DGRAM, 0); if (g_dgr_socket_send < 0) { addLogAdv(LOG_INFO, LOG_FEATURE_DGR,"DRV_DGR_CreateSocket_Send: failed to do socket\n"); return; } addLogAdv(LOG_INFO, LOG_FEATURE_DGR,"DRV_DGR_CreateSocket_Send: socket created\n"); - - - } void DRV_DGR_Send_Generic(byte *message, int len) { - //struct sockaddr_in addr; - //int nbytes; - // if this send is as a result of use RXing something, // don't send it.... if (g_inCmdProcessing){ return; } - g_dgr_send_seq++; -#if 1 // This is here only because sending UDP from MQTT callback crashes BK for me // So instead, we are making a queue which is sent in quick tick DGR_AddToSendQueue(message, len); addLogAdv(LOG_EXTRADEBUG, LOG_FEATURE_DGR, "DGR adds to queue %i",len); -#else - - // set up destination address - // - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = inet_addr(dgr_group); - addr.sin_port = htons(dgr_port); - - nbytes = sendto( - g_dgr_socket_send, - (const char*) message, - len, - 0, - (struct sockaddr*) &addr, - sizeof(addr) - ); - - rtos_delay_milliseconds(1); - - // send twice with same seq. - nbytes = sendto( - g_dgr_socket_send, - (const char*) message, - len, - 0, - (struct sockaddr*) &addr, - sizeof(addr) - ); - - DRV_DGR_Dump(message, len); - - addLogAdv(LOG_EXTRADEBUG, LOG_FEATURE_DGR,"DRV_DGR_Send_Generic: sent message with seq %i\n",g_dgr_send_seq); -#endif - } void DRV_DGR_Dump(byte *message, int len){ @@ -592,7 +516,6 @@ void DRV_DGR_RunQuickTick() { return; } - if (g_mySockAddr.sin_addr.s_addr == addr.sin_addr.s_addr) { continue; } @@ -607,31 +530,6 @@ void DRV_DGR_RunQuickTick() { DGR_ProcessIncomingPacket(msgbuf, nbytes); } } -//static void DRV_DGR_Thread(beken_thread_arg_t arg) { -// -// (void)( arg ); -// -// DRV_DGR_CreateSocket_Receive(); -// while(1) { -// DRV_DGR_RunQuickTick(); -// } -// -// return ; -//} -//xTaskHandle g_dgr_thread = NULL; - -//void DRV_DGR_StartThread() -//{ -// OSStatus err = kNoErr; -// -// -// err = rtos_create_thread( &g_dgr_thread, BEKEN_APPLICATION_PRIORITY, -// "DGR_server", -// (beken_thread_function_t)DRV_DGR_Thread, -// 0x100, -// (beken_thread_arg_t)0 ); -// -//} void DRV_DGR_Shutdown() { if(g_dgr_socket_receive>=0) { @@ -695,12 +593,7 @@ void DRV_DGR_OnLedDimmerChange(int iVal) { return; } -#if 0 - g_dgr_ledDimmerPendingSend = true; - g_dgr_ledDimmerPendingSend_value = iVal; -#else DRV_DGR_Send_Brightness(CFG_DeviceGroups_GetName(), Val100ToVal255(iVal)); -#endif } void DRV_DGR_OnLedFinalColorsChange(byte rgbcw[5]) { @@ -717,12 +610,7 @@ void DRV_DGR_OnLedFinalColorsChange(byte rgbcw[5]) { return; } -#if 0 - //g_dgr_ledDimmerPendingSend = true; - //g_dgr_ledDimmerPendingSend_value = iVal; -#else DRV_DGR_Send_RGBCW(CFG_DeviceGroups_GetName(), rgbcw); -#endif } @@ -741,12 +629,7 @@ void DRV_DGR_OnLedEnableAllChange(int iVal) { return; } -#if 0 - g_dgr_ledPowerPendingSend = true; - g_dgr_ledPowerPendingSend_value = iVal; -#else DRV_DGR_Send_Power(CFG_DeviceGroups_GetName(), iVal, 1); -#endif } void DRV_DGR_OnChannelChanged(int ch, int value) { int channelValues; @@ -796,9 +679,6 @@ void DRV_DGR_OnChannelChanged(int ch, int value) { if(channelsCount>0){ DRV_DGR_Send_Power(groupName,channelValues,channelsCount); } - - - } // DGR_SendBrightness roomLEDstrips 128 // DGR_SendBrightness stringGroupName integerBrightness @@ -895,13 +775,10 @@ void DRV_DGR_Init() { memset(&g_dgrMembers[0],0,sizeof(g_dgrMembers)); g_curDGRMembers = 0; -#if 0 - DRV_DGR_StartThread(); -#else + DRV_DGR_CreateSocket_Receive(); DRV_DGR_CreateSocket_Send(); -#endif //cmddetail:{"name":"DGR_SendPower","args":"[GroupName][ChannelValues][ChannelsCount]", //cmddetail:"descr":"Sends a POWER message to given Tasmota Device Group with no reliability. Requires no prior setup and can control any group, but won't retransmit.", //cmddetail:"fn":"CMD_DGR_SendPower","file":"driver/drv_tasmotaDeviceGroups.c","requires":"",