CmapGpsu/CmapGpsu.cpp
De Wiki EELL.
(Différences entre les versions)
(re:) |
m (Catégorisation) |
||
| (2 versions intermédiaires masquées) | |||
| Ligne 1 : | Ligne 1 : | ||
| - | +1 | + | <pre> |
| + | /*O | ||
| + | NOM DU FICHIER: CmapGpsu.cpp | ||
| + | PROJET INITIAL: CmapGpsu Convertisseur de route CmapECS vers GPSUtility | ||
| + | DOSSIER: CmapGpsu | ||
| + | PROGRAMMEUR: ... | ||
| + | DATE: 20 février 2004 | ||
| + | MODIFICATIONS: | ||
| + | le:30/01/2010 par .............. | ||
| + | objet de la modification: Compil pour Win32 Console UNICODE Windows 7 | ||
| + | le: ../../.. par | ||
| + | |||
| + | */ | ||
| + | |||
| + | /*D | ||
| + | CmapGpsu | ||
| + | ----------------------------------------------------------------------------- | ||
| + | ACTION: | ||
| + | Lit le fichier Cmap ECS et crée un fichier texte pour GPS Utility | ||
| + | |||
| + | SYNTAXE: | ||
| + | #include <CmapGpsu.h> | ||
| + | int CmapGpsu( int argc, char *argv[] ) | ||
| + | |||
| + | PORTABILITE: | ||
| + | x86 Win32_Console UNICODE | ||
| + | |||
| + | DESCRIPTION: | ||
| + | int argc : Nombre de paramètres passés à la fonction CmapGpsu() | ||
| + | char *argv[] : Tableau des commandes ou fichiers (cmap) passés. | ||
| + | |||
| + | VALEUR RETOURNEE: | ||
| + | int 0 dans cette version (console) | ||
| + | |||
| + | VOIR AUSSI: | ||
| + | |||
| + | EXEMPLES: | ||
| + | |||
| + | */ | ||
| + | |||
| + | /*H // CmapGpsu.c: | ||
| + | extern int CmapGpsu( int argc, char *argv[] ); | ||
| + | */ | ||
| + | |||
| + | // Validation du test unitaire | ||
| + | // #define TESTS_U | ||
| + | |||
| + | #ifdef TESTS_U | ||
| + | #include "..\..\include\CmapGpsu.h" | ||
| + | #include<stdlib.h> | ||
| + | #endif | ||
| + | #ifndef TESTS_U | ||
| + | //#include <CmapGpsu.h> | ||
| + | #include "..\include\CmapGpsu.h" | ||
| + | #endif | ||
| + | //#include <windows.h> | ||
| + | #include <stdio.h> | ||
| + | #include <string.h> | ||
| + | #include <malloc.h> | ||
| + | |||
| + | void LireLong(FILE *stream, long * Data) | ||
| + | { | ||
| + | //long int Data; | ||
| + | *Data=(getc(stream)+256*getc(stream)+256*256*getc(stream)+256*256*256*getc(stream)); | ||
| + | //return Data; | ||
| + | } | ||
| + | |||
| + | char * LireChaine(FILE *stream, int Taille) | ||
| + | { | ||
| + | char *string; | ||
| + | int i; | ||
| + | string=(char*)calloc((Taille+1),sizeof(char)); | ||
| + | if(string==NULL)return NULL; | ||
| + | else | ||
| + | { | ||
| + | if(Taille==0)string[0]='\0'; | ||
| + | else for(i=0;i<Taille;i++)string[i]=getc(stream); | ||
| + | string[i]='\0'; | ||
| + | } | ||
| + | return string; | ||
| + | } | ||
| + | |||
| + | struct WayPoint * LirePoint(FILE *stream) | ||
| + | { | ||
| + | #ifdef TESTS_U | ||
| + | static int i=0; | ||
| + | #endif | ||
| + | struct WayPoint * point; | ||
| + | point=(struct WayPoint*)malloc(sizeof(struct WayPoint)); | ||
| + | #ifdef TESTS_U | ||
| + | printf("Lecture du point %d\n",i++); | ||
| + | #endif | ||
| + | /*O Lire le séparateur 0x02 puis le crochet '[' */ | ||
| + | if(getc(stream)==0x02); else return NULL; | ||
| + | if(getc(stream)=='['); else return NULL; | ||
| + | |||
| + | /*O Lire les champs de la structure WayPoint. */ | ||
| + | LireLong(stream, &point->TailleType); // 6L | ||
| + | if(point->TailleType>80L)return(NULL); | ||
| + | point->Type=LireChaine(stream, point->TailleType); | ||
| + | LireLong(stream, &point->crsss1); // 1L | ||
| + | LireLong(stream, &point->TailleLabel); | ||
| + | if(point->TailleLabel>80L)return(NULL); | ||
| + | point->Label=LireChaine(stream, point->TailleLabel); | ||
| + | LireLong(stream, &point->TailleLatitude); | ||
| + | if(point->TailleLatitude>10L)return(NULL); | ||
| + | point->Latitude=LireChaine(stream, point->TailleLatitude); | ||
| + | LireLong(stream, &point->TailleLongitude); | ||
| + | if(point->TailleLongitude>10L)return(NULL); | ||
| + | point->Longitude=LireChaine(stream, point->TailleLongitude); | ||
| + | LireLong(stream, &point->Turn); | ||
| + | LireLong(stream, &point->crsss2); // 1L | ||
| + | LireLong(stream, &point->TailleRemark); | ||
| + | if(point->TailleRemark>80L)return(NULL); | ||
| + | point->Remark=LireChaine(stream, point->TailleRemark); | ||
| + | if(getc(stream)!=']')return(NULL); | ||
| + | #ifdef TESTS_U | ||
| + | printf("Latitude : %s\nLongitude : %s\nRemarques : %s\n\n", | ||
| + | point->Latitude, | ||
| + | point->Longitude, | ||
| + | point->Remark); | ||
| + | #endif | ||
| + | |||
| + | return point; | ||
| + | } | ||
| + | |||
| + | struct Leg * LireLien(FILE *stream) | ||
| + | { | ||
| + | |||
| + | #ifdef TETS_U | ||
| + | static int i=0; | ||
| + | #endif | ||
| + | struct Leg * lien; | ||
| + | lien=(struct Leg*)malloc(sizeof(struct Leg)); | ||
| + | |||
| + | #ifdef TETS_U | ||
| + | printf("Lecture du lien %d\n",i++);exit(0); | ||
| + | #endif*/ | ||
| + | /*O Lire le séparateur 0x02 puis le crochet '[' */ | ||
| + | if(getc(stream)==0x02); else return NULL; | ||
| + | if(getc(stream)=='['); else return NULL; | ||
| + | LireLong(stream, &lien->TailleType); // 4L | ||
| + | if(lien->TailleType>80L)return(NULL); | ||
| + | lien->Type=LireChaine(stream, lien->TailleType); | ||
| + | LireLong(stream, &lien->crsss1); // 1L | ||
| + | LireLong(stream, &lien->TailleLabel); | ||
| + | if(lien->TailleLabel>80L)return(NULL); | ||
| + | lien->Label=LireChaine(stream, lien->TailleLabel); | ||
| + | LireLong(stream, &lien->Deviation); | ||
| + | LireLong(stream, &lien->Speed); | ||
| + | LireLong(stream, &lien->TailleNoChar1); | ||
| + | if(lien->TailleNoChar1>80L)return(NULL); | ||
| + | lien->NoChar1=LireChaine(stream, lien->TailleNoChar1); | ||
| + | LireLong(stream, &lien->crsss2); | ||
| + | LireLong(stream, &lien->StartLegOnWpt); | ||
| + | LireLong(stream, &lien->EndLegOnWpt); | ||
| + | LireLong(stream, &lien->Num); | ||
| + | LireLong(stream, &lien->TailleNoChar2); | ||
| + | if(lien->TailleNoChar2>80L)return(NULL); | ||
| + | lien->NoChar2=LireChaine(stream, lien->TailleNoChar2); | ||
| + | LireLong(stream, (long*)&lien->Safety); | ||
| + | |||
| + | /*O Lire les champs de la structure Leg. */ | ||
| + | if(getc(stream)!=']')return(NULL); | ||
| + | #ifdef TESTS_U | ||
| + | printf("Label : %s\nDeviation : %ld\nSpeed : %ld\nStartWpt = %ld\nEndWpt = %ld\nSafety : %lx\n\n", | ||
| + | lien->Label, | ||
| + | lien->Deviation, | ||
| + | lien->Speed, | ||
| + | lien->StartLegOnWpt, | ||
| + | lien->EndLegOnWpt, | ||
| + | lien->Safety | ||
| + | ); | ||
| + | #endif | ||
| + | |||
| + | return lien; | ||
| + | } | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | /*O Programme CmapGpsu pour shells ou windows */ | ||
| + | int CmapGpsu( int argc, char *argv[]) | ||
| + | { | ||
| + | int Iret = 0; // retour de fonction | ||
| + | int Retf = 0; | ||
| + | char ch = ' '; // variable caractère de saisie | ||
| + | int i; // entier de comptage de boucle | ||
| + | long int lPoint; // entier numéro de point | ||
| + | long int l; // entier de comptage | ||
| + | FILE *InFile; // flux d'entrée | ||
| + | FILE *OutGpsuFile; // flux d'écriture GPSU | ||
| + | char OutGpsu[100]="";// nom du fichier GPSU | ||
| + | FILE *OutReviewFile; // flux d'écriture de vérification et modif | ||
| + | char OutRev[100]=""; // nom du fichier de vérification | ||
| + | struct VersionCmap VCmap; //={0L,0L,"-------"}; | ||
| + | struct HeaderData Header; | ||
| + | struct WayPoint **Wpt; | ||
| + | struct Leg **Lien; | ||
| + | // Entête d'un fichier GPSU | ||
| + | char *HeaderGPSU = "H SOFTWARE NAME & VERSION\n\ | ||
| + | I GPSU 4.04 FREEWARE VERSION\n\ | ||
| + | S DateFormat=dd/mm/yy\n\ | ||
| + | S Timezone=2\n\ | ||
| + | S Units=N,M\n\ | ||
| + | S SymbolSet=1\n\ | ||
| + | \n\ | ||
| + | H R DATUM\n\ | ||
| + | M E WGS 84 100 0.0000000E+00 0.0000000E+00 0 0 0\n\ | ||
| + | \n\ | ||
| + | H COORDINATE SYSTEM\n\ | ||
| + | U LAT LON DM\n\ | ||
| + | \n\ | ||
| + | F ID---- Latitude Longitude Symbol---- T Comment\n"; | ||
| + | |||
| + | |||
| + | /*O Si le deuxième argument est vide quitter le programme */ | ||
| + | if(argc==1)ExitError(-1); | ||
| + | /*O Ouvrir le fichier source de Route Cmap */ | ||
| + | #ifdef TESTS_U | ||
| + | printf("Ouverture du fichier %s\n",argv[1]); | ||
| + | #endif | ||
| + | //if(InFile=fopen(argv[1],"rb")) // Version déprécioée | ||
| + | if(!fopen_s(&InFile,argv[1],"rb")) | ||
| + | { | ||
| + | #ifdef TESTS_U | ||
| + | printf("Fichier %s ouvert\n",argv[1]); | ||
| + | //for (i=0;i<16;i++) printf("%x\n",fgetc(InFile)); exit(0); | ||
| + | #endif | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | #ifdef TESTS_U | ||
| + | printf("Erreur à l'ouverture du fichier %s\n",argv[1]); | ||
| + | #endif | ||
| + | ExitError(1); // erreur à l'ouverture du fichier CmapRoute | ||
| + | } | ||
| + | |||
| + | |||
| + | /*O Lire La version du fichier et son type */ | ||
| + | if((ch=fgetc(InFile))!=0x3a) ExitError(2); //erreur de type de fichier | ||
| + | puts("0x3a OK"); // Test après erreur | ||
| + | LireLong(InFile,(long*)&VCmap.Version); | ||
| + | LireLong(InFile,&VCmap.TailleType); | ||
| + | if(VCmap.TailleType>80) ExitError(2); | ||
| + | puts("TailleType OK"); // Test après erreur | ||
| + | VCmap.Type=LireChaine(InFile, VCmap.TailleType); | ||
| + | |||
| + | #ifdef TESTS_U | ||
| + | printf("\nVersion:0x%lx \nTailleType:0x%lx \nType:%s\n\n", | ||
| + | VCmap.Version, | ||
| + | VCmap.TailleType, | ||
| + | VCmap.Type); | ||
| + | //exit(0); | ||
| + | #endif | ||
| + | |||
| + | /*O Si la version et le type sont corrects */ | ||
| + | if (VCmap.Version==0x0101L); else ExitError(2); // erreur de type de fichier | ||
| + | if (VCmap.TailleType==0x07L); else ExitError(2); | ||
| + | if (strcmp(VCmap.Type,"CMROUTE")!=0) ExitError(2); | ||
| + | |||
| + | /*O Alors : */ | ||
| + | else | ||
| + | { | ||
| + | /*O Lire le séparateur 0x02 puis le crochet '[' */ | ||
| + | if(fgetc(InFile)==0x02); else ExitError(3); | ||
| + | if(getc(InFile)=='['); else ExitError(3); | ||
| + | |||
| + | /*O Lire l'entête des données et les stocker dans la structure HeaderData */ | ||
| + | LireLong(InFile,&Header.TailleType); // 6L | ||
| + | if(Header.TailleType>80)ExitError(4); | ||
| + | Header.Type=LireChaine(InFile, Header.TailleType); | ||
| + | LireLong(InFile,&Header.crsss1); // 1L | ||
| + | LireLong(InFile,&Header.TailleRoute); | ||
| + | if(Header.TailleRoute>80)ExitError(4); | ||
| + | Header.Route=LireChaine(InFile, Header.TailleRoute); | ||
| + | LireLong(InFile,&Header.Num); | ||
| + | LireLong(InFile,&Header.StartWayPoint); | ||
| + | LireLong(InFile,&Header.EndWayPoint); | ||
| + | LireLong(InFile,&Header.NbWayPoint); | ||
| + | Header.NbLeg=Header.NbWayPoint-1; // Vérifier + loin ... | ||
| + | #ifdef TESTS_U | ||
| + | printf("TTyp: %ld , Typ: %s\nTRte: %ld , Rte: %s\nStart: %ld , End: %ld\nNbWayPts = %ld\nNbLegs = %ld\n\n", | ||
| + | Header.TailleType, | ||
| + | Header.Type, | ||
| + | Header.TailleRoute, | ||
| + | Header.Route, | ||
| + | Header.StartWayPoint, | ||
| + | Header.EndWayPoint, | ||
| + | Header.NbWayPoint, | ||
| + | Header.NbLeg | ||
| + | ); | ||
| + | //exit(0); | ||
| + | #endif | ||
| + | |||
| + | /*O Si le Nombre de WayPoint est suppérieur à 0: */ | ||
| + | if (Header.NbWayPoint > 0L) | ||
| + | { | ||
| + | l=0; | ||
| + | Wpt=(struct WayPoint**)calloc(Header.NbWayPoint,sizeof(struct WayPoint*)); | ||
| + | |||
| + | /*O Tant qu'il y a des WayPoint: */ | ||
| + | while (l<Header.NbWayPoint) | ||
| + | { | ||
| + | #ifdef TESTS_U | ||
| + | printf("NbPoint=%ld\nl=%ld\n",Header.NbWayPoint,l); | ||
| + | #endif | ||
| + | if((Wpt[l]=LirePoint(InFile))!=NULL);else ExitError(5); | ||
| + | l++; | ||
| + | } | ||
| + | #ifdef TESTS_U | ||
| + | for(l=0;l<Header.NbWayPoint;l++) | ||
| + | printf("Label:%s|Lat=%s|Lon=%s|Rem:%s\n", | ||
| + | Wpt[l]->Label, | ||
| + | Wpt[l]->Latitude, | ||
| + | Wpt[l]->Longitude, | ||
| + | Wpt[l]->Remark | ||
| + | ); | ||
| + | #endif //exit(0); | ||
| + | } | ||
| + | |||
| + | |||
| + | /*O Lire le nombre de traits */ | ||
| + | LireLong(InFile,&Header.NbLeg); | ||
| + | |||
| + | /*O Si le nombre de traits est suppérieur à 0: */ | ||
| + | if (l=Header.NbLeg>0L) | ||
| + | { | ||
| + | l=0; | ||
| + | Lien=(struct Leg**)calloc(Header.NbLeg,sizeof(struct Leg*)); | ||
| + | |||
| + | /*O Tant qu'il y a des liens (des traits): */ | ||
| + | while (l<Header.NbLeg) | ||
| + | { | ||
| + | #ifdef TESTS_U | ||
| + | printf("\nNbLeg=%ld\nl=%ld\n",Header.NbLeg,l); | ||
| + | #endif | ||
| + | //Lien[l]=LireLien(InFile); | ||
| + | if((Lien[l]=LireLien(InFile))!=NULL);else ExitError(6); | ||
| + | l++; | ||
| + | } | ||
| + | |||
| + | /*O Si le prochain caractère est ']' tout s'est passé correctement! */ | ||
| + | if (getc(InFile)==']');else ExitError(7); | ||
| + | fclose (InFile); | ||
| + | } | ||
| + | |||
| + | /*O Réinitialiser le nombre de traits */ | ||
| + | i=(int)Header.NbLeg; | ||
| + | |||
| + | /*O Ouvrir les fichiers texte Gpsu, et Modif de Route */ | ||
| + | strcpy_s(OutGpsu,Header.Route); | ||
| + | strcat_s(OutGpsu,".txt"); | ||
| + | if(fopen_s(&OutGpsuFile,OutGpsu,"w+"))ExitError(8); | ||
| + | // if(OutGpsuFile==NULL)ExitError(8); // ancienne version | ||
| + | |||
| + | /*O Ecrire l'entête du fichier GPSU */ | ||
| + | fprintf(OutGpsuFile,"%s",HeaderGPSU); | ||
| + | |||
| + | /*O Initialiser le Point qui a pour adresse HeaderData.StartWayPoint */ | ||
| + | lPoint=Header.StartWayPoint; | ||
| + | |||
| + | /*O Tant qu'il y a des Points écrire dans les fichiers texte: */ | ||
| + | l=0L; | ||
| + | while(l<Header.NbWayPoint) | ||
| + | { | ||
| + | static int n=10; | ||
| + | long int li; | ||
| + | int found = 0; | ||
| + | char ch; | ||
| + | // W 0010 N43°33.1700' E004°04.8700' Waypoint - GM PORT | ||
| + | // F ID---- Latitude Longitude Symbol---- T Comment | ||
| + | // W WP0010 N43°33.1700' E004°04.8700' Waypoint - GM PORT | ||
| + | |||
| + | //l=NextWpt; | ||
| + | |||
| + | /*O Le numéro de ligne "W 0010 " sur 8 caractères, */ | ||
| + | fprintf(OutGpsuFile,"W WP%.4d N",n); | ||
| + | n=n+10; | ||
| + | |||
| + | /*O La Latitude sous la forme: " N43°33.1700'" sur 13 caractères */ | ||
| + | if((ch=Wpt[lPoint]->Latitude[1])==' ')ch='0'; | ||
| + | fputc(ch,OutGpsuFile); | ||
| + | if((ch=Wpt[lPoint]->Latitude[2])==' ')ch='0'; | ||
| + | fputc(ch,OutGpsuFile); | ||
| + | fputc('°',OutGpsuFile); | ||
| + | if((ch=Wpt[lPoint]->Latitude[4])==' ')ch='0'; | ||
| + | fputc(ch,OutGpsuFile); | ||
| + | if((ch=Wpt[lPoint]->Latitude[5])==' ')ch='0'; | ||
| + | fputc(ch,OutGpsuFile); | ||
| + | fputc('.',OutGpsuFile); | ||
| + | if((ch=Wpt[lPoint]->Latitude[7])==' ')ch='0'; | ||
| + | fputc(ch,OutGpsuFile); | ||
| + | if((ch=Wpt[lPoint]->Latitude[8])==' ')ch='0'; | ||
| + | fputc(ch,OutGpsuFile); | ||
| + | |||
| + | /*O La Longitude sous la forme: " E004°04.8700'" sur 14 caractères */ | ||
| + | fprintf(OutGpsuFile,"00' E"); | ||
| + | if((ch=Wpt[lPoint]->Longitude[0])==' ')ch='0'; | ||
| + | fputc(ch,OutGpsuFile); | ||
| + | if((ch=Wpt[lPoint]->Longitude[1])==' ')ch='0'; | ||
| + | fputc(ch,OutGpsuFile); | ||
| + | if((ch=Wpt[lPoint]->Longitude[2])==' ')ch='0'; | ||
| + | fputc(ch,OutGpsuFile); | ||
| + | fputc('°',OutGpsuFile); | ||
| + | if((ch=Wpt[lPoint]->Longitude[4])==' ')ch='0'; | ||
| + | fputc(ch,OutGpsuFile); | ||
| + | if((ch=Wpt[lPoint]->Longitude[5])==' ')ch='0'; | ||
| + | fputc(ch,OutGpsuFile); | ||
| + | fputc('.',OutGpsuFile); | ||
| + | if((ch=Wpt[lPoint]->Longitude[7])==' ')ch='0'; | ||
| + | fputc(ch,OutGpsuFile); | ||
| + | if((ch=Wpt[lPoint]->Longitude[8])==' ')ch='0'; | ||
| + | fputc(ch,OutGpsuFile); | ||
| + | |||
| + | /*O L'étiquette sous la forme " GM PORT" non limité en taille */ | ||
| + | fprintf(OutGpsuFile,"00' Waypoint - %s\n",Wpt[lPoint]->Remark); | ||
| + | |||
| + | /*O Chercher le lien et l'adresse du point suivant */ | ||
| + | for(li=0L;li<Header.NbLeg&&found==0;li++) | ||
| + | { | ||
| + | //printf("\n%ld %ld -> %ld\n",lPoint,Lien[li]->StartLegOnWpt,Lien[li]->EndLegOnWpt); | ||
| + | if(Lien[li]->StartLegOnWpt==lPoint) | ||
| + | { | ||
| + | lPoint=Lien[li]->EndLegOnWpt; | ||
| + | found=1; | ||
| + | } | ||
| + | } | ||
| + | l++; | ||
| + | } | ||
| + | fclose(OutGpsuFile); | ||
| + | |||
| + | /*O Ecrire l'entête du fichier Route */ | ||
| + | strcpy_s(OutRev,Header.Route); | ||
| + | strcat_s(OutRev,".cmv"); | ||
| + | if(fopen_s(&OutReviewFile,OutRev,"w+"))ExitError(9); | ||
| + | // if(OutReviewFile==NULL)ExitError(9); ancienne version pour open() | ||
| + | fprintf(OutReviewFile,"%s //Route\n",Header.Route); | ||
| + | fprintf(OutReviewFile,"%.8ld //Num\n",Header.Num); | ||
| + | fprintf(OutReviewFile,"%.8ld //Start Legs\n",Header.StartWayPoint); | ||
| + | fprintf(OutReviewFile,"%.8ld //End Legs\n",Header.EndWayPoint); | ||
| + | fprintf(OutReviewFile,"%.8ld //Nb WayPoints\n",Header.NbWayPoint); | ||
| + | fprintf(OutReviewFile,"%.8ld //Nb Legs\n",Header.NbLeg); | ||
| + | #ifdef EN | ||
| + | fprintf(OutReviewFile,"WayPoints\nLine|Latitude |Longitude |Turn|Label|Remark|\n"); | ||
| + | fprintf(OutReviewFile, " Num|Deg Min |Deg Min | (m)| | |\n"); | ||
| + | #endif | ||
| + | #ifdef FR | ||
| + | fprintf(OutReviewFile,"WayPoints\nLign|Latitude |Longitude |Turn|Label |Remark |\n"); | ||
| + | fprintf(OutReviewFile, " Num|Deg Min |Deg Min | (m)|Etiquette|Remarque|\n"); | ||
| + | #endif | ||
| + | for(l=0L;l<Header.NbWayPoint;l++) | ||
| + | { | ||
| + | fprintf(OutReviewFile,"%4ld|%s|%s|%4d|%s|%s\n",\ | ||
| + | l,\ | ||
| + | Wpt[l]->Latitude,\ | ||
| + | Wpt[l]->Longitude,\ | ||
| + | Wpt[l]->Turn,\ | ||
| + | Wpt[l]->Label,\ | ||
| + | Wpt[l]->Remark | ||
| + | ); | ||
| + | } | ||
| + | |||
| + | #ifdef EN | ||
| + | fprintf(OutReviewFile,"Legs\nDeviat|Speed|StartL|EndLeg| Safety|Label|\n"); | ||
| + | fprintf(OutReviewFile," (m)| kN|LineWp|LineWp| Code| |\n"); | ||
| + | #endif | ||
| + | #ifdef FR | ||
| + | fprintf(OutReviewFile,"Traits\nDeviat|Speed|DebTr.|FinTr.| Safety|Label|\n"); | ||
| + | fprintf(OutReviewFile," (m)|Noeud|LignWp|LignWp| Code| |\n"); | ||
| + | #endif | ||
| + | for(l=0L;l<Header.NbLeg;l++) | ||
| + | { | ||
| + | fprintf(OutReviewFile,"%6ld|%5ld|%6ld|%6ld|Ox%.8lX|%s|\n",\ | ||
| + | Lien[l]->Deviation,\ | ||
| + | Lien[l]->Speed,\ | ||
| + | Lien[l]->StartLegOnWpt,\ | ||
| + | Lien[l]->EndLegOnWpt,\ | ||
| + | Lien[l]->Safety,\ | ||
| + | Lien[l]->Label\ | ||
| + | ); | ||
| + | } | ||
| + | fclose(OutReviewFile); | ||
| + | } | ||
| + | return (Iret); | ||
| + | } | ||
| + | |||
| + | #ifdef TESTS_U /*T pour DOS uniquement ou QWIN */ | ||
| + | int main(int argc, char *argv[]) /*T*/ | ||
| + | { /*T*/ | ||
| + | int Iret; /*T*/ | ||
| + | printf("VERSION_CmapGpsu: %s\n",VERSION_CmapGpsu); /*T*/ | ||
| + | printf("TEST UNITAIRE du module \'CmapGpsu\'\n"); /*T*/ | ||
| + | Iret=CmapGpsu(argc, argv); /*T*/ | ||
| + | printf("FIN DU TEST UNITAIRE du module \'CmapGpsu\'\n"); /*T*/ | ||
| + | return 0; /*T*/ | ||
| + | } /*T*/ | ||
| + | #endif /*T*/ | ||
| + | </pre> | ||
| + | |||
| + | [[Catégorie:CmapGpsu]] | ||
Version actuelle en date du 9 février 2014 à 15:31
/*O
NOM DU FICHIER: CmapGpsu.cpp
PROJET INITIAL: CmapGpsu Convertisseur de route CmapECS vers GPSUtility
DOSSIER: CmapGpsu
PROGRAMMEUR: ...
DATE: 20 février 2004
MODIFICATIONS:
le:30/01/2010 par ..............
objet de la modification: Compil pour Win32 Console UNICODE Windows 7
le: ../../.. par
*/
/*D
CmapGpsu
-----------------------------------------------------------------------------
ACTION:
Lit le fichier Cmap ECS et crée un fichier texte pour GPS Utility
SYNTAXE:
#include <CmapGpsu.h>
int CmapGpsu( int argc, char *argv[] )
PORTABILITE:
x86 Win32_Console UNICODE
DESCRIPTION:
int argc : Nombre de paramètres passés à la fonction CmapGpsu()
char *argv[] : Tableau des commandes ou fichiers (cmap) passés.
VALEUR RETOURNEE:
int 0 dans cette version (console)
VOIR AUSSI:
EXEMPLES:
*/
/*H // CmapGpsu.c:
extern int CmapGpsu( int argc, char *argv[] );
*/
// Validation du test unitaire
// #define TESTS_U
#ifdef TESTS_U
#include "..\..\include\CmapGpsu.h"
#include<stdlib.h>
#endif
#ifndef TESTS_U
//#include <CmapGpsu.h>
#include "..\include\CmapGpsu.h"
#endif
//#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
void LireLong(FILE *stream, long * Data)
{
//long int Data;
*Data=(getc(stream)+256*getc(stream)+256*256*getc(stream)+256*256*256*getc(stream));
//return Data;
}
char * LireChaine(FILE *stream, int Taille)
{
char *string;
int i;
string=(char*)calloc((Taille+1),sizeof(char));
if(string==NULL)return NULL;
else
{
if(Taille==0)string[0]='\0';
else for(i=0;i<Taille;i++)string[i]=getc(stream);
string[i]='\0';
}
return string;
}
struct WayPoint * LirePoint(FILE *stream)
{
#ifdef TESTS_U
static int i=0;
#endif
struct WayPoint * point;
point=(struct WayPoint*)malloc(sizeof(struct WayPoint));
#ifdef TESTS_U
printf("Lecture du point %d\n",i++);
#endif
/*O Lire le séparateur 0x02 puis le crochet '[' */
if(getc(stream)==0x02); else return NULL;
if(getc(stream)=='['); else return NULL;
/*O Lire les champs de la structure WayPoint. */
LireLong(stream, &point->TailleType); // 6L
if(point->TailleType>80L)return(NULL);
point->Type=LireChaine(stream, point->TailleType);
LireLong(stream, &point->crsss1); // 1L
LireLong(stream, &point->TailleLabel);
if(point->TailleLabel>80L)return(NULL);
point->Label=LireChaine(stream, point->TailleLabel);
LireLong(stream, &point->TailleLatitude);
if(point->TailleLatitude>10L)return(NULL);
point->Latitude=LireChaine(stream, point->TailleLatitude);
LireLong(stream, &point->TailleLongitude);
if(point->TailleLongitude>10L)return(NULL);
point->Longitude=LireChaine(stream, point->TailleLongitude);
LireLong(stream, &point->Turn);
LireLong(stream, &point->crsss2); // 1L
LireLong(stream, &point->TailleRemark);
if(point->TailleRemark>80L)return(NULL);
point->Remark=LireChaine(stream, point->TailleRemark);
if(getc(stream)!=']')return(NULL);
#ifdef TESTS_U
printf("Latitude : %s\nLongitude : %s\nRemarques : %s\n\n",
point->Latitude,
point->Longitude,
point->Remark);
#endif
return point;
}
struct Leg * LireLien(FILE *stream)
{
#ifdef TETS_U
static int i=0;
#endif
struct Leg * lien;
lien=(struct Leg*)malloc(sizeof(struct Leg));
#ifdef TETS_U
printf("Lecture du lien %d\n",i++);exit(0);
#endif*/
/*O Lire le séparateur 0x02 puis le crochet '[' */
if(getc(stream)==0x02); else return NULL;
if(getc(stream)=='['); else return NULL;
LireLong(stream, &lien->TailleType); // 4L
if(lien->TailleType>80L)return(NULL);
lien->Type=LireChaine(stream, lien->TailleType);
LireLong(stream, &lien->crsss1); // 1L
LireLong(stream, &lien->TailleLabel);
if(lien->TailleLabel>80L)return(NULL);
lien->Label=LireChaine(stream, lien->TailleLabel);
LireLong(stream, &lien->Deviation);
LireLong(stream, &lien->Speed);
LireLong(stream, &lien->TailleNoChar1);
if(lien->TailleNoChar1>80L)return(NULL);
lien->NoChar1=LireChaine(stream, lien->TailleNoChar1);
LireLong(stream, &lien->crsss2);
LireLong(stream, &lien->StartLegOnWpt);
LireLong(stream, &lien->EndLegOnWpt);
LireLong(stream, &lien->Num);
LireLong(stream, &lien->TailleNoChar2);
if(lien->TailleNoChar2>80L)return(NULL);
lien->NoChar2=LireChaine(stream, lien->TailleNoChar2);
LireLong(stream, (long*)&lien->Safety);
/*O Lire les champs de la structure Leg. */
if(getc(stream)!=']')return(NULL);
#ifdef TESTS_U
printf("Label : %s\nDeviation : %ld\nSpeed : %ld\nStartWpt = %ld\nEndWpt = %ld\nSafety : %lx\n\n",
lien->Label,
lien->Deviation,
lien->Speed,
lien->StartLegOnWpt,
lien->EndLegOnWpt,
lien->Safety
);
#endif
return lien;
}
/*O Programme CmapGpsu pour shells ou windows */
int CmapGpsu( int argc, char *argv[])
{
int Iret = 0; // retour de fonction
int Retf = 0;
char ch = ' '; // variable caractère de saisie
int i; // entier de comptage de boucle
long int lPoint; // entier numéro de point
long int l; // entier de comptage
FILE *InFile; // flux d'entrée
FILE *OutGpsuFile; // flux d'écriture GPSU
char OutGpsu[100]="";// nom du fichier GPSU
FILE *OutReviewFile; // flux d'écriture de vérification et modif
char OutRev[100]=""; // nom du fichier de vérification
struct VersionCmap VCmap; //={0L,0L,"-------"};
struct HeaderData Header;
struct WayPoint **Wpt;
struct Leg **Lien;
// Entête d'un fichier GPSU
char *HeaderGPSU = "H SOFTWARE NAME & VERSION\n\
I GPSU 4.04 FREEWARE VERSION\n\
S DateFormat=dd/mm/yy\n\
S Timezone=2\n\
S Units=N,M\n\
S SymbolSet=1\n\
\n\
H R DATUM\n\
M E WGS 84 100 0.0000000E+00 0.0000000E+00 0 0 0\n\
\n\
H COORDINATE SYSTEM\n\
U LAT LON DM\n\
\n\
F ID---- Latitude Longitude Symbol---- T Comment\n";
/*O Si le deuxième argument est vide quitter le programme */
if(argc==1)ExitError(-1);
/*O Ouvrir le fichier source de Route Cmap */
#ifdef TESTS_U
printf("Ouverture du fichier %s\n",argv[1]);
#endif
//if(InFile=fopen(argv[1],"rb")) // Version déprécioée
if(!fopen_s(&InFile,argv[1],"rb"))
{
#ifdef TESTS_U
printf("Fichier %s ouvert\n",argv[1]);
//for (i=0;i<16;i++) printf("%x\n",fgetc(InFile)); exit(0);
#endif
}
else
{
#ifdef TESTS_U
printf("Erreur à l'ouverture du fichier %s\n",argv[1]);
#endif
ExitError(1); // erreur à l'ouverture du fichier CmapRoute
}
/*O Lire La version du fichier et son type */
if((ch=fgetc(InFile))!=0x3a) ExitError(2); //erreur de type de fichier
puts("0x3a OK"); // Test après erreur
LireLong(InFile,(long*)&VCmap.Version);
LireLong(InFile,&VCmap.TailleType);
if(VCmap.TailleType>80) ExitError(2);
puts("TailleType OK"); // Test après erreur
VCmap.Type=LireChaine(InFile, VCmap.TailleType);
#ifdef TESTS_U
printf("\nVersion:0x%lx \nTailleType:0x%lx \nType:%s\n\n",
VCmap.Version,
VCmap.TailleType,
VCmap.Type);
//exit(0);
#endif
/*O Si la version et le type sont corrects */
if (VCmap.Version==0x0101L); else ExitError(2); // erreur de type de fichier
if (VCmap.TailleType==0x07L); else ExitError(2);
if (strcmp(VCmap.Type,"CMROUTE")!=0) ExitError(2);
/*O Alors : */
else
{
/*O Lire le séparateur 0x02 puis le crochet '[' */
if(fgetc(InFile)==0x02); else ExitError(3);
if(getc(InFile)=='['); else ExitError(3);
/*O Lire l'entête des données et les stocker dans la structure HeaderData */
LireLong(InFile,&Header.TailleType); // 6L
if(Header.TailleType>80)ExitError(4);
Header.Type=LireChaine(InFile, Header.TailleType);
LireLong(InFile,&Header.crsss1); // 1L
LireLong(InFile,&Header.TailleRoute);
if(Header.TailleRoute>80)ExitError(4);
Header.Route=LireChaine(InFile, Header.TailleRoute);
LireLong(InFile,&Header.Num);
LireLong(InFile,&Header.StartWayPoint);
LireLong(InFile,&Header.EndWayPoint);
LireLong(InFile,&Header.NbWayPoint);
Header.NbLeg=Header.NbWayPoint-1; // Vérifier + loin ...
#ifdef TESTS_U
printf("TTyp: %ld , Typ: %s\nTRte: %ld , Rte: %s\nStart: %ld , End: %ld\nNbWayPts = %ld\nNbLegs = %ld\n\n",
Header.TailleType,
Header.Type,
Header.TailleRoute,
Header.Route,
Header.StartWayPoint,
Header.EndWayPoint,
Header.NbWayPoint,
Header.NbLeg
);
//exit(0);
#endif
/*O Si le Nombre de WayPoint est suppérieur à 0: */
if (Header.NbWayPoint > 0L)
{
l=0;
Wpt=(struct WayPoint**)calloc(Header.NbWayPoint,sizeof(struct WayPoint*));
/*O Tant qu'il y a des WayPoint: */
while (l<Header.NbWayPoint)
{
#ifdef TESTS_U
printf("NbPoint=%ld\nl=%ld\n",Header.NbWayPoint,l);
#endif
if((Wpt[l]=LirePoint(InFile))!=NULL);else ExitError(5);
l++;
}
#ifdef TESTS_U
for(l=0;l<Header.NbWayPoint;l++)
printf("Label:%s|Lat=%s|Lon=%s|Rem:%s\n",
Wpt[l]->Label,
Wpt[l]->Latitude,
Wpt[l]->Longitude,
Wpt[l]->Remark
);
#endif //exit(0);
}
/*O Lire le nombre de traits */
LireLong(InFile,&Header.NbLeg);
/*O Si le nombre de traits est suppérieur à 0: */
if (l=Header.NbLeg>0L)
{
l=0;
Lien=(struct Leg**)calloc(Header.NbLeg,sizeof(struct Leg*));
/*O Tant qu'il y a des liens (des traits): */
while (l<Header.NbLeg)
{
#ifdef TESTS_U
printf("\nNbLeg=%ld\nl=%ld\n",Header.NbLeg,l);
#endif
//Lien[l]=LireLien(InFile);
if((Lien[l]=LireLien(InFile))!=NULL);else ExitError(6);
l++;
}
/*O Si le prochain caractère est ']' tout s'est passé correctement! */
if (getc(InFile)==']');else ExitError(7);
fclose (InFile);
}
/*O Réinitialiser le nombre de traits */
i=(int)Header.NbLeg;
/*O Ouvrir les fichiers texte Gpsu, et Modif de Route */
strcpy_s(OutGpsu,Header.Route);
strcat_s(OutGpsu,".txt");
if(fopen_s(&OutGpsuFile,OutGpsu,"w+"))ExitError(8);
// if(OutGpsuFile==NULL)ExitError(8); // ancienne version
/*O Ecrire l'entête du fichier GPSU */
fprintf(OutGpsuFile,"%s",HeaderGPSU);
/*O Initialiser le Point qui a pour adresse HeaderData.StartWayPoint */
lPoint=Header.StartWayPoint;
/*O Tant qu'il y a des Points écrire dans les fichiers texte: */
l=0L;
while(l<Header.NbWayPoint)
{
static int n=10;
long int li;
int found = 0;
char ch;
// W 0010 N43°33.1700' E004°04.8700' Waypoint - GM PORT
// F ID---- Latitude Longitude Symbol---- T Comment
// W WP0010 N43°33.1700' E004°04.8700' Waypoint - GM PORT
//l=NextWpt;
/*O Le numéro de ligne "W 0010 " sur 8 caractères, */
fprintf(OutGpsuFile,"W WP%.4d N",n);
n=n+10;
/*O La Latitude sous la forme: " N43°33.1700'" sur 13 caractères */
if((ch=Wpt[lPoint]->Latitude[1])==' ')ch='0';
fputc(ch,OutGpsuFile);
if((ch=Wpt[lPoint]->Latitude[2])==' ')ch='0';
fputc(ch,OutGpsuFile);
fputc('°',OutGpsuFile);
if((ch=Wpt[lPoint]->Latitude[4])==' ')ch='0';
fputc(ch,OutGpsuFile);
if((ch=Wpt[lPoint]->Latitude[5])==' ')ch='0';
fputc(ch,OutGpsuFile);
fputc('.',OutGpsuFile);
if((ch=Wpt[lPoint]->Latitude[7])==' ')ch='0';
fputc(ch,OutGpsuFile);
if((ch=Wpt[lPoint]->Latitude[8])==' ')ch='0';
fputc(ch,OutGpsuFile);
/*O La Longitude sous la forme: " E004°04.8700'" sur 14 caractères */
fprintf(OutGpsuFile,"00' E");
if((ch=Wpt[lPoint]->Longitude[0])==' ')ch='0';
fputc(ch,OutGpsuFile);
if((ch=Wpt[lPoint]->Longitude[1])==' ')ch='0';
fputc(ch,OutGpsuFile);
if((ch=Wpt[lPoint]->Longitude[2])==' ')ch='0';
fputc(ch,OutGpsuFile);
fputc('°',OutGpsuFile);
if((ch=Wpt[lPoint]->Longitude[4])==' ')ch='0';
fputc(ch,OutGpsuFile);
if((ch=Wpt[lPoint]->Longitude[5])==' ')ch='0';
fputc(ch,OutGpsuFile);
fputc('.',OutGpsuFile);
if((ch=Wpt[lPoint]->Longitude[7])==' ')ch='0';
fputc(ch,OutGpsuFile);
if((ch=Wpt[lPoint]->Longitude[8])==' ')ch='0';
fputc(ch,OutGpsuFile);
/*O L'étiquette sous la forme " GM PORT" non limité en taille */
fprintf(OutGpsuFile,"00' Waypoint - %s\n",Wpt[lPoint]->Remark);
/*O Chercher le lien et l'adresse du point suivant */
for(li=0L;li<Header.NbLeg&&found==0;li++)
{
//printf("\n%ld %ld -> %ld\n",lPoint,Lien[li]->StartLegOnWpt,Lien[li]->EndLegOnWpt);
if(Lien[li]->StartLegOnWpt==lPoint)
{
lPoint=Lien[li]->EndLegOnWpt;
found=1;
}
}
l++;
}
fclose(OutGpsuFile);
/*O Ecrire l'entête du fichier Route */
strcpy_s(OutRev,Header.Route);
strcat_s(OutRev,".cmv");
if(fopen_s(&OutReviewFile,OutRev,"w+"))ExitError(9);
// if(OutReviewFile==NULL)ExitError(9); ancienne version pour open()
fprintf(OutReviewFile,"%s //Route\n",Header.Route);
fprintf(OutReviewFile,"%.8ld //Num\n",Header.Num);
fprintf(OutReviewFile,"%.8ld //Start Legs\n",Header.StartWayPoint);
fprintf(OutReviewFile,"%.8ld //End Legs\n",Header.EndWayPoint);
fprintf(OutReviewFile,"%.8ld //Nb WayPoints\n",Header.NbWayPoint);
fprintf(OutReviewFile,"%.8ld //Nb Legs\n",Header.NbLeg);
#ifdef EN
fprintf(OutReviewFile,"WayPoints\nLine|Latitude |Longitude |Turn|Label|Remark|\n");
fprintf(OutReviewFile, " Num|Deg Min |Deg Min | (m)| | |\n");
#endif
#ifdef FR
fprintf(OutReviewFile,"WayPoints\nLign|Latitude |Longitude |Turn|Label |Remark |\n");
fprintf(OutReviewFile, " Num|Deg Min |Deg Min | (m)|Etiquette|Remarque|\n");
#endif
for(l=0L;l<Header.NbWayPoint;l++)
{
fprintf(OutReviewFile,"%4ld|%s|%s|%4d|%s|%s\n",\
l,\
Wpt[l]->Latitude,\
Wpt[l]->Longitude,\
Wpt[l]->Turn,\
Wpt[l]->Label,\
Wpt[l]->Remark
);
}
#ifdef EN
fprintf(OutReviewFile,"Legs\nDeviat|Speed|StartL|EndLeg| Safety|Label|\n");
fprintf(OutReviewFile," (m)| kN|LineWp|LineWp| Code| |\n");
#endif
#ifdef FR
fprintf(OutReviewFile,"Traits\nDeviat|Speed|DebTr.|FinTr.| Safety|Label|\n");
fprintf(OutReviewFile," (m)|Noeud|LignWp|LignWp| Code| |\n");
#endif
for(l=0L;l<Header.NbLeg;l++)
{
fprintf(OutReviewFile,"%6ld|%5ld|%6ld|%6ld|Ox%.8lX|%s|\n",\
Lien[l]->Deviation,\
Lien[l]->Speed,\
Lien[l]->StartLegOnWpt,\
Lien[l]->EndLegOnWpt,\
Lien[l]->Safety,\
Lien[l]->Label\
);
}
fclose(OutReviewFile);
}
return (Iret);
}
#ifdef TESTS_U /*T pour DOS uniquement ou QWIN */
int main(int argc, char *argv[]) /*T*/
{ /*T*/
int Iret; /*T*/
printf("VERSION_CmapGpsu: %s\n",VERSION_CmapGpsu); /*T*/
printf("TEST UNITAIRE du module \'CmapGpsu\'\n"); /*T*/
Iret=CmapGpsu(argc, argv); /*T*/
printf("FIN DU TEST UNITAIRE du module \'CmapGpsu\'\n"); /*T*/
return 0; /*T*/
} /*T*/
#endif /*T*/

