uint8_t vNet_DataAvailable_M1() { /* If there are incoming data, the uip_input() issue a callback that set the vnetlenght value to the length of the vNet frame, then the value is returned and the retrieve function provide to get the data from the buffer */ uint8_t dlen = ETH_FAIL; if(srvcln_dataavailable(ETH_PORT)) { dlen = srvcln_dataavailable(ETH_PORT); } else if(srvcln_dataavailable(ETH_MODBUS)) { // Modbus frame are not handled at this stage, but requires a dedicated // call to Modbus method in the main program } else if(srvcln_dataavailable(ETH_HTTP)) { // HTTP frame are not handled at this stage, but requires a dedicated // call to HTTP method in the main program } else vNet_uIP(); // Retrieve and process the incoming data // Return data length, if any return dlen; }
void cln_waitsend(uint8_t sock) { /* Process the stack until data where sent and no pending frames are waiting for ack */ do { vNet_uIP(); delay(uIP_DELAY); } while(uip_conns[sock].tcpstateflags != CLOSED); // Reset vnetlenght=0; }
void srv_waitsend(uint8_t sock) { /* Process the stack until data where sent and no pending frames are waiting for ack */ do { vNet_uIP(); delay(uIP_DELAY); } while((uip_outstanding(&uip_conns[sock])) || (uip_conns[sock].appstate & SENDDATA)); // Reset vnetlenght=0; }
uint8_t vNet_Send_M1(uint16_t addr, oFrame *frame, uint8_t len) { uint8_t sock, ip_addr[4]; uint16_t count = 0, vNet_port; // Check message length if ((len == 0) || (len >= UIP_PAYLOADSIZE)) return ETH_FAIL; // If the frame is not empty, there are waiting data oFrame_Define(&vNetM1_oFrame); if(oFrame_isBusy()) return ETH_FAIL; // Build a frame with len of payload as first byte vNetM1_header = len+1; oFrame_Set(&vNetM1_header, 0, 1, 0, frame); // Define the standard vNet port vNet_port = ETH_PORT; // Define the IP address to be used if((addr == VNET_ADDR_BRDC) || (addr == VNET_ADDR_wBRDC) || (addr == VNET_ADDR_nBRDC) || ((addr > VNET_ADDR_L_M3) && (addr < VNET_ADDR_H_M3))) { // Set the IP broadcast address for(U8 i=0;i<4;i++) ip_addr[i]=0xFF; } else { // Verify the User Mode #if(UMODE_ENABLE) if ((addr & 0xFF00) != 0x0000) { // The first byte is the User Mode Index, if in range 0x01 - 0x64 // a standard client/server connection is used with the user interface // this give routing and NATting passthrough if(!UserMode_Get(addr, &ip_addr[0], (uint8_t*)(&vNet_port))) { // Flag the error oFrame_Reset(); return ETH_FAIL; } } else #endif eth_vNettoIP(addr, &ip_addr[0]); // Get the IP address } // Setup the connection, data will be sent using a callback function if(!uip_udp_sock((u16_t*)ip_addr, vNet_port, (u16_t)ETH_PORT)) { // Flag the error oFrame_Reset(); return ETH_FAIL; } // Data are processed with the IP stack vNet_uIP(); // At this stage data are processed or socket is failed, so we can // securely reset the oFrame oFrame_Reset(); return ETH_SUCCESS; }