Benutzer-Werkzeuge

Webseiten-Werkzeuge


contiki:simple-udp-workshop

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
contiki:simple-udp-workshop [2015/05/27 17:46] – [5. Interaktion mit dem UDP-Service] admincontiki:simple-udp-workshop [2018/12/03 14:53] (aktuell) admin
Zeile 5: Zeile 5:
    * Die Installation von [[http://www.contiki-os.org/start.html|Instant Contiki]] benötigt [[http://www.vmware.com/go/downloadplayer/|VMWare Player]], oder [[https://www.virtualbox.org/wiki/Downloads|Virtualbox]]    * Die Installation von [[http://www.contiki-os.org/start.html|Instant Contiki]] benötigt [[http://www.vmware.com/go/downloadplayer/|VMWare Player]], oder [[https://www.virtualbox.org/wiki/Downloads|Virtualbox]]
    * Anmeldung an //Instant Contiki// mit dem Passwort: ''user''    * Anmeldung an //Instant Contiki// mit dem Passwort: ''user''
-   * Die folgende Beschreibung bezieht sich immer auf das Quellcode-Verzeichnis: ''/home/user/contiki-2.7/''+   * Die folgende Beschreibung bezieht sich immer auf das Quellcode-Verzeichnis: ''/home/user/contiki-3.0/''
  
 ==== 2. Anpassungen des Quellcodes ==== ==== 2. Anpassungen des Quellcodes ====
Zeile 12: Zeile 12:
  
 === 2.1 Erstellen eines neuen Projekt-Verzeichnisses === === 2.1 Erstellen eines neuen Projekt-Verzeichnisses ===
-  - Erstellen Sie das Verzeichnis: ''/home/user/contiki-2.7/examples/simpleUDP''+  - Erstellen Sie das Verzeichnis: ''/home/user/contiki-3.0/examples/simpleUDP''
  
-=== 2.2 Erstellen des Quellcodes ===+=== 2.2 Erstellen des Makefiles ===
  
 Für das Projekt werden eine C-Datei und ein Makefile benötigt. Für das Projekt werden eine C-Datei und ein Makefile benötigt.
Zeile 44: Zeile 44:
 </code> </code>
  
 +=== 2.3 Erstellen des Quellcodes ===
  
   - Erstellen Sie die C-Datei ''simpleUDP.c'':   - Erstellen Sie die C-Datei ''simpleUDP.c'':
Zeile 57: Zeile 58:
 #include "contiki-lib.h" #include "contiki-lib.h"
 #include "contiki-net.h" #include "contiki-net.h"
-#include "net/uip.h"+#include "net/ip/uip.h"
 #include "net/netstack.h" #include "net/netstack.h"
 #include <stdio.h> /* For printf() */ #include <stdio.h> /* For printf() */
Zeile 173: Zeile 174:
  
 #include "contiki.h" #include "contiki.h"
-#include "contiki-net.h" +#include "sys/ctimer.h" 
-#include "contiki-lib.h" +#include "sys/etimer.h" 
-#include <stdio.h> /* For printf() */+#include "net/ip/uip.h" 
 +#include "net/ipv6/uip-ds6.h" 
 +#include <stdio.h> 
 +#include <string.h>
  
-#define MAX_PAYLOAD_LEN 120 +#include "simple-udp.h" 
-static struct uip_udp_conn *udpconn;+#define UDP_PORT 40000 
 +#define SEND_INTERVAL           (10 * CLOCK_SECOND) 
 + 
 +static struct simple_udp_connection client_connection;
  
 /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
-PROCESS(hello_world_process, "Hello world process"); +PROCESS(client_example_process, "UDP client example process"); 
-AUTOSTART_PROCESSES(&hello_world_process);+AUTOSTART_PROCESSES(&client_example_process);
 /*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
-PROCESS_THREAD(hello_world_processev, data)+static void 
 +receiver(struct simple_udp_connection *c, 
 +         const uip_ipaddr_t *sender_addr, 
 +         uint16_t sender_port, 
 +         const uip_ipaddr_t *receiver_addr, 
 +         uint16_t receiver_port, 
 +         const uint8_t *data
 +         uint16_t datalen)
 { {
 +  printf("Data received on port %d from port %d with length %d\n",
 +         receiver_port, sender_port, datalen);
 +}
 +/*---------------------------------------------------------------------------*/
 +PROCESS_THREAD(client_example_process, ev, data)
 +{
 +  static struct etimer periodic_timer;
 +  uip_ipaddr_t addr;
 +
   PROCESS_BEGIN();   PROCESS_BEGIN();
 +  //ohne simple_udp_register funktioniert das Senden nicht!
 +  simple_udp_register(&client_connection, UDP_PORT,
 +                      NULL, UDP_PORT, receiver);
  
-  printf("Helloworld\n");+  etimer_set(&periodic_timerSEND_INTERVAL); 
 +  while(1)  
 +  { 
 +    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer)); 
 +    etimer_reset(&periodic_timer);
  
-  char buf[MAX_PAYLOAD_LEN]+    printf("Sending UDP-Packet\n")
-  uip_ipaddr_t ipaddr; + 
-  uip_ipaddr(&ipaddr10,0,2,2); +    // senden auf die eigene Adresse 172.18.0.2 funktioniert bei 
-  udpconn = udp_new(&ipaddrUIP_HTONS(40000)NULL); +    // Instant-Contiki nicht: arp auf tun0-Interface? 
-  /*Schreibe Daten in Buffer*/ +    //uip_ipaddr(&addr, 172,18,0,1); 
-  sprintf(buf, "Hello from the Client!\n "); +    uip_ipaddr(&addr127,0,0,1); 
-  /*Versende das Packet*/ +    simple_udp_sendto(&client_connection, "Test", 4&addr); 
-  int i; +  }
-  for (i=0; i<100; i++) +
-    uip_udp_packet_send(udpconnbufstrlen(buf));  +
-  printf("So, Paket hoffentlich versendet!");+
   PROCESS_END();   PROCESS_END();
 } }
 </code> </code>
contiki/simple-udp-workshop.1432748761.txt.gz · Zuletzt geändert: 2017/01/24 18:49 (Externe Bearbeitung)