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