command.c (2134B)
1 #include "command.h" 2 3 void command_init(Command* command) { 4 command->code.is_set = false; 5 command->param_s.is_set = false; 6 command->param_x.is_set = false; 7 command->param_y.is_set = false; 8 command->param_z.is_set = false; 9 command->param_e.is_set = false; 10 command->param_f.is_set = false; 11 } 12 13 CommandStatus command_process_token(Command* command, const Token* token) { 14 switch (token->type) { 15 case TOKEN_M_CODE: { 16 if (command->code.is_set) { 17 return COMMAND_STATUS__READY; 18 } 19 command->code.is_set = true; 20 command->code.type = CODE_M; 21 command->code.value = token->value.code_value; 22 break; 23 } 24 case TOKEN_G_CODE: { 25 if (command->code.is_set) { 26 return COMMAND_STATUS__READY; 27 } 28 command->code.is_set = true; 29 command->code.type = CODE_G; 30 command->code.value = token->value.code_value; 31 break; 32 } 33 case TOKEN_S_PARAM: { 34 command->param_s.is_set = true; 35 command->param_s.value = token->value.param_value; 36 break; 37 } 38 case TOKEN_X_PARAM: { 39 command->param_x.is_set = true; 40 command->param_x.value = token->value.param_value; 41 break; 42 } 43 case TOKEN_Y_PARAM: { 44 command->param_y.is_set = true; 45 command->param_y.value = token->value.param_value; 46 break; 47 } 48 case TOKEN_Z_PARAM: { 49 command->param_z.is_set = true; 50 command->param_z.value = token->value.param_value; 51 break; 52 } 53 case TOKEN_E_PARAM: { 54 command->param_e.is_set = true; 55 command->param_e.value = token->value.param_value; 56 break; 57 } 58 case TOKEN_F_PARAM: { 59 command->param_f.is_set = true; 60 command->param_f.value = token->value.param_value; 61 break; 62 } 63 default: 64 return COMMAND_STATUS__UNRECOGNIZED_TOKEN; 65 } 66 return COMMAND_STATUS__NOT_READY; 67 }