carte_strategie_2019

Dependencies:   mbed SerialHalfDuplex SDFileSystem DISCO-F469NI_portrait liaison_Bluetooth ident_crac

Committer:
marwanesaich
Date:
Sun May 26 15:24:59 2019 +0000
Revision:
69:7caf86f53ff8
Parent:
67:96f914f92d2d

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sitkah 29:41e02746041d 1 #include "global.h"
Sitkah 29:41e02746041d 2
antbig 0:ad97421fb1fb 3
Sitkah 29:41e02746041d 4 SDFileSystem sd(PB_15, PB_14,PD_3,PH_6,"sd");
antbig 0:ad97421fb1fb 5
antbig 0:ad97421fb1fb 6 enum E_InstructionType charToInstructionType(char type)
antbig 0:ad97421fb1fb 7 {
antbig 0:ad97421fb1fb 8 switch(type)
antbig 0:ad97421fb1fb 9 {
Artiom 67:96f914f92d2d 10 case 'B': return MV_BEZIER;
antbig 0:ad97421fb1fb 11 case 'C': return MV_COURBURE;
antbig 0:ad97421fb1fb 12 case 'L': return MV_LINE;
antbig 0:ad97421fb1fb 13 case 'T': return MV_TURN;
antbig 0:ad97421fb1fb 14 case 'X': return MV_XYT;
antbig 0:ad97421fb1fb 15 case 'R': return MV_RECALAGE;
antbig 0:ad97421fb1fb 16 case 'A': return ACTION;
Sitkah 38:76f886a1c8e6 17 case 'P': return POSITION_DEBUT;
antbig 0:ad97421fb1fb 18 default: return UNKNOWN;
antbig 0:ad97421fb1fb 19 }
antbig 0:ad97421fb1fb 20 }
antbig 0:ad97421fb1fb 21
antbig 0:ad97421fb1fb 22 enum E_InstructionDirection charToInstructionDirection(char type)
antbig 0:ad97421fb1fb 23 {
antbig 0:ad97421fb1fb 24 switch(type)
antbig 0:ad97421fb1fb 25 {
antbig 0:ad97421fb1fb 26 case 'B': return BACKWARD;
antbig 0:ad97421fb1fb 27 case 'F': return FORWARD;
antbig 0:ad97421fb1fb 28 case 'R': return RELATIVE;
antbig 0:ad97421fb1fb 29 case 'A': return ABSOLUTE;
antbig 11:ed13a480ddca 30 case 'L': return LEFT;
antbig 0:ad97421fb1fb 31 default: return NODIRECTION;
antbig 0:ad97421fb1fb 32 }
antbig 0:ad97421fb1fb 33 }
antbig 0:ad97421fb1fb 34
antbig 0:ad97421fb1fb 35 enum E_InstructionPrecisionOuRecalage charToInstructionPrecisionOuRecalage(char type)
antbig 0:ad97421fb1fb 36 {
antbig 0:ad97421fb1fb 37 switch(type)
antbig 0:ad97421fb1fb 38 {
antbig 0:ad97421fb1fb 39 case 'P': return PRECISION;
antbig 0:ad97421fb1fb 40 case 'X': return RECALAGE_X;
antbig 0:ad97421fb1fb 41 case 'Y': return RECALAGE_Y;
Sitkah 34:6aa4b46b102e 42 case 'T': return RECALAGE_T;
antbig 0:ad97421fb1fb 43 default: return NOPRECISION;
antbig 0:ad97421fb1fb 44 }
antbig 0:ad97421fb1fb 45 }
antbig 0:ad97421fb1fb 46
antbig 0:ad97421fb1fb 47 enum E_InstructionNextActionType charToInstructionNextActionType(char type)
antbig 0:ad97421fb1fb 48 {
antbig 0:ad97421fb1fb 49 switch(type)
antbig 0:ad97421fb1fb 50 {
antbig 0:ad97421fb1fb 51 case 'J': return JUMP;
antbig 0:ad97421fb1fb 52 case 'W': return WAIT;
antbig 0:ad97421fb1fb 53 case 'E': return ENCHAINEMENT;
Sitkah 34:6aa4b46b102e 54 case 'M': return MECANIQUE;
Sitkah 34:6aa4b46b102e 55 case 'C': return CAPTEUR;
antbig 0:ad97421fb1fb 56 default: return NONEXTACTION;
antbig 0:ad97421fb1fb 57 }
antbig 0:ad97421fb1fb 58 }
antbig 0:ad97421fb1fb 59
antbig 0:ad97421fb1fb 60 enum E_InstructionNextActionJumpType charToInstructionNextActionJumpType(char type)
antbig 0:ad97421fb1fb 61 {
antbig 0:ad97421fb1fb 62 switch(type)
antbig 0:ad97421fb1fb 63 {
antbig 0:ad97421fb1fb 64 case 'T': return JUMP_TIME;
antbig 0:ad97421fb1fb 65 case 'P': return JUMP_POSITION;
antbig 0:ad97421fb1fb 66 default: return NONEXTACTIONJUMPTYPE;
antbig 0:ad97421fb1fb 67 }
antbig 0:ad97421fb1fb 68 }
antbig 0:ad97421fb1fb 69
antbig 4:88431b537477 70 /****************************************************************************************/
antbig 4:88431b537477 71 /* FUNCTION NAME: stringToInstruction */
antbig 4:88431b537477 72 /* DESCRIPTION : Conversion d'une ligne du fichier de strat en instruction */
antbig 4:88431b537477 73 /****************************************************************************************/
antbig 0:ad97421fb1fb 74 struct S_Instruction stringToInstruction(char line[]) {
antbig 0:ad97421fb1fb 75 struct S_Instruction instruction;
antbig 0:ad97421fb1fb 76
antbig 0:ad97421fb1fb 77 char instructionOrder;
antbig 0:ad97421fb1fb 78 char instructionDirection;
antbig 0:ad97421fb1fb 79 char instructionPrecision;
antbig 0:ad97421fb1fb 80 char instructionNextActionType;
antbig 0:ad97421fb1fb 81 char instructionJumpAction;
antbig 1:116040d14164 82 int errorCode = 0;
antbig 0:ad97421fb1fb 83 /*
antbig 0:ad97421fb1fb 84 Info sur la fonction sscanf
antbig 0:ad97421fb1fb 85 %d -> Entier signé
antbig 0:ad97421fb1fb 86 %u -> Entié non signé
antbig 0:ad97421fb1fb 87 %c -> char
antbig 0:ad97421fb1fb 88 */
Artiom 67:96f914f92d2d 89 errorCode = sscanf(line, "%d,%c,%c,%u,%u,%d,%c,%c,%c,%u,%u,%d,%d,%u,%u,%d",
antbig 0:ad97421fb1fb 90 &instruction.lineNumber,
antbig 0:ad97421fb1fb 91 &instructionOrder,
antbig 0:ad97421fb1fb 92 &instructionDirection,
antbig 0:ad97421fb1fb 93 &instruction.arg1,
antbig 0:ad97421fb1fb 94 &instruction.arg2,
antbig 0:ad97421fb1fb 95 &instruction.arg3,
antbig 0:ad97421fb1fb 96 &instructionPrecision,
antbig 0:ad97421fb1fb 97 &instructionNextActionType,
antbig 0:ad97421fb1fb 98 &instructionJumpAction,
antbig 0:ad97421fb1fb 99 &instruction.JumpTimeOrX,
antbig 0:ad97421fb1fb 100 &instruction.JumpY,
antbig 0:ad97421fb1fb 101 &instruction.nextLineOK,
Artiom 67:96f914f92d2d 102 &instruction.nextLineError,
Artiom 67:96f914f92d2d 103 &instruction.arg4,
Artiom 67:96f914f92d2d 104 &instruction.arg5,
Artiom 67:96f914f92d2d 105 &instruction.arg6
antbig 0:ad97421fb1fb 106 );
antbig 1:116040d14164 107 /*
antbig 1:116040d14164 108 if(errorCode != 13) {
antbig 1:116040d14164 109 errorInstructionLoop();//L'instruction est pas bonne !!
antbig 1:116040d14164 110 }*/
antbig 0:ad97421fb1fb 111
antbig 0:ad97421fb1fb 112 instruction.order = charToInstructionType(instructionOrder);
antbig 0:ad97421fb1fb 113 instruction.direction = charToInstructionDirection(instructionDirection);
antbig 0:ad97421fb1fb 114 instruction.precision = charToInstructionPrecisionOuRecalage(instructionPrecision);
antbig 0:ad97421fb1fb 115 instruction.nextActionType = charToInstructionNextActionType(instructionNextActionType);
antbig 0:ad97421fb1fb 116 instruction.jumpAction = charToInstructionNextActionJumpType(instructionJumpAction);
antbig 0:ad97421fb1fb 117
antbig 0:ad97421fb1fb 118
antbig 0:ad97421fb1fb 119 return instruction;
antbig 0:ad97421fb1fb 120 }
antbig 0:ad97421fb1fb 121
antbig 4:88431b537477 122 /****************************************************************************************/
antbig 4:88431b537477 123 /* FUNCTION NAME: loadAllInstruction */
antbig 4:88431b537477 124 /* DESCRIPTION : Charger toutes les instructions du fichier de stratégie */
antbig 4:88431b537477 125 /* Il faut utiliser strcpy(cheminFileStart,"/local/strat.txt"); */
antbig 4:88431b537477 126 /* pour indiquer le fichier à utiliser */
antbig 4:88431b537477 127 /****************************************************************************************/
Sitkah 29:41e02746041d 128 void loadAllInstruction( signed char Strategie) {
antbig 0:ad97421fb1fb 129
antbig 0:ad97421fb1fb 130 struct S_Instruction instruction;
antbig 0:ad97421fb1fb 131 char LineBuffer[SIZE];
antbig 0:ad97421fb1fb 132 printf("Reading file : ");
Sitkah 29:41e02746041d 133 printf(strat_sd[Strategie]);
antbig 0:ad97421fb1fb 134 printf("\n");
Sitkah 29:41e02746041d 135 strcpy(PATH[Strategie],"/sd/");
Sitkah 29:41e02746041d 136 strcat(PATH[Strategie],strat_sd[Strategie]);
Sitkah 29:41e02746041d 137 strcat(PATH[Strategie],".txt");
Sitkah 29:41e02746041d 138 FILE *testFile = fopen(PATH[Strategie], "rt"); //Ouverture du fichier en mode lecture seul au format string
antbig 0:ad97421fb1fb 139
antbig 0:ad97421fb1fb 140 nb_instructions = 0;
antbig 0:ad97421fb1fb 141 while (fgets(LineBuffer, SIZE, testFile) != NULL) {
antbig 0:ad97421fb1fb 142 instruction = stringToInstruction(LineBuffer);
antbig 0:ad97421fb1fb 143 strat_instructions[nb_instructions] = instruction;
antbig 1:116040d14164 144 if(strat_instructions[nb_instructions].order == UNKNOWN) {
Sitkah 29:41e02746041d 145 Button STRAT_1 (0, 30, 190, 110, PATH[Strategie]);
Sitkah 29:41e02746041d 146 STRAT_1.Draw(0xFFF0F0F0, 0);
antbig 1:116040d14164 147 errorInstructionLoop();//L'instruction est pas bonne !!
antbig 1:116040d14164 148 }
antbig 0:ad97421fb1fb 149 //printf(LineBuffer);
antbig 0:ad97421fb1fb 150 //debug_Instruction(instruction);
antbig 0:ad97421fb1fb 151 nb_instructions++;
antbig 0:ad97421fb1fb 152 }
antbig 0:ad97421fb1fb 153 printf("nb instruction = %d\n",nb_instructions);
antbig 0:ad97421fb1fb 154 fclose(testFile);
antbig 0:ad97421fb1fb 155
antbig 0:ad97421fb1fb 156 }
antbig 4:88431b537477 157
antbig 4:88431b537477 158 /****************************************************************************************/
antbig 4:88431b537477 159 /* FUNCTION NAME: FileExists */
antbig 4:88431b537477 160 /* DESCRIPTION : Permet de vérifier si un fichier existe */
antbig 4:88431b537477 161 /****************************************************************************************/
antbig 4:88431b537477 162 int FileExists(const char *fname)
antbig 4:88431b537477 163 {
antbig 4:88431b537477 164 FILE *file;
Sitkah 29:41e02746041d 165 if (file == fopen(fname, "r"))
antbig 4:88431b537477 166 {
antbig 4:88431b537477 167 fclose(file);
antbig 4:88431b537477 168 return 1;
antbig 4:88431b537477 169 }
antbig 4:88431b537477 170 return 0;
antbig 4:88431b537477 171 }