From 713b4147969da5710adb6bb3ee4f7102a07fe708 Mon Sep 17 00:00:00 2001 From: troj Date: Wed, 18 Feb 2015 00:54:11 +0000 Subject: [PATCH] Commit Fin de projet --- exec.php | 9 ++++++--- index.html | 26 +++++++++++++++++++------- test_impr.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test_impr.sh | 6 ++++++ test_modem.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test_modem.sh | 7 +++++++ 6 files changed, 287 insertions(+), 10 deletions(-) create mode 100644 test_impr.c create mode 100755 test_impr.sh create mode 100644 test_modem.c create mode 100755 test_modem.sh diff --git a/exec.php b/exec.php index f75a485..4f521f7 100755 --- a/exec.php +++ b/exec.php @@ -1,10 +1,13 @@

"; - if (isset($_POST["button"]) { - $resultat = system("sudo python /var/www/cgi-bin/main.py"); + if (isset($_POST["button"])) { + $resultat = system("sudo python /var/www/cgi-bin/thread_dd.py"); } - if (isset($_POST["live"]) { + if (isset($_POST["live"])) { $resultat = system("sudo python /var/www/cgi-bin/live.py"); } + if (isset($_POST["modem"])) { + $resultat = system("sudo ../cgi-bin/test_modem.sh"); + } echo "

"; ?> diff --git a/index.html b/index.html index 5f94782..7fb042a 100755 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ - P45 Orchestre Electronique - Page de test + P45 Orchestre Electronique

IMA4 Projets S8 - P45 Orchestre Electronique

@@ -11,20 +11,32 @@

ROJ Thomas - IMA4SC

LETELLIER Joshua - IMA4SA

-

Prototype d'interface WEB

-

Premier programme : La marche impériale - sur 2 FDD

- +

Interface de commande des instruments

+
- +
-
+ +
+ +
+
+ +
+ +
+
+ +
+
+
+ diff --git a/test_impr.c b/test_impr.c new file mode 100644 index 0000000..4723b78 --- /dev/null +++ b/test_impr.c @@ -0,0 +1,136 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +struct termios saveterm; + +int init_serial(char *device,int speed) { // Fonction pour initialiser le port Serie + struct termios new; + 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 + if(fd<0){perror(device); exit(-1);} + tcgetattr(fd,&saveterm); // save current port settings + bzero(&new,sizeof(new)); + new.c_cflag=CLOCAL|CREAD|speed|CS8; + new.c_iflag=0; + new.c_oflag=0; + new.c_lflag=0; // set input mode (non-canonical, no echo,...) + new.c_cc[VTIME]=0; // inter-character timer unused + new.c_cc[VMIN]=1; // blocking read until 1 char received + tcflush(fd, TCIFLUSH); + tcsetattr(fd,TCSANOW,&new); + return fd; +} + +void close_serial(int fd) { // fermeture du Port Série + tcsetattr(fd,TCSANOW,&saveterm); + close(fd); +} + +int main(void) { + int fd = init_serial("/dev/usb/lp0", 9600); + int cpt_data = 0; + printf("Debut de contrôle imprimante\n"); + unsigned char c=0x1B; //ESC + //unsigned char d = 0x40; //@ + unsigned char e = 0x0D; //CR + unsigned char f = 0x0A; //LF + unsigned char g = 0x28; // ( + unsigned char h = 0x47; // G + unsigned char i = 0x01; //1 + unsigned char j = 0x00; //0 + unsigned char de = 0x02; //2 + unsigned char s = 0x7F; //127 + unsigned char v = 0x40; //64 + unsigned char ae = 0x56; //V + unsigned char af = 0x55; //U + unsigned char p = 0x2E; //. + unsigned char hu = 0x08; + unsigned char full_data = 0xFF; + unsigned char empty_data = 0x00; + unsigned char semi_data = 0x55; + unsigned char data = 0x0F; + unsigned char data_t = 0xF0; + unsigned char data_o = 0xA1; + unsigned char data_a = 0x22; + unsigned char data_p = 0xB7; + unsigned char fin = 0x0C; //FF + unsigned char nh = 0xC8; + write(fd, &c, 1); //ESC + //write(fd, &d, 1); //@ : ESC @ permet d'initialiser l'imprimante + //write(fd,&e, 1);//CR + //write(fd, &f, 1); + write(fd, &g, 1); // ( + write(fd, &h, 1); + write(fd, &i, 1); + write(fd, &j, 1); + write(fd, &i, 1); //ESC ( G 1 0 1 pour passer en mode graphique + write (fd, &c,1); + write(fd, &g, 1); + write(fd, &af, 1); + write(fd, &i, 1); + write(fd, &j, 1); + write(fd, &i, 1); + write(fd, &j, 1); //ESC ( U 10 10 dot density + write(fd, &c, 1); + write(fd, &g,1); + write(fd, &ae, 1); + write(fd, &de, 1); + write(fd, &i, 1); + write(fd, &s,1); + write(fd, &v, 1); //ESC ( V 2 0 127 64 position de depart + write(fd, &c, 1); + write(fd, &p, 1); + write(fd, &j, 1); + write(fd, &i, 1); + write(fd, &j, 1); + write(fd, &i, 1); + write(fd, &j, 1); + write(fd, &hu, 1); + write(fd, &i, 1); + write(fd, &j, 1); + + write(fd, &c, 1); + write(fd, &p, 1); + write(fd, &j, 1); + write(fd, &i, 1); + write(fd, &j, 1); + write(fd, &i, 1); + write(fd, &j, 1); + write(fd, &hu, 1); + write(fd, &i, 1); + write(fd, &nh, 1); + while (cpt_data < 200) { + write(fd, &(full_data), 1); + write(fd, &(data_o), 1); + write(fd, &(data), 1); + cpt_data++; + } + cpt_data = 0; + while(cpt_data < 200) { + write(fd, &(semi_data), 1); + write(fd, &(data_o), 1); + write(fd, &(full_data), 1); + cpt_data++; + } + cpt_data = 0; + while (cpt_data < 200) { + write(fd, &(data), 1); + write(fd, &(data_p), 1); + write(fd, &(data_t), 1); + cpt_data++; + } + cpt_data = 0; + while(cpt_data < 200) { + write(fd, &(data_p), 1); + write(fd, &(full_data), 1); + write(fd, &(semi_data), 1); + cpt_data++; + } + close_serial(fd); + return 0; +} diff --git a/test_impr.sh b/test_impr.sh new file mode 100755 index 0000000..3d47852 --- /dev/null +++ b/test_impr.sh @@ -0,0 +1,6 @@ +#! /bin/sh + +echo "Content-type: text/html" +echo " " +cd ../cgi-bin/ +./test_impr diff --git a/test_modem.c b/test_modem.c new file mode 100644 index 0000000..be8778a --- /dev/null +++ b/test_modem.c @@ -0,0 +1,113 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** Constantes **/ + +#define SERIALDEV "/dev/ttyUSB0" +#define BAUDRATE B9600 +#define TAILLE_TAMPON 3 + +void Reponse(int ds) +{ + register int i; + char d[TAILLE_TAMPON]; + sync(); + for(i=0;i0) fprintf(stdout," ("); + for(i=0;i0) fprintf(stdout,")\n"); +} + +void ModeCommande(int ds) +{ + #ifdef DEBUG + printf("{xbeeModeCommande}\n"); + #endif + char *cmd="+++++++++++++++++"; + sleep(1); + sync(); + write(ds,cmd,strlen(cmd)); + Reponse(ds); +} + +void Answer(int ds) +{ + #ifdef DEBUG + printf("{xbeeRecupereVitesse}\n"); + #endif + char *cmd="TAATAATAATAATAATA\r"; + write(ds,cmd,strlen(cmd)); + Reponse(ds); +} + +static struct termios sauvegarde; + +/** Ouverture d'un port serie **/ + +int ouvertureSerie(char *periph,int vitesse) +{ + struct termios nouveau; + int df=open(periph,O_RDWR|O_NOCTTY); + if(df<0) return -1; + + tcgetattr(df,&sauvegarde); /* save current port settings */ + bzero(&nouveau,sizeof(nouveau)); + nouveau.c_cflag=CLOCAL|CREAD|vitesse|CS8; + nouveau.c_iflag=0; + nouveau.c_oflag=0; + nouveau.c_lflag=0; + nouveau.c_cc[VTIME]=0; + nouveau.c_cc[VMIN]=1; + tcflush(df, TCIFLUSH); + tcsetattr(df,TCSANOW,&nouveau); + + return df; +} + +/** Fermeture d'un port serie **/ + +void fermetureSerie(int df) +{ + tcsetattr(df,TCSANOW,&sauvegarde); + close(df); +} + +/** Programme principal **/ + +int main(void) { + int ds; + ds=ouvertureSerie(SERIALDEV,BAUDRATE); + if(ds<0){ + fprintf(stderr,"Erreur sur la connexion série.\n"); + exit(-1); + } + char enter = '\r'; + ModeCommande(ds); + write(ds, &enter, 1); + write(ds, &enter, 1); + write(ds, &enter,1); + write(ds,&enter,1); + write(ds,&enter,1); + Answer(ds); + sleep(15); + write(ds,&enter,1); + fermetureSerie(ds); + return 0; +} diff --git a/test_modem.sh b/test_modem.sh new file mode 100755 index 0000000..8ed1598 --- /dev/null +++ b/test_modem.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +echo "Content-type: text/html" +echo "" + +cd ../cgi-bin/ +./test_modem -- libgit2 0.21.2