homologation gros robot et test avec les ack de la carte a tout faire
Fork of CRAC-Strat_2017_HOMOLOGATION_PETIT_ROBOT by
Instruction.cpp
00001 #include "Instruction.h" 00002 00003 00004 char cheminFileStart[SIZE+8]="/local/"; 00005 struct S_Instruction strat_instructions[SIZE_BUFFER_FILE];//Liste des instructions 00006 unsigned char nb_instructions = 0;//Le nombre d'instruction dans le fichier de strategie 00007 unsigned char actual_instruction = 0;//La ligne de l'instruction en cours d'execution 00008 00009 LocalFileSystem local("local"); 00010 00011 enum E_InstructionType charToInstructionType(char type) 00012 { 00013 switch(type) 00014 { 00015 case 'C': return MV_COURBURE; 00016 case 'L': return MV_LINE; 00017 case 'T': return MV_TURN; 00018 case 'X': return MV_XYT; 00019 case 'R': return MV_RECALAGE; 00020 case 'A': return ACTION; 00021 default: return UNKNOWN; 00022 } 00023 } 00024 00025 enum E_InstructionDirection charToInstructionDirection(char type) 00026 { 00027 switch(type) 00028 { 00029 case 'B': return BACKWARD; 00030 case 'F': return FORWARD; 00031 case 'R': return RELATIVE; 00032 case 'A': return ABSOLUTE; 00033 case 'L': return LEFT; 00034 default: return NODIRECTION; 00035 } 00036 } 00037 00038 enum E_InstructionPrecisionOuRecalage charToInstructionPrecisionOuRecalage(char type) 00039 { 00040 switch(type) 00041 { 00042 case 'P': return PRECISION; 00043 case 'X': return RECALAGE_X; 00044 case 'Y': return RECALAGE_Y; 00045 default: return NOPRECISION; 00046 } 00047 } 00048 00049 enum E_InstructionNextActionType charToInstructionNextActionType(char type) 00050 { 00051 switch(type) 00052 { 00053 case 'J': return JUMP; 00054 case 'W': return WAIT; 00055 case 'E': return ENCHAINEMENT; 00056 default: return NONEXTACTION; 00057 } 00058 } 00059 00060 enum E_InstructionNextActionJumpType charToInstructionNextActionJumpType(char type) 00061 { 00062 switch(type) 00063 { 00064 case 'T': return JUMP_TIME; 00065 case 'P': return JUMP_POSITION; 00066 default: return NONEXTACTIONJUMPTYPE; 00067 } 00068 } 00069 00070 /****************************************************************************************/ 00071 /* FUNCTION NAME: stringToInstruction */ 00072 /* DESCRIPTION : Conversion d'une ligne du fichier de strat en instruction */ 00073 /****************************************************************************************/ 00074 struct S_Instruction stringToInstruction(char line[]) { 00075 struct S_Instruction instruction; 00076 00077 char instructionOrder; 00078 char instructionDirection; 00079 char instructionPrecision; 00080 char instructionNextActionType; 00081 char instructionJumpAction; 00082 int errorCode = 0; 00083 /* 00084 Info sur la fonction sscanf 00085 %d -> Entier signé 00086 %u -> Entié non signé 00087 %c -> char 00088 */ 00089 errorCode = sscanf(line, "%d,%c,%c,%u,%u,%d,%c,%c,%c,%u,%u,%d,%d", 00090 &instruction.lineNumber, 00091 &instructionOrder, 00092 &instructionDirection, 00093 &instruction.arg1, 00094 &instruction.arg2, 00095 &instruction.arg3, 00096 &instructionPrecision, 00097 &instructionNextActionType, 00098 &instructionJumpAction, 00099 &instruction.JumpTimeOrX, 00100 &instruction.JumpY, 00101 &instruction.nextLineOK, 00102 &instruction.nextLineError 00103 ); 00104 /* 00105 if(errorCode != 13) { 00106 errorInstructionLoop();//L'instruction est pas bonne !! 00107 }*/ 00108 00109 instruction.order = charToInstructionType(instructionOrder); 00110 instruction.direction = charToInstructionDirection(instructionDirection); 00111 instruction.precision = charToInstructionPrecisionOuRecalage(instructionPrecision); 00112 instruction.nextActionType = charToInstructionNextActionType(instructionNextActionType); 00113 instruction.jumpAction = charToInstructionNextActionJumpType(instructionJumpAction); 00114 00115 00116 return instruction; 00117 } 00118 00119 /****************************************************************************************/ 00120 /* FUNCTION NAME: loadAllInstruction */ 00121 /* DESCRIPTION : Charger toutes les instructions du fichier de stratégie */ 00122 /* Il faut utiliser strcpy(cheminFileStart,"/local/strat.txt"); */ 00123 /* pour indiquer le fichier à utiliser */ 00124 /****************************************************************************************/ 00125 void loadAllInstruction(void) { 00126 00127 struct S_Instruction instruction; 00128 char LineBuffer[SIZE]; 00129 printf("Reading file : "); 00130 printf(cheminFileStart); 00131 printf("\n"); 00132 FILE *testFile = fopen(cheminFileStart, "rt"); //Ouverture du fichier en mode lecture seul au format string 00133 00134 nb_instructions = 0; 00135 while (fgets(LineBuffer, SIZE, testFile) != NULL) { 00136 instruction = stringToInstruction(LineBuffer); 00137 strat_instructions[nb_instructions] = instruction; 00138 if(strat_instructions[nb_instructions].order == UNKNOWN) { 00139 errorInstructionLoop();//L'instruction est pas bonne !! 00140 } 00141 //printf(LineBuffer); 00142 //debug_Instruction(instruction); 00143 nb_instructions++; 00144 } 00145 printf("nb instruction = %d\n",nb_instructions); 00146 fclose(testFile); 00147 00148 } 00149 00150 /****************************************************************************************/ 00151 /* FUNCTION NAME: FileExists */ 00152 /* DESCRIPTION : Permet de vérifier si un fichier existe */ 00153 /****************************************************************************************/ 00154 int FileExists(const char *fname) 00155 { 00156 FILE *file; 00157 if (file = fopen(fname, "r")) 00158 { 00159 fclose(file); 00160 return 1; 00161 } 00162 return 0; 00163 }
Generated on Wed Jul 13 2022 01:53:39 by 1.7.2