LeJOS Protocols. Serial Class Serial class found in josx.platform.rcx package Serial class found in josx.platform.rcx package RCX – IR, RCX – RCX communication.

Slides:



Advertisements
Similar presentations
Network Programming and Java Sockets
Advertisements

Introduction to Java 2 Programming Lecture 7 IO, Files, and URLs.
Socket Programming ENTERPRISE JAVA. 2 Content  Sockets  Streams  Threads  Readings.
MOD III. Input / Output Streams Byte streams Programs use byte streams to perform input and output of 8-bit bytes. This Stream handles the 8-bit.
Java I/O The Cheat Sheet. Reading and Writing The basic architecture of Java IO is pluggable. The idea is to have some very simple classes do very simple.
III. Streams. Introduction Often a program needs to bring in information from an external source or to send out information to an external destination.
Chapter - 12 File and Streams (continued) This chapter includes -  DataOutputStream  DataInputStream  Object Serialization  Serializing Objects 
Using Processing Stream. Predefined Streams System.in InputStream used to read bytes from the keyboard System.out PrintStream used to write bytes to the.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Internetworking (Contd) Chapter 4. Figure 3.26 ATM protocol layers.
Overview of Java I/O. Stream A Program often needs to read/write information from/to outer source/destination. Outer source/destination can be : –A File.
Java Networking -- Socket Server socket class: ServerSocket wait for requests from clients. after a request is received, a client socket is generated.
System Programming Practical session 11 Multiple clients server Non-Blocking I/O.
2: Application Layer1 Socket Programming. 2: Application Layer2 Socket-programming using TCP Socket: a door between application process and end- end-transport.
Programming with Lejos Part 1. What is lejos? Cut-down version of Java for the RCX platform Includes: –Lejos API –JVM API includes functionality needed.
Socket Communication Sockets provide an abstraction of two-point communication The two sides only read/write without concern for how data is translated.
User Datagram Protocol UDP. Remember, UDP is Not reliable; data may be dropped No guarantee of in-order delivery Duplicate data is possible No built-in.
WXES2106 Network Technology Semester /2005 Chapter 8 Intermediate TCP CCNA2: Module 10.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
SOCKET PROGRAMMING. Client/Server Communication At a basic level, network-based systems consist of a server, client, and a media for communication as.
Patterns, frameworks & Lejos
NET0183 Networks and Communications Lecture 31 The Socket API 8/25/20091 NET0183 Networks and Communications by Dr Andy Brooks Lecture powerpoints from.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
5-Oct-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Streams and Files Maj Joel Young.
Prepared by : A.Alzubair Hassan Kassala university Dept. Computer Science Lecture 2 I/O Streams 1.
HW2: Q&A Oct. 02, Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign.
UDP vs TCP UDP Low-level, connectionless No reliability guarantee TCP Connection-oriented Not as efficient as UDP.
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
Chapter 9 1 Chapter 9 – Part 1 l Overview of Streams and File I/O l Text File I/O l Binary File I/O l File Objects and File Names Streams and File I/O.
Lecture 9 Network programming. Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet.
1 Week 12 l Overview of Streams and File I/O l Text File I/O Streams and File I/O.
Li Tak Sing COMPS311F. Case study: consumers and producers A fixed size buffer which can hold at most certain integers. A number of producers which generate.
1 Network Programming and Java Sockets. 2 Network Request Result a client, a server, and network Client Server Client machine Server machine Elements.
From Coulouris, Dollimore, Kindberg and Blair Distributed Systems: Concepts and Design Edition 5, © Addison-Wesley 2012 Slides for Chapter 4: Interprocess.
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
Introduction to Programming G50PRO University of Nottingham Unit 11 : Files Input/Ouput Paul Tennent
1 cs205: engineering software university of virginia fall 2006 Network Programming* * Just enough to make you dangerous Bill Cheswick’s map of the Internet.
Slides for Chapter 4: Interprocess Communication From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 4, © Addison-Wesley.
2: Application Layer1 Socket programming Socket API Explicitly created, used, released by apps Client/server paradigm Two types of transport service via.
Java Server Programming Web Interface for Java Programs.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
By Vivek Dimri. Basic Concepts on Networking IP Address – Protocol – Ports – The Client/Server Paradigm – Sockets The Java Networking Package – The InetAddress.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
I/O Basics 26 January Aside from print( ) and println( ), none of the I/O methods have been used significantly. The reason is simple: most real.
Prepared by Dr. Jiying Zhao University of Ottawa Canada.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
Java Programming II Java Network (I) Java Programming II.
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
CSE 501N Fall ‘09 22: Introduction to Networking November Nick Leidenfrost.
Network Programming with Java java.net.InetAddress: public static void main(String[] args) throws UnknownHostException { InetAddress localAddress = InetAddress.getLocalHost();
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
File Input & Output1 Streams & File I/O. Introduction (1) The Java platform includes a number of packages that are concerned with the movement of data.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
Generic Connection Framework Connection FileConnectionSocketConnectionHTTPConnection InputConnection OutputConnection StreamConnection.
Network Programming Communication between processes Many approaches:
Java 13. Networking public class SumTest {
Sequential files creation & writing
Transport Layer.
PRESENTED To: Sir Abid………. PRESENTED BY: Insharah khan………. SUBJECT:
Accessing Files in Java
null, true, and false are also reserved.
Input and Output Stream
class PrintOnetoTen { public static void main(String args[]) {
Sadalage & Fowler (Amazon)
CPSC 441 UDP Socket Programming
Socket Programming with UDP
Podcast Ch23c Title: Binary Files
Review Communication via paired sockets, one local and one remote
Presentation transcript:

leJOS Protocols

Serial Class Serial class found in josx.platform.rcx package Serial class found in josx.platform.rcx package RCX – IR, RCX – RCX communication RCX – IR, RCX – RCX communication sendPacket(byte[] aBuffer, int aOffset, int aLen) sendPacket(byte[] aBuffer, int aOffset, int aLen) Returns a true or a false based on whether the send was completed or not Returns a true or a false based on whether the send was completed or not Sends a packet to an IR tower or to a RCX Sends a packet to an IR tower or to a RCX isPacketAvailable() isPacketAvailable() Checks to see if a packet is available Checks to see if a packet is available readPacket(byte[] aBuffer) readPacket(byte[] aBuffer) Reads a packet received by the RCX, if available Reads a packet received by the RCX, if available

rcxcomm package Provides methods for communicating between the PC and the RCX Provides methods for communicating between the PC and the RCX 2 types of protocols based on LLC and LNP 2 types of protocols based on LLC and LNP IR signal – physical layer IR signal – physical layer Before any kind of communication the ports need to be opened(open()). Before any kind of communication the ports need to be opened(open()). Likewise at the end the ports need to be closed(close()). Likewise at the end the ports need to be closed(close()).

LLC 2 messaging layers 2 messaging layers LLC Handler LLC Handler LLCReliableHandler LLCReliableHandler Deals with data packets and acks. Deals with data packets and acks. Allows data to be sent in both directions Allows data to be sent in both directions Broadcast protocol Broadcast protocol Data is read from the input stream at the default port by using read(). Data is read from the input stream at the default port by using read(). Data is written to the output stream at the default port by using write(). Data is written to the output stream at the default port by using write().

LLC Reliable Handler Guarantees reliable delivery using checksums,acks and single bit sequence number Guarantees reliable delivery using checksums,acks and single bit sequence number Packet organization Packet organization Sequence NumberData Checksum

RCXLNP Port/Addressing Based on LNP protocol ( leJOS onwards) Based on LNP protocol ( leJOS onwards) Has 3 messaging layers Has 3 messaging layers LNPHandler LNPHandler LNPIntegrityHandler LNPIntegrityHandler LNPAddressingHandler LNPAddressingHandler RCXLNPPort class supports only broadcasting. RCXLNPPort class supports only broadcasting. RCXLNPAddressing class supports point to point addressing. RCXLNPAddressing class supports point to point addressing.

RCXLNP Port/Addressing 2 types of addressing 2 types of addressing Between specific RCX’s Between specific RCX’s Between a PC and a RCX. Between a PC and a RCX. 2 types of packets 2 types of packets Integrity Integrity Addressing Addressing Integrity packets are broadcast. Integrity packets are broadcast. Addressing packets have specific source and destination addresses. Addressing packets have specific source and destination addresses. Opcodes used to distinguish between broadcasting and addressing. Opcodes used to distinguish between broadcasting and addressing. 0xf0 – Broadcasts 0xf0 – Broadcasts 0xf1 – Addressing 0xf1 – Addressing

RCXLNP Addressing LNPHandler LNPHandler Implements the LNP packet format Implements the LNP packet format LNPIntegrityHandler LNPIntegrityHandler Handles the checksums for reliability Handles the checksums for reliability LNPAddressingHandler LNPAddressingHandler Implements addressing Implements addressing OpCode Size of the Packet Data Checksum Destination Source

Examples import josx.platform.rcx.*; import josx.platform.rcx.*; class Sender class Sender { public static void main(String [] args) { public static void main(String [] args) { Sender s = new Sender(); Sender s = new Sender(); try { try { for(byte i=0;i<200;++i) { for(byte i=0;i<200;++i) { Button.RUN.waitForPressAndRelease(); Button.RUN.waitForPressAndRelease(); Sound.beep(); Sound.beep(); s.sendByte(i); s.sendByte(i); } } } catch(Exception e){} catch(Exception e){} } } private byte[] packet = {(byte)0xf7, (byte)0x00}; private byte[] packet = {(byte)0xf7, (byte)0x00}; /** /** * Send a single byte * Send a single byte */ */ protected void sendByte(byte b) { protected void sendByte(byte b) { packet[1] = b; packet[1] = b; josx.platform.rcx.Serial.sendPacket(packet, 0, 2); josx.platform.rcx.Serial.sendPacket(packet, 0, 2); } } }

import josx.platform.rcx.*; import josx.platform.rcx.*; public class Receiver { public class Receiver { public static void main(String [] args) throws Exception { public static void main(String [] args) throws Exception { Receiver r = new Receiver(); Receiver r = new Receiver(); for(;;) { for(;;) { if(Serial.isPacketAvailable()) { if(Serial.isPacketAvailable()) { Sound.beep(); Sound.beep(); LCD.showNumber(r.receiveByte()); LCD.showNumber(r.receiveByte()); } } private byte[] buffer = new byte[10]; private byte[] buffer = new byte[10]; /** /** * Receive a single byte * Receive a single byte */ */ protected byte receiveByte() { protected byte receiveByte() { josx.platform.rcx.Serial.readPacket(buffer); josx.platform.rcx.Serial.readPacket(buffer); return buffer[1]; return buffer[1]; } } }

import java.io.*; import java.io.*; import josx.rcxcomm.*; import josx.rcxcomm.*; public class ReadSensor { public class ReadSensor { public static void main(String[] args) { public static void main(String[] args) { try { try { RCXPort port = new RCXPort(); RCXPort port = new RCXPort(); InputStream is = port.getInputStream(); InputStream is = port.getInputStream(); OutputStream os = port.getOutputStream(); OutputStream os = port.getOutputStream(); DataInputStream dis = new DataInputStream(is); DataInputStream dis = new DataInputStream(is); DataOutputStream dos = new DataOutputStream(os); DataOutputStream dos = new DataOutputStream(os); System.out.println("Reading Light Sensor"); System.out.println("Reading Light Sensor"); int sendTime = (int)System.currentTimeMillis(); int sendTime = (int)System.currentTimeMillis(); for(int i=0;i<20;i++) { for(int i=0;i<20;i++) { dos.writeByte(1); dos.writeByte(1); dos.flush(); dos.flush(); int n = dis.readShort(); int n = dis.readShort(); System.out.println("Received " + n); System.out.println("Received " + n); } } System.out.println("Time = " + ((int)System.currentTimeMillis() - sendTime)); System.out.println("Time = " + ((int)System.currentTimeMillis() - sendTime)); } } catch (Exception e) { catch (Exception e) { System.out.println("Exception " + e.getMessage()); System.out.println("Exception " + e.getMessage()); } } }

import java.io.*; import java.io.*; import josx.rcxcomm.*; import josx.rcxcomm.*; import josx.platform.rcx.*; import josx.platform.rcx.*; public class SensorReader { public class SensorReader { public static void main(String args[]) { public static void main(String args[]) { int sensorID, sensorValue; int sensorID, sensorValue; RCXPort port = null; RCXPort port = null; try { try { port = new RCXPort(); port = new RCXPort(); DataOutputStream out = new DataOutputStream(port.getOutputStream()); DataOutputStream out = new DataOutputStream(port.getOutputStream()); while (true) { while (true) { sensorID = port.getInputStream().read(); sensorID = port.getInputStream().read(); sensorValue = Sensor.readSensorValue(sensorID, 0); sensorValue = Sensor.readSensorValue(sensorID, 0); LCD.showNumber(sensorValue); LCD.showNumber(sensorValue); out.writeShort(sensorValue); out.writeShort(sensorValue); out.flush(); out.flush(); } } } catch (IOException ioE) { } catch (IOException ioE) { LCD.showNumber(1111); LCD.showNumber(1111); } finally { } finally { port.close(); port.close(); } } }

References lejos.sourceforge.net lejos.sourceforge.net rcxcomm package rcxcomm package