| The program 
              described here was run in a Javelin 
              evaluation card and provided a temperature data value over the 
              serial line when sent a request from the program discussed in Chapter 
              23. We created three classes to run in the Javelin: 
              SendTempDataFromJavelin 
                - the main program that sets up the temperature sensor, creates 
                UART virtual peripheral objects to transmit and recieve data over 
                the serial line.
 
TempDataGenJavelin 
                - gets the temperature value from a DS1620 
                chip via the I/O pins. This class extends the abstract 
                DataGenerator 
                class. 
 
DataGenerator 
                - abstract class to represent data sources of different sorts. 
                It's getData() 
                method must be overriden by concrete subclasses. The program creates both a receive and a transmit 
              UART Virtual Peripheral class objects to provide 2-way serial communications. 
              Each constructor assigns two I/O pins to the appropriate function 
              and sets the serial mode for 9600 baud.  The reset signal will start the main() 
              routine, which creates an instance of TempDataGenJavelin, 
              which is reference by a DataGenerator 
              type variable. DataGenerator 
              is an abstract class (Javelin does not allow interfaces) with the 
              single method getData(). 
              The class TempDataGenJavelin 
              extends DataGenerator 
              and overrides getData() 
              with a method that obtains temperature readings from the chip DS1620. 
             The process then goes into a loop and immediately 
              invokes checkPW(). 
              This method provides for a simple protocol that requires that the 
              request for data first include a short password number. The method 
              invokes the receiveInt(), 
              which will wait for the requestor to transmit a two byte number 
              that matches the password value. The method receives 2 bytes in 
              big-endian format. That is, the least significant byte arrives first 
              and the most significant last. It makes an int value with the two 
              bytes (remember that in the Javelin, the integers are a maximum 
              of two bytes long.)  If the password value is valid, then a string 
              confirmation is transmitted to the requestor. Back in the main loop, 
              the data int value is obtained from the DataGenerator and then transmitted 
              as two bytes in big-endian format (Java specifications require big-endian 
              representation). The loop then returns to the receiveInt() method 
              again and waits for the next data request.  Note that the DS1620 chip can also be used to 
              control a thermostat. So a straight-forward extension of the programs 
              here would allow for setting the thermostat.  See code listing 
              on next page.   References 
              and Web Resources Latest update: Dec. 14, 2004 |