Programme carte strategie (disco)

Dependencies:   mbed SerialHalfDuplex SDFileSystem DISCO-F469NI_portrait liaison_Bluetooth ident_crac

Committer:
Sitkah
Date:
Thu Apr 26 20:14:18 2018 +0000
Revision:
34:6aa4b46b102e
Parent:
29:41e02746041d
Child:
38:76f886a1c8e6
Ne pas tenir compte si besoin du code 2017

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