week6

Siteplayer

 

10/15/03

I made a team with JungEun. And we decide to use siteplayer although we don't know at all about siteplayer. Because I ordered all parts of siteplayer board and I can't give up to use this. So the long suffer of this week starts. I am going to write down to keep in mind or refer it later in detail what I understood, suffered and expereinced.

1. SPD file
2. SPI files
3. HTML files
4. PIC code on the Siteplayer board
5. A few things to know
6. still confusing parts (Java)
7. Asciitable

At first, I opened 'siteplayer tester' in the start menu and check the siteplayer MAC address. If I can see a Mac address, it's a good news that your siteplayer is OK. Then if I click on the "Get IP" button you can see that my siteplayer is set 192.168.1.250. as default. So I need to set up your IP address by hitting button of "set IP". To confirm it, open a web browser and go to the address I set it to. I can get a page indicating successful connection to the siteplayer. Now I am ready to start programming on my siteplayer.

To program on my siteplayer, I need to prepare a few files before.

http://stage.itp.nyu.edu/~tigoe/pcomp/siteplayer/siteplayer-intro.shtml

At first, I need SPD file(siteplayer definition file), HTML file, SPI file(siteplayer interface file). in the spd file, I am going to use Tom's Map.spd example at first time. But I need to fix the contents little bit.

Here is my spd file.

SPD file
counter.spi
Download file(index.html)
indexer.spi
testpage.html

Compare it with Tom's which is at :

SPD file
counter.spi
Download file(index.html)
indexer.spi
testpage.html

http://stage.itp.tsoa.nyu.edu/~tigoe/pcomp/blog/archives/cat_networked_objects.shtml.

 

And here are the MAC and IP address which I am going to use.

my siteplayer MAC address
00-03-75-0F-57-3A
128.122.151.108

Jung Eun's siteplayer MAC address
00-03-75-0F-51-82
128.122.151.139

1. SPD file

;$devicename sets the name or description of the device
$devicename
"HJ's Siteplayer"

;$DHCP on tells Siteplayer to find its IP address from a DHCP server
$DHCP
on (or $ DHCP off)

;$DownloadPassword sets password for downloading web pages
$DownloadPassword
"password"

;$SitePassword sets password for browsing web pages
$SitePassword ""

;$InitialIP sets Siteplayer's IP address to use
$InitialIP
"128.122.151.108"

;$Sitefile sets the binary image filename that will be created
$sitefile
"C:\WINDOWS\Desktop\siteplayer\map.spb"

;$Sitepath sets the root path of the web pages for this project
$sitepath
"C:\WINDOWS\Desktop\siteplayer\1016"

;$Include sets the name of a file to include during make process
$Include "C:\Program Files\Siteplayer\pcadef.inc"

org 0h
byteVar dB 2 ;a byte variable with the initial value 2
fooVar dB 0 ;a byte variable with the initial value 0
bigVar dw 921 ;a word variable with the initial value 921


; This series of variables holds a 7-byte message;
; it's the format for sending one byte (the dataByte, below)
; to another siteplayer.

org 0Ah
header db "OBJ"
loch db "FFFF"
locv db "FFFF"
sensorType db "D"
sensorValue db "FF"

org 0FF1Ah
baudrate dw 65015 ; set serial baud rate to 9600

org 02D0h
; TOM's powerbook
udpmac1 dhex 00h
udpmac2 dhex 03h
udpmac3 dhex 93h
udpmac4 dhex 5Ah
udpmac5 dhex D3h
udpmac6 dhex 1Ch
udpip1 db 128
udpip2 db 122
udpip3 db 151
udpip4 db 128
udpport dw 26482
udpaddr dw 0Ah
udpcount dw 14

org FFE6h ; the IP address of this siteplayer

myip1 ds 1
myip2 ds 1
myip3 ds 1
myip4 ds 1

I changed my name for my siteplayer, although it's not important. Then I am not sure what's different between '$DHCP on' or '$ DHCP off'. Anyway, DHCP means 'Dynamic Host Change Protocol'. And changing password at this time made me disturbed later. because when this spd file compliled, next siteplayer remember this password for downloading. So I need to rember always the past password. And in siteplayer Linker program you need to fix it at the password section. And before downloading I made sure that the spd file is on some folder and the others, spi and html files should be placed in the same sub folder in the spd folder. and in the spd file I need to set the what name will be put for the spb file.
$sitefile "C:\WINDOWS\Desktop\hje\map.spb"

and what is the sub folder name including html and spi files
$sitepath "C:\WINDOWS\Desktop\hje\1016"

the spd file seems to have a important relationship with HTML file. because HTML variable default seems to be set by the value in SPD. I will write it later.

2. SPI files

<indexer.spi>
HTTP/1.0 302 Found
Location: /index.htm

<counter.spi>
HTTP/1.0 302 Found
Location: /testpage.htm

this file seems to let the siteplayer find the route. According to Tom's page;
The SPI file allows you to input data to the siteplayer from a browser using the GET method, much like a CGI script on a regular server. The SPI file can return perform any function in the HTTP 1.0 specification. Most commonly, it's used to redirect the browser to a new page after a form has been completed. It's possible to use objects in the SPI file to direct the browser to different pages depending on the value of a variable.

3. HTML files

<html>
<head>

<title>Midterm!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="yellow"><p>
<h2>Midterm!</h2>
My IP address: 128.122.151.108
<P>
<P>
<a href="indexer.spi?COM=A">Send an &quot;A&quot; (ascii 65) out the serial port</A><BR>
<a href="indexer.spi?COM=B">Send a &quot;B&quot; (ascii 66) out the serial port</A><BR>
<a href="indexer.spi?COM=Hello%20World!%0A%0D">Send Hello World! out the serial port</A><BR>
<a href="indexer.spi?COM=%00">Send a 0 (ascii 0) out the serial port</A><BR>
<a href="indexer.spi?com=%01%FF">send the value 1 and the value 255 (FF in hexadecimal)</a>
<P>
<a href="indexer.spi?COM=0">Send &quot;0&quot; (ascii 48) out the serial port</A><BR>
<a href="indexer.spi?COM=1">Send &quot;1&quot; (ascii 49) out the serial port</A><BR>
<a href="indexer.spi?COM=2">Send &quot;2&quot; (ascii 50) out the serial port</A><BR>
<a href="indexer.spi?COM=3">Send &quot;3&quot; (ascii 51) out the serial port</A><BR>
<a href="indexer.spi?COM=4">Send &quot;4&quot; (ascii 52) out the serial port</A><BR>
<a href="indexer.spi?COM=5">Send &quot;5&quot; (ascii 53) out the serial port</A><BR>
<a href="indexer.spi?COM=6">Send &quot;6&quot; (ascii 54) out the serial port</A><BR>
<a href="indexer.spi?COM=7">Send &quot;7&quot; (ascii 55) out the serial port</A><BR>
<a href="indexer.spi?COM=8">Send &quot;8&quot; (ascii 56) out the serial port</A><BR>
<a href="indexer.spi?COM=9">Send &quot;9&quot; (ascii 57) out the serial port</A><BR>

<P>
udprcvr = 1<br><br>
<P>

<P>
<form method="get" action="counter.spi">
<div align="left"><b><font size="4">UDP Send</font></b><br>
MAC Address (Hex)
<input type="text" name="udpmac1" size="3" maxlength="3" value="00">-
<input type="text" name="udpmac2" size="3" maxlength="3" value="03">-
<input type="text" name="udpmac3" size="3" maxlength="3" value="93">-
<input type="text" name="udpmac4" size="3" maxlength="3" value="5A">-
<input type="text" name="udpmac5" size="3" maxlength="3" value="D3">-
<input type="text" name="udpmac6" size="3" maxlength="3" value="1C">
<br>
IP Address
<input type="text" name="udpip1" size="3" maxlength="3" value="128">.
<input type="text" name="udpip2" size="3" maxlength="3" value="122">.
<input type="text" name="udpip3" size="3" maxlength="3" value="151">.
<input type="text" name="udpip4" size="3" maxlength="3" value="128">
: Port
<input type="text" name="udpport" size="5" maxlength="5" value="26482">
<br>

SitePlayer Address (Decimal)
<input type="text" name="udpaddr" size="5" maxlength="5" value="10"><br>
Length
<input type="text" name="udpcount" size="4" maxlength="4" value="14"><br>
Header
<input type="text" name="Header" size="4" maxlength="4" value="OBJ"><br>
My location X
<input type="text" name="loch" size="4" maxlength="4" value="^loch"><br>
My location Y
<input type="text" name="locv" size="4" maxlength="4" value="^locv"><br>
Sensor Type
<input type="text" name="sensorType" size="4" maxlength="4" value="^sensorType"><br>
Sensor Value
<input type="text" name="sensorValue" size="4" maxlength="4" value="^sensorValue"><br>

<input type="hidden" name="udpsend" value="1">

<!-- the hidden field udpsend sends it out on submit-->
<input type="submit" name="Submit" value="Submit">
</div>
</form>


</body>
</html>

---------------------------------------------------------------

the spd file seems to have a important relationship with HTML file. because HTML variable default seems to be set due to the value in SPD. in the html, caret '^' represent variables, so you can see the change of variable on the screen directly.

org 0Ah
header db "OBJ"
loch db "FFFF"
locv db "FFFF"
sensorType db "D"
sensorValue db "FF"

syntax in the spd file comes in html and set it to its default value. These seem to find their variable names. But here the the siteplayer address 'org 0Ah' looks very important.
SitePlayer Address (Decimal)

<input type="text" name="udpaddr" size="5" maxlength="5" value="10"><br> ;
at here decimal 10 means hex 0A, so it would look at the address 'OAh'.

to send a udp message the udp count sldo seems to imprtnat. if udpcount is set to 7, only 7 byte meaage is sent. And if it set to 14, then it send 14 bute message. OBJ, loch X, loc Y, Sensor type, Sensor value is the protocol to use for midterm. if I send this default messsge to broadcast and in the UDP send terster screen to see the result, I can see "4F 42 4A 46 46 46 46 46 46 46 46 41 42'

HEX : 4F 42 4A 46 46 46 46 46 46 46 46 41 42
Dec : 79 66 74 70 70 70 70 70 70 70 70 65 66
Ascii : O B J F F F F F F F F A B


if I send udpcount 15, then the send result appears like this in the udp sender tester.

HEX : 4F 42 4A 46 46 46 46 46 46 46 46 41 42 00
Dec : 79 66 74 70 70 70 70 70 70 70 70 65 66 0
Ascii : O B J F F F F F F F F A B

if I use sample spd file and send udp message, it appears like this

01 FE 19 FF 0A 00 00

because I set it like below and sent 7 byte because of using value updcount 7. 01 is numbyte, FE is compliment byte (255 - 1 =254 ), 19 FF are address , and 0A is databyte value, 00 00 are two tail bytes. simple... So i can guess that PIC is just sending data as follow what comes in the UDP message. because now I am using 'Serout2 PORTC.6, 84, [$50]' in the PIC 16F877. This syntax means whatever comes in the UDP message. send them all through serial out.

;$devicename sets the name or description of the device
$devicename "Tom's Siteplayer"

;$DHCP on tells Siteplayer to find its IP address from a DHCP server
$DHCP on

;$DownloadPassword sets password for downloading web pages
$DownloadPassword "password"

;$SitePassword sets password for browsing web pages
$SitePassword ""

;$InitialIP sets Siteplayer's IP address to use
$InitialIP "128.122.151.39"

;$Sitefile sets the binary image filename that will be created
$sitefile "C:\Documents and Settings\tigoe\My Documents\siteplayer apps\sampleapp\udpgame.spb"

;$Sitepath sets the root path of the web pages for this project
$sitepath "C:\Documents and Settings\tigoe\My Documents\siteplayer apps\sampleapp\site_root"

;$Include sets the name of a file to include during make process
$Include "C:\Program Files\Siteplayer\pcadef.inc"

org 0h
byteVar dB 2 ;a byte variable with the initial value 2
fooVar dB 0 ;a byte variable with the initial value 0
bigVar dw 921 ;a word variable with the initial value 921


; This series of variables holds a 7-byte message;
; it's the format for sending one byte (the dataByte, below)
; to another siteplayer.

org 0Ah
numBytes db 01
byteComplement db FEh
sendAddr1 db 19h
sendAddr2 db FFh
dataByte1 db 65
tailByte1 db 00
tailByte2 db 00

org 0FF1Ah
baudrate dw 65015 ; set serial baud rate to 9600

org 02D0h
udpmac1 dhex 255
udpmac2 dhex 255
udpmac3 dhex 255
udpmac4 dhex 255
udpmac5 dhex 255
udpmac6 dhex 255
udpip1 db 128
udpip2 db 122
udpip3 db 151
udpip4 db 255
udpport dw 26482
udpaddr dw 0Ah
udpcount dw 7


org FFE6h ; the IP address of this siteplayer

myip1 ds 1
myip2 ds 1
myip3 ds 1
myip4 ds 1

 

4. PIC code on the Siteplayer board

'****************************************************************
'* Name : UDPsend.BAS
'* Author : HYUN JEAN LEE and JUNG EUN YOO (modify Tom Igoe's)
'* Notice : Copyright (c) 2002
'* : All Rights Reserved
'* Date : 5/30/2002
'* Version : 1.0
'* Notes : Instructs SitePlayer to send UDP packets.
'* :
'* : Assumes the following hardware attached to PIC:
'* : serial out to siteplayer: portc.6
'* : serial in from siteplayer: portc.7
'* :
'* : Serial is not inverted in software.
'* : Serial signal goes through a hex inverter to
'* : Siteplayer.
'* :
'* : LED indicator: portc.5 --if it gets ascii A
'* : portD.3 --if it gets ascii B
'* : portB.7 --if it gets ascii 0
'* : portB.6 --if it gets ascii 1
'* : portB.5 --if it gets ascii 2
'* : portB.4 --if it gets ascii 3
'* : portB.3 --if it gets ascii 4
'* : portB.2 --if it gets ascii 5
'* : portB.1 --if it gets ascii 6
'* : portB.0 --if it gets ascii 7
'* : portD.5 --if it gets ascii 8
'* : portD.4 --if it gets ascii 9
'* :
'* : input switch: portc.4 --Send UDP
'* :
'****************************************************************
INCLUDE "modedefs.bas"

DEFINE OSC 4

input portc.4
output portc.5
output portd.3
outByte var byte
dataAddress var byte
indata var byte
indata = 0

' initial pause to make sure all components have stated:
Pause 500


' tell siteplayer to enable UDP Receives
' (set 0FF20h to 1):
'serout2 PORTC.6, 16468, [$90, $20, $FF, $01]
serout2 PORTC.6, 84, [$90, $20, $FF, $01]

main:
' if switch is closed, send a byte to the siteplayer
' and have the siteplayer send a UDP message:'
if portc.4 = 1 then
outbyte = 65

' memory address you want to write to in the SP:
dataAddress = 2
gosub sendByte
gosub sendUDP

else
' if the switch is open, then listen for
' serial messages from the siteplayer
' (return to main if no data in 100 ms):
'Serin2 PORTC.7, 16468, 100, main, [inData]
Serin2 PORTC.7, 84, 100, main, [inData]

'----different LEDs
if inData = 48 then '---if PortB.7 got ascii 0
High portB.7
Low portB.6
Low portB.5
Low portB.4
Low portB.3
Low portB.2
Low portB.1
Low portB.0
Low portD.5
Low portD.4
endif

if inData = 49 then '---if PortB.6 got ascii 1
High portB.6
Low portB.7
Low portB.5
Low portB.4
Low portB.3
Low portB.2
Low portB.1
Low portB.0
Low portD.5
Low portD.4
endif

if inData = 50 then '---if PortB.5 got ascii 2
high portB.5
Low portB.7
Low portB.6
Low portB.4
Low portB.3
Low portB.2
Low portB.1
Low portB.0
Low portD.5
Low portD.4
endif

if inData = 51 then '---if PortB.4 got ascii 3
high portB.4
Low portB.7
Low portB.6
Low portB.5
Low portB.3
Low portB.2
Low portB.1
Low portB.0
Low portD.5
Low portD.4
endif

if inData = 52 then '---if PortB.3 got ascii 4
high portB.3
Low portB.7
Low portB.6
Low portB.5
Low portB.4
Low portB.2
Low portB.1
Low portB.0
Low portD.5
Low portD.4
endif

if inData = 53 then '---if PortB.2 got ascii 5
high portB.2
Low portB.7
Low portB.6
Low portB.5
Low portB.4
Low portB.3
Low portB.1
Low portB.0
Low portD.5
Low portD.4
endif

if inData = 54 then '---if PortB.1 got ascii 6
high portB.1
Low portB.7
Low portB.6
Low portB.5
Low portB.4
Low portB.3
Low portB.2
Low portB.0
Low portD.5
Low portD.4
endif

if inData = 55 then '---if PortB.0 got ascii 7
high portB.0
Low portB.7
Low portB.6
Low portB.5
Low portB.4
Low portB.3
Low portB.2
Low portB.1
Low portD.5
Low portD.4
endif

if inData = 56 then '---if PortD.5 got ascii 8
high portD.5
Low portB.7
Low portB.6
Low portB.5
Low portB.4
Low portB.3
Low portB.2
Low portB.1
Low portB.0
Low portD.4
endif

if inData = 57 then '--- if PortD.4 got ascii 9
high portD.4
Low portB.7
Low portB.6
Low portB.5
Low portB.4
Low portB.3
Low portB.2
Low portB.1
Low portB.0
Low portD.5
endif

' if we got a 65 from the siteplayer, then
' turn on the LED:
if inData = 65 then
high portc.5
low portd.3
endif

' if we got a 66 from the siteplayer, then
' turn on the LED:
if inData = 66 then
high portd.3
low portc.5
endif

endif

goto main


sendByte:
' write a byte to the siteplayer's memory:
'Serout2 PORTC.6, 16468, [$80, dataAddress, outByte]
Serout2 PORTC.6, 84, [$80, dataAddress, outByte]
return

sendUDP:
' tell the siteplayer to send a UDP message:
'Serout2 PORTC.6, 16468, [$50]

Serout2 PORTC.6, 84, [$50]


High portB.7
High portB.6
High portB.5
High portB.4
High portB.3
High portB.2
High portB.1
High portB.0
High portD.5
High portD.4
pause 500
LOW portB.7
LOW portB.6
LOW portB.5
LOW portB.4
LOW portB.3
LOW portB.2
LOW portB.1
LOW portB.0
LOW portD.5
LOW portD.4


return

 


5. A few things to know

A .

Jumpers position

  When you are downloading SPD files using serial and Ethernet cable, the jumper locaton on the siteplayer board is important. you should it upper position. But after downloading you need to relocate jumper on the down position.
B. USP receive enable button
  If your connection is perfect, in the HTML page, you can notice it directly. Because you have to see that the radio button of 'UDP receive enable' is checked.
C. Download ports In the siteplayer Linker program
  you need to remember your password for next. And the downloading port needs to be set to '26481'.
D. Broadcasting
  MAC address : FF FF FF FF FF FF FF FF
  IP address : 128. 122.151. 255
E. In the siteplayer UDP send tester program,
  you need to set the port to '26482'. According to Tom's note, siteplayer only communicate through 26482 port.

 

6. still confusing parts

If I send ascii A using java file on the telnet stage.itp. nyu.edu. and java Send_udp, I can recieve a form my borad beacuse it is set to light on a specific LED when it get "A". But I send UDP packet which is delivered to broadcating message, using java. this LED can't get that value. Why the braodcasting message does not delivered to here? is't because java server or something else? To send 'A', I am using this java file made by Tom. And to send "A" to broadcast, I modify the address below to 128.122.151.255.

import java.net.*;
import java.util.*;
import java.io.*;
import java.text.*;

public class Send_udp {
// set port to send to (Siteplayer only listens on 26482)
static final int PORT = 26482;
DatagramSocket ds = null;

public static void main(String[] args) {
Send_udp mysender = new Send_udp();
mysender.sendstuff();
}

public Send_udp() {
try {
ds = new DatagramSocket(PORT);
} catch (SocketException exp) {}
}

public void sendstuff() {
InetAddress address = null;

try {
// fill in your IP address here
address = InetAddress.getByName("128.122.151.62");
} catch (UnknownHostException uhe) {}

byte[] dataBuffer1 = new byte[7];
DatagramPacket dpsend =
new DatagramPacket(dataBuffer1,
dataBuffer1.length, address, PORT);

// this is where we construct the UDP message byte by byte:

// number of bytes to send:
dataBuffer1[0] = 0x01;
// complement of number of bytes to send:
dataBuffer1[1] = (byte) 0xFE;
// low byte of address of COM:
dataBuffer1[2] = 0x19;
// high byte of address of COM:
dataBuffer1[3] = (byte) 0xFF;
// ASCII "A":
dataBuffer1[4] = 0x41;
// udp must end with two zero bytes:
dataBuffer1[5] = 0x00;
dataBuffer1[6] = 0x00;

try {
ds.send(dpsend);
System.out.println("Sent it\n")
} catch (IOException expe) {}
}
}

See Sonny's Java servers for siteplayer, a few useful examples for communicating to a siteplayer from a server. This example is derived from Sonny's example.

 

7. Asciitable

 

 

 

 

 

 

 

 

 

Journal Index