This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UDP connection based on CMSIS library

Hello,

I need to send a UDP package with this function( netUDP_Send )

https://www.keil.com/pack/doc/mw/Network/html/group__udp__user__api.html#ga7a82db98b82300e5fd03ce1b7afb6cba

But I don't have remote IP and Port number.  I have added a new variable to get remote IP and Port number but it shows me an error.

NET_ADDR4 addrUDP;

uint32_t udp_cb_func (int32_t socket, const NET_ADDR *addr, const uint8_t *buf, uint32_t len) {
    addrUDP=addr;
    return 0;
}

How can I send a UDP package?

Parents Reply Children
  • Thank you so much, I have changed my code to:

    NET_ADDR addrUDP;
    
    uint32_t udp_cb_func (int32_t socket,  NET_ADDR *addr, const uint8_t *buf, uint32_t len) {
    	addrUDP.addr_type=*addr->addr_type;
    	addrUDP.port=*addr->port;
    	addrUDP.addr=*addr->addr;
    	return 0;
    }

    But I got this error:

    error:  #75: operand of "*" must be a pointer addrUDP.addr_type=*addr->addr_type;

  • In addition I have changed to:

       addrUDP.addr_type=addr->addr_type;
       addrUDP.port=addr->port;
      addrUDP.addr=addr->addr;

    But I got:

    error:  #137: expression must be a modifiable lvalue

    I removed   addrUDP.addr=addr->addr; but still it doesn't work. I just broadcast my UDP package to receive it in all network.

  • Whenever you get a message telling you that you must do something - do it!

    That message tells you:

    operand of "*" must be a pointer

    So do that!

  • That's another message telling you something which you must do - so do it!

    If you don't know what a "modifiable lvalue" is, look it up in your 'C' textbook (it is a standard 'C' term), or google it ...

    I removed   addrUDP.addr=addr->addr; but still it doesn't work

    Of course it won't - we've already established that you need to have the address!

  • Hello, Here is my program which works fine for broadcast.

    int main (void){
    
    netInitialize ();
    Eth();
    
    while(1){
    Sendd();
    osDelay(100);
    
    }
    
    }
    
    
    NET_ADDR4 addrUDP={ NET_ADDR_IP4, 2020, 192, 168, 255, 255 };
    
    uint32_t udp_cb_func (int32_t socket, const NET_ADDR *addr, const uint8_t *buf, uint32_t len) {
    	
    	return 0;
    }
    
    
    
    void Eth(){
    	
    uint8_t mac_addr [NET_ADDR_ETH_LEN];
    uint8_t ip4_addr [NET_ADDR_IP4_LEN];
    
    
    
    
    socket = netUDP_GetSocket(udp_cb_func);
    if (socket >= 0) {
    netUDP_Open(socket, 2050);
    }
    
    
    void Sendd(void){
    
    				sendbuf =  netUDP_GetBuffer (2);
    				sendbuf[0]=65;sendbuf[0]=66;
    				State=netUDP_Send (socket,(NET_ADDR *)&addrUDP, sendbuf,2);	
    				
    
    }

    I received transmitted data in my PC. However, by specifying the remote IP(NET_ADDR4 addrUDP={ NET_ADDR_IP4, 2020, 192, 168, 100, 20 };) it doesn't work even it doesn't respond to ping command. I have added "netARP_CacheIP " function based on "http://www.keil.com/pack/doc/mw/Network/html/group__udp__user__api.html?_ga=2.246941447.2042184398.1570359907-552607041.1563512165" but it only helps me to ping the device properly. but it still doesn't send anything. Here is my code

    int main (void){
    
    netInitialize ();
    Eth();
    
    while(1){
    Sendd();
    osDelay(100);
    
    }
    
    }
    
    
    NET_ADDR4 addrUDP={ NET_ADDR_IP4, 2020, 192, 168, 100, 20 };
    
    uint32_t udp_cb_func (int32_t socket, const NET_ADDR *addr, const uint8_t *buf, uint32_t len) {
    	
    	return 0;
    }
    
    
    
    void Eth(){
    	
    uint8_t mac_addr [NET_ADDR_ETH_LEN];
    uint8_t ip4_addr [NET_ADDR_IP4_LEN];
    
    
    netIP_aton ("192.168.100.100", NET_ADDR_IP4, ip4_addr);
    
    while (netARP_GetMAC (NET_IF_CLASS_ETH | 0, ip4_addr, mac_addr) != netOK) {
      netARP_CacheIP (NET_IF_CLASS_ETH | 0, ip4_addr, netARP_CacheTemporaryIP);
      osDelay (1000);
    }
    
    socket = netUDP_GetSocket(udp_cb_func);
    if (socket >= 0) {
    netUDP_Open(socket, 2050);
    }
    
    
    void Sendd(void){
    
    				sendbuf =  netUDP_GetBuffer (2);
    				sendbuf[0]=65;sendbuf[0]=66;
    				State=netUDP_Send (socket,(NET_ADDR *)&addrUDP, sendbuf,2);	
    				
    
    }

    My computer address IP is 192.168.100.50 and both subnet mask is 255.255.0.0 . Ping shows me that "192.168.100.100" is available on my network but it doesn't send anything to the remote IP ( after setting broadcast IP 192.168.255.255 and removing 

    netIP_aton ("192.168.100.100", NET_ADDR_IP4, ip4_addr);
    
    while (netARP_GetMAC (NET_IF_CLASS_ETH | 0, ip4_addr, mac_addr) != netOK) {
      netARP_CacheIP (NET_IF_CLASS_ETH | 0, ip4_addr, netARP_CacheTemporaryIP);
      osDelay (1000);
    }

    it sends a broadcast and complete message to my PC. what is my mistake?