#include #include #include #include #include #include struct nux { char chain[250]; char lib[250]; int cpt; int org[30]; int nb[30]; int nbch[30]; int ccx[30]; int ccy[30]; int cxx[30]; int adrchar[30]; int lgch[30]; int genre[30]; int ccar; int cmasq; char ein_datum[9]; }p; void init(int nb_car,char avec_lequel); void clrscr(void); void position(int xx,int yy); void affiche(int no_coul_palet,int caract); void sendung(int coul,int posy,int posx,char *str); void calculmq(void); void masque(void); int chiffre(char *alpha); int verif(void); int lirecla(int a1,int a2,int a3,int a4,int a5); int fenetre(int nbchoix,int longeur,int horx,int verty); void makepal (void); void affiche(int no_coul_palet,int caract) { wattron(stdscr,A_NORMAL | COLOR_PAIR(no_coul_palet) ); waddch(stdscr,caract); wattroff(stdscr,A_NORMAL | COLOR_PAIR(no_coul_palet) ); refresh(); } void calculmq(void) { int t; int i; int c2; int f; int len; len=strlen(p.lib); p.cpt=0; p.org[0]=0; c2=0; for (f=0;f < F8 REJET > "); } int fenetre(int nbchoix,int longeur,int horx,int verty) { char buf[40]; int i; int b; int chx; int ret; sendung(4,verty,horx," "); for (i=1;ix;t--) { p.chain[t]=p.chain[t-1]; } p.chain[x]=' '; ll=0; for (t=p.adrchar[w];t31) && (car<127) ) { if (x==p.lgch[w]) { if(w==p.cpt-1) { } else { w++; y=p.cxx[w]; x=p.adrchar[w]; position(p.ccy[w],y); } } if(x!=p.lgch[w]) { position(p.ccy[w],y); affiche(p.ccar,car); position(p.ccy[w],y+1); p.chain[x]=(unsigned char)car; x++; y++; if (x>=p.lgch[w]) { x=p.lgch[w]; } } } }while( (car!=KEY_F(1)) && (car!=KEY_F(8)) ); if (car==KEY_F(1)) { car=67; } else { car=-1; } return car; } void makepal(void) { init_pair(1,COLOR_WHITE,COLOR_BLUE); init_pair(2,COLOR_WHITE,COLOR_BLACK); init_pair(3,COLOR_WHITE,COLOR_RED); init_pair(4,COLOR_BLACK,COLOR_CYAN); init_pair(5,COLOR_BLACK,COLOR_BLACK); init_pair(6,COLOR_YELLOW,COLOR_BLACK); init_pair(7,COLOR_WHITE,COLOR_GREEN); } void masque(void) { int boucle; char imprime[80]; calculmq(); for (boucle=0;boucle-1;i--) { if (p.genre[i]==1) { if ( (p.chain[p.adrchar[i]]!='0') && (p.chain[p.adrchar[i]]!='1') ) { retour=i; aus++; } } if (p.genre[i]==3) { if (p.chain[p.adrchar[i]]<33) { retour=i; aus++; } } } } if(y==-1) { aus=0; retour=y; } if (aus!=0) { } }while (aus!=0); return retour; } int bintoint(char alpha[8]) { int zuruk; zuruk=0; if (alpha[7]=='1') { zuruk=zuruk | 1; } if (alpha[6]=='1') { zuruk=zuruk | 2; } if (alpha[5]=='1') { zuruk=zuruk | 4; } if (alpha[4]=='1') { zuruk=zuruk | 8; } if (alpha[3]=='1') { zuruk=zuruk | 16; } if (alpha[2]=='1') { zuruk=zuruk | 32; } if (alpha[1]=='1') { zuruk=zuruk | 64; } if (alpha[0]=='1') { zuruk=zuruk | 128; } return zuruk; } void prog(void) { int x; FILE *f; char ligne[12]; x=0; strcpy(p.lib,"PONY-STK200"); strcat(p.lib,"DAPA "); strcat(p.lib,"STK200 "); strcat(p.lib,"DT006 "); strcat(p.lib,"QUITTER "); while(x!=5) { x=fenetre(5,11,20,13); if (x==1) { f=fopen("/avrmenu/programmateur.txt","w+"); strcpy(ligne,"pony-stk200"); ligne[11]=0x0; fputs(ligne,f); fclose(f); sendung(1,15,34," VALEUR ENREGISTRE PONY-STK200 "); } if (x==2) { f=fopen("/avrmenu/programmateur.txt","w+"); strcpy(ligne,"dapa"); ligne[4]=0x0; fputs(ligne,f); fclose(f); sendung(1,15,34," VALEUR ENREGISTRE DAPA "); } if (x==3) { f=fopen("/avrmenu/programmateur.txt","w+"); strcpy(ligne,"stk200"); ligne[6]=0x0; fputs(ligne,f); fclose(f); sendung(1,15,34," VALEUR ENREGISTRE STK200 "); } if (x==4) { f=fopen("/avrmenu/programmateur.txt","w+"); strcpy(ligne,"dt006"); ligne[5]=0x0; fputs(ligne,f); fclose(f); sendung(1,15,34," VALEUR ENREGISTRE DT006 "); } } } void newscreen(void) { initscr(); if (has_colors()) { start_color(); makepal(); noecho(); cbreak(); keypad(stdscr,TRUE); clrscr(); } } void endscreen(void) { clrscr(); endwin(); } void ecrit_hex() { struct fich { char hex[15]; char port[15]; char uc[15]; }fi; FILE *tmp; FILE *prj; FILE *progra; char cmd[80]; int x; char ligne[15]; progra=fopen("/avrmenu/programmateur.txt","r"); fgets(ligne,14,progra); fclose(progra); sendung(2,4,45,"PROGRAMMATEUR : "); sendung(2,4,61,ligne); prj=fopen("/avrmenu/projet/proj.prj","r+b"); fread(&fi,sizeof(fi),1,prj); fclose(prj); sendung(2,5,45," FICHIER .HEX : "); sendung(2,5,61,fi.hex); sendung(2,6,45," PORT : "); sendung(2,6,53,fi.port); sendung(2,7,45," uc : "); sendung(2,7,51,fi.uc); sendung(3,20,20," ECRIRE ABANDON "); x=getch(); if (x==KEY_F(1)) { sprintf(cmd,"avrdude -c %s -P %s -p %s -U flash:w:%s%c",ligne,fi.port,fi.uc,fi.hex,0x0); sendung(3,1,1,cmd); sendung(3,20,20," HIT A KEY "); x=getch(); endscreen(); x=system(cmd); x=getch(); } } void verif_hex() { struct fich { char hex[15]; char port[15]; char uc[15]; }fi; FILE *tmp; FILE *prj; FILE *progra; char cmd[80]; int x; char ligne[15]; progra=fopen("/avrmenu/programmateur.txt","r"); fgets(ligne,14,progra); fclose(progra); sendung(2,4,45,"PROGRAMMATEUR : "); sendung(2,4,61,ligne); prj=fopen("/avrmenu/projet/proj.prj","r+b"); fread(&fi,sizeof(fi),1,prj); fclose(prj); sendung(2,5,45," FICHIER .HEX : "); sendung(2,5,61,fi.hex); sendung(2,6,45," PORT : "); sendung(2,6,53,fi.port); sendung(2,7,45," uc : "); sendung(2,7,51,fi.uc); sendung(3,20,20," VERIF ABANDON "); x=getch(); if (x==KEY_F(1)) { sprintf(cmd,"avrdude -c %s -P %s -p %s -U eeprom:v:%s%c",ligne,fi.port,fi.uc,fi.hex,0x0); sendung(3,1,1,cmd); sendung(3,20,20," HIT A KEY "); x=getch(); endscreen(); x=system(cmd); x=getch(); } } void lit_hex() { struct fich { char hex[15]; char port[15]; char uc[15]; }fi; FILE *tmp; FILE *prj; FILE *progra; char cmd[80]; int x; char ligne[15]; progra=fopen("/avrmenu/programmateur.txt","r"); fgets(ligne,14,progra); fclose(progra); sendung(2,4,45,"PROGRAMMATEUR : "); sendung(2,4,61,ligne); prj=fopen("/avrmenu/projet/proj.prj","r+b"); fread(&fi,sizeof(fi),1,prj); fclose(prj); sendung(2,5,45," FICHIER .HEX : "); sendung(2,5,61,fi.hex); sendung(2,6,45," PORT : "); sendung(2,6,53,fi.port); sendung(2,7,45," uc : "); sendung(2,7,51,fi.uc); sendung(3,20,20," LIRE ABANDON "); x=getch(); if (x==KEY_F(1)) { sprintf(cmd,"avrdude -c %s -P %s -p %s -U eeprom:r:%s%c",ligne,fi.port,fi.uc,fi.hex,0x0); sendung(3,1,1,cmd); sendung(3,20,20," HIT A KEY "); x=getch(); endscreen(); x=system(cmd); x=getch(); } } void sendung_projet() { struct fich { char hex[15]; char port[15]; char uc[15]; }fi; FILE *tmp; FILE *prj; FILE *progra; char ligne[15]; progra=fopen("/avrmenu/programmateur.txt","r"); fgets(ligne,14,progra); fclose(progra); sendung(2,4,45,"PROGRAMMATEUR : "); sendung(2,4,61,ligne); prj=fopen("/avrmenu/projet/proj.prj","r+b"); fread(&fi,sizeof(fi),1,prj); fclose(prj); sendung(2,5,45," FICHIER .HEX : "); sendung(2,5,61,fi.hex); sendung(2,6,45," PORT : "); sendung(2,6,53,fi.port); sendung(2,7,45," uc : "); sendung(2,7,51,fi.uc); } void m1(void) { strcpy(p.lib," PROJET : 3 .HEX : 3 PORT : 3 UC : 3"); p.ccx[0]=40;p.ccy[0]=4;p.nbch[0]=14; p.ccx[1]=40;p.ccy[1]=6;p.nbch[1]=14; p.ccx[2]=40;p.ccy[2]=8;p.nbch[2]=14; p.ccx[3]=40;p.ccy[3]=10;p.nbch[3]=14; p.ccar=4; p.cmasq=1; } void m2(void) { strcpy(p.lib," PROJET : 3"); p.ccx[0]=20;p.ccy[0]=6;p.nbch[0]=14; p.ccar=4; p.cmasq=1; } void m3(void) { strcpy(p.lib," 1 1 1 1 1 1 1 1"); p.ccx[0]=32;p.ccy[0]=4;p.nbch [0]=1; p.ccx[1]=32;p.ccy[1]=5;p.nbch[1]=1; p.ccx[2]=32;p.ccy[2]=6;p.nbch[2]=1; p.ccx[3]=32;p.ccy[3]=7;p.nbch[3]=1; p.ccx[4]=32;p.ccy[4]=8;p.nbch[4]=1; p.ccx[5]=32;p.ccy[5]=9;p.nbch[5]=1; p.ccx[6]=32;p.ccy[6]=10;p.nbch[6]=1; p.ccx[7]=32;p.ccy[7]=11;p.nbch[7]=1; p.ccar=3; p.cmasq=4; sendung(4,4,24," CKDIV8 "); sendung(4,5,24," CKOUT "); sendung(4,6,24," SUT1 "); sendung(4,7,24," SUT0 "); sendung(4,8,24," CKSEL3 "); sendung(4,9,24," CKSEL2 "); sendung(4,10,24," CKSEL1 "); sendung(4,11,24," CKSEL0 "); } void m4(void) { strcpy(p.lib," 1 1 1 1 1 1 1 1"); p.ccx[0]=32;p.ccy[0]=4;p.nbch [0]=1; p.ccx[1]=32;p.ccy[1]=5;p.nbch[1]=1; p.ccx[2]=32;p.ccy[2]=6;p.nbch[2]=1; p.ccx[3]=32;p.ccy[3]=7;p.nbch[3]=1; p.ccx[4]=32;p.ccy[4]=8;p.nbch[4]=1; p.ccx[5]=32;p.ccy[5]=9;p.nbch[5]=1; p.ccx[6]=32;p.ccy[6]=10;p.nbch[6]=1; p.ccx[7]=32;p.ccy[7]=11;p.nbch[7]=1; p.ccar=3; p.cmasq=4; sendung(4,4,24,"RSTDISBL"); sendung(4,5,24,"DWEN "); sendung(4,6,24,"SPIEN "); sendung(4,7,24,"WDTON "); sendung(4,8,24,"EESAVE "); sendung(4,9,24,"BODLEV2 "); sendung(4,10,24,"BODLEV1 "); sendung(4,11,24,"BODLEV0 "); } void m5(void) { strcpy(p.lib," 1 1 1 1 1 1 1 1"); p.ccx[0]=32;p.ccy[0]=4;p.nbch [0]=1; p.ccx[1]=32;p.ccy[1]=5;p.nbch[1]=1; p.ccx[2]=32;p.ccy[2]=6;p.nbch[2]=1; p.ccx[4]=32;p.ccy[4]=8;p.nbch[4]=1; p.ccx[5]=32;p.ccy[5]=9;p.nbch[5]=1; p.ccx[6]=32;p.ccy[6]=10;p.nbch[6]=1; p.ccx[7]=32;p.ccy[7]=11;p.nbch[7]=1; p.ccar=3; p.cmasq=4; sendung(4,4,24,"BIT 7"); sendung(4,5,24,"BIT 6"); sendung(4,6,24,"BIT 5"); sendung(4,7,24,"BIT 4"); sendung(4,8,24,"BIT 3"); sendung(4,9,24,"BOOTSZ1 "); sendung(4,10,24,"BOOTSZ0 "); sendung(4,11,24,"BOOTRST "); } int lbyte(void) { struct fich { char hex[15]; char port[15]; char uc[15]; }fi; FILE *tmp; FILE *prj; FILE *progra; char cmd[80]; int x; char hex[5]; char ligne[15]; int bin; char strbin[8]; int b; progra=fopen("/avrmenu/programmateur.txt","r"); fgets(ligne,14,progra); fclose(progra); sendung(2,4,45,"PROGRAMMATEUR : "); sendung(2,4,61,ligne); prj=fopen("/avrmenu/projet/proj.prj","r+b"); fread(&fi,sizeof(fi),1,prj); fclose(prj); sendung(2,5,45," PORT : "); sendung(2,5,53,fi.port); sendung(2,6,45," UC: "); sendung(2,6,51,fi.uc); sendung(3,20,25," PROJ OK REJET "); x=getch(); sendung(2,20,25," "); if (x==KEY_F(1)) { sendung(4,2,24,"LOW BYTE FUSE NON PROGRAMME=1 PROGRAMME=0 "); sendung(4,14,24," F1=VALIDATION F8=ECHAP "); init(60,' '); while(x!=0) { m3(); masque(); x=verif(); if (x==0) { strncpy(strbin+0,p.chain+0,8); bin=bintoint(strbin); sprintf(hex,"0x%x%c",bin,0x0); sendung(4,14,24," ECRIRE LE BIT FUSIBLE : ANNULE "); sendung(3,14,53,hex); b=getch(); if (b==KEY_F(1)) { sprintf(cmd,"avrdude -c %s -P %s -p %s -U lfuse:w:0x%x:m%c",ligne,fi.port,fi.uc,bin,0x0); sendung(3,23,1,cmd); b=getch(); endscreen(); b=system("clear"); b=system(cmd); b=getch(); } } } } return 0; } int hbyte(void) { struct fich { char hex[15]; char port[15]; char uc[15]; }fi; FILE *tmp; FILE *prj; FILE *progra; char cmd[80]; int x; char hex[5]; char ligne[15]; int bin; char strbin[8]; int b; progra=fopen("/avrmenu/programmateur.txt","r"); fgets(ligne,14,progra); fclose(progra); sendung(2,4,45,"PROGRAMMATEUR : "); sendung(2,4,61,ligne); prj=fopen("/avrmenu/projet/proj.prj","r+b"); fread(&fi,sizeof(fi),1,prj); fclose(prj); sendung(2,5,45," PORT : "); sendung(2,5,53,fi.port); sendung(2,6,45," UC: "); sendung(2,6,51,fi.uc); sendung(3,20,25," PROJ OK REJET "); x=getch(); sendung(2,20,25," "); if (x==KEY_F(1)) { sendung(4,2,24,"HIGHT BYTE FUSE NON PROGRAMME=1 PROGRAMME=0 "); sendung(4,14,24," F1=VALIDATION F8=ECHAP "); init(60,' '); while(x!=0) { m4(); masque(); x=verif(); if (x==0) { strncpy(strbin+0,p.chain+0,8); bin=bintoint(strbin); sprintf(hex,"0x%x%c",bin,0x0); sendung(4,14,24," ECRIRE LE BIT FUSIBLE : ANNULE "); sendung(3,14,53,hex); b=getch(); if (b==KEY_F(1)) { sprintf(cmd,"avrdude -c %s -P %s -p %s -U hfuse:w:0x%x:m%c",ligne,fi.port,fi.uc,bin,0x0); sendung(3,23,1,cmd); b=getch(); endscreen(); b=system("clear"); b=system(cmd); b=getch(); } } } } return 0; } int ebyte(void) { struct fich { char hex[15]; char port[15]; char uc[15]; }fi; FILE *tmp; FILE *prj; FILE *progra; char cmd[80]; int x; char hex[5]; char ligne[15]; int bin; char strbin[8]; int b; progra=fopen("/avrmenu/programmateur.txt","r"); fgets(ligne,14,progra); fclose(progra); sendung(2,4,45,"PROGRAMMATEUR : "); sendung(2,4,61,ligne); prj=fopen("/avrmenu/projet/proj.prj","r+b"); fread(&fi,sizeof(fi),1,prj); fclose(prj); sendung(2,5,45," PORT : "); sendung(2,5,53,fi.port); sendung(2,6,45," UC: "); sendung(2,6,51,fi.uc); sendung(3,20,25," PROJ OK REJET "); x=getch(); sendung(2,20,25," "); if (x==KEY_F(1)) { sendung(4,2,24,"EXTEND BYTE FUSE NON PROGRAMME=1 PROGRAMME=0 "); sendung(4,14,24," F1=VALIDATION F8=ECHAP "); init(60,' '); while(x!=0) { m5(); masque(); x=verif(); if (x==0) { strncpy(strbin+0,p.chain+0,8); bin=bintoint(strbin); sprintf(hex,"0x%x%c",bin,0x0); sendung(4,14,24," ECRIRE LE BIT FUSIBLE : ANNULE "); sendung(3,14,53,hex); b=getch(); if (b==KEY_F(1)) { sprintf(cmd,"avrdude -c %s -P %s -p %s -U efuse:w:0x%x:m%c",ligne,fi.port,fi.uc,bin,0x0); sendung(3,23,1,cmd); b=getch(); endscreen(); b=system("clear"); b=system(cmd); b=getch(); } } } } return 0; } int lirebyte(void) { struct fich { char hex[15]; char port[15]; char uc[15]; }fi; FILE *tmp; FILE *prj; FILE *progra; char cmd[80]; int x; char hex[5]; char ligne[15]; int bin; char strbin[8]; int b; progra=fopen("/avrmenu/programmateur.txt","r"); fgets(ligne,14,progra); fclose(progra); sendung(2,4,45,"PROGRAMMATEUR : "); sendung(2,4,61,ligne); prj=fopen("/avrmenu/projet/proj.prj","r+b"); fread(&fi,sizeof(fi),1,prj); fclose(prj); sendung(2,5,45," PORT : "); sendung(2,5,53,fi.port); sendung(2,6,45," UC: "); sendung(2,6,51,fi.uc); sendung(3,20,25," PROJ OK REJET "); x=getch(); sendung(2,20,25," "); endscreen(); if (x==KEY_F(1)) { sprintf(cmd,"avrdude -c %s -P %s -p %s -U lfuse:r:m%c",ligne,fi.port,fi.uc,bin,0x0); b=system("clear"); b=system(cmd); b=getch(); sprintf(cmd,"avrdude -c %s -P %s -p %s -U hfuse:r:m%c",ligne,fi.port,fi.uc,bin,0x0); b=system("clear"); b=system(cmd); b=getch(); sprintf(cmd,"avrdude -c %s -P %s -p %s -U efuse:r:m%c",ligne,fi.port,fi.uc,bin,0x0); b=system("clear"); b=system(cmd); b=getch(); } return 0; } void cpfich(char *chemin) { struct fic { char hex[15]; char port[15]; char uc[15]; }fi; FILE *org; FILE *dest; org=fopen(chemin,"r+b"); dest=fopen("/avrmenu/projet/proj.prj","w+b"); fread(&fi,sizeof(fi),1,org); fwrite(&fi,sizeof(fi),1,dest); fclose(org); fclose(dest); } void charge_proj(void) { int x; FILE *f; char cmd[61]; char ligne[15]; char ch[31]; init(20,' '); m2(); masque(); sendung(4,20,34," =VALID "); x=verif(); for(x=0;x<15;x++) { if (p.chain[x]<33) { p.chain[x]=0x0; } } strncpy(ligne+0,p.chain+0,14); ligne[14]=0x0; sprintf(ch,"/avrmenu/projet/%s%c",ligne,0x0); f=fopen(ch,"r"); if (f!=NULL) { fclose(f); sprintf(cmd,"/avrmenu/projet/%s%c",ligne,0x0); cpfich(cmd); sendung_projet(); } else { sendung(3,5,30," PROJET INEXISTANT "); } x=getch(); } int los(void) { int bl; int y; int x; char nomfic[31]; char ligne[15]; FILE *proj; struct prj { char hex[15]; char port[15]; char uc[15]; }pj; x=0; while(x!=11) { newscreen(); strcpy(p.lib,"NOUV PROJET "); strcat(p.lib,"CHARGE PRJ "); strcat(p.lib,"ECRIRE .HEX "); strcat(p.lib,"LIRE .HEX "); strcat(p.lib,"VERIF .HEX "); strcat(p.lib,"LOW BYTE "); strcat(p.lib,"HIGHT BYTE "); strcat(p.lib,"EXT. BYTE "); strcat(p.lib,"PROGRAMMATEUR "); strcat(p.lib,"LIRE FUSIBLES "); strcat(p.lib,"QUITTER "); x=fenetre(11,14,4,4); if(x==1) { sendung(1,23,26," SAUVEGARDE SORTIE "); init(60,' '); m1(); masque(); y=verif(); if (y!=-1) { strncpy(ligne+0,p.chain+0,14); ligne[14]=0x0; for (bl=0;bl<15;bl++) { if (ligne[bl]<33) { ligne[bl]=0x0; } } strcpy(nomfic,"/avrmenu/projet/"); strcat(nomfic,ligne); nomfic[30]=0x0; strncpy(pj.hex+0,p.chain+14,14); for (bl=0;bl<15;bl++) { if (pj.hex[bl]<33) { pj.hex[bl]=0x0; } } pj.hex[14]=0x0; strncpy(pj.port+0,p.chain+28,14); for (bl=0;bl<15;bl++) { if (pj.port[bl]<33) { pj.port[bl]=0x0; } } pj.port[14]=0x0; strncpy(pj.uc+0,p.chain+42,14); for (bl=0;bl<15;bl++) { if (pj.uc[bl]<33) { pj.uc[bl]=0x0; } } pj.uc[14]=0x0; proj=fopen(nomfic,"w+b"); fwrite(&pj,sizeof(pj),1,proj); fclose(proj); } endscreen(); } if(x==2) { charge_proj(); } if(x==3) { ecrit_hex(); } if(x==4) { lit_hex(); } if(x==5) { verif_hex(); } if(x==6) { lbyte(); } if(x==7) { hbyte(); } if(x==8) { ebyte(); } if(x==9) { prog(); } if(x==10) { lirebyte(); } } endscreen(); return 0; } int main() { los(); return 0; }