Skip to content

Commit

Permalink
buffer length correction
Browse files Browse the repository at this point in the history
  • Loading branch information
Yves BAZIN authored and Yves BAZIN committed Oct 23, 2020
1 parent e2c669a commit 72ea58e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 21 deletions.
76 changes: 55 additions & 21 deletions ArtnetESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <ArtnetESP32.h>
#include <lwip/sockets.h>
#include <lwip/netdb.h>
#define BUFFER_SIZE 800

ArtnetESP32::ArtnetESP32() {}

Expand Down Expand Up @@ -107,7 +108,7 @@ void ArtnetESP32::begin(uint16_t nbpixels,uint16_t nbpixelsperuniverses)
nbNeededUniverses++;
}
//artnetleds1= (uint8_t *)malloc(nbpixels*buffernumber*3);
artnetleds1= (uint8_t *)malloc( (nbpixelsperuniverses*3+ART_DMX_START)*nbNeededUniverses*2 +8);
artnetleds1= (uint8_t *)malloc( (nbpixelsperuniverses*3+ART_DMX_START)*nbNeededUniverses*2 +8+BUFFER_SIZE);
if(artnetleds1==NULL)
{
Serial.printf("impossible to create the buffer\n");
Expand Down Expand Up @@ -293,7 +294,7 @@ uint32_t ArtnetESP32::getElaspseTime()

}

uint16_t ArtnetESP32::read3()
uint16_t ArtnetESP32::readWithoutWaiting()
{
struct sockaddr_in si_other;
int slen = sizeof(si_other) , len;
Expand All @@ -306,6 +307,39 @@ uint16_t ArtnetESP32::read3()
uint8_t * offset;
bool resetframe=true;

timef=millis();
offset=artnetleds1+currentframenumber*decal2;
while(incomingUniverse!=nbNeededUniverses-1)
{
if(millis()-timef>1000)
{
Serial.println("Time out fired");
return 0;
}

if ((len = recvfrom(Udp.udp_server, offset, BUFFER_SIZE, MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) >0 )//1460
{

incomingUniverse = *(offset+14);
}
}


}

uint16_t ArtnetESP32::read3()
{
struct sockaddr_in si_other;
int slen = sizeof(si_other) , len;
long timef=0;

//timef=millis();
incomingUniverse=99;
uint32_t decal=nbPixelsPerUniverse*3+ART_DMX_START;
uint32_t decal2=nbNeededUniverses*decal;
uint8_t * offset;
// bool resetframe=true;

er:
timef=millis();
offset=artnetleds1+currentframenumber*decal2;
Expand All @@ -317,28 +351,28 @@ uint16_t ArtnetESP32::read3()
Serial.println("Time out fired");
return 0;
}
if ((len = recvfrom(Udp.udp_server, offset, 800, MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) >0 )//1460
if ((len = recvfrom(Udp.udp_server, offset, BUFFER_SIZE, MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) >0 )//1460
{

incomingUniverse = offset[14] ;
}
}
// if(resetframe==true or frameslues==0)
// {
// current_time=ESP.getCycleCount();
// if(frameslues==0)
// {
// start_time=current_time;
// }
// elaspe[currentframenumber]=(current_time-start_time);
// /*if(elaspe[currentframenumber]/240000<30)
// Serial.printf("frame:%d time:%lu\n",frameslues,elaspe[currentframenumber]/240);*/
// start_time=current_time;
// }
// if(resetframe==true or frameslues==0)
// {
// current_time=ESP.getCycleCount();
// if(frameslues==0)
// {
// start_time=current_time;
// }
// elaspe[currentframenumber]=(current_time-start_time);
// /*if(elaspe[currentframenumber]/240000<30)
// Serial.printf("frame:%d time:%lu\n",frameslues,elaspe[currentframenumber]/240);*/
// start_time=current_time;
// }
for(int uni=1;uni<nbNeededUniverses;uni++)
{
offset+=decal;
while((len = recvfrom(Udp.udp_server, offset, 800, MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) <=0)
while((len = recvfrom(Udp.udp_server, offset, BUFFER_SIZE, MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) <=0)
{
if(millis()-timef>1000)
{
Expand All @@ -350,7 +384,7 @@ uint16_t ArtnetESP32::read3()
if(incomingUniverse!=uni)
{
lostframes++;
resetframe=false;
// resetframe=false;
goto er;
}
}
Expand Down Expand Up @@ -387,7 +421,7 @@ uint16_t ArtnetESP32::read2()
Serial.println("Time out fired");
return 0;
}
if ((len = recvfrom(Udp.udp_server, offset, 800, MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) >0 )//1460
if ((len = recvfrom(Udp.udp_server, offset, BUFFER_SIZE, MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) >0 )//1460
{

incomingUniverse = offset[14] ;
Expand All @@ -408,7 +442,7 @@ uint16_t ArtnetESP32::read2()
for(int uni=1;uni<nbNeededUniverses;uni++)
{
offset+=decal;
while((len = recvfrom(Udp.udp_server, offset, 800, MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) <=0)
while((len = recvfrom(Udp.udp_server, offset, BUFFER_SIZE, MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) <=0)
{
if(millis()-timef>1000)
{
Expand Down Expand Up @@ -481,7 +515,7 @@ uint16_t ArtnetESP32::read2(TaskHandle_t task)
Serial.println("Time out fired");
return 0;
}
if ((len = recvfrom(Udp.udp_server, offset, 800, MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) >0 )//1460
if ((len = recvfrom(Udp.udp_server, offset, BUFFER_SIZE, MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) >0 )//1460
{

incomingUniverse = offset[14] ;//+ Udp.udpBuffer[15];
Expand All @@ -494,7 +528,7 @@ uint16_t ArtnetESP32::read2(TaskHandle_t task)
for(int uni=1;uni<nbNeededUniverses;uni++)
{
offset+=decal;
while((len = recvfrom(Udp.udp_server, offset, 800, MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) <=0)
while((len = recvfrom(Udp.udp_server, offset, BUFFER_SIZE, MSG_DONTWAIT, (struct sockaddr *) &si_other, (socklen_t *)&slen)) <=0)
{
if(millis()-timef>1000)
{
Expand Down
1 change: 1 addition & 0 deletions ArtnetESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class ArtnetESP32
uint16_t read();
uint16_t read2();
uint16_t read3();
uint16_t readWithoutWaiting();
uint16_t read2(TaskHandle_t task);
uint16_t read(TaskHandle_t task);
void printPacketHeader();
Expand Down

0 comments on commit 72ea58e

Please sign in to comment.