carte_strategie_2019
Dependencies: mbed SerialHalfDuplex SDFileSystem DISCO-F469NI_portrait liaison_Bluetooth ident_crac
Instruction/Instruction.cpp@38:76f886a1c8e6, 2018-05-09 (annotated)
- Committer:
- Sitkah
- Date:
- Wed May 09 19:36:20 2018 +0000
- Revision:
- 38:76f886a1c8e6
- Parent:
- 34:6aa4b46b102e
- Child:
- 67:96f914f92d2d
test avant match
Who changed what in which revision?
User | Revision | Line number | New 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; |
Sitkah | 38:76f886a1c8e6 | 20 | case 'P': return POSITION_DEBUT; |
antbig | 0:ad97421fb1fb | 21 | default: return UNKNOWN; |
antbig | 0:ad97421fb1fb | 22 | } |
antbig | 0:ad97421fb1fb | 23 | } |
antbig | 0:ad97421fb1fb | 24 | |
antbig | 0:ad97421fb1fb | 25 | enum E_InstructionDirection charToInstructionDirection(char type) |
antbig | 0:ad97421fb1fb | 26 | { |
antbig | 0:ad97421fb1fb | 27 | switch(type) |
antbig | 0:ad97421fb1fb | 28 | { |
antbig | 0:ad97421fb1fb | 29 | case 'B': return BACKWARD; |
antbig | 0:ad97421fb1fb | 30 | case 'F': return FORWARD; |
antbig | 0:ad97421fb1fb | 31 | case 'R': return RELATIVE; |
antbig | 0:ad97421fb1fb | 32 | case 'A': return ABSOLUTE; |
antbig | 11:ed13a480ddca | 33 | case 'L': return LEFT; |
antbig | 0:ad97421fb1fb | 34 | default: return NODIRECTION; |
antbig | 0:ad97421fb1fb | 35 | } |
antbig | 0:ad97421fb1fb | 36 | } |
antbig | 0:ad97421fb1fb | 37 | |
antbig | 0:ad97421fb1fb | 38 | enum E_InstructionPrecisionOuRecalage charToInstructionPrecisionOuRecalage(char type) |
antbig | 0:ad97421fb1fb | 39 | { |
antbig | 0:ad97421fb1fb | 40 | switch(type) |
antbig | 0:ad97421fb1fb | 41 | { |
antbig | 0:ad97421fb1fb | 42 | case 'P': return PRECISION; |
antbig | 0:ad97421fb1fb | 43 | case 'X': return RECALAGE_X; |
antbig | 0:ad97421fb1fb | 44 | case 'Y': return RECALAGE_Y; |
Sitkah | 34:6aa4b46b102e | 45 | case 'T': return RECALAGE_T; |
antbig | 0:ad97421fb1fb | 46 | default: return NOPRECISION; |
antbig | 0:ad97421fb1fb | 47 | } |
antbig | 0:ad97421fb1fb | 48 | } |
antbig | 0:ad97421fb1fb | 49 | |
antbig | 0:ad97421fb1fb | 50 | enum E_InstructionNextActionType charToInstructionNextActionType(char type) |
antbig | 0:ad97421fb1fb | 51 | { |
antbig | 0:ad97421fb1fb | 52 | switch(type) |
antbig | 0:ad97421fb1fb | 53 | { |
antbig | 0:ad97421fb1fb | 54 | case 'J': return JUMP; |
antbig | 0:ad97421fb1fb | 55 | case 'W': return WAIT; |
antbig | 0:ad97421fb1fb | 56 | case 'E': return ENCHAINEMENT; |
Sitkah | 34:6aa4b46b102e | 57 | case 'M': return MECANIQUE; |
Sitkah | 34:6aa4b46b102e | 58 | case 'C': return CAPTEUR; |
antbig | 0:ad97421fb1fb | 59 | default: return NONEXTACTION; |
antbig | 0:ad97421fb1fb | 60 | } |
antbig | 0:ad97421fb1fb | 61 | } |
antbig | 0:ad97421fb1fb | 62 | |
antbig | 0:ad97421fb1fb | 63 | enum E_InstructionNextActionJumpType charToInstructionNextActionJumpType(char type) |
antbig | 0:ad97421fb1fb | 64 | { |
antbig | 0:ad97421fb1fb | 65 | switch(type) |
antbig | 0:ad97421fb1fb | 66 | { |
antbig | 0:ad97421fb1fb | 67 | case 'T': return JUMP_TIME; |
antbig | 0:ad97421fb1fb | 68 | case 'P': return JUMP_POSITION; |
antbig | 0:ad97421fb1fb | 69 | default: return NONEXTACTIONJUMPTYPE; |
antbig | 0:ad97421fb1fb | 70 | } |
antbig | 0:ad97421fb1fb | 71 | } |
antbig | 0:ad97421fb1fb | 72 | |
antbig | 4:88431b537477 | 73 | /****************************************************************************************/ |
antbig | 4:88431b537477 | 74 | /* FUNCTION NAME: stringToInstruction */ |
antbig | 4:88431b537477 | 75 | /* DESCRIPTION : Conversion d'une ligne du fichier de strat en instruction */ |
antbig | 4:88431b537477 | 76 | /****************************************************************************************/ |
antbig | 0:ad97421fb1fb | 77 | struct S_Instruction stringToInstruction(char line[]) { |
antbig | 0:ad97421fb1fb | 78 | struct S_Instruction instruction; |
antbig | 0:ad97421fb1fb | 79 | |
antbig | 0:ad97421fb1fb | 80 | char instructionOrder; |
antbig | 0:ad97421fb1fb | 81 | char instructionDirection; |
antbig | 0:ad97421fb1fb | 82 | char instructionPrecision; |
antbig | 0:ad97421fb1fb | 83 | char instructionNextActionType; |
antbig | 0:ad97421fb1fb | 84 | char instructionJumpAction; |
antbig | 1:116040d14164 | 85 | int errorCode = 0; |
antbig | 0:ad97421fb1fb | 86 | /* |
antbig | 0:ad97421fb1fb | 87 | Info sur la fonction sscanf |
antbig | 0:ad97421fb1fb | 88 | %d -> Entier signé |
antbig | 0:ad97421fb1fb | 89 | %u -> Entié non signé |
antbig | 0:ad97421fb1fb | 90 | %c -> char |
antbig | 0:ad97421fb1fb | 91 | */ |
antbig | 1:116040d14164 | 92 | errorCode = sscanf(line, "%d,%c,%c,%u,%u,%d,%c,%c,%c,%u,%u,%d,%d", |
antbig | 0:ad97421fb1fb | 93 | &instruction.lineNumber, |
antbig | 0:ad97421fb1fb | 94 | &instructionOrder, |
antbig | 0:ad97421fb1fb | 95 | &instructionDirection, |
antbig | 0:ad97421fb1fb | 96 | &instruction.arg1, |
antbig | 0:ad97421fb1fb | 97 | &instruction.arg2, |
antbig | 0:ad97421fb1fb | 98 | &instruction.arg3, |
antbig | 0:ad97421fb1fb | 99 | &instructionPrecision, |
antbig | 0:ad97421fb1fb | 100 | &instructionNextActionType, |
antbig | 0:ad97421fb1fb | 101 | &instructionJumpAction, |
antbig | 0:ad97421fb1fb | 102 | &instruction.JumpTimeOrX, |
antbig | 0:ad97421fb1fb | 103 | &instruction.JumpY, |
antbig | 0:ad97421fb1fb | 104 | &instruction.nextLineOK, |
antbig | 0:ad97421fb1fb | 105 | &instruction.nextLineError |
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 | } |