carte_strategie_2019

Dependencies:   mbed SerialHalfDuplex SDFileSystem DISCO-F469NI_portrait liaison_Bluetooth ident_crac

Committer:
kyxstark
Date:
Sat Jun 01 02:50:52 2019 +0000
Revision:
91:42ae63e5daf5
Parent:
67:96f914f92d2d
Child:
69:7caf86f53ff8
reprise erreur asserv correction bug;

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