u16 LCD_GetPoint(u16 x,u16 y)//读取某像素点的颜色值 { u16 pixel=0; Set_Addr(x,y); LCD_Read(); DelayN(2); pixel=LCD_Read(); return pixel; }
*/ DEVICE_CMD Listen_Socket(REBREQ *sock) /* ** Setup a server (listening) socket (TCP or UDP). ** ** Before usage: ** Open_Socket(); ** Set local_port to desired port number. ** ** Use this instead of Connect_Socket(). ** ***********************************************************************/ { int result; int len = 1; SOCKAI sa; // Setup socket address range and port: Set_Addr(&sa, INADDR_ANY, sock->net.local_port); // Allow listen socket reuse: result = setsockopt(sock->socket, SOL_SOCKET, SO_REUSEADDR, (char*)(&len), sizeof(len)); if (result) { lserr: sock->error = GET_ERROR; return DR_ERROR; } // Bind the socket to our local address: result = bind(sock->socket, (struct sockaddr *)&sa, sizeof(sa)); if (result) goto lserr; SET_FLAG(sock->state, RSM_BIND); // For TCP connections, setup listen queue: if (!GET_FLAG(sock->modes, RST_UDP)) { result = listen(sock->socket, SOMAXCONN); if (result) goto lserr; SET_FLAG(sock->state, RSM_LISTEN); } Get_Local_IP(sock); sock->command = RDC_CREATE; // the command done on wakeup return DR_PEND; }
void LCD_SetPoint(u16 x,u16 y,u8 color)//以指定的颜色填充某一像素点 { Set_Addr(x,y); Write_DAT(colors[color]); }
*/ DEVICE_CMD Connect_Socket(REBREQ *sock) /* ** Connect a socket to a service. ** Only required for connection-based protocols (e.g. not UDP). ** The IP address must already be resolved before calling. ** ** This function is asynchronous. It will return immediately. ** You can call this function again to check the pending connection. ** ** The function will return: ** =0: connection succeeded (or already is connected) ** >0: in-progress, still trying ** <0: error occurred, no longer trying ** ** Before usage: ** Open_Socket() -- to allocate the socket ** ***********************************************************************/ { int result; SOCKAI sa; if (GET_FLAG(sock->modes, RST_LISTEN)) return Listen_Socket(sock); if (GET_FLAG(sock->state, RSM_CONNECT)) return DR_DONE; // already connected Set_Addr(&sa, sock->net.remote_ip, sock->net.remote_port); result = connect(sock->socket, (struct sockaddr *)&sa, sizeof(sa)); if (result != 0) result = GET_ERROR; WATCH2("connect() error: %d - %s\n", result, strerror(result)); switch (result) { case 0: // no error case NE_ISCONN: // Connected, set state: CLR_FLAG(sock->state, RSM_ATTEMPT); SET_FLAG(sock->state, RSM_CONNECT); Get_Local_IP(sock); Signal_Device(sock, EVT_CONNECT); return DR_DONE; // done #ifdef TO_WIN32 case NE_INVALID: // Corrects for Microsoft bug #endif case NE_WOULDBLOCK: case NE_INPROGRESS: case NE_ALREADY: // Still trying: SET_FLAG(sock->state, RSM_ATTEMPT); return DR_PEND; default: // An error happened: CLR_FLAG(sock->state, RSM_ATTEMPT); sock->error = result; //Signal_Device(sock, EVT_ERROR); return DR_ERROR; } }