Skip to content

Commit

Permalink
some little DGR optimizations (avoid calling get IP in quick tick, etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Nov 26, 2023
1 parent f0cb3c5 commit ee33a58
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/driver/drv_tasmotaDeviceGroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ void DRV_DGR_Send_Generic(byte *message, int len) {
}

void DRV_DGR_Dump(byte *message, int len){
#ifdef DGRLOADMOREDEBUG
char tmp[100];
char *p = tmp;
for (int i = 0; i < len && i < 49; i++){
Expand All @@ -263,7 +262,6 @@ void DRV_DGR_Dump(byte *message, int len){
}
*p = 0;
addLogAdv(LOG_INFO, LOG_FEATURE_DGR,"DRV_DGR_Send_Generic: %s",tmp);
#endif
}

void DRV_DGR_Send_Power(const char *groupName, int channelValues, int numChannels){
Expand Down Expand Up @@ -534,6 +532,12 @@ int DGR_CheckSequence(uint16_t seq) {
}

void DRV_DGR_RunEverySecond() {
const char *myip;

// TODO: do it only on IP change?
myip = HAL_GetMyIPString();
g_mySockAddr.sin_addr.s_addr = inet_addr(myip);

if(g_dgr_socket_receive<=0 || g_dgr_socket_send <= 0) {
dgr_retry_time_left--;
addLogAdv(LOG_INFO, LOG_FEATURE_DGR,"no sockets, will retry creation soon, in %i secs\n",dgr_retry_time_left);
Expand Down Expand Up @@ -572,28 +576,26 @@ void DGR_ProcessIncomingPacket(char *msgbuf, int nbytes) {

// don't send things that result from something we rxed...
g_inCmdProcessing = 1;
#ifdef DGRLOADMOREDEBUG
DRV_DGR_Dump((byte*)msgbuf, nbytes);

#endif
DGR_Parse((byte*)msgbuf, nbytes, &def, (struct sockaddr *)&addr);
g_inCmdProcessing = 0;

}
struct sockaddr_in g_mySockAddr;

void DRV_DGR_RunQuickTick() {
char msgbuf[64];
struct sockaddr_in me;
const char *myip;
char msgbuf[64];
socklen_t addrlen;
int nbytes;
int i;

if(g_dgr_socket_receive<=0 || g_dgr_socket_send <= 0) {
return ;
}
// send pending
// send pending
DGR_FlushSendQueue();

myip = HAL_GetMyIPString();
me.sin_addr.s_addr = inet_addr(myip);

// NOTE: 'addr' is global, and used in callbacks to determine the member.
for (i = 0; i < 10; i++) {
Expand All @@ -611,7 +613,7 @@ void DRV_DGR_RunQuickTick() {
}


if (me.sin_addr.s_addr == addr.sin_addr.s_addr) {
if (g_mySockAddr.sin_addr.s_addr == addr.sin_addr.s_addr) {
continue;
}

Expand Down

0 comments on commit ee33a58

Please sign in to comment.