Programme carte strategie (disco)
Dependencies: mbed SerialHalfDuplex SDFileSystem DISCO-F469NI_portrait liaison_Bluetooth ident_crac
Diff: Instruction/Instruction.cpp
- Revision:
- 0:ad97421fb1fb
- Child:
- 1:116040d14164
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Instruction/Instruction.cpp Wed Apr 13 22:04:54 2016 +0000 @@ -0,0 +1,131 @@ +#include "Instruction.h" + + +char cheminFileStart[SIZE+8]="/local/"; +struct S_Instruction strat_instructions[SIZE_BUFFER_FILE];//Liste des instructions +unsigned char nb_instructions = 0;//Le nombre d'instruction dans le fichier de strategie +unsigned char actual_instruction = 0;//La ligne de l'instruction en cours d'execution + +LocalFileSystem local("local"); + +enum E_InstructionType charToInstructionType(char type) +{ + switch(type) + { + case 'C': return MV_COURBURE; + case 'L': return MV_LINE; + case 'T': return MV_TURN; + case 'X': return MV_XYT; + case 'R': return MV_RECALAGE; + case 'A': return ACTION; + default: return UNKNOWN; + } +} + +enum E_InstructionDirection charToInstructionDirection(char type) +{ + switch(type) + { + case 'B': return BACKWARD; + case 'F': return FORWARD; + case 'R': return RELATIVE; + case 'A': return ABSOLUTE; + default: return NODIRECTION; + } +} + +enum E_InstructionPrecisionOuRecalage charToInstructionPrecisionOuRecalage(char type) +{ + switch(type) + { + case 'P': return PRECISION; + case 'X': return RECALAGE_X; + case 'Y': return RECALAGE_Y; + default: return NOPRECISION; + } +} + +enum E_InstructionNextActionType charToInstructionNextActionType(char type) +{ + switch(type) + { + case 'J': return JUMP; + case 'W': return WAIT; + case 'E': return ENCHAINEMENT; + default: return NONEXTACTION; + } +} + +enum E_InstructionNextActionJumpType charToInstructionNextActionJumpType(char type) +{ + switch(type) + { + case 'T': return JUMP_TIME; + case 'P': return JUMP_POSITION; + default: return NONEXTACTIONJUMPTYPE; + } +} + + +struct S_Instruction stringToInstruction(char line[]) { + struct S_Instruction instruction; + + char instructionOrder; + char instructionDirection; + char instructionPrecision; + char instructionNextActionType; + char instructionJumpAction; + + /* + Info sur la fonction sscanf + %d -> Entier signé + %u -> Entié non signé + %c -> char + */ + sscanf(line, "%d,%c,%c,%u,%u,%d,%c,%c,%c,%u,%u,%d,%d", + &instruction.lineNumber, + &instructionOrder, + &instructionDirection, + &instruction.arg1, + &instruction.arg2, + &instruction.arg3, + &instructionPrecision, + &instructionNextActionType, + &instructionJumpAction, + &instruction.JumpTimeOrX, + &instruction.JumpY, + &instruction.nextLineOK, + &instruction.nextLineError + ); + + instruction.order = charToInstructionType(instructionOrder); + instruction.direction = charToInstructionDirection(instructionDirection); + instruction.precision = charToInstructionPrecisionOuRecalage(instructionPrecision); + instruction.nextActionType = charToInstructionNextActionType(instructionNextActionType); + instruction.jumpAction = charToInstructionNextActionJumpType(instructionJumpAction); + + + return instruction; +} + +void loadAllInstruction(void) { + + struct S_Instruction instruction; + char LineBuffer[SIZE]; + printf("Reading file : "); + printf(cheminFileStart); + printf("\n"); + FILE *testFile = fopen(cheminFileStart, "rt"); //Ouverture du fichier en mode lecture seul au format string + + nb_instructions = 0; + while (fgets(LineBuffer, SIZE, testFile) != NULL) { + instruction = stringToInstruction(LineBuffer); + strat_instructions[nb_instructions] = instruction; + //printf(LineBuffer); + //debug_Instruction(instruction); + nb_instructions++; + } + printf("nb instruction = %d\n",nb_instructions); + fclose(testFile); + +}