Skip to content
Snippets Groups Projects
Commit 5bb818b7 authored by Alvise de'Faveri's avatar Alvise de'Faveri
Browse files

Fixed dsgamma-test

There are still some problems on reading, and sometimes it goes in stack overflow.
parent a4d3117d
Branches
Tags
No related merge requests found
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
using namespace std; using namespace std;
using namespace miosix; using namespace miosix;
#define MSG_LEN 6 #define PKT_LEN 24
typedef Gpio<GPIOG_BASE,13> greenLed; typedef Gpio<GPIOG_BASE,13> greenLed;
typedef Gpio<GPIOG_BASE,14> redLed; typedef Gpio<GPIOG_BASE,14> redLed;
...@@ -44,8 +44,8 @@ long long sendTime = 0; ...@@ -44,8 +44,8 @@ long long sendTime = 0;
int nTentativi = 0; int nTentativi = 0;
int tot = 0; int tot = 0;
void sender(); void sender(void *arg);
void receiver(void *arg); void receiver();
int main() { int main() {
//Discovery gpio setup //Discovery gpio setup
...@@ -56,14 +56,15 @@ int main() { ...@@ -56,14 +56,15 @@ int main() {
button::mode(Mode::INPUT); button::mode(Mode::INPUT);
} }
sender(); Thread::create(sender, STACK_MIN);
receiver();
return 0; return 0;
} }
void sender(){ void sender(void *arg){
while(1){ while(1){
while(1){ while(1){
...@@ -72,15 +73,13 @@ void sender(){ ...@@ -72,15 +73,13 @@ void sender(){
printf("Writing... \n"); printf("Writing... \n");
nTentativi++; char msg[PKT_LEN];
if(nTentativi == 1) Thread::create(receiver, STACK_MIN); for(int i = 0; i < PKT_LEN; i++){
char msg[MSG_LEN];
for(int i = 0; i < nTentativi; i++){
msg[i] = '#'; msg[i] = '#';
} }
sendTime = miosix::getTick(); sendTime = miosix::getTick();
nTentativi++;
gamma.send(msg); gamma.send(msg);
printf("Ok \n" ); printf("Ok \n" );
...@@ -88,15 +87,16 @@ void sender(){ ...@@ -88,15 +87,16 @@ void sender(){
} }
} }
void receiver(void *arg){ void receiver(){
while(1){ while(1){
//read //read
char inputBuf[MSG_LEN]; // int len = 1; // SENDER ONLY
int len = PKT_LEN;
char inputBuf[len];
printf("Reading: \n"); printf("Reading: \n");
gamma.receive(MSG_LEN, inputBuf); gamma.receive(len, inputBuf);
for(int i = 0; i < MSG_LEN ; i++){ for(int i = 0; i < len ; i++){
printf("Received: %c\n", inputBuf[i]); printf("Received: %c\n", inputBuf[i]);
} }
...@@ -106,15 +106,13 @@ void receiver(void *arg){ ...@@ -106,15 +106,13 @@ void receiver(void *arg){
printf("--------------RESULT------------"); printf("--------------RESULT------------");
tot += rtt; tot += rtt;
if(nTentativi > 0)
printf("Tentativi: %d Media: %d \n", nTentativi, tot/(2*nTentativi)); printf("Tentativi: %d Media: %d \n", nTentativi, tot/(2*nTentativi));
// RECEIVER ONLY // RECEIVER ONLY
//Thread::sleep(50); Thread::sleep(200);
//gamma.send(inputBuf); gamma.send(inputBuf);
//Thread::sleep(200); //Thread::sleep(1000);
} }
} }
\ No newline at end of file
...@@ -54,10 +54,10 @@ bool Gamma868::send(const char *msg) ...@@ -54,10 +54,10 @@ bool Gamma868::send(const char *msg)
bool Gamma868::receive(int bufLen, char *buf) bool Gamma868::receive(int bufLen, char *buf)
{ {
//TODO synchronize //TODO synchronize
char received[bufLen+2]; char received[bufLen+1];
read(fd, &received, bufLen+2); read(fd, &received, bufLen+1);
for(int i = 0; bufLen < bufLen; i++){ for(int i = 0; i < bufLen; i++){
buf[i] = received[i]; buf[i] = received[i];
} }
return true; return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment