Communication on a wire - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Communication on a wire

Description:

Cars vs Buses. A point-to-point connection is just a wire connecting two end-points. ... share this transmission path. Unlike RS 232, TX and RX share same ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 13
Provided by: orgCsa
Category:

less

Transcript and Presenter's Notes

Title: Communication on a wire


1
(No Transcript)
2
Communication on a wire
  • Bits on a wire
  • sender and receiver agree on data rate, r.
  • sender puts new bit on wire every 1/r seconds
  • receiver can figure out the start time of each
    bit either by a phase-lock loop or sync clocks.
  • phase lock loops takes time for the receiver to
    zoom in on when the
  • Time Division Multiplexing (TDM)
  • messages always start at specific times and for
    specific duration of time

3
Cars vs Buses
  • A point-to-point connection is just a wire
    connecting two end-points.
  • RS 232 (Com ports, serial connection)
  • TX and RX lines
  • Printer port (parallel connection)
  • A Bus connection is just a wire connecting more
    than two end-points
  • ISA (old fashion card connection in PCs)
  • same connector CF cards
  • PCI (modern connection for putting boards into a
    PC, such as a sound card)
  • same connector as PC-Card, usually found on
    laptops)

4
Wireless Data Communication
  • It all started in Hawaii with the Aloha-net
  • Radio link between Islands and Mainland
  • How to know when to transmit?
  • Listen and if quiet then transmit
  • But what if two stations hear silence and then
    transmit?
  • garbled result
  • Talk and listen at same time
  • if hear other transmissions, stop, wait random
    time and try again if silence.

5
Ethernet (wireless in a wire)
6
USB
  • Two signal lines carry data
  • All devices share this transmission path
  • Unlike RS 232, TX and RX share same signal line
  • Traffic divided into Frames or microframes
  • Low and Full Speeds frame is one millisecond
  • High Speeds Frame divided into 8 microframes
  • microframe is 125 microsecond
  • Each frame begins with Start-of-Frame timing
    reference

7
Python Sockets (Server)
import sys import socket if len(sys.argv) lt 2
print "usage socketserver ltportgt"
sys.exit(2) create the server socket s
socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port int(sys.argv1) allow the socket to
be re-used immediately after a close s.setsockopt(
socket.SOL_SOCKET, socket.SO_REUSEADDR,
1) s.bind( ("0.0.0.0", port) )
8
Python Sockets (Server)
start the server socket s.listen(5) print
"waiting for new connection on port d"
port (client, address) s.accept() print
"accepted connection from sd" (address0,
address1) while True data
client.recv(1024) if len(data) 0
print "connection with s closed." address0
break sys.stdout.write(data) client.cl
ose()
9
Python Sockets (Client)
import sys import socket if len(sys.argv) lt 3
print "usage socketclient ltaddressgt ltportgt"
sys.exit(2) s socket.socket(socket.AF_INET,
socket.SOCK_STREAM) s.connect( (sys.argv1,
int(sys.argv2) ) ) print "connected. type
stuff." while True data
sys.stdin.readline() if len(data) 0
print "closing connection with server"
break s.send(data)
10
Bluetooth
  • Like a combination of USB and 802.11 (WiFi)
  • More like ad-hoc WiFi network
  • most people use infrastructure mode
  • Discovery
  • WiFi -- use IP addresses
  • of DNS, but need to know IP of DNS server
  • DHCP sends all this IP info to new attached
    device
  • Rendezvous (pushed by Apple) -- discover WiFi
    devices nearby. This is like Bluetooth
  • We are building Python interfaces

11
BluetoothL2CapSource
// set the connection parameters (who
to connect to) memset(addr, 0,
sizeof(addr)) addr.l2_family
AF_BLUETOOTH addr.l2_psm htobs(L2S_PSM)
baswap(addr.l2_bdaddr, strtoba(dest)) //
connect to server if( connect(s, (struct
sockaddr )addr, sizeof(addr)) lt 0 )
perror("connect") return -1
printf("connected. type stuff.\n")
while(1) bytes_read read(1, buf,
BUF_SZ) if( bytes_read lt 0 ) break
// write buffer to the bluetooth connection
if( write(s, buf, bytes_read) lt 0 )
break close(s)
/ file l2capsource.c auth albert huang
(albert_at_csail.mit.edu) desc gcc
-o l2capsource l2capsource.c -lbluetooth
/ include ltunistd.hgt include
ltstdio.hgt include ltstring.hgt include
ltsys/socket.hgt include ltbluetooth/bluetooth.hgt i
nclude ltbluetooth/l2cap.hgt define L2S_PSM
0x1001 define BUF_SZ 300 int main(int argc,
char argv) struct sockaddr_l2 addr
int s, err, bytes_read char bufBUF_SZ
if(argc lt 2) fprintf(stderr,
"usage s ltbt_addrgt\n", argv0)
exit(2) char dest18
memset(dest, 0, 18) strncpy(dest, argv1,
18) // allocate a socket if ((s
socket(PF_BLUETOOTH, SOCK_SEQPACKET,
BTPROTO_L2CAP)) lt 0) return -1
12
BluetoothL2CapSink
/ file l2capsink.c auth albert huang
(albert_at_csail.mit.edu) desc Opens
up a listening L2CAP socket on a predefined PSM
and accepts one connection. Outputs all
data received on that conncetion to stdout.
gcc -o l2capsink l2capsink.c -lbluetooth
/ include ltunistd.hgt include
ltstdio.hgt include ltstring.hgt include
ltsys/socket.hgt include ltbluetooth/bluetooth.hgt i
nclude ltbluetooth/l2cap.hgt define L2S_PSM
0x1001 define BUF_SZ 1024 int main(int argc,
char argv) struct sockaddr_l2 loc_addr,
rem_addr int s, client, opt, bytes_read
char bufBUF_SZ // allocate socket s
socket(PF_BLUETOOTH, SOCK_SEQPACKET,
BTPROTO_L2CAP) // bind socket to first
available bluetooth device on local machine
memset(loc_addr, 0, sizeof(loc_addr))
loc_addr.l2_family AF_BLUETOOTH baswap(
loc_addr.l2_bdaddr, BDADDR_ANY )
loc_addr.l2_psm htobs(L2S_PSM) bind(s,
(struct sockaddr )loc_addr, sizeof(loc_addr))

// put socket into listening mode
listen(s, 10) // accept one connection
opt sizeof(rem_addr) fprintf(stderr,
"waiting for connection on PSM 0xx\n",
L2S_PSM) client accept(s, (struct sockaddr
)rem_addr, opt) memset(buf, 0, BUF_SZ)
ba2str( rem_addr.l2_bdaddr, buf )
fprintf(stderr, "accepted connection from s\n",
buf) while(1) memset(buf, 0,
BUF_SZ) // read data from the client
bytes_read read(client, buf, BUF_SZ)
if(bytes_read lt 0) break write(0,
buf, bytes_read) memset(buf, 0,
BUF_SZ) ba2str( rem_addr.l2_bdaddr, buf )
fprintf(stderr, "connection closed with s\n",
buf) close(client) close(s)
Write a Comment
User Comments (0)
About PowerShow.com