void Modo_Servidor() { string cmd; Conexao c; _Mensagem _msg; Mensagem msg = &_msg; bool encerra = false; try { c = Cria_Conexao (); // Inicializa conexao. } catch (string s_comando) { cout << s_comando; return; } while (!encerra) { char buffer[256]; cmd = ""; Recebe_Msg(c,msg); while (msg->Tipo == TIPO_C) { strncpy(buffer, (char*) msg->dados, msg->Tamanho); // Guarda em 'buffer' buffer[msg->Tamanho] = '\0'; // os dados da msg. (no caso, o comando) cmd = cmd + buffer; Limpa_Dados(msg); Recebe_Msg(c,msg); } Send_Command(cmd, c); } }
void Motion(unsigned char DATA0) { unsigned char CS1; unsigned char CS2; CS1 = (Packet^pID^CMD^DATA0^DATA1) & 0xfe; CS2 = (~(Packet^pID^CMD^DATA0^DATA1)) & 0xfe; Send_Command(CS1, CS2, DATA0); printf("DATA0=%x\n", DATA0); printf("CS1=%x\n", CS1); printf("CS2=%x\n", CS2); DelayLoop(15000000); // 3second delay }
void Init_SSD1306() { for(int i=0;i<22;i++){ Send_Command(0x78,0x00,Sequence[i]); } }
/** Reads the joystick and button status, sending commands to the launcher as needed. */ void Read_Joystick_Status(void) { uint8_t JoyStatus_LCL = Joystick_GetStatus(); uint8_t Buttons_LCL = Buttons_GetStatus(); if (Buttons_LCL & BUTTONS_BUTTON1) Send_Command(CMD_FIRE); else if (JoyStatus_LCL & JOY_UP) Send_Command(CMD_UP); else if (JoyStatus_LCL & JOY_DOWN) Send_Command(CMD_DOWN); else if (JoyStatus_LCL & JOY_LEFT) Send_Command(CMD_LEFT); else if (JoyStatus_LCL & JOY_RIGHT) Send_Command(CMD_RIGHT); else if (CmdState != CMD_STOP) Send_Command(CMD_STOP); }
int main(void) { int Temp_Che; int File_fd; unsigned int n; unsigned char *Buf; SetforI2C(); GPIOInit(); //PB3 = 0; force M4 to Update.when done ,it need to change //PB4 = 0; Rest M4; //PB4 = 1; before this step,need think whether there is a delay(usleep) Program_Size = Get_file_size(File_Path); if(Program_Size == -1) { printf("Get_file_size failed\n"); //need other handle } Buf = (unsigned char *)malloc(Program_Size); Command_Init(); if((File_fd = open(File_Path, O_RDONLY)) < 0 ) { printf("file open failed\n"); } if(read(File_fd, Buf, Program_Size) < 0) { printf("file read failed\n"); } Temp_Che = -1; while(Temp_Che == -1 ) { Temp_Che = Send_Command(command_ping, 1); } Temp_Che = -1; while(Temp_Che == -1) { Temp_Che = Send_Command(command_download, 9); } n = Program_Size / 100; while(n--) { strncpy(command_send_data + 1, Buf, 100); Temp_Che = -1; while(Temp_Che == -1) { Temp_Che = Send_Command(command_send_data, 101); } Buf = Buf + 100; } Temp_Che = -1; strncpy(command_send_data + 1, Buf + n * 100, Program_Size - n * 100); while(Temp_Che == -1) { Temp_Che = Send_Command(command_send_data, (Program_Size - n * 100) + 1); } free(Buf); close(File_fd); return 0; }