Commit f3af3787dafde03c91795f2e597244eacb0d956a

Authored by csaad
2 parents ebafc595 9d49ca3a

Merge branch 'master' of archives.plil.fr:jsenella/veilleuse_connectee

Mise à jour des deux cote

 Merge branch 'master' of archives.plil.fr:jsenella/veilleuse_connectee
liaisonSerie/serial.c 0 → 100644
... ... @@ -0,0 +1,55 @@
  1 +/*
  2 + * Serial library
  3 + */
  4 +
  5 +////
  6 +// Include files
  7 +////
  8 +#include <stdio.h>
  9 +#include <stdlib.h>
  10 +#include <unistd.h>
  11 +#include <fcntl.h>
  12 +#include <termios.h>
  13 +#include <strings.h>
  14 +#include <sys/types.h>
  15 +#include <sys/ioctl.h>
  16 +#include <sys/file.h>
  17 +#include <linux/serial.h>
  18 +
  19 +#include "serial.h"
  20 +
  21 +////
  22 +// Functions
  23 +////
  24 +
  25 +//
  26 +// Open serial port device
  27 +//
  28 +int serialOpen(char *device,int mode){
  29 +int flags=(mode==SERIAL_READ?O_RDONLY:(mode==SERIAL_WRITE?O_WRONLY:O_RDWR));
  30 +int fd=open(device,flags|O_NOCTTY);
  31 +if(fd<0){ perror(device); exit(-1); }
  32 +return fd;
  33 +}
  34 +
  35 +//
  36 +// Serial port configuration
  37 +//
  38 +void serialConfig(int fd,int speed){
  39 +struct termios new;
  40 +bzero(&new,sizeof(new));
  41 +new.c_cflag=CLOCAL|CREAD|speed|CS8;
  42 +new.c_iflag=0;
  43 +new.c_oflag=0;
  44 +new.c_lflag=0; /* set input mode (non-canonical, no echo,...) */
  45 +new.c_cc[VTIME]=0; /* inter-character timer unused */
  46 +new.c_cc[VMIN]=1; /* blocking read until 1 char received */
  47 +if(tcsetattr(fd,TCSANOW,&new)<0){ perror("serialInit.tcsetattr"); exit(-1); }
  48 +}
  49 +
  50 +//
  51 +// Serial port termination
  52 +//
  53 +void serialClose(int fd){
  54 +close(fd);
  55 +}
... ...
liaisonSerie/serial.h 0 → 100644
... ... @@ -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);
... ...
liaisonSerie/test.c 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +/*
  2 + * Test on serial device
  3 + */
  4 +
  5 +////
  6 +// Include files
  7 +////
  8 +#include <stdio.h>
  9 +#include <stdlib.h>
  10 +#include <unistd.h>
  11 +#include <termios.h>
  12 +
  13 +#include "serial.h"
  14 +
  15 +////
  16 +// Constants
  17 +////
  18 +#define SERIAL_DEVICE "/dev/ttyACM0"
  19 +
  20 +////
  21 +// Global variables
  22 +////
  23 +
  24 +////
  25 +// Main function
  26 +////
  27 +
  28 +int main(void){
  29 +int c=0;
  30 +int sd=serialOpen(SERIAL_DEVICE,SERIAL_BOTH);
  31 +serialConfig(sd,B9600);
  32 +if(write(sd,&c,sizeof(char))!=1){ perror("main.write"); exit(-1); }
  33 +int i;
  34 +for(i=0;i<8;i++){
  35 + if(read(sd,&c,sizeof(char))!=1){ perror("main.read"); exit(-1); }
  36 + printf("%02x\n",c);
  37 + }
  38 +serialClose(sd);
  39 +exit(0);
  40 +}
... ...
liaisonSerie/test.c~ 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +/*
  2 + * Test on serial device
  3 + */
  4 +
  5 +////
  6 +// Include files
  7 +////
  8 +#include <stdio.h>
  9 +#include <stdlib.h>
  10 +#include <unistd.h>
  11 +#include <termios.h>
  12 +
  13 +#include "serial.h"
  14 +
  15 +////
  16 +// Constants
  17 +////
  18 +#define SERIAL_DEVICE "/dev/ttyACM0"
  19 +
  20 +////
  21 +// Global variables
  22 +////
  23 +
  24 +////
  25 +// Main function
  26 +////
  27 +
  28 +int main(void){
  29 +int c=0;
  30 +int sd=serialOpen(SERIAL_DEVICE,SERIAL_BOTH);
  31 +serialConfig(sd,B9600);
  32 +if(write(sd,&c,sizeof(char))!=1){ perror("main.write"); exit(-1); }
  33 +int i;
  34 +for(i=0;i<8;i++){
  35 + if(read(sd,&c,sizeof(char))!=1){ perror("main.read"); exit(-1); }
  36 + printf("%02x\n",c);
  37 + }
  38 +serialClose(sd);
  39 +exit(0);
  40 +}
... ...
pageHTML/Menu.css
1 1 .introduction {
2   - color: red;
3 2 font-size: 40px;
4 3 font-family: Verdana;
5 4 font-style: italic;
... ... @@ -9,7 +8,7 @@
9 8  
10 9 body
11 10 {
12   - color: black; /* Le texte de la page sera blanc */
  11 + color: black;
13 12 }
14 13  
15 14 .onoffswitch {
... ...
pageHTML/Menu.html
1 1 <!DOCTYPE html>
2   -<html lang="en">
3   -<head>
  2 +<html>
  3 + <head>
4 4 <meta charset="UTF-8">
  5 + <script src="jquery.js"></script>
  6 + <script type= "text/javascript">
  7 + window.Websocket = (window.Websocket || window.MozWebSocket);
  8 + var websocket = new WebSocket('ws://192.168.43.222:9000, 'myprotocol');};
  9 + websocket.onerror=function(){ $('h1').css('color','red');};
  10 + websocket.onopen=function(){ $('h1').css('color','green');};
  11 +
  12 + webscket.onmessage=function(message){
  13 + console.log(message.data);
  14 + $('#messages').append($('<p>',{ text: message.data}));
  15 + };
  16 +
  17 + function sendMessage(){
  18 + websocket.send($('#message').val());
  19 + $('message').val('');
  20 + }
  21 + </script>
  22 +
5 23 <link rel="stylesheet" href="Menu.css" />
6 24 <title>Menu Veilleuse connectée</title>
7   -</head>
8   -<body>
9   -<h1 class = "introduction">Bienvenue sur le menu de votre veilleuse connectée</h1>
10   -
11   -<ul class = "choix">
12   - <li><h2><a href="intensite.html">Changement de l'intensité</a></h2></li>
13   - <li><h2><a href = "couleur.html">Changement de la couleur</a></h2></li>
14   - <li><h2><a href = "mode.html">Sélection du mode</a></h2></li>
15   -</ul>
16   -<h4 classe = "etat">Etat de la veilleuse</h4>
17   -<div class="onoffswitch">
18   - <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
19   - <label class="onoffswitch-label" for="myonoffswitch">
  25 + </head>
  26 +
  27 + <body>
  28 + <h1 class = "introduction">Bienvenue sur le menu de votre veilleuse connectée</h1>
  29 +
  30 + <ul class = "choix">
  31 + <li><h2><a href="intensite.html">Changement de l'intensité</a></h2></li>
  32 + <li><h2><a href = "couleur.html">Changement de la couleur</a></h2></li>
  33 + <li><h2><a href = "mode.html">Sélection du mode</a></h2></li>
  34 + </ul>
  35 + <h4 classe = "etat">Etat de la veilleuse</h4>
  36 + <div class="onoffswitch">
  37 + <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
  38 + <label class="onoffswitch-label" for="myonoffswitch">
20 39 <span class="onoffswitch-inner"></span>
21 40 <span class="onoffswitch-switch"></span>
22   - </label>
23   -</div>
24   -</body>
  41 + </label>
  42 + </div>
  43 + </body>
25 44 </html>
... ...
pageHTML/intensite.html deleted
... ... @@ -1,18 +0,0 @@
1   -<!DOCTYPE html>
2   -<html lang="en">
3   -<head>
4   - <meta charset="UTF-8">
5   - <title>Changement d'intensité</title>
6   -
7   -</head>
8   -<body>
9   -<h1>Changement d'intensite de votre veilleuse connectée</h1>
10   -<div id = "slider">
11   - <input type ="range" min ="0" max="255" value ="100" onchange = "rangevalue.value=value">
12   - <span class = "highlight"></span>
13   - <output id="rangevalue">50</output>
14   -</div>
15   -
16   -<h3><a href="Menu.html">Retour</a></h3>
17   -</body>
18   -</html>
pageHTML/mode.css deleted
... ... @@ -1,45 +0,0 @@
1   -.onoffswitch {
2   - position: relative; width: 138px;
3   - -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
4   -}
5   -.onoffswitch-checkbox {
6   - display: none;
7   -}
8   -.onoffswitch-label {
9   - display: block; overflow: hidden; cursor: pointer;
10   - border: 2px solid #999999; border-radius: 19px;
11   -}
12   -.onoffswitch-inner {
13   - display: block; width: 200%; margin-left: -100%;
14   - transition: margin 0.3s ease-in 0s;
15   -}
16   -.onoffswitch-inner:before, .onoffswitch-inner:after {
17   - display: block; float: left; width: 50%; height: 34px; padding: 0; line-height: 34px;
18   - font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
19   - box-sizing: border-box;
20   -}
21   -.onoffswitch-inner:before {
22   - content: "Automatique";
23   - padding-left: 10px;
24   - background-color: #30A9C7; color: #FFFFFF;
25   -}
26   -.onoffswitch-inner:after {
27   - content: "Manuel";
28   - padding-right: 10px;
29   - background-color: #EEEEEE; color: #999999;
30   - text-align: right;
31   -}
32   -.onoffswitch-switch {
33   - display: block; width: 23px; margin: 5.5px;
34   - background: #FFFFFF;
35   - position: absolute; top: 0; bottom: 0;
36   - right: 100px;
37   - border: 2px solid #999999; border-radius: 19px;
38   - transition: all 0.3s ease-in 0s;
39   -}
40   -.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
41   - margin-left: 0;
42   -}
43   -.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
44   - right: 0px;
45   -}
46 0 \ No newline at end of file
pageHTML/mode.html deleted
... ... @@ -1,20 +0,0 @@
1   -<!DOCTYPE html>
2   -<html lang="en">
3   -<head>
4   - <meta charset="UTF-8">
5   - <link rel="stylesheet" href="mode.css" />
6   - <title>Changement de mode</title>
7   -</head>
8   -<body>
9   -<h1>Changement de mode de votre veilleuse connectée</h1>
10   -<div class="onoffswitch">
11   - <input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
12   - <label class="onoffswitch-label" for="myonoffswitch">
13   - <span class="onoffswitch-inner"></span>
14   - <span class="onoffswitch-switch"></span>
15   - </label>
16   -</div>
17   -
18   -<h3><a href="Menu.html">Retour</a></h3>
19   -</body>
20   -</html>
serveur/serveur 0 → 100755
No preview for this file type
serveur/serveur.c
... ... @@ -7,80 +7,81 @@
7 7 #define WAIT_DELAY 50
8 8  
9 9 static int callback_http(
10   - struct libwebsocket_context *this,
11   -struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason,
12   -void *user,void *in,size_t len)
  10 + struct libwebsocket_context *this,
  11 + struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason,
  12 + void *user,void *in,size_t len)
13 13 {
14   -return 0;
  14 + return 0;
15 15 }
16 16  
17 17 static int callback_my(
18   - struct libwebsocket_context * this,
19   -struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason,
20   -void *user,void *in,size_t len)
  18 + struct libwebsocket_context * this,
  19 + struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason,
  20 + void *user,void *in,size_t len)
21 21 {
22   -static char *message=NULL;
23   -static int msize=0;
24   -switch(reason){
25   -case LWS_CALLBACK_ESTABLISHED:
26   - printf("connection established\n");
27   -message=NULL;
28   -// Declenchement d'un prochain envoi au navigateur
29   -libwebsocket_callback_on_writable(this,wsi);
30   -break;
31   -case LWS_CALLBACK_RECEIVE:
32   -// Ici sont traites les messages envoyes par le navigateur
33   - printf("received data: %s\n",(char *)in);
34   -message=malloc(len+LWS_SEND_BUFFER_PRE_PADDING+LWS_SEND_BUFFER_POST_PADDING);
35   -if(message==NULL){ perror("callback_my.malloc"); exit(EXIT_FAILURE); }
36   -memcpy(message+LWS_SEND_BUFFER_PRE_PADDING,in,len);
37   -// Declenchement d'un prochain envoi au navigateur
38   -msize=len;
39   -libwebsocket_callback_on_writable(this,wsi);
40   -break;
41   -case LWS_CALLBACK_SERVER_WRITEABLE:
42   -// Ici sont envoyes les messages au navigateur
43   -if(message!=NULL){
44   -char *out=message+LWS_SEND_BUFFER_PRE_PADDING;
45   -libwebsocket_write(wsi,(unsigned char *)out,msize,LWS_WRITE_TEXT);
46   -free(message);
47   -message=NULL;
48   -}
49   -break;
50   -default:
51   -break;
52   -}
53   -return 0;
  22 + static char *message=NULL;
  23 + static int msize=0;
  24 + switch(reason){
  25 + case LWS_CALLBACK_ESTABLISHED:
  26 + printf("connection established\n");
  27 + message=NULL;
  28 + // Declenchement d'un prochain envoi au navigateur
  29 + libwebsocket_callback_on_writable(this,wsi);
  30 + break;
  31 + case LWS_CALLBACK_RECEIVE:
  32 + // Ici sont traites les messages envoyes par le navigateur
  33 + printf("received data: %s\n",(char *)in);
  34 + message=malloc(len+LWS_SEND_BUFFER_PRE_PADDING+LWS_SEND_BUFFER_POST_PADDING);
  35 + if(message==NULL){ perror("callback_my.malloc"); exit(EXIT_FAILURE); }
  36 + memcpy(message+LWS_SEND_BUFFER_PRE_PADDING,in,len);
  37 + // Declenchement d'un prochain envoi au navigateur
  38 + msize=len;
  39 + libwebsocket_callback_on_writable(this,wsi);
  40 + break;
  41 + case LWS_CALLBACK_SERVER_WRITEABLE:
  42 + // Ici sont envoyes les messages au navigateur
  43 + if(message!=NULL){
  44 + char *out=message+LWS_SEND_BUFFER_PRE_PADDING;
  45 + libwebsocket_write(wsi,(unsigned char *)out,msize,LWS_WRITE_TEXT);
  46 + free(message);
  47 + message=NULL;
  48 + }
  49 + break;
  50 + default:
  51 + break;
  52 + }
  53 + return 0;
54 54 }
55 55  
56 56 static struct libwebsocket_protocols protocols[] = {
57   - {
58   - "http-only", // name
59   - callback_http, // callback
60   - 0, // data size
61   - 0 // maximum frame size
62   - },
63   - {"myprotocol",callback_my,0,MAX_FRAME_SIZE},
64   - {NULL,NULL,0,0}
  57 + {
  58 + "http-only", // name
  59 + callback_http, // callback
  60 + 0, // data size
  61 + 0 // maximum frame size
  62 + },
  63 + {"myprotocol",callback_my,0,MAX_FRAME_SIZE},
  64 + {NULL,NULL,0,0}
65 65 };
66 66  
67 67 int main(void) {
68   - int port=9000;
69   - struct lws_context_creation_info info;
70   - memset(&info,0,sizeof info);
71   - info.port=port;
72   - info.protocols=protocols;
73   - info.gid=-1;
74   - info.uid=-1;
75   - struct libwebsocket_context *context=libwebsocket_create_context(&info);
76   - if(context==NULL){
77   - fprintf(stderr, "libwebsocket init failed\n");
78   - return -1;
79   - }
80   - printf("starting server...\n");
81   - while(1){
82   - libwebsocket_service(context,WAIT_DELAY);
83   - }
84   - libwebsocket_context_destroy(context);
85   - return 0;
86   -}
87 68 \ No newline at end of file
  69 + //port du serveur
  70 + int port=9000;
  71 + struct lws_context_creation_info info;
  72 + memset(&info,0,sizeof info);
  73 + info.port=port;
  74 + info.protocols=protocols;
  75 + info.gid=-1;
  76 + info.uid=-1;
  77 + struct libwebsocket_context *context=libwebsocket_create_context(&info);
  78 + if(context==NULL){
  79 + fprintf(stderr, "libwebsocket init failed\n");
  80 + return -1;
  81 + }
  82 + printf("starting server...\n");
  83 + while(1){
  84 + libwebsocket_service(context,WAIT_DELAY);
  85 + }
  86 + libwebsocket_context_destroy(context);
  87 + return 0;
  88 +}
... ...