Commit 78a024f7ade45ffd271d72cb1d8081bfbfd29365
1 parent
4ed129b3
Ajustements et clarifications
Showing
3 changed files
with
43 additions
and
29 deletions
Show diff stats
page_web/index.html
@@ -76,7 +76,6 @@ setTimeout('autoSend4();', 200); | @@ -76,7 +76,6 @@ setTimeout('autoSend4();', 200); | ||
76 | } | 76 | } |
77 | function autoSend4(){ | 77 | function autoSend4(){ |
78 | websocket.send('4'); | 78 | websocket.send('4'); |
79 | -//setTimeout('autoSend0();', 500); | ||
80 | } | 79 | } |
81 | setInterval(autoSend0, 1000); | 80 | setInterval(autoSend0, 1000); |
82 | 81 |
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +/* | ||
2 | + * Public definitions for serial library | ||
3 | + */ | ||
4 | + | ||
5 | +//// | ||
6 | +// Constants | ||
7 | +//// | ||
8 | + | ||
9 | +#define SERIAL_READ 0 | ||
10 | +#define SERIAL_WRITE 1 | ||
11 | +#define SERIAL_BOTH 2 | ||
12 | + | ||
13 | +//// | ||
14 | +// Public prototypes | ||
15 | +//// | ||
16 | +int serialOpen(char *device,int mode); | ||
17 | +void serialConfig(int fd,int speed); | ||
18 | +void serialClose(int fd); |
serveur/websocket_server.c
@@ -38,56 +38,53 @@ static int callback_my( | @@ -38,56 +38,53 @@ static int callback_my( | ||
38 | struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, | 38 | struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, |
39 | void *user,void *in,size_t len) | 39 | void *user,void *in,size_t len) |
40 | { | 40 | { |
41 | -printf("boucle\n"); | ||
42 | -static char *message=NULL; | 41 | +static char *mesage=NULL; |
43 | static int msize=0; | 42 | static int msize=0; |
44 | switch(reason) | 43 | switch(reason) |
45 | { | 44 | { |
46 | - printf("%s\n",reason); | ||
47 | case LWS_CALLBACK_ESTABLISHED: | 45 | case LWS_CALLBACK_ESTABLISHED: |
48 | printf("connection established\n"); | 46 | printf("connection established\n"); |
49 | - message=NULL; | 47 | + mesage=NULL; |
50 | 48 | ||
51 | // Declenchement d'un prochain envoi au navigateur | 49 | // Declenchement d'un prochain envoi au navigateur |
52 | libwebsocket_callback_on_writable(this,wsi); | 50 | libwebsocket_callback_on_writable(this,wsi); |
53 | break; | 51 | break; |
52 | + | ||
54 | case LWS_CALLBACK_RECEIVE: | 53 | case LWS_CALLBACK_RECEIVE: |
55 | 54 | ||
56 | - // Ici sont traites les messages envoyes par le navigateur | ||
57 | - printf("received data: %s\n",(char *)in); | ||
58 | - message=malloc(len+LWS_SEND_BUFFER_PRE_PADDING+LWS_SEND_BUFFER_POST_PADDING); | ||
59 | - if(message==NULL) | ||
60 | - { | 55 | + // Ici sont traites les mesages envoyes par le navigateur |
56 | + char* recei=(char *)in; | ||
57 | + int rec = *recei - 48; //réception de l'instruction, convertie en entier | ||
58 | + printf("received data: %d\n",rec); | ||
59 | + mesage=malloc(len+LWS_SEND_BUFFER_PRE_PADDING+LWS_SEND_BUFFER_POST_PADDING); | ||
60 | + if(mesage==NULL) | ||
61 | + { | ||
61 | perror("callback_my.malloc"); | 62 | perror("callback_my.malloc"); |
62 | exit(EXIT_FAILURE); | 63 | exit(EXIT_FAILURE); |
63 | - } | ||
64 | - | ||
65 | - int a=0; | ||
66 | - char value[3]; | ||
67 | - sprintf (value, "%d", serial_read(&a)) ; | ||
68 | - printf("value = %s\n",value); | ||
69 | - //char* value = "0"; | ||
70 | - // memcpy(message+LWS_SEND_BUFFER_PRE_PADDING,in,len); | ||
71 | - memcpy(message+LWS_SEND_BUFFER_PRE_PADDING,value,1 + strlen(value)); | 64 | + } |
65 | + char value[3]; | ||
66 | + sprintf (value, "%d", (10*serial_read(&rec))+rec); //réception de la valeur demandée, sous forme de str | ||
67 | + printf("value = %s\n",value); | ||
68 | + memcpy(mesage+LWS_SEND_BUFFER_PRE_PADDING,value,1 + strlen(value)); | ||
72 | 69 | ||
73 | // Declenchement d'un prochain envoi au navigateur | 70 | // Declenchement d'un prochain envoi au navigateur |
74 | - //msize=len; | ||
75 | msize=strlen(value); | 71 | msize=strlen(value); |
76 | libwebsocket_callback_on_writable(this,wsi); | 72 | libwebsocket_callback_on_writable(this,wsi); |
77 | break; | 73 | break; |
74 | + | ||
78 | case LWS_CALLBACK_SERVER_WRITEABLE: | 75 | case LWS_CALLBACK_SERVER_WRITEABLE: |
79 | - | ||
80 | - // Ici sont envoyes les messages au navigateur | ||
81 | - if(message!=NULL){ | ||
82 | - char *out=message+LWS_SEND_BUFFER_PRE_PADDING; | 76 | + // Ici sont envoyes les mesages au navigateur |
77 | + if(mesage!=NULL) | ||
78 | + { | ||
79 | + char *out=mesage+LWS_SEND_BUFFER_PRE_PADDING; | ||
83 | printf("%s\n",out); | 80 | printf("%s\n",out); |
84 | printf("%d\n",msize); | 81 | printf("%d\n",msize); |
85 | libwebsocket_write(wsi,(unsigned char *)out,msize,LWS_WRITE_TEXT); | 82 | libwebsocket_write(wsi,(unsigned char *)out,msize,LWS_WRITE_TEXT); |
86 | - //libwebsocket_write(wsi,(unsigned char *)out,msize,LWS_WRITE_TEXT); | ||
87 | - free(message); | ||
88 | - message=NULL; | ||
89 | - } | 83 | + free(mesage); |
84 | + mesage=NULL; | ||
85 | + } | ||
90 | break; | 86 | break; |
87 | + | ||
91 | default: | 88 | default: |
92 | break; | 89 | break; |
93 | } | 90 | } |
@@ -160,7 +157,7 @@ int n=0; | @@ -160,7 +157,7 @@ int n=0; | ||
160 | int value=0; | 157 | int value=0; |
161 | int sd=serialOpen(SERIAL_DEVICE,SERIAL_BOTH); | 158 | int sd=serialOpen(SERIAL_DEVICE,SERIAL_BOTH); |
162 | serialConfig(sd,B9600); | 159 | serialConfig(sd,B9600); |
163 | -if(write(sd,&c,sizeof(char))!=1){ perror("main.write"); exit(-1); } | 160 | +if(write(sd,&c,sizeof(char))!=1){ perror("main.write"); exit(-1); } //Envoi de l'instruction |
164 | 161 | ||
165 | //Read the number of decimals | 162 | //Read the number of decimals |
166 | if(read(sd,&n,sizeof(char))!=1){ perror("main.read"); exit(-1); } | 163 | if(read(sd,&n,sizeof(char))!=1){ perror("main.read"); exit(-1); } |