REC Prototype function
Jump to navigation
Jump to search
#include "variables.h" //Function to put in the while true in main void rec_generic_driver (void) { //Every second this send the ids message (Timer1 0.1sec) if (T1_overflow >= 10) { T1_overflow = 0; printf ("IDS\t"ID_DO_HARDWARE"\t%s\r", state); if (strcmp (state, "STOPED") != 0) time_out++; if (time_out >= TIME_OUT) { sprintf (state, "STOPPING"); time_out = 0; } } //When occur a reset do it if (_SWR || _WDTO) { _SWR = 0; _WDTO = 0; sprintf (state, "RESETING"); printf ("FEZ RESET\n\r"); } //If the computer send a command this code see what command was sended if (command_received) { //ids - identification command if (strncmp (RXbuffer, "ids", 3) == 0) { printf ("IDS\t"ID_DO_HARDWARE"\t%s\r", state); } /*cfg - configure command and save the N command (as a string) in the parameters[N][]*/ if (strncmp (RXbuffer, "cfg", 3) == 0) { sscanf (RXbuffer, "%*s\t%d\t%d\t%d\t%d\t%d", &protocolo, ¤t, &angle, &pos_init, &n_samples); cfg_validation (); printf ("CFG\t%d\t%d\t%d\t%d\t%d\r", protocolo, current, angle, pos_init, n_samples); sprintf (state, "CONFIGURING"); } //cur - current configuration command if (strncmp (RXbuffer, "cur", 3) == 0) { printf ("CUR\t%d\t%d\t%d\t%d\t%d\r", protocolo, current, angle, pos_init, n_samples); } //str - start command if (strncmp (RXbuffer, "str", 3) == 0) { sprintf (state, "STARTING"); printf ("STR\r"); } //stp command if (strncmp (RXbuffer, "stp", 3) == 0) { printf ("STP\r"); sprintf (state, "STOPPING"); } if (strncmp (RXbuffer, "rst", 3) == 0) { printf ("RST\r"); __delay_ms (500); //para o pic ter tempo de mandar o comando correctamente asm ("RESET"); } clear_RXbuffer (); command_received = 0; } }