Skip to content

Commit

Permalink
cosmetic-only cleanup of DGR code
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Nov 29, 2023
1 parent 3cd75b9 commit 4ecaf87
Showing 1 changed file with 1 addition and 124 deletions.
125 changes: 1 addition & 124 deletions src/driver/drv_tasmotaDeviceGroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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){
Expand Down Expand Up @@ -592,7 +516,6 @@ void DRV_DGR_RunQuickTick() {
return;
}


if (g_mySockAddr.sin_addr.s_addr == addr.sin_addr.s_addr) {
continue;
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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]) {
Expand All @@ -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
}


Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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":"",
Expand Down

0 comments on commit 4ecaf87

Please sign in to comment.