Commit 713b4147969da5710adb6bb3ee4f7102a07fe708

Authored by troj
1 parent 35887fe7

Commit Fin de projet

exec.php
1 1 <?php
2 2 echo "<html><body><p>";
3   - if (isset($_POST["button"]) {
4   - $resultat = system("sudo python /var/www/cgi-bin/main.py");
  3 + if (isset($_POST["button"])) {
  4 + $resultat = system("sudo python /var/www/cgi-bin/thread_dd.py");
5 5 }
6   - if (isset($_POST["live"]) {
  6 + if (isset($_POST["live"])) {
7 7 $resultat = system("sudo python /var/www/cgi-bin/live.py");
8 8 }
  9 + if (isset($_POST["modem"])) {
  10 + $resultat = system("sudo ../cgi-bin/test_modem.sh");
  11 + }
9 12 echo "</p></body></html>";
10 13 ?>
... ...
index.html
... ... @@ -3,7 +3,7 @@
3 3 <head>
4 4 <meta charset="UTF-8">
5 5 <link rel="stylesheet" href="css/style_index.css">
6   - <title>P45 Orchestre Electronique - Page de test</title>
  6 + <title>P45 Orchestre Electronique</title>
7 7 </head>
8 8 <body>
9 9 <h1> IMA4 Projets S8 - P45 Orchestre Electronique </h1>
... ... @@ -11,20 +11,32 @@
11 11 <p class="p1"> ROJ Thomas - IMA4SC</p>
12 12 <p class="p2"> LETELLIER Joshua - IMA4SA</p>
13 13 </div>
14   - <h3 class="desc"> Prototype d'interface WEB</h3>
15   - <p class="part1"> Premier programme : La marche impériale
16   - sur 2 FDD </p>
17   -
  14 + <h3 class="desc"> Interface de commande des instruments</h3>
  15 + <div class="bouton">
18 16 <form action="exec.php" method="POST">
19 17 <div class="play">
20   - <input type="submit" name="button" value="Play Imperial March">
  18 + <input type="submit" name="button" value="Activate 2 FDD">
21 19 </div>
22 20 </form>
23 21  
24   - <form action="exec.php method="POST">
  22 + <form action="exec.php" method="POST">
  23 + <div class="play_dd">
  24 + <input type="submit" name="button" value="Activate HDD">
  25 + </div>
  26 + </form>
  27 +
  28 + <form action="exec.php" method="POST">
25 29 <div class="live">
26 30 <input type="submit" name="live" value="Play in live with computer input">
27 31 </div>
28 32 </form>
  33 +
  34 + <form action="exec.php" method="POST">
  35 + <div class="modem">
  36 + <input type="submit" name="modem" value="Activate Modem">
  37 + </div>
  38 + </form>
  39 + </div>
  40 +
29 41 </body>
30 42 </html>
... ...
test_impr.c 0 → 100644
... ... @@ -0,0 +1,136 @@
  1 +#include <stdio.h>
  2 +#include <stdlib.h>
  3 +#include <unistd.h>
  4 +#include <termios.h>
  5 +#include <sys/types.h>
  6 +#include <sys/stat.h>
  7 +#include <fcntl.h>
  8 +#include <strings.h>
  9 +
  10 +struct termios saveterm;
  11 +
  12 +int init_serial(char *device,int speed) { // Fonction pour initialiser le port Serie
  13 + struct termios new;
  14 + int fd=open(device,O_RDWR|O_NOCTTY);// On ouvre un descripteur de fichier en mode lecture et ecriture, ici ça sera notre port série
  15 + if(fd<0){perror(device); exit(-1);}
  16 + tcgetattr(fd,&saveterm); // save current port settings
  17 + bzero(&new,sizeof(new));
  18 + new.c_cflag=CLOCAL|CREAD|speed|CS8;
  19 + new.c_iflag=0;
  20 + new.c_oflag=0;
  21 + new.c_lflag=0; // set input mode (non-canonical, no echo,...)
  22 + new.c_cc[VTIME]=0; // inter-character timer unused
  23 + new.c_cc[VMIN]=1; // blocking read until 1 char received
  24 + tcflush(fd, TCIFLUSH);
  25 + tcsetattr(fd,TCSANOW,&new);
  26 + return fd;
  27 +}
  28 +
  29 +void close_serial(int fd) { // fermeture du Port Série
  30 + tcsetattr(fd,TCSANOW,&saveterm);
  31 + close(fd);
  32 +}
  33 +
  34 +int main(void) {
  35 + int fd = init_serial("/dev/usb/lp0", 9600);
  36 + int cpt_data = 0;
  37 + printf("Debut de contrôle imprimante\n");
  38 + unsigned char c=0x1B; //ESC
  39 + //unsigned char d = 0x40; //@
  40 + unsigned char e = 0x0D; //CR
  41 + unsigned char f = 0x0A; //LF
  42 + unsigned char g = 0x28; // (
  43 + unsigned char h = 0x47; // G
  44 + unsigned char i = 0x01; //1
  45 + unsigned char j = 0x00; //0
  46 + unsigned char de = 0x02; //2
  47 + unsigned char s = 0x7F; //127
  48 + unsigned char v = 0x40; //64
  49 + unsigned char ae = 0x56; //V
  50 + unsigned char af = 0x55; //U
  51 + unsigned char p = 0x2E; //.
  52 + unsigned char hu = 0x08;
  53 + unsigned char full_data = 0xFF;
  54 + unsigned char empty_data = 0x00;
  55 + unsigned char semi_data = 0x55;
  56 + unsigned char data = 0x0F;
  57 + unsigned char data_t = 0xF0;
  58 + unsigned char data_o = 0xA1;
  59 + unsigned char data_a = 0x22;
  60 + unsigned char data_p = 0xB7;
  61 + unsigned char fin = 0x0C; //FF
  62 + unsigned char nh = 0xC8;
  63 + write(fd, &c, 1); //ESC
  64 + //write(fd, &d, 1); //@ : ESC @ permet d'initialiser l'imprimante
  65 + //write(fd,&e, 1);//CR
  66 + //write(fd, &f, 1);
  67 + write(fd, &g, 1); // (
  68 + write(fd, &h, 1);
  69 + write(fd, &i, 1);
  70 + write(fd, &j, 1);
  71 + write(fd, &i, 1); //ESC ( G 1 0 1 pour passer en mode graphique
  72 + write (fd, &c,1);
  73 + write(fd, &g, 1);
  74 + write(fd, &af, 1);
  75 + write(fd, &i, 1);
  76 + write(fd, &j, 1);
  77 + write(fd, &i, 1);
  78 + write(fd, &j, 1); //ESC ( U 10 10 dot density
  79 + write(fd, &c, 1);
  80 + write(fd, &g,1);
  81 + write(fd, &ae, 1);
  82 + write(fd, &de, 1);
  83 + write(fd, &i, 1);
  84 + write(fd, &s,1);
  85 + write(fd, &v, 1); //ESC ( V 2 0 127 64 position de depart
  86 + write(fd, &c, 1);
  87 + write(fd, &p, 1);
  88 + write(fd, &j, 1);
  89 + write(fd, &i, 1);
  90 + write(fd, &j, 1);
  91 + write(fd, &i, 1);
  92 + write(fd, &j, 1);
  93 + write(fd, &hu, 1);
  94 + write(fd, &i, 1);
  95 + write(fd, &j, 1);
  96 +
  97 + write(fd, &c, 1);
  98 + write(fd, &p, 1);
  99 + write(fd, &j, 1);
  100 + write(fd, &i, 1);
  101 + write(fd, &j, 1);
  102 + write(fd, &i, 1);
  103 + write(fd, &j, 1);
  104 + write(fd, &hu, 1);
  105 + write(fd, &i, 1);
  106 + write(fd, &nh, 1);
  107 + while (cpt_data < 200) {
  108 + write(fd, &(full_data), 1);
  109 + write(fd, &(data_o), 1);
  110 + write(fd, &(data), 1);
  111 + cpt_data++;
  112 + }
  113 + cpt_data = 0;
  114 + while(cpt_data < 200) {
  115 + write(fd, &(semi_data), 1);
  116 + write(fd, &(data_o), 1);
  117 + write(fd, &(full_data), 1);
  118 + cpt_data++;
  119 + }
  120 + cpt_data = 0;
  121 + while (cpt_data < 200) {
  122 + write(fd, &(data), 1);
  123 + write(fd, &(data_p), 1);
  124 + write(fd, &(data_t), 1);
  125 + cpt_data++;
  126 + }
  127 + cpt_data = 0;
  128 + while(cpt_data < 200) {
  129 + write(fd, &(data_p), 1);
  130 + write(fd, &(full_data), 1);
  131 + write(fd, &(semi_data), 1);
  132 + cpt_data++;
  133 + }
  134 + close_serial(fd);
  135 + return 0;
  136 +}
... ...
test_impr.sh 0 → 100755
... ... @@ -0,0 +1,6 @@
  1 +#! /bin/sh
  2 +
  3 +echo "Content-type: text/html"
  4 +echo " "
  5 +cd ../cgi-bin/
  6 +./test_impr
... ...
test_modem.c 0 → 100644
... ... @@ -0,0 +1,113 @@
  1 +#include <stdio.h>
  2 +#include <stdlib.h>
  3 +#include <string.h>
  4 +#include <unistd.h>
  5 +#include <termios.h>
  6 +#include <netdb.h>
  7 +#include <netinet/in.h>
  8 +#include <sys/types.h>
  9 +#include <sys/stat.h>
  10 +#include <fcntl.h>
  11 +
  12 +/** Constantes **/
  13 +
  14 +#define SERIALDEV "/dev/ttyUSB0"
  15 +#define BAUDRATE B9600
  16 +#define TAILLE_TAMPON 3
  17 +
  18 +void Reponse(int ds)
  19 +{
  20 + register int i;
  21 + char d[TAILLE_TAMPON];
  22 + sync();
  23 + for(i=0;i<TAILLE_TAMPON;i++){
  24 + if(read(ds,d+i,1)!=1){ perror("xbeeReponse.read"); exit(-1); }
  25 + if(d[i]==0x0d) break;
  26 + }
  27 + int size=i;
  28 + for(i=0;i<size;i++)
  29 + if(d[i]!=0x0d) fprintf(stdout,"%c",d[i]);
  30 + if(size>0) fprintf(stdout," (");
  31 + for(i=0;i<size;i++){
  32 + fprintf(stdout,"%.2x",d[i]);
  33 + if(i<size-1) fprintf(stdout," ");
  34 + }
  35 + if(size>0) fprintf(stdout,")\n");
  36 +}
  37 +
  38 +void ModeCommande(int ds)
  39 +{
  40 + #ifdef DEBUG
  41 + printf("{xbeeModeCommande}\n");
  42 + #endif
  43 + char *cmd="+++++++++++++++++";
  44 + sleep(1);
  45 + sync();
  46 + write(ds,cmd,strlen(cmd));
  47 + Reponse(ds);
  48 +}
  49 +
  50 +void Answer(int ds)
  51 +{
  52 + #ifdef DEBUG
  53 + printf("{xbeeRecupereVitesse}\n");
  54 + #endif
  55 + char *cmd="TAATAATAATAATAATA\r";
  56 + write(ds,cmd,strlen(cmd));
  57 + Reponse(ds);
  58 +}
  59 +
  60 +static struct termios sauvegarde;
  61 +
  62 +/** Ouverture d'un port serie **/
  63 +
  64 +int ouvertureSerie(char *periph,int vitesse)
  65 +{
  66 + struct termios nouveau;
  67 + int df=open(periph,O_RDWR|O_NOCTTY);
  68 + if(df<0) return -1;
  69 +
  70 + tcgetattr(df,&sauvegarde); /* save current port settings */
  71 + bzero(&nouveau,sizeof(nouveau));
  72 + nouveau.c_cflag=CLOCAL|CREAD|vitesse|CS8;
  73 + nouveau.c_iflag=0;
  74 + nouveau.c_oflag=0;
  75 + nouveau.c_lflag=0;
  76 + nouveau.c_cc[VTIME]=0;
  77 + nouveau.c_cc[VMIN]=1;
  78 + tcflush(df, TCIFLUSH);
  79 + tcsetattr(df,TCSANOW,&nouveau);
  80 +
  81 + return df;
  82 +}
  83 +
  84 +/** Fermeture d'un port serie **/
  85 +
  86 +void fermetureSerie(int df)
  87 +{
  88 + tcsetattr(df,TCSANOW,&sauvegarde);
  89 + close(df);
  90 +}
  91 +
  92 +/** Programme principal **/
  93 +
  94 +int main(void) {
  95 + int ds;
  96 + ds=ouvertureSerie(SERIALDEV,BAUDRATE);
  97 + if(ds<0){
  98 + fprintf(stderr,"Erreur sur la connexion série.\n");
  99 + exit(-1);
  100 + }
  101 + char enter = '\r';
  102 + ModeCommande(ds);
  103 + write(ds, &enter, 1);
  104 + write(ds, &enter, 1);
  105 + write(ds, &enter,1);
  106 + write(ds,&enter,1);
  107 + write(ds,&enter,1);
  108 + Answer(ds);
  109 + sleep(15);
  110 + write(ds,&enter,1);
  111 + fermetureSerie(ds);
  112 + return 0;
  113 +}
... ...
test_modem.sh 0 → 100755
... ... @@ -0,0 +1,7 @@
  1 +#!/bin/sh
  2 +
  3 +echo "Content-type: text/html"
  4 +echo ""
  5 +
  6 +cd ../cgi-bin/
  7 +./test_modem
... ...