carte_strategie_2019

Dependencies:   mbed SerialHalfDuplex SDFileSystem DISCO-F469NI_portrait liaison_Bluetooth ident_crac

Committer:
antbig
Date:
Wed Apr 13 22:04:54 2016 +0000
Revision:
0:ad97421fb1fb
Child:
1:116040d14164
Ajout interruption fin de match

Who changed what in which revision?

UserRevisionLine numberNew contents of line
antbig 0:ad97421fb1fb 1 #include "Instruction.h"
antbig 0:ad97421fb1fb 2
antbig 0:ad97421fb1fb 3
antbig 0:ad97421fb1fb 4 char cheminFileStart[SIZE+8]="/local/";
antbig 0:ad97421fb1fb 5 struct S_Instruction strat_instructions[SIZE_BUFFER_FILE];//Liste des instructions
antbig 0:ad97421fb1fb 6 unsigned char nb_instructions = 0;//Le nombre d'instruction dans le fichier de strategie
antbig 0:ad97421fb1fb 7 unsigned char actual_instruction = 0;//La ligne de l'instruction en cours d'execution
antbig 0:ad97421fb1fb 8
antbig 0:ad97421fb1fb 9 LocalFileSystem local("local");
antbig 0:ad97421fb1fb 10
antbig 0:ad97421fb1fb 11 enum E_InstructionType charToInstructionType(char type)
antbig 0:ad97421fb1fb 12 {
antbig 0:ad97421fb1fb 13 switch(type)
antbig 0:ad97421fb1fb 14 {
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;
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 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;
antbig 0:ad97421fb1fb 44 default: return NOPRECISION;
antbig 0:ad97421fb1fb 45 }
antbig 0:ad97421fb1fb 46 }
antbig 0:ad97421fb1fb 47
antbig 0:ad97421fb1fb 48 enum E_InstructionNextActionType charToInstructionNextActionType(char type)
antbig 0:ad97421fb1fb 49 {
antbig 0:ad97421fb1fb 50 switch(type)
antbig 0:ad97421fb1fb 51 {
antbig 0:ad97421fb1fb 52 case 'J': return JUMP;
antbig 0:ad97421fb1fb 53 case 'W': return WAIT;
antbig 0:ad97421fb1fb 54 case 'E': return ENCHAINEMENT;
antbig 0:ad97421fb1fb 55 default: return NONEXTACTION;
antbig 0:ad97421fb1fb 56 }
antbig 0:ad97421fb1fb 57 }
antbig 0:ad97421fb1fb 58
antbig 0:ad97421fb1fb 59 enum E_InstructionNextActionJumpType charToInstructionNextActionJumpType(char type)
antbig 0:ad97421fb1fb 60 {
antbig 0:ad97421fb1fb 61 switch(type)
antbig 0:ad97421fb1fb 62 {
antbig 0:ad97421fb1fb 63 case 'T': return JUMP_TIME;
antbig 0:ad97421fb1fb 64 case 'P': return JUMP_POSITION;
antbig 0:ad97421fb1fb 65 default: return NONEXTACTIONJUMPTYPE;
antbig 0:ad97421fb1fb 66 }
antbig 0:ad97421fb1fb 67 }
antbig 0:ad97421fb1fb 68
antbig 0:ad97421fb1fb 69
antbig 0:ad97421fb1fb 70 struct S_Instruction stringToInstruction(char line[]) {
antbig 0:ad97421fb1fb 71 struct S_Instruction instruction;
antbig 0:ad97421fb1fb 72
antbig 0:ad97421fb1fb 73 char instructionOrder;
antbig 0:ad97421fb1fb 74 char instructionDirection;
antbig 0:ad97421fb1fb 75 char instructionPrecision;
antbig 0:ad97421fb1fb 76 char instructionNextActionType;
antbig 0:ad97421fb1fb 77 char instructionJumpAction;
antbig 0:ad97421fb1fb 78
antbig 0:ad97421fb1fb 79 /*
antbig 0:ad97421fb1fb 80 Info sur la fonction sscanf
antbig 0:ad97421fb1fb 81 %d -> Entier signé
antbig 0:ad97421fb1fb 82 %u -> Entié non signé
antbig 0:ad97421fb1fb 83 %c -> char
antbig 0:ad97421fb1fb 84 */
antbig 0:ad97421fb1fb 85 sscanf(line, "%d,%c,%c,%u,%u,%d,%c,%c,%c,%u,%u,%d,%d",
antbig 0:ad97421fb1fb 86 &instruction.lineNumber,
antbig 0:ad97421fb1fb 87 &instructionOrder,
antbig 0:ad97421fb1fb 88 &instructionDirection,
antbig 0:ad97421fb1fb 89 &instruction.arg1,
antbig 0:ad97421fb1fb 90 &instruction.arg2,
antbig 0:ad97421fb1fb 91 &instruction.arg3,
antbig 0:ad97421fb1fb 92 &instructionPrecision,
antbig 0:ad97421fb1fb 93 &instructionNextActionType,
antbig 0:ad97421fb1fb 94 &instructionJumpAction,
antbig 0:ad97421fb1fb 95 &instruction.JumpTimeOrX,
antbig 0:ad97421fb1fb 96 &instruction.JumpY,
antbig 0:ad97421fb1fb 97 &instruction.nextLineOK,
antbig 0:ad97421fb1fb 98 &instruction.nextLineError
antbig 0:ad97421fb1fb 99 );
antbig 0:ad97421fb1fb 100
antbig 0:ad97421fb1fb 101 instruction.order = charToInstructionType(instructionOrder);
antbig 0:ad97421fb1fb 102 instruction.direction = charToInstructionDirection(instructionDirection);
antbig 0:ad97421fb1fb 103 instruction.precision = charToInstructionPrecisionOuRecalage(instructionPrecision);
antbig 0:ad97421fb1fb 104 instruction.nextActionType = charToInstructionNextActionType(instructionNextActionType);
antbig 0:ad97421fb1fb 105 instruction.jumpAction = charToInstructionNextActionJumpType(instructionJumpAction);
antbig 0:ad97421fb1fb 106
antbig 0:ad97421fb1fb 107
antbig 0:ad97421fb1fb 108 return instruction;
antbig 0:ad97421fb1fb 109 }
antbig 0:ad97421fb1fb 110
antbig 0:ad97421fb1fb 111 void loadAllInstruction(void) {
antbig 0:ad97421fb1fb 112
antbig 0:ad97421fb1fb 113 struct S_Instruction instruction;
antbig 0:ad97421fb1fb 114 char LineBuffer[SIZE];
antbig 0:ad97421fb1fb 115 printf("Reading file : ");
antbig 0:ad97421fb1fb 116 printf(cheminFileStart);
antbig 0:ad97421fb1fb 117 printf("\n");
antbig 0:ad97421fb1fb 118 FILE *testFile = fopen(cheminFileStart, "rt"); //Ouverture du fichier en mode lecture seul au format string
antbig 0:ad97421fb1fb 119
antbig 0:ad97421fb1fb 120 nb_instructions = 0;
antbig 0:ad97421fb1fb 121 while (fgets(LineBuffer, SIZE, testFile) != NULL) {
antbig 0:ad97421fb1fb 122 instruction = stringToInstruction(LineBuffer);
antbig 0:ad97421fb1fb 123 strat_instructions[nb_instructions] = instruction;
antbig 0:ad97421fb1fb 124 //printf(LineBuffer);
antbig 0:ad97421fb1fb 125 //debug_Instruction(instruction);
antbig 0:ad97421fb1fb 126 nb_instructions++;
antbig 0:ad97421fb1fb 127 }
antbig 0:ad97421fb1fb 128 printf("nb instruction = %d\n",nb_instructions);
antbig 0:ad97421fb1fb 129 fclose(testFile);
antbig 0:ad97421fb1fb 130
antbig 0:ad97421fb1fb 131 }