/* handle_message - 处理每个 socket 上的消息收发 */ int handle_message(int new_fd) { char buf[MAXBUF + 1]; int len; // while(1){ /* 开始处理每个新连接上的数据收发 */ bzero(buf, MAXBUF + 1); /* 接收客户端的消息 */ len = recv(new_fd, buf, MAXBUF, 0); buf[len] = 0; if (len > 0) { printf("%d接收消息成功,共%d个字节的数据\n", new_fd, len); CHashUserData userData; PkgInfo inputPkg; PkgInfo outputPkg; memcpy(&inputPkg, buf, sizeof (inputPkg)); printf("-------%d----------\n",new_fd); //cmdTest if (inputPkg.id == 1) { cmdLogin(inputPkg, outputPkg); } else if(inputPkg.id == 6){ cmdUserQuery(inputPkg,outputPkg); } else if (inputPkg.id == 15) { cmdTest(inputPkg, outputPkg); } else if (inputPkg.id == 13) { cmdLogout(inputPkg, outputPkg); } else if (inputPkg.id == 5) { cmdGameQuery(inputPkg, outputPkg); } else if (inputPkg.id == 12) { cmdQueryUserList(inputPkg, outputPkg); } else if(inputPkg.id == 2){ cmdGameCreate(inputPkg, outputPkg); }else if(inputPkg.id == 11){ cmdQueryGameList(inputPkg,outputPkg); }else if(inputPkg.id == 3){ cmdGameJoin(inputPkg,outputPkg); }else if(inputPkg.id == 4){ cmdGamePlayHand(inputPkg,outputPkg); }else { printf("cmd unknow\n"); } if (send(new_fd, (char *) &outputPkg, sizeof (outputPkg), 0) == -1) { fprintf(stderr, "Write Error:%s\n", strerror(errno)); //exit(1); } } else { if (len < 0){ printf("消息接收失败!错误代码是%d,错误信息是'%s',len:%d\n",errno, strerror(errno),len); } } // } //close(new_fd); /* 处理每个新连接上的数据收发结束 */ return len; }
u8 usbListener() { volatile u16 resp; volatile u8 cmd; usb_buff8 = (u8 *) usb_buff; if (evd_fifoRxf())return 0; resp = evd_fifoRd(usb_buff, 1); if (resp != 0) return 1; if (usb_buff8[0] != 'C' || usb_buff8[1] != 'M' || usb_buff8[2] != 'D')return 2; cmd = usb_buff8[3]; switch (cmd) { case 'R': resp = cmdReadRom(); if (resp)return 10; break; case 'W': resp = cmdWriteRom(); if (resp)return 11; break; case 'T': resp = cmdTest(); if (resp)return 12; break; case 'F': resp = cmdFill(); if (resp)return 13; break; case 'S': //IO_WRITE(PI_BSD_DOM1_PGS_REG, 0x0c); //IO_WRITE(PI_BSD_DOM1_PGS_REG, 0x80); //evdSetESaveType(SAVE_TYPE_EEP16k); system_cic = CIC_6102; evd_lockRegs(); IO_WRITE(PI_STATUS_REG, 3); sleep(2); pif_boot(); break; } return 0; }