void example2_app(void) { struct example2_state *s; s = (struct example2_state *)uip_conn->appstate; if(uip_connected()) { s->state = WELCOME_SENT; uip_send("Welcome!\n", 9); return; } if(uip_acked() && s->state == WELCOME_SENT) { s->state = WELCOME_ACKED; } if(uip_newdata()) { uip_send("ok1\n", 4); led_on(); // while(1); led_off(); } if(uip_rexmit()) { switch(s->state) { case WELCOME_SENT: uip_send("Welcome!\n", 9); break; case WELCOME_ACKED: uip_send("ok2\n", 4); break; } } }
static void tty_vt100_main (void) { if (uip_connected()) STATE->send_all = 1; if (uip_acked()) { if (STATE->send_all) STATE->send_all = 0; STATE->acked = STATE->sent; } if (uip_newdata ()) { uint8_t len = uip_len; for (uint8_t i = 0; i < len; i ++) { int8_t ch = ((char *) uip_appdata)[i]; if (ch == 12) /* C-l, retransmit everything. */ { STATE->send_all = 1; continue; } _getch_queue (ch); } } if (uip_rexmit() || uip_newdata() || uip_acked() || uip_connected() || uip_poll()) { /* Send new data, if any. */ if (STATE->send_all) tty_vt100_send_all (); else { /* we're just sending an update, ... */ if (vt100_head > STATE->acked) { uint8_t len = vt100_head - STATE->acked; memcpy (uip_sappdata, STATE->acked, len); uip_send (uip_sappdata, len); } else if (vt100_head < STATE->acked) { /* vt100_head wrapped around, let's be careful. */ uint8_t len = vt100_end - STATE->acked; memcpy (uip_sappdata, STATE->acked, len); uint8_t len2 = vt100_head - vt100_buf; memcpy (uip_sappdata + len, vt100_buf, len2); uip_send (uip_sappdata, len + len2); } STATE->sent = vt100_head; } } }
/*---------------------------------------------------------------------------*/ static char data_is_sent_and_acked(CC_REGISTER_ARG struct psock *s) { /* If data has previously been sent, and the data has been acked, we increase the send pointer and call send_data() to send more data. */ if(s->state != STATE_DATA_SENT || uip_rexmit()) { if(s->sendlen > uip_mss()) { uip_send(s->sendptr, uip_mss()); } else { uip_send(s->sendptr, s->sendlen); } s->state = STATE_DATA_SENT; return 0; } else if(s->state == STATE_DATA_SENT && uip_acked()) { if(s->sendlen > uip_mss()) { s->sendlen -= uip_mss(); s->sendptr += uip_mss(); } else { s->sendptr += s->sendlen; s->sendlen = 0; } s->state = STATE_ACKED; return 1; } return 0; }
/***************************************************************************** 函 数 名 : example2_app 功能描述 : just a example function for tcp connect 输入参数 : void 输出参数 : 无 返 回 值 : 调用函数 : 被调函数 : 修改历史 : 1.日 期 : 2017年4月17日 作 者 : QSWWD 修改内容 : 新生成函数 *****************************************************************************/ static void example2_app(void) { struct example2_state *s; s = (struct example2_state *)uip_conn->appstate; if(uip_connected()) { s->state = WELCOME_SENT; uip_send("Welcome!\n\r", 10); return; } if(uip_acked() && s->state == WELCOME_SENT) { s->state = WELCOME_ACKED; } if(uip_newdata()) { uip_send("ok!You are trying to connect to UIP.\n\r", 43); } if(uip_rexmit()) { switch(s->state) { case WELCOME_SENT: uip_send("Welcome,the rexmit!\n\r", 20); break; case WELCOME_ACKED: uip_send("ok!this is retransmit.\n\r",30); break; default: uip_send("the rexmit ,Your's command is something error.\n\r", 50); break; } } }
void lp_tcp_appcall(void) { struct lp_tcp_state *s; s = &(uip_conn->appstate); if (uip_connected()) { s->state = WELCOME_SENT; uip_send("Handshake complete!\n", 20); return; } if (uip_acked() && s->state == WELCOME_SENT) { s->state = WELCOME_ACKED; } if (uip_newdata()) { P1OUT ^= BIT0; uip_send("Received packet\n", 16); } if (uip_rexmit()) { switch(s->state) { case WELCOME_SENT: uip_send("Handshake complete!\n", 20); break; case WELCOME_ACKED: uip_send("Received packet\n", 16); break; } } }
void yport_net_main(void) { if(uip_connected()) { if (yport_conn == NULL) { yport_conn = uip_conn; uip_conn->wnd = YPORT_BUFFER_LEN - 1; } else /* if we have already an connection, send an error */ uip_send("ERROR: Connection blocked\n", 27); } else if (uip_acked()) { /* If the peer is not our connection, close it */ if (yport_conn != uip_conn) uip_close(); else { /* Some data we have sent was acked, jipphie */ /* disable interrupts */ uint8_t sreg = SREG; cli(); yport_recv_buffer.len -= yport_recv_buffer.sent; /* We should use memmove, because the data may overlap */ memmove(yport_recv_buffer.data, yport_recv_buffer.data + yport_recv_buffer.sent, yport_recv_buffer.len); /* enable interrupts again */ SREG = sreg; } } else if (uip_closed() || uip_aborted() || uip_timedout()) { /* if the closed connection was our connection, clean yport_conn */ if (yport_conn == uip_conn) yport_conn = NULL; } else if (uip_newdata()) { if (uip_len <= YPORT_BUFFER_LEN && yport_rxstart(uip_appdata, uip_len) != 0) { /* Prevent the other side from sending more data */ uip_stop(); } } if (uip_poll() && uip_conn == yport_conn && uip_stopped(yport_conn) && yport_send_buffer.sent == yport_send_buffer.len) uip_restart(); /* Send data */ if ((uip_poll() || uip_acked() || uip_rexmit()) && yport_conn == uip_conn && yport_recv_buffer.len > 0) { /* We have recieved data, lets propagade it */ /* disable interrupts */ uint8_t sreg = SREG; cli(); /* Send the data */ uip_send(yport_recv_buffer.data, yport_recv_buffer.len); /* so many data was send */ yport_recv_buffer.sent = yport_recv_buffer.len; /* enable interrupts again */ SREG = sreg; } }
void UIP_UDP_APPCALL(void) { if (uip_flags & UIP_NEWDATA) { printf("UDP: UIP NEWDATA"); if (uip_udp_conn == bc_conn) printf("oops, this should not happen..."); if (uip_udp_conn == app_conn) appHandlePacket(); #ifdef USE_DHCPD if (uip_udp_conn == dhcpd_request_conn) dhcpdHandlePacket(); if (uip_udp_conn == dhcpd_reply_conn) { printf("packet to the reply connection?!?"); while (1); } #endif return; } if (uip_flags & UIP_POLL) { #ifdef USE_UDP if (state==CONNECTED && udp_disconnected==0) { state = NOT_CONNECTED; //lcdClear(); //lcdGoto(0); uint8_t* msg = "disconnected"; int i; //for (i=0; msg[i]; i++) lcdPrintChar(msg[i]); } //printf("{{{UDP: UIP POLL}}}"); if (state==NOT_CONNECTED && uip_udp_conn == bc_conn) { /* UIP does not know about UDP broadcasts, so we fix the ARP table manually * This function is declared static by default, so it needs to be made non-static to * call from here. */ uip_arp_update(&dhcpd_broadcast_ipaddr, &broadcast_ethaddr); uip_send("iLPC2148 Education Board\0", 25); udp_sync = 1000; /* send sync in one second */ //((uint8_t*) uip_appdata)[0] = 0; //uip_send(uip_appdata, 1); printf("<<< sending udp info packet >>>"); return; } if (state==CONNECTED && uip_udp_conn == app_conn) { if (state_change) { ((uint8_t*)uip_appdata)[0] = 's'; ((uint8_t*)uip_appdata)[1] = (uint8_t) switch14; uip_send(uip_appdata, 2); udp_sync = 1000; /* send sync in one second */ printf("<<< sending udp state packet >>>"); return; } if (udp_sync==0) { uip_send("h", 1); /* heartbeat */ udp_sync = 1000; /* send sync in one second */ } } #endif if (uip_udp_conn == dhcpd_reply_conn) dhcpdPollHandler(); return; } }
// obs³u¿ przychodz¹ce dane na port telnetowy void telnet_handle_packet(unsigned char* data, unsigned int len) { // komenda telnetowa - IAC? if (data[0] == TELNET_IAC) { // typ komendy switch(data[1]) { // Are You There? case TELNET_AYT: len = 0; // dodaj nazwê urz¹dzenia nadan¹ przez u¿ytkownika strcpy((char*)data, config_get()->name); len += strlen(config_get()->name); data[len++] = ' '; data[len++] = '|'; data[len++] = ' '; // sygnatura urz¹dzenia memcpy_P(data+len, RS2ETH_SIGNATURE, strlen_P(RS2ETH_SIGNATURE)); len += strlen_P(RS2ETH_SIGNATURE); data[len++] = 0x0D; // \r data[len++] = 0x0A; // \n uip_send(data, len); break; // negocjacja podopcji case TELNET_SB: // podopcja dla portu COM if (data[2] == TELNET_COM_SB) { if (telnet_handle_com_negotiation((data+3), len-3)) { uip_send(data, len); } } break; // przeœlij znak 0xFF case TELNET_IAC: rs_send(0xFF); break; } } // dane -> przeœlij na port COM else { if (len > 0) { LED_ON(LED_TX); } for (; len > 0; len--) { rs_send(*(data++)); } } }
/** HTTP Server State handler for the HTTP Response Header Send state. This state manages the transmission of * the HTTP response header to the receiving HTTP client. */ static void HTTPServerApp_SendResponseHeader(void) { uip_tcp_appstate_t* const AppState = &uip_conn->appstate; char* const AppData = (char*)uip_appdata; char* Extension = strpbrk(AppState->HTTPServer.FileName, "."); bool FoundMIMEType = false; /* If the file isn't already open, it wasn't found - send back a 404 error response and abort */ if (!(AppState->HTTPServer.FileOpen)) { /* Copy over the HTTP 404 response header and send it to the receiving client */ strcpy_P(AppData, HTTP404Header); strcpy(&AppData[strlen(AppData)], AppState->HTTPServer.FileName); uip_send(AppData, strlen(AppData)); AppState->HTTPServer.NextState = WEBSERVER_STATE_Closing; return; } /* Copy over the HTTP 200 response header and send it to the receiving client */ strcpy_P(AppData, HTTP200Header); /* Check to see if a MIME type for the requested file's extension was found */ if (Extension != NULL) { /* Look through the MIME type list, copy over the required MIME type if found */ for (uint8_t i = 0; i < (sizeof(MIMETypes) / sizeof(MIMETypes[0])); i++) { if (strcmp(&Extension[1], MIMETypes[i].Extension) == 0) { strcpy(&AppData[strlen(AppData)], MIMETypes[i].MIMEType); FoundMIMEType = true; break; } } } /* Check if a MIME type was found and copied to the output buffer */ if (!(FoundMIMEType)) { /* MIME type not found - copy over the default MIME type */ strcpy_P(&AppData[strlen(AppData)], DefaultMIMEType); } /* Add the end-of-line terminator and end-of-headers terminator after the MIME type */ strcpy(&AppData[strlen(AppData)], "\r\n\r\n"); /* Send the MIME header to the receiving client */ uip_send(AppData, strlen(AppData)); /* When the MIME header is ACKed, progress to the data send stage */ AppState->HTTPServer.NextState = WEBSERVER_STATE_SendData; }
//tcp appcall function void tcp_appcall(void) { char *hello = "Hi, This is a TCP test!\n"; if(uip_connected()) { uip_send(hello,strlen(hello)+1); } if(uip_newdata()) { uip_send(uip_appdata,uip_len); } }
/***************************************************************************** 函 数 名 : udp_8899_app 功能描述 : a uip udp function for local port is 8899 输入参数 : void 输出参数 : 无 返 回 值 : 调用函数 : 被调函数 : 修改历史 : 1.日 期 : 2017年4月17日 作 者 : QSWWD 修改内容 : 新生成函数 *****************************************************************************/ static void udp_8899_app(void) { if(uip_poll()) { char *tmp_dat = "the auto send!\n\r"; uip_send(tmp_dat,strlen(tmp_dat)); } if(uip_newdata()) { char *tmp_data = "receive the data!\n\r"; uip_send(tmp_data,strlen(tmp_data)); } }
/*-----------------------------------------------------------------------------------*/ static void senddata(struct telnet_state *s) { if(s->text == NULL) { uip_send(s->text, 0); return; } if(s->textlen > uip_mss()) { s->sentlen = uip_mss(); } else { s->sentlen = s->textlen; } uip_send(s->text, s->sentlen); }
/*---------------------------------------------------------------------------*/ static char send_data(register struct psock *s) { if(s->state != STATE_DATA_SENT || uip_rexmit()) { if(s->sendlen > uip_mss()) { uip_send(s->sendptr, uip_mss()); } else { uip_send(s->sendptr, s->sendlen); } s->state = STATE_DATA_SENT; return 1; } return 0; }
/*-----------------------------------------------------------------------------------*/ static void senddata(struct websocket_http_client_state *s) { uint16_t len; int curptr; char portnumber[10]; if(s->getrequestleft > 0) { windowstart = s->getrequestptr; curptr = 0; windowend = windowstart + uip_mss(); windowptr = (uint8_t *)uip_appdata - windowstart; curptr = window_copy(curptr, http_get, sizeof(http_get) - 1); curptr = window_copy(curptr, s->file, (unsigned char)strlen(s->file)); curptr = window_copy(curptr, " ", 1); curptr = window_copy(curptr, http_10, sizeof(http_10) - 1); curptr = window_copy(curptr, http_crnl, sizeof(http_crnl) - 1); curptr = window_copy(curptr, http_host, sizeof(http_host) - 1); curptr = window_copy(curptr, s->host, (unsigned char)strlen(s->host)); sprintf(portnumber, ":%d", s->port); curptr = window_copy(curptr, portnumber, (unsigned char)strlen(portnumber)); curptr = window_copy(curptr, http_crnl, sizeof(http_crnl) - 1); curptr = window_copy(curptr, http_request_fields, (unsigned char)strlen(http_request_fields)); curptr = window_copy(curptr, s->subprotocol, (unsigned char)strlen(s->subprotocol)); curptr = window_copy(curptr, http_crnl, strlen(http_crnl)); curptr = window_copy(curptr, http_crnl, strlen(http_crnl)); len = s->getrequestleft > uip_mss()? uip_mss(): s->getrequestleft; uip_send(uip_appdata, len); } else if(s->outputbufptr > 0 && s->outputbuf_sendnext != 0) { /* Retransmit previously sent data */ uip_send(s->outputbuf, s->outputbuf_sendnext); } else if(s->outputbufptr > 0 && s->outputbuf_sendnext == 0) { len = MIN(s->outputbufptr, uip_mss()); s->outputbuf_sendnext = len; uip_send(s->outputbuf, len); /* printf("Data on outputbuf to send, %d bytes, sending %d\n", s->outputbufptr, len);*/ } }
/*---------------------------------------------------------------------------*/ static void senddata(void) { static char *bufptr, *lineptr; static int buflen, linelen; bufptr = uip_appdata; buflen = 0; for(s.numsent = 0; s.numsent < TELNETD_CONF_NUMLINES && s.lines[s.numsent] != NULL ; ++s.numsent) { lineptr = s.lines[s.numsent]; linelen = strlen(lineptr); if(linelen > TELNETD_CONF_LINELEN) { linelen = TELNETD_CONF_LINELEN; } if(buflen + linelen < uip_mss()) { memcpy(bufptr, lineptr, linelen); bufptr += linelen; buflen += linelen; } else { break; } } uip_send(uip_appdata, buflen); }
/* * Sends the real data in the current connection's virtual buffer */ void send() { uip_tcp_appstate_t *app = &(uip_conn->appstate); // Find the intersection of the virtual buffer and the real uip buffer int len = (int)app->cursor - app->ackedCount; len = len < 0 ? 0 : len; len = len > (int)uip_conn->mss ? (int)uip_conn->mss : len; if (verbose) { Serial.print("TX "); Serial.print(len); Serial.println(" bytes"); } #ifdef DEBUG Serial.print(app->ackedCount); Serial.print(" - "); Serial.print(app->ackedCount + len - 1); Serial.print(" of "); Serial.println((int)app->cursor); #endif // DEBUG // Send the real bytes from the virtual buffer and record how many were sent uip_send(uip_appdata, len); app->sentCount = len; setTXPin(HIGH); }
/* * Sends the real data in the current connection's virtual buffer */ void send() { uip_tcp_appstate_t *app = &(uip_conn->appstate); // Find the intersection of the virtual buffer and the real uip buffer int len = (int)app->cursor - app->ackedCount; len = len < 0 ? 0 : len; len = len > (int)uip_conn->mss ? (int)uip_conn->mss : len; #ifdef DEBUG DebugPrintFO(f_tx); // Serial.print("-->TX "); Serial.print(len); DebugPrintF (f_bytes); // Serial.print (" bytes"); Serial.print(app->ackedCount); DebugPrintFO(f_hyphen); // Serial.print(" - "); Serial.print(app->ackedCount + len - 1); DebugPrintFO(f_of); // Serial.print(" of "); Serial.print((int)app->cursor); DebugPrint((char *)""); #endif // DEBUG // Send the real bytes from the virtual buffer and record how many were sent uip_send(uip_appdata, len); app->sentCount = len; setTXPin(HIGH); }
/*-----------------------------------------------------------------------------------*/ static void senddata(void) { u16_t len; char *getrequest; char *cptr; if(s.getrequestleft > 0) { cptr = getrequest = (char *)uip_appdata; cptr = copy_string(cptr, http_get, sizeof(http_get) - 1); cptr = copy_string(cptr, s.file, strlen(s.file)); *cptr++ = ISO_space; cptr = copy_string(cptr, http_10, sizeof(http_10) - 1); cptr = copy_string(cptr, http_crnl, sizeof(http_crnl) - 1); cptr = copy_string(cptr, http_host, sizeof(http_host) - 1); cptr = copy_string(cptr, s.host, strlen(s.host)); cptr = copy_string(cptr, http_crnl, sizeof(http_crnl) - 1); cptr = copy_string(cptr, http_user_agent_fields, strlen(http_user_agent_fields)); len = s.getrequestleft > uip_mss()? uip_mss(): s.getrequestleft; uip_send(&(getrequest[s.getrequestptr]), len); } }
/*---------------------------------------------------------------------------*/ static void send_request(void) { struct ntp_time time; struct ntp_msg *m = (struct ntp_msg *)uip_appdata; // build ntp request m->flags = FLAGS_LI_ALARM | FLAGS_VN(4) | FLAGS_MODE_CLIENT; m->stratum = 0; // unavailable m->poll = 4; // 2^4 = 16 sec m->precision = -6; // 2^-6 = 0.015625 sec = ~1/100 sec m->root_delay[0] = HTONS(1); // 1.0 sec m->root_delay[1] = 0; m->root_dispersion[0] = HTONS(1); // 1.0 sec m->root_dispersion[1] = 0; // we don't have a reference clock m->reference_identifier = 0; m->reference_timestamp[0] = m->reference_timestamp[1] = 0; // we don't know any time m->originate_timestamp[0] = m->originate_timestamp[1] = 0; m->receive_timestamp[0] = m->receive_timestamp[1] = 0; // put our own time into the transmit frame (whatever our own time is) clock_get_ntptime(&time); m->transmit_timestamp[0] = ntp_read_u32(time.seconds); m->transmit_timestamp[1] = ntp_read_u32(time.fraction); // and finally send request uip_send(uip_appdata, sizeof(struct ntp_msg)); }
/****************************************************************************** * static void senddata(void) * * This is the main send function. We split it into GET and POST. * * Per Exosite documentation, the format of a GET request should look like: * * GET /api:v1/stack/alias?1&temp&state HTTP/1.1 * Host: m2.exosite.com * X-Exosite-CIK: 576e95bf2e7026911f53356d38a9f2afd2b82f83 * Accept: application/x-www-form-urlencoded; charset=utf-8 * * Per Exosite documentation, the format of a POST request should look like: * * POST /api:v1/stack/alias HTTP/1.1 * Host: m2.exosite.com * X-Exosite-CIK: 576e95bf2e7026911f53356d38a9f2afd2b82f83 * Content-Type: application/x-www-form-urlencoded; charset=utf-8 * Content-Length: 31 * 1=453&temp=100402&state=running * ******************************************************************************/ static void senddata(void) { u16_t len; char *httprequest; char temp[100]; if(s.httprequestleft > 0) { httprequest = (char *)uip_appdata; if(s.state == EXO_STATE_POST) { strcpy(httprequest, POST_HEADER); strcat(httprequest, M2_HOST); strcat(httprequest, "X-Exosite-CIK: "); strncat(httprequest, s.cik, CIK_LENGTH); strcat(httprequest, "\r\nContent-Type: application/x-www-form-urlencoded; charset=utf-8\r\n"); sprintf(temp,"%s%d%s%s%s%s",CONTENT_LENGTH,strlen(s.file),NEXT_LINE,NEXT_LINE,s.file,NEXT_LINE); strcat(httprequest, temp); } else if (s.state == EXO_STATE_GET) { strcpy(httprequest, GET_HEADER); sprintf(temp,"%s%s",s.alias,HTTP11); strcat(httprequest, temp); strcat(httprequest, M2_HOST); strcat(httprequest, "X-Exosite-CIK: "); strncat(httprequest, s.cik, CIK_LENGTH); strcat(httprequest, "\r\nAccept: application/x-www-form-urlencoded; charset=utf-8\r\n\r\n\r\n"); } s.httprequestleft = strlen(httprequest); len = s.httprequestleft > uip_mss()? uip_mss(): s.httprequestleft; uip_send(&(httprequest[s.httprequestptr]), len); } }
//发送数据给客户端 void tcp_server_senddata(void) { struct tcp_demo_appstate *s = (struct tcp_demo_appstate *)&uip_conn->appstate; //s->textptr : 发送的数据包缓冲区指针 //s->textlen :数据包的大小(单位字节) if(s->textlen>0)uip_send(s->textptr, s->textlen);//发送TCP数据包 }
// okresowo sprawdzaj czy nie nadesz³y nowe dane na porcie COM void telnet_periodic() { unsigned char* buf = uip_appdata; unsigned int len = 0; unsigned char ch; // wyœlij dane z bufora odbiorczego if (!com_buf_is_empty(&com_buffer)) { // dla trybu RS485 poczekaj na przerwê miêdzy ramkami (RS_RX_TX_DELAY [ms]), aby wys³aæ ca³¹ ramkê Modbusa w jednym pakiecie #ifdef RS_485 if (rs_rx_tx_timer < RS_RX_TX_DELAY) { return; } else { rs_rx_tx_timer = 0; } #endif while ( !com_buf_is_empty(&com_buffer) && (len < 1470) ) { ch = com_buf_get(&com_buffer); buf[len++] = ch; // w³aœciwie koduj transfer binarny // @see RFC 854 if (ch == TELNET_IAC) { buf[len++] = ch; } } uip_send(buf, len); } }
/*-----------------------------------------------------------------------------------*/ static void senddata(void) { u16_t len; int curptr; if(s.getrequestleft > 0) { windowstart = s.getrequestptr; curptr = 0; windowend = windowstart + uip_mss(); windowptr = (char *)uip_appdata - windowstart; curptr = window_copy(curptr, http_get, sizeof(http_get) - 1); curptr = window_copy(curptr, s.file, (unsigned char)strlen(s.file)); curptr = window_copy(curptr, " ", 1); curptr = window_copy(curptr, http_10, sizeof(http_10) - 1); curptr = window_copy(curptr, http_crnl, sizeof(http_crnl) - 1); curptr = window_copy(curptr, http_host, sizeof(http_host) - 1); curptr = window_copy(curptr, s.host, (unsigned char)strlen(s.host)); curptr = window_copy(curptr, http_crnl, sizeof(http_crnl) - 1); curptr = window_copy(curptr, http_user_agent_fields, (unsigned char)strlen(http_user_agent_fields)); len = s.getrequestleft > uip_mss()? uip_mss(): s.getrequestleft; uip_send(uip_appdata, len); } }
void ems_net_main(void) { if (uip_connected()) { if (ems_conn == NULL) { ems_conn = uip_conn; uip_conn->wnd = EMS_BUFFER_LEN - 1; } else { /* if we have already an connection, send an error */ uip_send("ERROR: Connection blocked\n", 27); } } else if (uip_acked()) { /* If the peer is not our connection, close it */ if (ems_conn != uip_conn) { uip_close(); } else { /* Some data we have sent was acked, jipphie */ ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { ems_recv_buffer.len -= ems_recv_buffer.sent; memmove(ems_recv_buffer.data, ems_recv_buffer.data + ems_recv_buffer.sent, ems_recv_buffer.len); } } } else if (uip_closed() || uip_aborted() || uip_timedout()) {
/*-----------------------------------------------------------------------------------*/ static u8_t processes(void) { u8_t i; struct dispatcher_proc *p; p = DISPATCHER_PROCS(); for(i = 0; i < hs->count; ++i) { if(p != NULL) { p = p->next; } } if(uip_acked()) { /* If the previously sent data has been acknowledged, we move forward one connection. */ ++hs->count; if(p != NULL) { p = p->next; } if(p == NULL) { /* If all processes have been printed out, we are done and return 1. */ return 1; } } sprintf((char *)uip_appdata, "<tr align=\"center\"><td>%3d</td><td>%s</td><td>0x%04x</td><td>0x%04x</td><td>0x%04x</td></tr>\r\n", p->id, p->name, p->idle, p->signalhandler, p->uiphandler); uip_send(uip_appdata, strlen((char *)uip_appdata)); return 0; }
/*-----------------------------------------------------------------------------------*/ static void senddata(void) { u16_t len; char *getrequest; char *cptr; if(s.getrequestleft > 0) { cptr = getrequest = (char *)uip_appdata; #if 0 cptr = copy_string(cptr, http_get, sizeof(http_get) - 1); cptr = copy_string(cptr, s.file, strlen(s.file)); *cptr++ = ISO_space; cptr = copy_string(cptr, http_10, sizeof(http_10) - 1); cptr = copy_string(cptr, http_crnl, sizeof(http_crnl) - 1); cptr = copy_string(cptr, http_host, sizeof(http_host) - 1); cptr = copy_string(cptr, s.host, strlen(s.host)); cptr = copy_string(cptr, http_crnl, sizeof(http_crnl) - 1); cptr = copy_string(cptr, http_user_agent_fields, strlen(http_user_agent_fields)); #endif // copy the client transmit string into the TX buffer memcpy_P(cptr, twitter, strlen_P(twitter)); len = s.getrequestleft > uip_mss()?uip_mss():s.getrequestleft; uip_send(&(getrequest[s.getrequestptr]), len); } }
/** Sends a list of active TCP connections to the TELNET client. */ static void TELNETServerApp_DisplayTCPConnections(void) { char* const AppData = (char*)uip_appdata; strcpy_P(AppData, CurrentConnectionsHeader); uint16_t ResponseLen = strlen(AppData); uint8_t ActiveConnCount = 0; /* Loop through the complete uIP TCP connections list, looking for active connections */ for (uint8_t i = 0; i < UIP_CONNS; i++) { struct uip_conn* CurrConnection = &uip_conns[i]; /* If the connection is not closed, it is active and must be added to the out buffer */ if (CurrConnection->tcpstateflags != UIP_CLOSED) { /* Add the current connection's details to the out buffer */ ResponseLen += sprintf_P(&AppData[ResponseLen], PSTR("%u) %d.%d.%d.%d (Local Port %u <=> Remote Port %u)\r\n"), ++ActiveConnCount, CurrConnection->ripaddr.u8[0], CurrConnection->ripaddr.u8[1], CurrConnection->ripaddr.u8[2], CurrConnection->ripaddr.u8[3], HTONS(CurrConnection->lport), HTONS(CurrConnection->rport)); } } uip_send(AppData, ResponseLen); }
void uip_modbus_appcall(void) { if(uip_connected()) { PRINTF("connected!\r\n"); } if(uip_closed()) { PRINTF("closed\r\n"); } if(uip_newdata()) { PRINTF("request!\r\n"); // 获得modbus请求 memcpy(ucTCPRequestFrame, uip_appdata, uip_len ); ucTCPRequestLen = uip_len; // 向 modbus poll发送消息 xMBPortEventPost( EV_FRAME_RECEIVED ); } if(uip_poll()) { if(bFrameSent) { bFrameSent = FALSE; // uIP发送Modbus应答数据包 uip_send( ucTCPResponseFrame , ucTCPResponseLen ); } } }
PROCESS_THREAD(udpsend_process, ev, data) { static struct etimer etimer; static struct uip_udp_conn *c; PROCESS_EXITHANDLER(goto exit); PROCESS_BEGIN(); printf("udpsend_process starting\n"); { uip_ipaddr_t addr; uip_ipaddr(&addr, 255,255,255,255); /* Change address here! */ c = udp_new(&addr, UIP_HTONS(4321), NULL); c->ttl = 1; /* One hop only. */ } while(1) { etimer_set(&etimer, CLOCK_SECOND); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&etimer)); tcpip_poll_udp(c); PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); char buf[64]; sprintf(buf, "light sensors %d %d", sensors_light1(), sensors_light2()); uip_send(buf, strlen(buf) + 1); } exit: /* Contiki does automatic garbage collection of uIP state and we * need not worry about that. */ printf("udpsend_process exiting\n"); PROCESS_END(); }
static void send_request(void) { char str[] = "Hello. What is your name?\n"; memcpy(uip_appdata, str, strlen(str)); uip_send(uip_appdata, strlen(str)); }