Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface LM75B mbed-rtos mbed
Fork of communication by
Revision 4:4848f847d2ce, committed 2018-03-23
- Comitter:
- JelleRaes
- Date:
- Fri Mar 23 13:43:04 2018 +0000
- Parent:
- 3:9c600fb19ed2
- Commit message:
- projectlab
Changed in this revision
--- a/led.cpp Wed Mar 14 14:39:08 2018 +0000
+++ b/led.cpp Fri Mar 23 13:43:04 2018 +0000
@@ -12,65 +12,56 @@
colors[].blueValue = ;
*/
- count =10;
- colors[0].name= "red";
+ count =8;
+ colors[0].name= "RED";
colors[0].redValue = 0.0;
colors[0].greenValue = 1.0;
colors[0].blueValue = 1.0;
- colors[1].name= "green";
+ colors[1].name= "GREEN";
colors[1].redValue = 1.0;
colors[1].greenValue = 0.0;
colors[1].blueValue = 1.0;
- colors[2].name= "blue";
+ colors[2].name= "BLUE";
colors[2].redValue = 1.0;
colors[2].greenValue = 1.0;
colors[2].blueValue = 0.0;
- colors[3].name= "black";
+ colors[3].name= "BLACK";
colors[3].redValue = 1.0;
colors[3].greenValue = 1.0;
colors[3].blueValue = 1.0;
- colors[4].name= "white";
+ colors[4].name= "WHITE";
colors[4].redValue = 0.0;
colors[4].greenValue = 0.0;
colors[4].blueValue = 0.0;
- colors[5].name = "yellow";
+ colors[5].name = "ORANGE";
colors[5].redValue = 0.0;
colors[5].greenValue = 0.0;
colors[5].blueValue = 1.0;
- colors[6].name = "magenta";
+ colors[6].name = "MAGENTA";
colors[6].redValue = 0.0;
colors[6].greenValue = 1.0;
colors[6].blueValue = 0.0;
- colors[7].name = "cyan";
+ colors[7].name = "CYAN";
colors[7].redValue = 1.0;
colors[7].greenValue = 0.0;
colors[7].blueValue = 0.0;
-
- colors[8].name = "purple";
- colors[8].redValue = 0.498;
- colors[8].greenValue = 1.0;
- colors[8].blueValue = 0.498;
-
- colors[9].name = "brown";
- colors[9].redValue = 0.353;
- colors[9].greenValue = 0.835;
- colors[9].blueValue = 0.835;
}
led::COLOR led::getCOLOR(char *n){
- //led::COLOR temp;
+ led::COLOR temp;
for(int i=0;i<count;i++){
- if(strcmp(colors[i].name,n) ==0)
- n ="found";
- return colors[i];}
- //return temp;
- n = "failed";
+ if(strcmp(colors[i].name,n) ==0){
+ temp =colors[i];
+ break;
+ }
+ }
+ return temp;
}
\ No newline at end of file
--- a/led.h Wed Mar 14 14:39:08 2018 +0000 +++ b/led.h Fri Mar 23 13:43:04 2018 +0000 @@ -15,7 +15,7 @@ private: int count; -COLOR colors[10]; +COLOR colors[8]; }; #endif \ No newline at end of file
--- a/main.cpp Wed Mar 14 14:39:08 2018 +0000
+++ b/main.cpp Fri Mar 23 13:43:04 2018 +0000
@@ -40,11 +40,11 @@
char firstID[] = "192.168.0.";
pc.scanf("%3s",id);
ip = strcat(firstID,id);
- pc.printf("full IPadress is\n%s\n\r",ip);
- pc.printf("choose mode: up = master / down = slave\n\r");
+ pc.printf("full IPadress is: %s\n\r",ip);
+ pc.printf("choose mode with joystick: up = master / down = slave\n\r");
while(select == 0 || mode==0){
- if(joy.read()==1){mode = 1;pc.printf("mode set to master\n");while(joy.read()==1);}//set mode in master.
- if(joy.read()==2){mode = 2;pc.printf("mode set to slave\n");while(joy.read()==2);}//set mode in slave
+ if(joy.read()==1 && mode !=1){mode = 1;pc.printf("mode set to master\n\r");while(joy.read()==1);}//set mode in master.
+ if(joy.read()==2 && mode !=2){mode = 2;pc.printf("mode set to slave\n\r");while(joy.read()==2);}//set mode in slave
}
pc.printf("ok\n\r");
}
\ No newline at end of file
--- a/master.h Wed Mar 14 14:39:08 2018 +0000
+++ b/master.h Fri Mar 23 13:43:04 2018 +0000
@@ -2,11 +2,22 @@
#define MASTER_H
class master{
public:
- master();
+ master();//Empty constuctor
+
+ /*starts up the loop for the master which opens de connection after a
+ *a request has been send and closes the connection again after an
+ *acknowledge has been received
+ */
void startMaster(const char* ip);
private:
+ /*Function that allows the user to type a command after which it is placed
+ *inside a char array.
+ */
void typeRequest(char* buffer);
+
+ /*Function that allows the user to type the desired target IP
+ */
void typeIp(char* buffer);
};
#endif
\ No newline at end of file
--- a/slave.cpp Wed Mar 14 14:39:08 2018 +0000
+++ b/slave.cpp Fri Mar 23 13:43:04 2018 +0000
@@ -58,63 +58,42 @@
char *request = strtok((char*)buffer," ");//{buffer[0],buffer[1],buffer[2],'\0'};
char *resource = strtok(NULL," ");
slavepc.printf("\n\rresource =%s\n\r",resource);
+ char tempbuffer[512];
if(strcmp(request,"GET")==0){
- if(strcmp(resource,"/TEMPERATURE")==0){
- char tempbuffer[512];
- sprintf(tempbuffer,"ACK 2.05 %14s %3.3f", ip, getTemp());
+ if(strcmp(resource,"/temperature")==0){
+ sprintf(tempbuffer,"ACK 2.05 %3s %3.3f", getID(ip), getTemp());
slavepc.printf("%s\n\r",tempbuffer);
- return tempbuffer;
}
- else if(strcmp(resource,"/POTENTIOMETER")==0){
- char tempbuffer[512];
+ else if(strcmp(resource,"/potentiometer")==0){
slavepc.printf("%f",getPot());
- sprintf(tempbuffer,"ACK 2.05 %14s %3d", ip,int(255* getPot()));
+ sprintf(tempbuffer,"ACK 2.05 %3s %3d", getID(ip),int(255* getPot()));
slavepc.printf("%s\n\r",tempbuffer);
- return tempbuffer;
}
else{
- char tempbuffer[512];
- sprintf(tempbuffer,"ACK 4.00 %14s",ip);
- return tempbuffer;
+ sprintf(tempbuffer,"ACK 4.00 %3s",getID(ip));
}
}
else if(strcmp(request,"PUT")==0){
if(strcmp(resource,"/BUZZER")==0){
- putBuzzer(atoi(strtok(NULL," -")),atoi(strtok(NULL," -")));
- char tempbuffer[512];
- sprintf(tempbuffer,"ACK 2.04 %14s",ip);
- return tempbuffer;
+ putBuzzer(atoi(strtok(NULL," -_")),atoi(strtok(NULL," -_")));
+ sprintf(tempbuffer,"ACK 2.04 %3s",getID(ip));
}
else if(strcmp(resource,"/LED")==0){
- char *color=strtok(NULL,'\0');
- putLED(color);
- char tempbuffer[512];
- //if(strcmp(color,"found")==0){
- sprintf(tempbuffer,"ACK 2.04 %14s",ip);
- return tempbuffer;
- //}
- /*else{
- sprintf(tempbuffer,"ACK 4.00 %14s",ip);
- return tempbuffer;
- }*/
+ putLED(strtok(NULL,'\0'));
+ sprintf(tempbuffer,"ACK 2.04 %3s",getID(ip));
}
else if(strcmp(resource,"/LCD")==0){
putLCD(strtok(NULL,'\0'));
- char tempbuffer[512];
- sprintf(tempbuffer,"ACK 2.04 %14s",ip);
- return tempbuffer;
+ sprintf(tempbuffer,"ACK 2.04 %3s",getID(ip));
}
else{
- char tempbuffer[512];
- sprintf(tempbuffer,"ACK 4.00 %14s",ip);
- return tempbuffer;
+ sprintf(tempbuffer,"ACK 4.00 %3s",getID(ip));
}
}
else{
- char tempbuffer[512];
- sprintf(tempbuffer,"ACK 4.00 %14s",ip);
- return tempbuffer;
+ sprintf(tempbuffer,"ACK 4.00 %3s",getID(ip));
}
+ return tempbuffer;
}
float slave::getTemp(){
@@ -132,15 +111,10 @@
}
void slave::putLED(char *color){
- r=mijnobject.getCOLOR(color).redValue;
- g=mijnobject.getCOLOR(color).greenValue;
- b=mijnobject.getCOLOR(color).blueValue;
-}
-
-void slave::putLED(float red, float green, float blue){
- r= red;
- g= green;
- b= blue;
+ led::COLOR testcolor = mijnobject.getCOLOR(color);
+ r=testcolor.redValue;
+ g=testcolor.greenValue;
+ b=testcolor.blueValue;
}
void slave::putBuzzer(int start,int einde){
@@ -152,3 +126,14 @@
wait(delay[start]/1000);
}
}
+
+char *slave::getID(const char* ip){
+ char temp[14];
+ sprintf(temp,"%13s",(char*)ip);
+ char *temp2;
+ temp2 = strtok(temp,".");
+ temp2 = strtok(NULL,".");
+ temp2 = strtok(NULL,".");
+ char *id = strtok(NULL,'\0');
+ return id;
+}
\ No newline at end of file
--- a/slave.h Wed Mar 14 14:39:08 2018 +0000
+++ b/slave.h Fri Mar 23 13:43:04 2018 +0000
@@ -6,11 +6,11 @@
void startSlave(const char *ip);
private:
+ char *getID(const char* ip);
float getTemp();
float getPot();
void putLCD(char*);
void putLED(char*);
- void putLED(float, float, float);
void putBuzzer(int,int);
char *getResponse(const char *request,const char *ip);
};
