Skip to content

Commit

Permalink
Merge pull request #62 from soburi/microip_improvment
Browse files Browse the repository at this point in the history
MicroIP improvment
  • Loading branch information
soburi authored May 30, 2018
2 parents cf57182 + b6ab939 commit 7aced9f
Show file tree
Hide file tree
Showing 15 changed files with 489 additions and 135 deletions.
23 changes: 16 additions & 7 deletions boards.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
menu.config=Configuration
menu.trace=Debug Trace
menu.trace=Trace
menu.rpl=RPL

jn516x.name=NXP JN516x
jn516x.upload.tool=contiki-makehelper
Expand All @@ -11,7 +12,7 @@ jn516x.build.core=arduino
jn516x.build.variant=jn516x
jn516x.build.compiler.path=C:/NXP/bstudio_nxp/sdk/Tools/ba-elf-ba2-r36379/bin
jn516x.build.uploader.path=""
jn516x.build.make.vars=target_makefile='{runtime.platform.path}/variants/{build.variant}/Makefile.variant' CONTIKI_TARGET_MAIN=override-contiki-jn516x-main.c TARGET_WITH_UART1=1 PLATFORM_CONF_H='{runtime.platform.path}/variants/{build.variant}/{build.variant}-platform-conf.h' PREINCLUDE_FILES='{build.core.path}/weak_pragmas.h' {build.trace}
jn516x.build.make.vars=target_makefile='{runtime.platform.path}/variants/{build.variant}/Makefile.variant' CONTIKI_TARGET_MAIN=override-contiki-jn516x-main.c TARGET_WITH_UART1=1 PLATFORM_CONF_H='{runtime.platform.path}/variants/{build.variant}/{build.variant}-platform-conf.h' PREINCLUDE_FILES='{build.core.path}/weak_pragmas.h' {build.trace} {build.rpl}
jn516x.build.make.goals={build.project_name}.bin {build.project_name}.hex {build.project_name}.elf
jn516x.menu.config.jn5169=JN5169
jn516x.menu.config.jn5169.build.config_vars=CHIP=JN5169 LINKCMD='{runtime.platform.path}/variants/{build.variant}/ldscript/Arduinize_JN5169.ld'
Expand All @@ -23,10 +24,14 @@ jn516x.menu.config.jn5161=JN5161
jn516x.menu.config.jn5161.build.config_vars=CHIP=JN5161 LINKCMD='{runtime.platform.path}/variants/{build.variant}/ldscript/Arduinize.ld'
jn516x.menu.config.meshbee=Mesh Bee
jn516x.menu.config.meshbee.build.config_vars=CHIP=JN5168 LINKCMD='{runtime.platform.path}/variants/{build.variant}/ldscript/Arduinize.ld'
jn516x.menu.trace.OFF=Trace Off
jn516x.menu.trace.OFF=Off
jn516x.menu.trace.OFF.build.trace=
jn516x.menu.trace.ON=Trace On
jn516x.menu.trace.ON=On
jn516x.menu.trace.ON.build.trace=TRACE=1
jn516x.menu.rpl.ON=Enable
jn516x.menu.rpl.ON.build.rpl=CONTIKI_WITH_RPL=1
jn516x.menu.rpl.OFF=Disable
jn516x.menu.rpl.OFF.build.rpl=CONTIKI_WITH_RPL=0

twelite.name=Mono Wireless TWELITE
twelite.upload.tool=contiki-makehelper
Expand All @@ -38,16 +43,20 @@ twelite.build.core=arduino
twelite.build.variant=jn516x
twelite.build.compiler.path=C:/MWSDK/Tools/ba-elf-ba2-r36379/bin
twelite.build.uploader.path=""
twelite.build.make.vars=target_makefile='{runtime.platform.path}/variants/{build.variant}/Makefile.variant' CONTIKI_TARGET_MAIN=override-contiki-jn516x-main.c TARGET_WITH_UART1=1 PLATFORM_CONF_H='{runtime.platform.path}/variants/{build.variant}/{build.variant}-platform-conf.h' PREINCLUDE_FILES='{build.core.path}/weak_pragmas.h' {build.trace} SDK_BASE_DIR=C:/MWSDK/ChipLib/SW4063V1416 FLASH_PROGRAMMER=C:/MWSDK/Tools/ProductionFlashProgrammer/JN51xxProgrammer.exe
twelite.build.make.vars=target_makefile='{runtime.platform.path}/variants/{build.variant}/Makefile.variant' CONTIKI_TARGET_MAIN=override-contiki-jn516x-main.c TARGET_WITH_UART1=1 PLATFORM_CONF_H='{runtime.platform.path}/variants/{build.variant}/{build.variant}-platform-conf.h' PREINCLUDE_FILES='{build.core.path}/weak_pragmas.h' {build.trace} {build.rpl} SDK_BASE_DIR=C:/MWSDK/ChipLib/SW4063V1416 FLASH_PROGRAMMER=C:/MWSDK/Tools/ProductionFlashProgrammer/JN51xxProgrammer.exe
twelite.build.make.goals={build.project_name}.bin {build.project_name}.hex {build.project_name}.elf
twelite.menu.config.TWELITE_BLUE=TWELITE BLUE
twelite.menu.config.TWELITE_BLUE.build.config_vars=CHIP=JN5164 LINKCMD='{runtime.platform.path}/variants/{build.variant}/ldscript/Arduinize.ld'
twelite.menu.config.TWELITE_RED=TWELITE RED
twelite.menu.config.TWELITE_RED.build.config_vars=CHIP=JN5169 LINKCMD='{runtime.platform.path}/variants/{build.variant}/ldscript/Arduinize_JN5169.ld'
twelite.menu.trace.OFF=Trace Off
twelite.menu.trace.OFF=Off
twelite.menu.trace.OFF.build.trace=
twelite.menu.trace.ON=Trace On
twelite.menu.trace.ON=On
twelite.menu.trace.ON.build.trace=TRACE=1
twelite.menu.rpl.ON=Enable
twelite.menu.rpl.ON.build.rpl=CONTIKI_WITH_RPL=1
twelite.menu.rpl.OFF=Disable
twelite.menu.rpl.OFF.build.rpl=CONTIKI_WITH_RPL=0

native.name=native
native.upload.tool=contiki-makehelper
Expand Down
9 changes: 9 additions & 0 deletions cores/arduino/IPAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,14 @@ class IPAddress : public Printable {
};

const IPAddress INADDR_NONE;
#if NETSTACK_CONF_WITH_IPV6
const IPAddress IN6ADDR_ANY_INIT(0, 0, 0, 0, 0, 0, 0, 0);
const IPAddress IN6ADDR_LOOPBACK_INIT(0, 0, 0, 0, 0, 0, 0, 1);
const IPAddress IN6ADDR_LINKLOCAL_ALLNODES_INIT( 0xff02,0,0,0, 0,0,0,1);
const IPAddress IN6ADDR_LINKLOCAL_ALLROUTERS_INIT(0xff02,0,0,0, 0,0,0,2);
const IPAddress IN6ADDR_INTERFACELOCAL_ALLNODES_INIT(0xff01,0,0,0, 0,0,0,1);
const IPAddress IN6ADDR_INTERFACELOCAL_ALLROUTERS_INIT(0xff01,0,0,0, 0,0,0,2);
const IPAddress IN6ADDR_SITELOCAL_ALLROUTERS_INIT(0xff05,0,0,0, 0,0,0,2);
#endif

#endif
2 changes: 1 addition & 1 deletion cores/arduino/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ PROCESS_THREAD(main_thread, ev, data)

void yield()
{
YIELD_TO_MAIN_THREAD(WT_PAUSE, NULL, NULL, NULL, NULL);
delay(0);
}

void yield_until(fp_run run, void* run_param, fp_condition condition, void* condition_param)
Expand Down
4 changes: 2 additions & 2 deletions dist/submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"path": "system/contiki",
"url": "https://github.com/soburi/contiki",
"revision": "441f679658fee95fd93013af51d884cce6c988ab"
"revision": "c661080b2946bac7e616ecd7e32e95a8863f134e"
},
{
"path": "system/contiki/cpu/cc26xx-cc13xx/lib/cc13xxware",
Expand Down Expand Up @@ -34,4 +34,4 @@
"url": "https://github.com/g-oikonomou/sensniff.git",
"revision": "0d57c1129b601d29a58bffe6e34803af5e1701af"
}
]
]
135 changes: 135 additions & 0 deletions libraries/uIP/examples/Udp7EchoClientServer/Udp7EchoClientServer.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
Udp7EchoClientServer:
This is a client / server program which communicate
by "well-known udp/7" echo protocol.
Write same program to 2 nodes to use.
One is act as server, the other is client.
Program is start as echo server at boot up.
Server send response same data what if data received.
Enter the IPv6 address of the server to serial,
and act as a client when the address is recognized.
This program must compile with [RPL: "disabled"] configuration.
created 29 May 2018
by Tokita Hiroshi
*/

#include <MicroIp.h>
#include <MicroIpUdp.h>

IPAddress destAddr;

const size_t MAX_PAYLOAD_LEN = 33;
const size_t MAX_V6_ADDR_STR = 40;

const unsigned int ECHO_PORT = 7;

char packetBuffer[MAX_PAYLOAD_LEN];
char serialBuffer[MAX_V6_ADDR_STR];
size_t serialBufferLen;

MicroIPUDP Udp;

void setup() {
Serial.begin(1000000);

Serial.print("Echo protocol (");
Serial.print(ECHO_PORT);
Serial.println("/udp) listen start.");
Serial.println();

MicroIP.begin();

// Show link-local address
Serial.print("This linklocal Address is ");
Serial.println(MicroIP.linklocalAddress());
Serial.println();

Udp.begin(ECHO_PORT);

Serial.println();
Serial.println("Enter destination IP address.");
Serial.println("Or invalid IP address is entered, stop sending.");
Serial.println();
}

void loop() {

if (Serial.available())
{
memset(serialBuffer, 0, MAX_V6_ADDR_STR);
serialBufferLen = Serial.readBytes(serialBuffer, MAX_V6_ADDR_STR);

// Set destination IPaddress when string received from serial line.
if (destAddr == IN6ADDR_ANY_INIT)
{
bool valid = destAddr.fromString(serialBuffer);
if (valid)
{
Serial.print("Destination IP is ");
Serial.println(destAddr);
Serial.println("Enter message to send.");
}
else
{
Serial.print(serialBuffer);
Serial.println(" is invalid. Stop sending.");
}
serialBufferLen = 0;
}
}

// When destination is set, send serial buffer
if (!(destAddr == IN6ADDR_ANY_INIT) && serialBufferLen != 0)
{
// construct send data
memcpy(packetBuffer, serialBuffer, serialBufferLen);

Serial.print("Send to [");
Serial.print(destAddr);
Serial.print("]:");
Serial.print(ECHO_PORT);
Serial.print(" :");
Serial.println(serialBuffer);

// send packet
Udp.beginPacket(destAddr, ECHO_PORT);
Udp.write(serialBuffer, min(MAX_PAYLOAD_LEN, serialBufferLen) );
Udp.endPacket();

serialBufferLen = 0;
}

// print received data.
while (int packetSize = Udp.parsePacket()) {
Serial.print("Received packet from [");
Serial.print(Udp.remoteIP());
Serial.print("]:");
Serial.print(Udp.remotePort());
Serial.print(" datasize=");
Serial.println(packetSize);

// Read the packet into packetBufffer
memset(packetBuffer, 0, MAX_PAYLOAD_LEN);
Udp.read(packetBuffer, MAX_PAYLOAD_LEN);

if (destAddr == Udp.remoteIP()) {
// Not response to echo.
Serial.print("Received: ");
Serial.println(packetBuffer);
}
else {
// Send echo
Serial.print("Echo: ");
Serial.println(packetBuffer);
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(packetBuffer, packetSize);
Udp.endPacket();
}
}

}
113 changes: 84 additions & 29 deletions libraries/uIP/examples/udp-echo-client/udp-echo-client.ino
Original file line number Diff line number Diff line change
@@ -1,52 +1,107 @@
/*
UDP Echo client
A simple UDP communication demo.
The program send simple message to 'udp-echo-server-rpl' node,
the server node send echo on the message received.
The received echo message shows on serial port.
Even if RPL is enabled or disabled works.
Use same settings to compile server side programs.
This programs behavior is based on contiki os's
example(examples/udp-ipv6/udp-client.c).
created 24 Jan 2016
modified 29 May 2018
by Tokita Hiroshi
*/

#include <MicroIp.h>
#include <MicroIpUdp.h>
#include <IPAddress.h>

IPAddress server(0xaaaa, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001);

unsigned int localPort = 7;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
const size_t MAX_PAYLOAD_LEN = 40;
const char* UDP_CONNECTION_ADDR = "contiki-udp-server.local";
const unsigned short LOCAL_PORT = 3001;
const unsigned short DEST_PORT = 3000;
const int INTERVAL = 15;

MicroIPUDP Udp;
IPAddress server;

char packetBuffer[MAX_PAYLOAD_LEN];
long lastsend;
long seq_id;

void setup() {
Serial.begin(115200);
Serial.begin(1000000);
Serial.println("Start udp-echo-cleint");
MicroIP.begin();

server = MicroIP.lookup("udp-echo-server.local");
Udp.begin(localPort);
server = MicroIP.lookup(UDP_CONNECTION_ADDR);

if (server == IN6ADDR_ANY_INIT) {
Serial.print("Server [");
Serial.print(UDP_CONNECTION_ADDR);
Serial.println("] is not found.");
while (true) {
yield();
}
}

Serial.print("Server ");
Serial.print(UDP_CONNECTION_ADDR);
Serial.print(" is [");
Serial.print(server);
Serial.println("]");

Udp.begin(LOCAL_PORT);
Serial.print("Start listen port:");
Serial.println(LOCAL_PORT);
}

void loop() {

int avail = Serial.available();
if(avail) {
int len = min(avail, UDP_TX_PACKET_MAX_SIZE);
long now = millis();

for(int i=0; i<len; i++) {
packetBuffer[i] = Serial.read();
}
// Periodically send.
if ((now - lastsend) > (INTERVAL * 1000)) {
// format message
memset(packetBuffer, 0, MAX_PAYLOAD_LEN);
strcpy(packetBuffer, "Hello ");
itoa(++seq_id, packetBuffer + strlen(packetBuffer), 10);
strcpy(packetBuffer + strlen(packetBuffer), " from the client");

Udp.beginPacket(server, localPort);
Udp.write(packetBuffer, len);
Serial.print("Client sending to ");
Serial.print(server);
Serial.print(" (msg: ");
Serial.print(packetBuffer);
Serial.println(");");

// send packet
Udp.beginPacket(server, DEST_PORT);
Udp.write(packetBuffer, strlen(packetBuffer));
Udp.endPacket();

lastsend = now;
}

while(int packetSize = Udp.parsePacket()) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = Udp.remoteIP();
Serial.print(remote);
Serial.print(", port ");
Serial.println(Udp.remotePort());
while (int packetSize = Udp.parsePacket()) {
/*
//more info
Serial.print("Receive from ");
Serial.print(Udp.remoteIP());
Serial.print(":");
Serial.print(Udp.remotePort());
Serial.print(" size:");
Serial.println(packetSize);
*/

// read the packet into packetBufffer
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
for(int i=0; i<packetSize; i++) {
Serial.print(packetBuffer[i]);
}
Serial.println();
Udp.read(packetBuffer, packetSize);
Serial.print("Response from the server: '");
Serial.print(packetBuffer);
Serial.println("'");
}

}
Loading

0 comments on commit 7aced9f

Please sign in to comment.