Docstoc

Proj_003022_Track_and_trace

Document Sample
Proj_003022_Track_and_trace Powered By Docstoc
					        Hardware:
     2 x iMCU7100EVB
2 x iMCU7100-EVB add-on




      Software:
 Bascom-8051 2.0.14.0
               This project is a Wheelchair tracking system.
    It is a iMCU7100EVB-board with an GPS-mouse and a RFM12BP
 transceiver connected to a wheelchair and sending its coordinates to a

   iMCU7100EVB-board with a RFM12BP transceiver connected to the
                             Internet.

             The first one we call a W7100-Field Device,
             the second one we call a W7100-Gateway.

                         Both boards look like this




              Left, the RFM12BP transceiver, left/top the antenna,
                lower left the powerconnector for the RFM12BP


                               How it works:

                          W7100-Field Device

     Collects data from a GPS-mouse through the serial port of the
                            iMCU7100EVB.

Picks out the $GPRMC-line, converts the GPS-coordinates to Google Earth
  coordinates, adds a checksum, pads the line to make it 100 characters
                                 long

                 Sends this line to the W7100-Gateway

              Waits 10 seconds and starts all over again.
                      How it works:

                   W7100-Gateway

Receives the $GPRMC-line from the W7100-Field Device

 Calculates the checksum to check if all is received well

            Gets a request from Google Earth

       Assembles a Keynote Markup Language file

Sends it over the Internet to the Google Earth application
 We made a Wheelchair tracking system but anything in a range of 1 km
                           can be tracked.

                 How it is connected to the Internet

In the Google Earth client it is possible to make a network link to a device
         that generates a KML-file (Keynote Markup Language).




           The way to create a network link in Google Earth client

You don’t have to be near the object that you are following, and you don’t
 need to be near the W7100-Gateway. You can fire up Google Earth from
 anywhere, and make a network link to the W7100-Gateway through the
                                internet.
When you do a ‘Refresh’ and a ‘Fly to View on Refresh’ the object to follow will
always be in sight. We have done a refresh of 20 seconds. You can follow the
                           object almost realtime

The W7100-Field Devices is sending its coordinates every 10 seconds. So
   we have put the refresh rate on 20 seconds to get almost the latest
 coordinates. The W7100-Gateway first waits for a Google Earth request
   and after that waits to get new coordinates through the RFM12BP-
                               transceiver.
The details of the Refresh and Fly…
   We can follow all conversation between W7100-Field Device and W7100-
                  Gateway on the serial port of the Gateway

On HyperTerminal you can see the conversation between the W7100-Field
   Device and the W7100-Gateway. On the first line the W7100-Gateway
 waits for a line send by the W7100-Field Device. On the second line this
  $GPRMC-line is received. To keep the W7100-Gateway always available
for the Google Earth requests, we decided to do the conversion from GPS-
 coordinates to Google Earth-coordinates in the W7100-Field Device. The
$GPRMC-line is put in several variables and the W7100-Gateway waits for
                      the request from Google Earth.
And this is the result… Following Granny taking a trip…
 The frequencies used on the W7100-Field Devices are PMR-frequencies.
          They are free in the place were we made this project.

The transceivers we used are RFM12BP, 500 mW, transmitting on 433.400
                                 MHz.




                          RFM12BP-transceiver



                   And here the complete assembly:




      Left, W7100-Field Device with GPS-mouse, right W7100-Gateway.
                                 The firmware

         All firmware is written in Bascom-8051 version 2.0.14.0.




   In Bascom-8051 a lot of 8051 microcontrollers are supported. Each of
 them has it own specified register file, a so called .DAT-file. Because the
W7100 is new, there was no supported register file so we had to make our
                                    own




                 This is a register file for a plain vanilla 8051
     And this is the register file we have made for the W7100.




      The register-file for a W7100. In green all new registers….




Some small test, LED-blink, RS232, LCD showed we had to do with a
                  regular 8051 with a TCPIP-Core.




                          Some ‘basic’ tests
              Going through the firmware of the W7100-Field Device
                       In green our comments on the code



'Projectnumber: 003022

'W7100-Field-Device - Wheelchair tracking system

'W7100 - RFM12bp - GPS grab, LON/LAT convert,
'sending converted-GPS-GPRMC-line to W7100-Gateway

We have made a Add-On board for the iMCU7100EVB
On this board four switches we are not using at the moment
Connection to the RFM12BP transceiver and a LCD on a proper place

' grab 2000 GPS-characters and put them in XRAM from 2000 till 4000

' search for the $GPRMC (strst) and E (endstr)

' put the complete line in a buffer

' put an objectnr in front of it

' convert from GPS to Google Earth coordinates



'Switch   1   -   J2-4   -   P1.3   W7100
'Switch   2   -   J2-3   -   P1.2   W7100
'Switch   3   -   J2-2   -   P1.1   W7100
'Switch   4   -   J2-1   -   P1.0   W7100

'SDI      J4-5     -         P3.4 W7100
'SDO      J4-8     -         P3.7 W7100
'SCK      J4-6     -         P3.5 W7100
'/SEL     J4-7     -         P3.6 W7100
'/IRQ     VIA JUMPER         to J2-8 OF J5-11 P1.7 W7100 OR /INT2 W7100

'FSK      J2-7     - P1.6 W7100
'DCLK     J2-6     - P1.5 W7100
'CLK      J2-5     - P1.4 W7100
'RXEN     J4-3     - P3.2 W7100
'TXEN     J4-2 EN J5-9 P3.1 W7100 and /INT0 W7100
'/INT     J4-1     - P3.0 W7100
'/RES     J4-4     - P3.3 W7100

In Bascom-8051 we have to use a register file. The one we have made before.
Also we have to tell the speed of the crystal for calculating RS232, waits
etc. And with $baud we tell the processor what baudrate to use. With $large
we tell the processor it is dealing with code larger than 2048 bytes, so
make LCALL calls, and $default XRAM tells the compiler to store all
variables in external RAM.

$regfile = "w7100.dat"
$crystal = 11059200
$baud = 4800
$large
$default Xram
Here we tell the compiler to use aliases instead of real portnames. For the
programmer it is easier to talk about LED0, then to check the schematics to
find that port P0.3 is connected to LED0. So here are the aliases for the
RFM12BP transceiver, for the LEDS and for several lines of the LCD.

Nsel Alias P3.6
Sdi Alias P3.4
Sdo Alias P3.7
Sck Alias P3.5
Nres Alias P3.3
Led0 Alias P0.3
Led1 Alias P0.4
Led2 Alias P0.5
Lcd_rs Alias P0.0
Lcd_rw Alias P0.1
Lcd_e Alias P0.2

Give this W7100-Field Device is own unique code

Const Object = "obj01"

Dimension all the used variables. Like the Option Explicit in Visual Basic.

Dim   Addr As Word
Dim   Strt As Word
Dim   Endstr As Word
Dim   Buffer As Iram String * 100
Dim   R As Byte
Dim   C As Byte

'rfm12pb
Dim Dout As Word
Dim Dspi As Integer
Dim Dsdo As Integer
Dim Freq As Single
Dim Param As Word

'convert minuten to degrees
Dim Token As Iram String * 2
Dim A1 As Byte
Dim N1 As Byte
Dim E1 As Byte
Dim Lon_lat As Iram String * 10

'playground
Dim Shulp As Iram String * 3
Dim Bhulp As Byte
Dim Bhulp2 As Byte
Dim Bhulp3 As Byte
Dim Bhulp4 As Byte
Dim Ihulp As Integer
Dim Whulp As Word

'used for conversion
Dim Shulp2 As Iram String * 3
Dim Shulp3 As Iram String * 15
Dim Rxl As Single
Dim Sl1 As Iram String * 12
Dim Sl2 As Iram String * 12
Dim Sl3 As Iram String * 12
Dim Cnullen As Iram String * 5
We have to declare all used subroutines and use on some of them parameters

'declare of   used subroutines
Declare Sub   Lcd_reg(r As Byte)
Declare Sub   Lcd_char(c As Byte)
Declare Sub   Lcd_secondline
Declare Sub   Init_lcd
Declare Sub   Spi16(dout As Word)
Declare Sub   Freq_rfm12
Declare Sub   Init_rfm12bp
Declare Sub   Wait_rfm12
Declare Sub   Send_buffer

We had to change to registers to get the right baud rate

'4800 baud for the GPS-receive
Tl1 = &HD0
Th1 = &HA0

Putting to lines low for the LCD

'Init LCD and put some text on the LCD of prototype
Reset Lcd_rw
Reset Lcd_rs

Will be used for some formatting later on

Cnullen = "00000"

Initialize the LCD-display

Call Init_lcd

'reset RFM12BP
Nres = 1

Do

Reset Led0
'fill xram 2000-4000 with GPS-data
Whulp = 2000

No fancy RS232-input routine, grab 2000 characters from the GPS-mouse and
filter the $GPRMC-line from it

Do
  Bhulp = Inkey()
  If Bhulp <> 0 Then
    Incr Whulp
    Out Whulp , Bhulp
  End If
Loop Until Whulp = 4000

We like to see what is going on so using LED1 to check characters are
coming in

'some optical for test
Reset Led1
The 2000 characters are stored in external RAM (that is external but inside
the W7100) from 2000 to 4000. And in the next routine the $GPRMC-line is
filtert out


Endstr = 0
Strt = 0

'find $GPRMC line
For Whulp = 2000 To 4000
    Addr = Whulp
    Bhulp2 = Inp(addr)
    Bhulp = Asc( "$")
    If Bhulp2 = Bhulp Then
       Incr Addr
       Bhulp = Asc( "G")
       Bhulp2 = Inp(addr)
       If Bhulp2 = Bhulp Then
           Incr Addr
           Bhulp = Asc( "P")
           Bhulp2 = Inp(addr)
           If Bhulp2 = Bhulp Then
              Incr Addr
              Bhulp = Asc( "R")
              Bhulp2 = Inp(addr)
              If Bhulp2 = Bhulp Then
                  Incr Addr
                  Bhulp = Asc( "M")
                  Bhulp2 = Inp(addr)
                  If Bhulp2 = Bhulp Then
                     Incr Addr
                     Bhulp = Asc( "C")
                     Bhulp2 = Inp(addr)
                     If Bhulp2 = Bhulp Then
                         Strt = Addr - 6
                         'search for *
                         Bhulp = Asc( "*")
                         For Bhulp3 = 1 To 70
                             Incr Addr
                             Bhulp2 = Inp(addr)
                             If Bhulp2 = Bhulp Then
                                Endstr = Addr
                                Exit For
                             End If
                         Next Bhulp3
                     End If
                  End If
              End If
           End If
       End If
    End If
Next Whulp

You have got the $GPRMD-line, but the objectname of this W7100-Field Device
in front of it

'Put objectname and # at start of buffer
Buffer = Object + "#"
Got garbage and can’t find the $GPRMC-line. Create a error-code

'prevent buffer growing to big...
Bhulp = Endstr - Strt
If Bhulp > 90 Then
   Buffer = Object + "#ERROR no valid GPS-data"

   Goto Passthru
End If

Example of a $GPRMC line, time, longitude, latitude, speed, bearing, date

'obj01#$GPRMC,235033.200,A,5134.1505,N,00502.8012,E,0.03,0.00,180210,,,A*6F
"

Put the complete line we have found in the buffer

'put complete $GPRMC-line up to * characters in buffer
Incr Strt
For Whulp = Strt To Endstr
    Bhulp = Inp(whulp)
    Buffer = Buffer + Chr(bhulp)
Next Whulp

'find A in $GPRMC-string
Token = "A"
A1 = Instr(buffer , Token)

'find N in $GPRMC-string
Token = "N"
N1 = Instr(buffer , Token)

'find E in $GPRMC-string
Token = "E"
E1 = Instr(buffer , Token)

Incr A1
Incr A1

Bhulp = N1 - A1
Decr Bhulp

Check if we got a fix on the GPS-satellites
If not, create an error-line


'check if we got a satellite-fix (V=inValid, A=Active)
Shulp = Mid(buffer , 25 , 1)
If Shulp = "V" Then
   Buffer = Object + "#ERROR no fixed satellites"
   Goto Passthru
End If

Our GPS-mouse defaults to 36000.0000 when no coordinates can be found

Lon_lat = Mid(buffer , A1 , Bhulp)

'check if we got some coordinates
If Lon_lat = "36000.0000" Then
   Buffer = Object + "#ERROR no coordinates"
   Goto Passthru
End If

Perhaps small but this made things easy for us while debugging. When the
buffer was full, the $GPRMC-line was fetched, LED2 was on

Reset Led2

'format = 5134.2147

We had to convert the GPS-coordinates to Google Earth coordinates. Could do
that on the W7100-Gateway but that device had to be on alert for any Google
Earth KML-requests.

We are not completely sure this will work on any place of the earth.

'convert latitude from minutes into degrees
Bhulp4 = Len(lon_lat)
Shulp = "."

'find the first character after the dot
Bhulp = Instr(lon_lat , Shulp)
Incr Bhulp

'take the first 2 characters (51)
Shulp2 = Left(lon_lat , 2)

'take the 3 and 4 character (34)
Shulp3 = Mid(lon_lat , 3 , 2)

'char 3 and 4 and everything after the dot
Shulp3 = Shulp3 + Mid(lon_lat , Bhulp)

'check for leading zeros
Shulp = Mid(shulp3 , 1 , 1)
If Shulp = "0" Then
   Whulp = 1
   Shulp = Mid(shulp3 , 2 , 1)
   If Shulp = "0" Then
       Whulp = 2
   End If
End If

'convert that part from minutes to degrees
Rxl = Val(shulp3)
Rxl = Rxl / 60

'put calculation in string again
Sl1 = Str(rxl)

'remove the dot
Shulp = "."
Bhulp = Instr(sl1 , Shulp)
Incr Bhulp
Sl2 = Mid(sl1 , Bhulp)
Decr Bhulp
Decr Bhulp
Sl1 = Left(sl1 , Bhulp)

'add leading zeros
Lon_lat = Shulp2 + "."
Sl3 = Left(cnullen , Whulp)
Lon_lat = Lon_lat + Sl1
Lon_lat = Lon_lat + Sl2

Bhulp3 = Len(lon_lat)
If Bhulp3 < Bhulp4 Then
   Bhulp2 = Bhulp4 - Bhulp3
   Do
      Lon_lat = Lon_lat + "0"                ' make longer when to short
      Decr Bhulp2
   Loop Until Bhulp2 = 0
End If

Lon_lat = Left(lon_lat , Bhulp4)             'make shorter when to long

In the $GPRMC-line replace the old GPS-coordinates with the new Google
Earth coordinates

'replace old coord. with new coord.
Mid(buffer , A1 , Bhulp4) = Lon_lat

Do the conversion again for the longiture

'convert longitude

Incr N1
Incr N1

Bhulp = E1 - N1
Decr Bhulp
Lon_lat = Mid(buffer , N1 , Bhulp)

'format = 00502.8010

Bhulp4 = Len(lon_lat)
Shulp = "."

'find the first character after the dot
Bhulp = Instr(lon_lat , Shulp)
Incr Bhulp

'take the first character (5)
Shulp2 = Mid(lon_lat , 3 , 1)

'take the 4 and 5 character (02)
Shulp3 = Mid(lon_lat , 4 , 2)

'char 4 and 5 and everything after the dot
Shulp3 = Shulp3 + Mid(lon_lat , Bhulp)

'check for leading zero's
Shulp = Mid(shulp3 , 1 , 1)
If Shulp = "0" Then
   Whulp = 1
   Shulp = Mid(shulp3 , 2 , 1)
       If Shulp = "0" Then
       Whulp = 2
   End If
End If
'convert that part from minutes to degrees
Rxl = Val(shulp3)
Rxl = Rxl / 60

'make a string again
Sl1 = Str(rxl)

'remove the dot from the calculation
Shulp = "."
Bhulp = Instr(sl1 , Shulp)
Incr Bhulp
Sl2 = Mid(sl1 , Bhulp)
Decr Bhulp
Decr Bhulp
Sl1 = Left(sl1 , Bhulp)

'make it GE format
Shulp3 = Shulp2 + "."
Sl3 = Left(cnullen , Whulp)
Shulp3 = Shulp3 + Sl3
Shulp3 = Shulp3 + Sl1
Shulp3 = Shulp3 + Sl2
Lon_lat = Shulp3

Bhulp3 = Len(lon_lat)
If Bhulp3 < Bhulp4 Then
   Bhulp2 = Bhulp4 - Bhulp3
   Do
      Lon_lat = Lon_lat + "0"                'make it longer when to short
      Decr Bhulp2
   Loop Until Bhulp2 = 0
End If

Lon_lat = Left(lon_lat , Bhulp4)             'make it shorter when to long

'replace old coord. with new coord.
Mid(buffer , N1 , 10) = Lon_lat

Here the program jumps to when an error has occurred

'here a valid line or errorlines are being sent.
Passthru:

'optical test
Set Led0
Set Led1
Set Led2

Wait 10                                       ‘wait 10 seconds and send

Send it through the RFM12BP to the W7100-Gateway

'send buffer
Call Send_buffer

Loop
End
Subroutine to send a word (2 bytes) to the RFM12BP

'SPI out to rfm12bp
Sub Spi16(dout As Word)
   Nsel = 0
   Dsdo = 0
   For Ihulp = 1 To 16
      Dspi = Dout And &H8000
      If Dspi = 0 Then
          Sdi = 0
      Else
          Sdi = 1
      End If
      Dout = Dout * 2
      Dsdo = Dsdo * 2
      If Sdo = 1 Then
          Dsdo = Dsdo + 1
      End If
      Sck = 1
      Nop : Nop
      nop : nop
      nop : nop
      nop : nop
      nop : nop
      nop : nop
      nop : nop
      nop
      Sck = 0
   Next Ihulp
   Nsel = 1
End Sub

Subroutine to put the RFM12BP to the right frequency

'calculate frequency
Sub Freq_rfm12
   If Freq < 800 Then Freq = Freq * 2
   Freq = Freq - 860
   Whulp = Freq / 0.0050
   If Whulp < 96 Then Whulp = 96
   If Whulp > 3903 Then Whulp = 3903
   Whulp = Whulp + &HA000
   Call Spi16(whulp)
End Sub
Subroutine to initialize the RFM12BP (check the W7100-Gateway code for more
detail)

'Init RFM12PB
Sub Init_rfm12bp
Nsel = 1
Sck = 0
Call Spi16(&H80d7)                                           'see W7100-
Gateway for description
Call Spi16(&H82d9)
Call Spi16(&Ha67c)
Call Spi16(&Hc647)
Call Spi16(&H94a4)
Call Spi16(&Hc2ac)
Call Spi16(&Hca81)
Call Spi16(&Hc483)
Call Spi16(&H9850)
Call Spi16(&He000)
Call Spi16(&Hc800)
Call Spi16(&Hc000)

'put on the right frequency
Freq = 434.300
Call Freq_rfm12
End Sub


'wait till rfm12bp is ready
Sub Wait_rfm12
    Nsel = 0
    Do
    Loop Until Sdo = 1
End Sub

Subroutine to initialize the LCD


Sub Init_lcd
Waitms 15
Call Lcd_reg(&H30)
Waitms 10
Call Lcd_reg(&H30)
Waitms 1
Call Lcd_reg(&H30)
Waitms 4
Call Lcd_reg(&H20)
Waitms 1
Call Lcd_reg(&H20)
Call Lcd_reg(&H80)
Waitms 1
Call Lcd_reg(&H00)
Call Lcd_reg(&H80)
Waitms 1
Call Lcd_reg(&H00)
Call Lcd_reg(&Hc0)
Waitms 1
Call Lcd_reg(&H00)
Call Lcd_reg(&H10)
Waitms 1
Buffer = "GPS receive"
For Ihulp = 1 To Len(buffer)
      Shulp = Mid(buffer , Ihulp , 1)
      Call Lcd_char(asc(shulp))
Next Ihulp
Call Lcd_secondline
Buffer = "RFM12PB transmit"
For Ihulp = 1 To Len(buffer)
      Shulp = Mid(buffer , Ihulp , 1)
      Call Lcd_char(asc(shulp))
Next Ihulp
End Sub


'write lcd-register
Sub Lcd_reg(r As Byte)
P2 = R
'toggle E
Lcd_e = 1
Waitms 1
Lcd_e = 0
End Sub


'write lcd character (4-bit mode)
Sub Lcd_char(c As Byte)
P2 = C
'toggle E
'toggle RS
Lcd_e = 1
Lcd_rs = 1
Waitms 1
Lcd_e = 0
Lcd_rs = 0
Waitms 1
Rotate C , Left , 4
P2 = C
Lcd_e = 1
Lcd_rs = 1
Waitms 1
Lcd_e = 0
Lcd_rs = 0
Waitms 1
End Sub

Subroutine to write something on the second line of the LCD


Sub Lcd_secondline
Call Lcd_reg(&H00)
Call Lcd_reg(&H20)
For Bhulp = 1 To 40
    Call Lcd_reg(&H10)
    Call Lcd_reg(&H40)
Next Bhulp
End Sub
Subroutine to send the buffer to the RFM12BP

'send buffer to rfm12bp
Sub Send_buffer
Call Init_rfm12bp
Whulp = 0
Buffer = Buffer + "#"
Bhulp3 = Len(buffer)

'make the buffer 100 characters long
If Bhulp3 < 96 Then
   For Bhulp = Bhulp3 To 95
        Buffer = Buffer + "#"
   Next Bhulp
End If

'calculate the checksum
Bhulp2 = 0
Bhulp3 = Len(buffer)
For Bhulp = 1 To Bhulp3
    Shulp = Mid(buffer , Bhulp , 1)
    Bhulp2 = Bhulp2 + Asc(shulp)
Next Bhulp
Buffer = Buffer + "[" + Hex(bhulp2) + "]"

'start rfm12bp
'Wait 10
Call Spi16(&H8238)
Call Wait_rfm12
Call Spi16(&Hb8aa)
Call Wait_rfm12
Call Spi16(&Hb8aa)
Call Wait_rfm12
Call Spi16(&Hb8aa)
Call Wait_rfm12

'send magic bytes
Call Spi16(&Hb82d)
Call Wait_rfm12
Call Spi16(&Hb8d4)
Call Wait_rfm12

'send the filled buffer
Bhulp3 = Len(buffer)
For Bhulp = 1 To Bhulp3
    Shulp = Mid(buffer , Bhulp , 1)
    Bhulp2 = Asc(shulp)
    Param = &HB800 + Bhulp2
    Call Spi16(param)
    Call Wait_rfm12
Next Bhulp

'some synchronize bytes and end
Call Spi16(&Hb8aa)
Call Wait_rfm12
Call Spi16(&Hb8aa)
Call Wait_rfm12
Call Spi16(&H8208)
End Sub
                  Going through the firmware of the W7100-Gateway
                         In green our comments on the code


'Projectnumber: 003022

'W7100-Gateway - Granny in wheelchair trackingsystem

'W7100 - RFM12bp - Receiving converted-GPS-GPRMC-line and generating KML-
file.

'Switch   1   -   J2-4   -   P1.3   W7100
'Switch   2   -   J2-3   -   P1.2   W7100
'Switch   3   -   J2-2   -   P1.1   W7100
'Switch   4   -   J2-1   -   P1.0   W7100

'SDI      J4-5     -         P3.4   W7100
'SDO      J4-8     -         P3.7   W7100
'SCK      J4-6     -         P3.5   W7100
'/SEL     J4-7     -         P3.6   W7100
'/IRQ     VIA JUMPER         NAAR   J2-8 OF J5-11 P1.7 W7100 OF /INT2 W7100

'FSK      J2-7     - P1.6 W7100
'DCLK     J2-6     - P1.5 W7100
'CLK      J2-5     - P1.4 W7100
'RXEN     J4-3     - P3.2 W7100
'TXEN     J4-2 EN J5-9 P3.1 W7100 EN /INT0 W7100
'/INT     J4-1     - P3.0 W7100
'/RES     J4-4     - P3.3 W7100

DAT-file we are using as register file for the W7100
We will be using 115200 baud

$regfile = "w7100.dat"                                'Dat-file with W7100-registers
$crystal = 11059200                                   'Crystal frequency
$baud = 115200                                        'Baud-rate
$default Xram                                         'All variables stored in XRAM
$large                                                'Instructs the compiler that
                                                      'LCALL statements must be used.

Tl1 = &HFC                                            '115200 baud
Th1 = &HFE

We want to use some routines of the W7100 bootrom so we create here some
space.

$romstart = &H0800                                    'leave some room for the bootrom

Use some aliases to make programming a bit easy

Nsel Alias P3.6                                       'RFM12BP   /SELECT
Sdi Alias P3.4                                        'RFM12BP   serial data in
Sdo Alias P3.7                                        'RFM12BP   serial data out
Sck Alias P3.5                                        'RFM12BP   clock
Nres Alias P3.3                                       'RFM12BP   /RESET
Do all dimensions of used variables

Dim Adres As Iram Word                      'in internal ram
                                            'exchange xram and TCP/IP-Xram
Dim Value As Iram Byte

Const Common_base = 0

$include "W7100.inc"                        'Include file for all
                                            'TCPIP-core-registers

Declare all subroutines

'Declare all subroutines
Declare Sub Lcd_reg(btmp_hulp1 As Byte)
Declare Sub Lcd_char(btmp_hulp2 As Byte)
Declare Sub Init_lcd
Declare Sub W7100_write(adres As Word , Value As Byte)
Declare Sub W7100_read(adres As Word)
Declare Sub W7100_init
Declare Sub W7100_reset
Declare Sub W7100_disconnect
Declare Sub W7100_receive
Declare Sub W7100_send
Declare Sub Spi16(dout As Word)
Declare Sub Freq_rfm12
Declare Sub Init_rfm12bp
Declare Sub Wait_rfm12
Declare Sub Configure
Declare Sub Read_dataflash
Declare Sub Write_dataflash

Dimension some variables. There are a few that are stored in internal RAM
because they are the connection between External Ram and TCPIP-Core RAM.
While switching to TCPIP-Core RAM you can’t get to your variables stored in
External RAM. So we used some Internal RAM to solve this

'playground in   internal ram
Dim Btmp_hulp1   As Iram Byte
Dim Btmp_hulp2   As Iram Byte
Dim Btmp_hulp3   As Iram Byte
Dim Btmp_hulp4   As Iram Byte
Dim Btmp_hulp5   As Iram Byte
Dim Btmp_hulp6   As Iram Byte

'TCP
Dim Status As Byte
Dim Oldstatus As Byte

'General
Dim Pointer As Word
Dim X As Integer
Dim Bytes_rcv As Word
Dim Pos_tx As Word
Dim Freesize As Word
Dim Offset As Word
Dim Tx_wr As Word
Dim Startadress As Word
Dim Offsend As Word
Dim Uppersize As Word
Dim Glaenge As Word
Dim Startpos As Word
Dim Tmp_value As Byte
Dim Itmp_hulp1 As Integer

'rfm12pb
Dim Dout As Word
Dim Nspi As Integer
Dim Dspi As Integer
Dim Dsdo As Integer
Dim Freq As Single
Dim Wd As Word
Dim E As Byte
Dim Bchecksum1 As Byte
Dim Checksum As Byte
Dim F As Byte
Dim N As Byte

'strings in internal ram
Dim Hulp As Iram String * 12
Dim Lon As Iram String * 12
Dim Lat As Iram String * 12
Dim Strq1 As Iram String * 3
Dim Strobj As Iram String * 5
Dim Buffer As Iram String * 100
Dim Stmp_str As Iram String * 2
Dim Bearing As Iram String * 10
Dim Speed As Iram String * 10

We like to   put our TCP/IP-settings like IP-number, Gateway, NetMask, MAC-
address in   dataflash. So we made a array of 256 byte to read and write in
Dataflash.   The variable Q is pointing to the place in External RAM where
this array   is.

'Array for dataflash
Dim Dataflash(256) As Byte            'array for the dataflash (IP-settings)
Dim Q As Word                         'pointer to place of array dataflash

Remarks what information is stored in the dataflash

'dataflash(1)    IP-number
'dataflash(2)    IP-number
'dataflash(3)    IP-number
'dataflash(4)    IP-number
'dataflash(5)    Netmask
'dataflash(6)    Netmask
'dataflash(7)    Netmask
'dataflash(8)    Netmask
'dataflash(9)    Gateway
'dataflash(10)   Gateway
'dataflash(11)   Gateway
'dataflash(12)   Gateway
'dataflash(13)   MAC
'dataflash(14)   MAC
'dataflash(15)   MAC
'dataflash(16)   MAC
'dataflash(17)   MAC
'dataflash(18)   MAC
We are not using any interrupts

Disable Interrupts                      'we are not using the interrupts

Some aliases for the display connections

Lcd_rs Alias P0.0                       'LCD RS
Lcd_rw Alias P0.1                       'LCD R/W
Lcd_e Alias P0.2                        'LCD E

Reset Lcd_rw                            'LCD R/W to GND
Reset Lcd_rs                            'LCD RS to GND

Initialize the LCD-display

Call Init_lcd                           'Init the LCD

Show on the RS232-port the configuration settings (network)

Call Configuration                      'Show networksettings

Initialize the W7100

Call W7100_init                          'Init W7100

This is the main routine. Waiting for a request from Google Earth

Do
     Call W7100_read(w7100_s0_sr)       'get socket status
     Status = Value

     If Status <> Oldstatus Then
        Oldstatus = Status
     End If

     If Status = &H0 Or Status = &H1C Then    'connection was closed, we
                                              'start the socket new
        Call W7100_disconnect
     End If
                                    'as long as connection is
                                    'established (&H17)
                                    'we will look if client sends new data
     If Status = &H17 Then
        Print
        Print "Request from Google Earth"
        Buffer = ""
        '
        Wait 1                   'this one is important get complete packet
        '
        Call W7100_receive

       Print "Waiting for data from W7100-Field Device"
       Print

Get new data from the W7100-Field Device

       Call Rfmpart

    End If
Loop
End
The part that handles all RFM12BP traffic

Sub Rfmpart

Initialize the RFM12BP

Call Init_rfm12bp

'start receiver, matched data
    Call Spi16(&H82c8)
    Call Spi16(&Hca83)
    Buffer = ""
    Checksum = 0
    For N = 1 To 100
      Wait_rfm12
      Call Spi16(&Hb000)
      Buffer = Buffer + Chr(dsdo)
    Next N

    Print Buffer
    Print

On some place you can expect some kind of characters, check it…

    'plausibiliteitscontrole
    Hulp = Left(buffer , 3)
    If Hulp = "obj" Then
       Hulp = Mid(buffer , 6 , 8)
       If Hulp = "#$GPRMC," Then
          Hulp = Mid(buffer , 97 , 1)
          If Hulp = "[" Then
             Hulp = Mid(buffer , 100 , 1)
             If Hulp = "]" Then
                F = Len(buffer)
                F = F - 4
                'calculation checksum
                For E = 1 To F
                    Stmp_str = Mid(buffer , E , 1)
                    Checksum = Checksum + Asc(stmp_str)
                Next E
                '
                Hulp = Mid(buffer , 98 , 2)
                Bchecksum1 = Hexval(hulp)

                   If Bchecksum1 = Checksum Then

Fill all variables with the right information

                      ' Checksum OK
                      Strobj = Left(buffer , 5)
                      Hulp = Mid(buffer , 14 , 2)
                      Hulp = Hulp + ":" + Mid(buffer , 16 , 2)
                      Hulp = Hulp + ":" + Mid(buffer , 18 , 2)

                      Print "Receiving data from W7100-Field Device"
                      Print

                      Print "Object    = " ; Strobj
                      Print "Time      = " ; Hulp

                      Strq1 = ",A,"
Btmp_hulp1 = Instr(1 , Buffer , Strq1 )

Strq1 = ",N,"
Btmp_hulp2 = Instr(1 , Buffer , Strq1 )

Strq1 = ",E,"
Btmp_hulp3 = Instr(1 , Buffer , Strq1 )

Btmp_hulp4 = Btmp_hulp1 + 3                'position
Btmp_hulp5 = Btmp_hulp2 - Btmp_hulp4       'length

Hulp = Mid(buffer , Btmp_hulp4 , Btmp_hulp5)
'first coordinaat

Print "Latitute   = " ; Hulp
Lat = Hulp

Btmp_hulp4 = Btmp_hulp2 + 3
Btmp_hulp5 = Btmp_hulp3 - Btmp_hulp4

Hulp = Mid(buffer , Btmp_hulp4 , Btmp_hulp5)
'second coordinaat

Print "Longitude = " ; Hulp
Lon = Hulp

Btmp_hulp1 = Btmp_hulp3 + 3

Buffer = Mid(buffer , Btmp_hulp1)

Strq1 = ","
Btmp_hulp1 = Instr(1 , Buffer , Strq1)
Btmp_hulp1 = Btmp_hulp1 - 1

Hulp = Left(buffer , Btmp_hulp1)

Print "Speed      = " ; Hulp
Speed = Hulp

Btmp_hulp1 = Btmp_hulp1 + 2

Buffer = Mid(buffer , Btmp_hulp1)

Strq1 = ","
Btmp_hulp1 = Instr(1 , Buffer , Strq1)
Decr Btmp_hulp1

Hulp = Left(buffer , Btmp_hulp1)

Print "Bearing    = " ; Hulp
Bearing = Hulp

Incr Btmp_hulp1
Incr Btmp_hulp1

Buffer = Mid(buffer , Btmp_hulp1)

Strq1 = ","
Btmp_hulp1 = Instr(1 , Buffer , Strq1)
Decr Btmp_hulp1
                     Hulp = Left(buffer , Btmp_hulp1)

                      Print "UTC-Date = " ; Hulp
                      Else
                      Print "Error in received string from W7100-Field Device"
                  End If
               End If
           End If
        End If
    End If
   Print
End Sub

Subroutine to initialize the LCD

Sub Init_lcd                                                    'Init LCD
Waitms 15
Call Lcd_reg(&H30)
Waitms 10
Call Lcd_reg(&H30)
Waitms 1
Call Lcd_reg(&H30)
Waitms 4
Call Lcd_reg(&H20)
Waitms 1
Call Lcd_reg(&H20)
Call Lcd_reg(&H80)
Waitms 1
Call Lcd_reg(&H00)
Call Lcd_reg(&H80)
Waitms 1
Call Lcd_reg(&H00)
Call Lcd_reg(&Hc0)
Waitms 1
Call Lcd_reg(&H00)
Call Lcd_reg(&H10)
Waitms 1

Buffer = "Gran Wheelchair" + Space(25) + "tracking system"
For Itmp_hulp1 = 1 To Len(buffer)
      Stmp_str = Mid(buffer , Itmp_hulp1 , 1)
      Call Lcd_char(asc(stmp_str))
Next Itmp_hulp1
Buffer = ""
End Sub


Sub Lcd_reg(btmp_hulp1 As Byte)                                 'LCD register
P2 = Btmp_hulp1
Lcd_e = 1                                                       'toggle E
Waitms 1
Lcd_e = 0
End Sub
Sub Lcd_char(btmp_hulp2 As Byte)                              'LCD
character
P2 = Btmp_hulp2
Lcd_e = 1
Lcd_rs = 1
Waitms 1
Lcd_e = 0
Lcd_rs = 0
Waitms 1
Rotate Btmp_hulp2 , Left , 4
P2 = Btmp_hulp2
Lcd_e = 1
Lcd_rs = 1
Waitms 1
Lcd_e = 0
Lcd_rs = 0
Waitms 1
End Sub

At startup, put the network settings on the terminal

'Routine to put the networksettings on the RS232 port
Sub Configuration
Print Chr(&H1b) ; "[2J";              'ANSI goto 0/0
Print
Print "Granny wheelchair tracking system"
Print "================================="
Print
Print
Print "Present configuration:"
Call Read_dataflash                   'get the IP-settings from dataflash

Print
Print "IP-number:   ";
Print Dataflash(1) ; "." ; Dataflash(2) ; "." ; Dataflash(3) ; "." ;
Dataflash(4)
Print

Print "Netmask:     ";
Print Dataflash(5) ; "." ; Dataflash(6) ; "." ; Dataflash(7) ; "." ;
Dataflash(8)
Print

Print "Gateway:     ";
Print Dataflash(9) ; "." ; Dataflash(10) ; "." ; Dataflash(11) ; "." ;
Dataflash(12)
Print

Print "MAC-address: ";

Printhex   Dataflash(13)   ;   "-"   ;
Printhex   Dataflash(14)   ;   "-"   ;
Printhex   Dataflash(15)   ;   "-"   ;
Printhex   Dataflash(16)   ;   "-"   ;
Printhex   Dataflash(17)   ;   "-"   ;
Printhex   Dataflash(18)
Print

Print "Running..."
End Sub
Subroutine to reset the W7100

Sub W7100_reset
   Call W7100_write(mr , Mr_rst)
   Waitms 5
End Sub

Subroutine to initialize the W7100. Here we are switching between the
dataflash and the ‘normal’ TCPIP-core registers. Because dataflash array is
in external RAM we have to use a few variables in internal RAM to get hold
of them.

Sub W7100_init

    Call W7100_write(w7100_s0_mr , Mr_rst)
                    'reset the TCPIP-core

    'move from    external ram to internal ram
    Btmp_hulp1    = Dataflash(10)
    Btmp_hulp2    = Dataflash(11)
    Btmp_hulp3    = Dataflash(12)
    Btmp_hulp4    = Dataflash(13)

    Dpx0 = &HFE                                              'Gateway
    Out Gar0 , Btmp_hulp1
    Out Gar1 , Btmp_hulp2
    Out Gar2 , Btmp_hulp3
    Out Gar3 , Btmp_hulp4
    Dpx0 = 0

    Btmp_hulp1    =    Dataflash(5)
    Btmp_hulp2    =    Dataflash(6)
    Btmp_hulp3    =    Dataflash(7)
    Btmp_hulp4    =    Dataflash(8)

    Dpx0 = &HFE                                               'Netmask
    Out Subr0 ,       Btmp_hulp1
    Out Subr1 ,       Btmp_hulp2
    Out Subr2 ,       Btmp_hulp3
    Out Subr3 ,       Btmp_hulp4
    Dpx0 = 0

    Btmp_hulp1    =   Dataflash(13)
    Btmp_hulp2    =   Dataflash(14)
    Btmp_hulp3    =   Dataflash(15)
    Btmp_hulp4    =   Dataflash(16)
    Btmp_hulp5    =   Dataflash(17)
    Btmp_hulp6    =   Dataflash(18)

    Dpx0 = &HFE                                              'MAC-addres
    Out Shar0 ,       Btmp_hulp1
    Out Shar1 ,       Btmp_hulp2
    Out Shar2 ,       Btmp_hulp3
    Out Shar3 ,       Btmp_hulp4
    Out Shar4 ,       Btmp_hulp5
    Out Shar5 ,       Btmp_hulp6
    Dpx0 = 0
    Btmp_hulp1    =    Dataflash(1)
    Btmp_hulp2    =    Dataflash(2)
    Btmp_hulp3    =    Dataflash(3)
    Btmp_hulp4    =    Dataflash(4)

    Dpx0 = &HFE                                                 'IP-number
    Out Sipr0 ,       Btmp_hulp1
    Out Sipr1 ,       Btmp_hulp2
    Out Sipr2 ,       Btmp_hulp3
    Out Sipr3 ,       Btmp_hulp4
    Dpx0 = 0

    'for   HTTP initialize socket 0 with TCP on Port 80
    Call   W7100_write(w7100_s0_mr , Sn_mr_tcp)
    Call   W7100_write(w7100_s0_port0 , 0)
    Call   W7100_write(w7100_s0_port1 , &H50)

    Call W7100_disconnect
End Sub

Subroutine to write value to a specific address of the W7100

Sub W7100_write(adres , Value)
    Dpx0 = &HFE
    Out Adres , Value
    Dpx0 = 0
End Sub

Subroutine to read a value from a specific address of the W7100

Sub W7100_read
    Dpx0 = &HFE
    Value = Inp(adres)
    Dpx0 = 0
End Sub

A disconnect, open and listen again

Sub W7100_disconnect
    Call W7100_write(w7100_s0_cr , Sn_cr_close)
    Call W7100_write(w7100_s0_cr , Sn_cr_open)
    Call W7100_write(w7100_s0_cr , Sn_cr_listen)
End Sub

Receiving data

Sub W7100_receive                            'check for new incoming data
    Print
    Print "Reply to Google Earth request"
    Print
    Call W7100_read(w7100_s0_rx_rsr0)
    Bytes_rcv = Value
    Shift , Bytes_rcv , Left , 8
    Call W7100_read(w7100_s0_rx_rsr1)
    Bytes_rcv = Bytes_rcv + Value
    If Bytes_rcv > 0 Then

       For Itmp_hulp1 = 0 To Bytes_rcv
           Btmp_hulp1 = Itmp_hulp1 + &HC000          'rx memory socket 0
           Call W7100_read(btmp_hulp1)
       Next I

       Call W7100_write(w7100_s0_sr , &H40)          'set RECV flag

       Call W7100_send                               'send the XML-file

    End If
End Sub

The routine that is actual assembling the KML-file


Sub W7100_send
    Restore Header                 'put pointer at the start of the XML-code

    Do                             'read every line and compare for commands
    Read Buffer
    If Buffer = "%END%" Then
       Exit Do
    End If

    If Buffer = "%SPEED0%" Then
       Buffer = Speed
    End If

    If Buffer = "%BEARING0%" Then
       Buffer = Bearing
    End If

    If Buffer   =   "%LINE01%" Then
       Buffer   =   "<Snippet maxLines=" + Chr(34)
       Buffer   =   Buffer + "0"
       Buffer   =   Buffer + Chr(34)
       Buffer   =   Buffer + ">"
       Buffer   =   Buffer + "</Snippet>"
    End If

    If Buffer   =   "%LINE02%" Then
       Buffer   =   "<description><![CDATA[<table border=" + Chr(034)
       Buffer   =   Buffer + "1" + Chr(34)
       Buffer   =   Buffer + " cellspacing=" + Chr(34)
       Buffer   =   Buffer + "1" + Chr(34)
       Buffer   =   Buffer + " cellpadding=" + Chr(34)
       Buffer   =   Buffer + "1" + Chr(34)
       Buffer   =   Buffer + " width=" + Chr(34)
       Buffer   =   Buffer + "200" + Chr(34)

    End If

    If Buffer   =   "%LINE03%" Then
       Buffer   =   "><caption><img alt=" + Chr(34) + Chr(34)
       Buffer   =   Buffer + " src=" + Chr(34)
       Buffer   =   Buffer + "http://<a big secret>/imcu/grandma.jpg"
       Buffer   =   Buffer + Chr(34) + " />"
    End If
    If Buffer   =   "%LINE04%" Then
       Buffer   =   "</caption><tbody><tr><td><span style=" + Chr(34)
       Buffer   =   Buffer + "font-family: Verdana" + Chr(34)
       Buffer   =   Buffer + "><b>Longitude</b></span></td><td>"
    End If

    If Buffer   =   "%LINE05%" Then
       Buffer   =   "<td></tr><tr><td><span style=" + Chr(34)
       Buffer   =   Buffer + "font-family: Verdana" + Chr(34)
       Buffer   =   Buffer + "><b>Latitude</b></span></td><td>"
    End If

    If Buffer   =   "%LINE06%" Then
       Buffer   =   "</td></tr><tr><td><span style=" + Chr(34)
       Buffer   =   Buffer + "font-family: Verdana" + Chr(34)
       Buffer   =   Buffer + "><b>Speed</b></span></td><td>"
    End If

    If Buffer   =   "%LINE07%" Then
       Buffer   =   "</td></tr><tr><td><span style=" + Chr(34)
       Buffer   =   Buffer + "font-family: Verdana" + Chr(34)
       Buffer   =   Buffer + "><b>Bearing</b></span></td><td>"
    End If

    If Buffer = "%LINE08%" Then
       Buffer = "</td></tr></tbody></table>"
       Buffer = Buffer + "]]></description><LookAt><longitude>"
    End If

    If Buffer = "%LINE10%" Then Buffer = "</longitude><latitude>"

    If Buffer = "%LINE11%" Then Buffer =
"</latitude><altitude>0</altitude><range>434.5551491589756</range>"

    If Buffer = "%LINE11a%" Then Buffer = "<tilt>0</tilt><heading>-
0.5853228144721971</heading>"

    If Buffer = "%LINE12%" Then Buffer =
"<altitudeMode>relativeToGround</altitudeMode>"

    If Buffer = "%LINE12a%" Then Buffer =
"<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>"

    If Buffer = "%LINE13%" Then Buffer =
"</LookAt><styleUrl>#msn_wheel_chair_accessible</styleUrl>"

    If Buffer = "%LINE14%" Then Buffer = "<Point id=" + Chr(34)

    If Buffer = "%LINE15%" Then Buffer = Chr(34) + "><coordinates>"

    If Buffer = "%LINE16%" Then Buffer = ","

    If Buffer = "%LINE17%" Then Buffer =
",0</coordinates></Point></Placemark>"

    Hulp = Left(buffer , 10)
    If Hulp = "%Placemark" Then
       Buffer = "<Placemark><name>Wheelchair with Granny"
       Buffer = Buffer + "</name>"
    End If
    Hulp = Left(buffer , 7)
    If Hulp = "%PAT_ID" Then
       Hulp = Mid(buffer , 8 , 1)
       Buffer = "KMLe_1" + Hulp
    End If

    'get real LATITUDE from RFM12BP
    If Buffer = "%LAT0%" Then Buffer = Lat

    'get real LONGITUDE from RFM12BP
    If Buffer = "%LON0%" Then Buffer = Lon

    Itmp_hulp1 = Len(buffer)

Here the roll-over for the transmit memory is taking care of

    Freesize:
       Call W7100_read(w7100_s0_tx_fsr0)
       Freesize = Value
       Shift Freesize , Left , 8
       Call W7100_read(w7100_s0_tx_fsr1)
       Freesize = Freesize + Value

      If Freesize < Itmp_hulp1 Then
         Goto Freesize
      End If

      Call W7100_read(w7100_s0_tx_wr0)
      Tx_wr = Value
      Shift Tx_wr , Left , 8
      Call W7100_read(w7100_s0_tx_wr1)
      Tx_wr = Tx_wr + Value

      Startpos = Tx_wr

      Offset = Tx_wr And &H7FF
      Startadress = &H8000 + Offset
      Offsend = Offset + Itmp_hulp1
      Pointer = Startadress

      If Offsend > &H800 Then
         Uppersize = &H800 - Offset

          For X = 1 To Uppersize
              Stmp_str = Mid(buffer , X , 1)
              Tmp_value = Asc(stmp_str)
              Call W7100_write(pointer , Tmp_value)
              Incr Pointer
          Next X

          Pointer = &H8000
          Incr Uppersize

         For X = Uppersize To Itmp_hulp1
              Stmp_str = Mid(buffer , X , 1)
              Tmp_value = Asc(stmp_str)
              Call W7100_write(pointer , Tmp_value)
              Incr Pointer
         Next X
      Else
           For X = 1 To Itmp_hulp1
                 Stmp_str = Mid(buffer , X , 1)
                 Tmp_value = Asc(stmp_str)
                 Call W7100_write(pointer , Tmp_value)
                 Incr Pointer
              Next X
          End If

Routine to read what is coming to the W7100-Gateway

          Call W7100_read(w7100_s0_tx_wr0)
          Startpos = Value
          Shift Startpos , Left , 8
          Call W7100_read(w7100_s0_tx_wr1)
          Startpos = Startpos + Value
          Glaenge = Startpos + Itmp_hulp1

          Btmp_hulp1 = High(glaenge)                 'send KML-file
          Call W7100_write(w7100_s0_tx_wr0 , Btmp_hulp1)

          Btmp_hulp1 = Low(glaenge)
          Call W7100_write(w7100_s0_tx_wr1 , Btmp_hulp1)

          Call W7100_write(w7100_s0_cr , &H20)       'set send flag
   Loop

   Call W7100_write(w7100_s0_cr , &H8)               'set DISCON flag
End Sub

Routine to read the Dataflash, using the bootrom routine

Sub Read_dataflash
        Q = Varptr(dataflash(1))       'read dataflash to array dataflash()
        Wconf.7 = 0                    'reboot after operation disabled
        Wconf.6 = 0                    'activate bootrom from 0000-07FF
        Tmpr0 = Low(q)                 'pointer to dataflash(256)
        Tmpr1 = High(q)
        Ispaddrh = Tmpr1
        Ispaddrl = Tmpr0
        Ispid = &HD2                   'ISPID = Read
        Call &H07FD                    'call bootrom routine
        Wconf.6 = 1                    'deactivate bootrom
        'in array dataflash() the 256 byte from the dataflash
End Sub
We are not finished yet, routine to get the buffer from the RFM12BP

Sub Spi16(dout As Word)                     'RFM12BP write routine
   Nsel = 0
   Dsdo = 0
   For Nspi = 1 To 16                       'clock 16 bits out
      Dspi = Dout And &H8000
      If Dspi = 0 Then
         Sdi = 0                            'shiftout a 0
      Else
         Sdi = 1                            'shiftout a 1
      End If
      Dout = Dout * 2
      Dsdo = Dsdo * 2
      If Sdo = 1 Then
         Dsdo = Dsdo + 1
      End If
      Sck = 1
      Nop : Nop : nop                        'small wait
      nop : nop : nop
      nop : nop : nop
      nop : nop : nop
      nop : nop: nop
      Sck = 0
   Next Nspi
   Nsel = 1
   'spi16 = dsdo
End Sub

Put the RFM12BP on 433.400 MHz

Sub Freq_rfm12                               'Frequency for the RFM12BP
   If Freq < 800 Then Freq = Freq * 2
   Freq = Freq - 860
   Wd = Freq / 0.0050
   If Wd < 96 Then Wd = 96
   If Wd > 3903 Then Wd = 3903
   Wd = Wd + &HA000
   Call Spi16(wd)
End Sub

Initialize the RFM12BP

Sub Init_rfm12bp                             'Init the RFM12BP transceiver
Nsel = 1
Sck = 0
Call Spi16(&H80d7)
'Configuration Settings Command:
'433 Mhz, 12 pf, enable TX reg, enable RX FIFO
Call Spi16(&H82d9)
'Power Management Command:
'enable receiver, enable base band block
'enable synthesizer, enable crystal osc
'disable clock output pin
Call Spi16(&Ha67c)
'Frequency Setting Command:
'F=1660 frequency setting
Call Spi16(&Hc647)
'Data Rate Command: 4789 kbps
Call Spi16(&H94a4)
'Receiver Control Command:
'VDI, fast, 134 kHz, LNA Gain Max, DRSSI -79 dBm
Call Spi16(&Hc2ac)
'Data Filter Command:
'CLK recovery mode auto, clk recovery speed slow
'data filter type digital, data quality treshold 4
Call Spi16(&Hca81)
'FIFO and Rset Mode Command:
'FIFO IT level 8, synchron length 2 bytes
'FIFO fill start synchron, reset sensivity low
Call Spi16(&Hc483)
'Automatic Frequency Control Command:
'AFC Mode: Keep the F offset only during VDI=high
'Offset register limit: No restrictions
'Enable AFC, Enabe Frequency Offset Register
Call Spi16(&H9850)
'TX Control command: sign pos freq shift
'deviation 90 kHz, power out 0 dB Max
Call Spi16(&He000)
Call Spi16(&Hc800)
'Low Duty Cycle Command: D=0, disabled
Call Spi16(&Hc000)
'Low Battery Detect and uC CLK Command:
'treshold 2,2 volt
Freq = 434.300
'Put the frequency on 434.300 at startup
Call Freq_rfm12
End Sub

Wait routine for the RFM12BP

Sub Wait_rfm12                           'RFM12BP waitroutine
    Nsel = 0
    Do
    Loop Until Sdo = 1
End Sub

The KML-file that is send. Every ‘command’ is replaced by code or
variables. It is expandable for more than one W7100-Field Device.
That’s why you see commands like %Placemark0%, %SPEED0%, %BEARING0% etc.
This one has been made for obj01 (Granny).


'XML-code for KML-file
Header:
Data "<?xml version=" , &H22 , "1.0" , &H22 , " encoding=" , &H22 , "UTF-8"
, &H22 , "?>"
Data "<kml xmlns=" , &H22 , "http://www.opengis.net/kml/2.2" , &H22 , "
xmlns:gx=" , &H22
Data "http://www.google.com/kml/ext/2.2" , &H22 , " xmlns:kml=" , &H22
Data "http://www.opengis.net/kml/2.2" , &H22 , " xmlns:atom=" , &H22 ,
"http://www.w3.org/2005/Atom" , &H22 , ">"
Data "<Document><name>Patients</name><open>1</open>"
Data "<Style id=" , &H22 , "sh_wheel_chair_accessible" , &H22 , ">"
Data "<IconStyle><scale>2.33333</scale><Icon>"
Data
"<href>http://maps.google.com/mapfiles/kml/shapes/wheel_chair_accessible.pn
g</href>"
Data "</Icon><hotSpot x=" , &H22 , "0.5" , &H22 , " y=" , &H22 , "0" , &H22
, " xunits="
Data &H22 , "fraction" , &H22 , " yunits=" , &H22 , "fraction" , &H22 ,
"/>"
Data "</IconStyle><ListStyle></ListStyle></Style><Style id=" , &H22
Data "sn_wheel_chair_accessible" , &H22 , ">"
Data "<IconStyle><scale>2</scale><Icon>"
Data
"<href>http://maps.google.com/mapfiles/kml/shapes/wheel_chair_accessible.pn
g</href>"
Data "</Icon><hotSpot x=" , &H22 , "0.5" , &H22 , " y=" , &H22 , "0" , &H22
, " xunits="
Data &H22 , "fraction" , &H22 , " yunits=" , &H22 , "fraction" , &H22 ,
"/>"
Data "</IconStyle><ListStyle></ListStyle></Style>"
Data "<StyleMap id=" , &H22 , "msn_wheel_chair_accessible" , &H22 , ">"
Data
"<Pair><key>normal</key><styleUrl>#sn_wheel_chair_accessible</styleUrl>"
Data
"</Pair><Pair><key>highlight</key><styleUrl>#sh_wheel_chair_accessible</sty
leUrl>"
Data "</Pair></StyleMap>"

Placemark0:
Data "%Placemark0%"
Data "%LINE01%" , "%LINE02%" , "%LINE03%" , "%LINE04%" , "%LON0%" ,
"%LINE05%" , "%LAT0%" , "%LINE06%"
Data "%SPEED0%" , "%LINE07%" , "%BEARING0%" , "%LINE08%" , "%LINE10%" ,
"%LAT0%" , "%LINE11%" , "%LINE11a%" , "%LINE12%"
Data "%LINE12a%" , "%LINE13%" , "%LINE14%" , "%PAT_ID0%" , "%LINE15%" ,
"%LON0%" , "%LINE16%"
Data "%LAT0%" , "%LINE17%"

Footer:
Data "</Document></kml>"
Data "%END%"
Some extra pictures:




                         Information from a GPS




   Selected only the $GPRMC-line and converted from GPS to Google Earth
      coordinates. Padding # to 100 characters and adding a checksum
The Eagle add on we made for the RFM12BP and some switches
A KML-file generated by the W7100-Gateway

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:41
posted:6/29/2011
language:English
pages:43