Home
WIRELESS DIGITAL VIDEO CAMERA
Contents
1. delay_us 30 sendBmpHeader PIC HEIGHT PIC WIDTA printf rh r delay_us 100 sendBmpInfoheader PIC_HEIGHT PIC_WIDTH delay_us 6000 atea NN e a Ye sendBmpTable print NERVE asm cli actCapture fasm sei 7 IG delay for PC side to prepare for rx 32 Wireless Digital Video Camera 3 3 1 3 rf h include lt stdio h gt include lt mega644_uart_tx h gt include lt delay h gt transceiver registers sendEndPreamble resetCam delay ms 2 writeCam 0x11 delay_ms 2 rxFrame 0 define TRX_STATUS 0x01 define TRX_STATE 0x02 define TRX_CTRL_O 0x03 define IRQ MASK Ox0E define IRQ STATUS Ox0F states of transceiver define TX START 0x02 define FORCE TRX OFF 0x03 define RX_ON 0x06 define TRX OFF 0x08 define PLL ON 0x09 define RX AACK ON 0x22 define TX_ARET_ON 0x25 pins define DDR_MOSI define DDR_MISO define DDR_SCLK define SEL define DDR_SEL define IRQ define DDR_IRO define SLP_TR define DDR_SLP_TR define RESET define DDR_RESET define IRQ TRX END 0x08 define ACT OxA5 define HEADER BYTE Ox5A void initSPI void void void void void void initTransceiver void rfSetRxMode void rfsetTxMode void rfSendFrame void rfRxListenAndWait void 0x25 0 DDRB gt 5 DDRB 6 DDRB 7 PORTB 4 DDRB 4 PINB 2 DDRB 2 PORTB 3 DDRB 3 PORTB 1 DDRB 1 interrupt Erom PC side Head
2. E ass gt 2 2 3 I rt 1 6 x x UNBAL nc 2 ayss SELL amp S 2 5 ot BALUN Rore 22pF 3 1 Avss Most 22 A 4V c1 L BAL BAL 4_ RFP pyss El SSE ATB6RF 230 O ta zer 5_ RFN misol ee Y 6 avss seck L ND 7 TST sa Dyss 18 ve R1 8 oono 1 vw AAA HK 17 V a 10K REST GS o a GH A A gt uw CLKM W KM ve gt gt 4153 gt gt WwW gt Re EO W1 A An A A 660 Y4 1 YCC_3p6 Te SCS Ar 0 ae ve L_VCE3p6 YCC_3p6 e3 a CBS _ CB4 2 2pF SDA SCL V ves 1 AGN XCL DE 21 VCC _3p6 AGN cL1 a uva 23Q 24 14 CL3 uve 29 300 259 260 Bo 1UF e eur Be uva 272 28 cnp 319 320440 34 Cornell University Transcei ver camera board Rev 2 0 10 3 2008 Benjamin Tang Page 1 Figure 4 Schematic diagram for transceiver camera board Wireless Digital Video Camera 2 1 7 Layout The cheapest PCB fabrication deal from ExpressPCB limits the size of a double layer PCB to 3 8 x2 5 at time of design I managed to design the layout of the PC side PCB that contains only the transceiver circuitry to have a size of about 1 2 x1 2 The camera side PCB that has both the transceiver and camera circuitries occupies a board area of about 3 8 x1 2 Therefore I could fit 2 PC side PCB and 1 camera side PCB on a single 3 8 x2 5 PCB with plenty of space between them The individual PCBs are meant to be cut out from the bigger piece of PCB as show
3. Embedded program Figure 17 Host software UML diagram 2 3 1 HostManager The HostManager class 1s the main class where the host software starts executing from It extends Java s JFrame class It creates instances of SerialManager Panel and DataAnalyzer classes in the correct sequence and passes on the instances to other classes that need them At start up an instance of SerialManager defined as serialManager_ is created first followed by an instance of Panel defined as panel which receives the said SerialManager instance Next an instance of DataAnalyzer defined as dataAnalyzer_ which receives the said SerialManager and Panel instances 1s created The GUI classes are then linked together in a network as shown in Figure 17 Besides that as an extension to JFrame the HostManager class works as a platform to hold the Panel class which 1s the main graphical user interface of the software 232 SerialManager The SerialManager class handles all the serial communication functions of the software It uses the open source RXTX API to handle all low level serial communication with the computer call to the enableSerial function searches for available serial ports and displays a message window that requests for user selection of a serial port SerialManager then attempts to connect to the selected serial port The status of the serial 19 Wireless Digital Video Camera connection is updated accordingly on the Panel as shown
4. register select 2 stop bits 8 bits reset camera void resetCam void twiReadRegister TWI_CAMERA WRITE ADDRESS TWI CAMERA READ ADDRESS 0x12 1 twiDataBuffer twiDataBuffer 0 0610000000 twiWriteRegister TWI_CAMERA WRITE ADDRESS 0x12 1 twiDataBuffer write to camera register void writeCam unsigned int reg unsigned char value twiDataBuffer 0 value twiWriteRegister TWI_CAMERA WRITE ADDRESS reg 1 twiDataBuffer read from camera register unsigned char readCam unsigned int reg I twiReadRegister TWI_CAMERA_WRITE_ADDRESS TWI CAMERA READ ADDRESS reg 1 twiDataBuffer return twiDataBuffer 0 create and send header void sendBmpHeader unsigned int height unsigned int width unsigned char bytelow unsigned char bytehigh unsigned int sizefile unsigned int 1078 height width bytelow sizefile lt lt 8 gt gt 8 bytehigh sizefile gt gt 8 2 Bytes BM bitmap signature txFrame 0 B txFrame 1 M 4 Bytes Filesize 14 40 1024 HEIGHT WIDTH txFrame 2 bytelow txFrame 3 bytehigh txFrame 4 0 txFrame 5 0 4 Bytes of reserved 0 txFrame 6 0 txFrame 7 0 txFrame 8 0 txFrame 9 0 4 Bytes of offset for location of raster data txFrame 10 0x36 txFrame 11 0x04 txFrame 12 0 txFrame 13 0 txDataLength 14 rfSetTxMode rfSendFrame create and send inf
5. 18 addGroup controlsPanel_Layout createParallelGroup javax swing GroupLayout Alignment BASELINE addComponent recButton_ Javax swing GroupLayout PREFERRED_SIZE javax swing GroupLayout DEFAULT SIZE javax swing GroupLayout PREFERRED_SIZE addComponent deleteButton_ javax swing GroupLayout PREFERRED SIZE javax swing GroupLayout DEFAULT SIZE javax swing GroupLayout PREFERRED_SIZE addComponent playButton_ Javax swing GroupLayout PREFERRED SIZE javax swing GroupLayout DEFAULT SIZE javax swing GroupLayout PREFERRED_SIZE addContainerGap javax swing GroupLayout layout new javax swing GroupLayout this this setLayout layout layout setHorizontalGroup layout createParallelGroup javax swing GroupLayout Alignment LEADING addGroup layout createSequentialGroup addContainerGap addGroup layout createParallelGroup Javax swing GroupLayout Alignment LEADING addComponent controlsPanel_ javax swing GroupLayout PREFERRED SIZE javax swing GroupLayout DEFAULT SIZE Javax swing GroupLayout PREFERRED SIZE addComponent topPanel javax swing GroupLayout DEFAULT SIZE javax swing GroupLayout DEFAULT SIZE Short MAX VALUE addComponent statusPanel_ 0 280 Short MAX VALUE addContainerGap layout setVerticalGroup layout createParallelGroup javax swing GroupLayout Alignment LEADING addGroup layout createSequentialGroup addContainerGap
6. The main power supply provides 9V The 5V regulator LM340 converts the 9V DC supply to 5V to power the camera circuit and the 3 6V regulator The 3 6V regulator LP2985 converts the 5V supply to 3 6V to power the MCU and transceiver circuits Wireless Digital Video Camera Wall wart 9V cell 20 OS Solar battery module 5V regulator 3 6V regulator 3 6V MCU circuit Transceiver circuit Figure 3 Power supply 2 1 6 Connectors As shown in the schematic diagram there are altogether 5 connectors J1 J2 J3 J4 and J5 used in the PC side and camera side PCB design The PC side PCB has only the transceiver circuitry whereas the camera side PCB has both the transceiver and camera circuitries Therefore the PC side PCB only requires one connector J1 The camera side PCB uses all 5 connectors J1 J2 J3 J4 and JS Connectors J1 and J2 interface with the GPIO VCC and GND pins aligned along the edge of the MCU PCB Connector J3 interfaces with the pins on the C3088 camera Connector J4 is an auxiliary connector that duplicates the camera UV pins for ease of feature expansion in the future Connector JS 1s also an auxiliary connector that duplicates the MCU s Port C pins AVCC_3p6 UF CB Cxi Exe 12pF 12pF CBI os 1uF Y a op 00 N Ne 19 U3 888888 J 5
7. addComponent topPanel_ javax swing GroupLayout PREFERRED SIZE javax swing GroupLayout DEFAULT SIZE jJavax swing GroupLayout PREFERRED SIZE addPreferredGap javax swing LayoutStyle ComponentPlacement UNRELATED addComponent statusPanel_ javax swing GroupLayout PREFERRED SIZE Javax swing Grouplayout DEFAULT_SIZE javax swing GroupLayout PREFERRED_SIZE addPreferredGap javax swing LayoutStyle ComponentPlacement UNRELATED addComponent controlsPanel_ javax swing GroupLayout DEFAULT SIZE javax swing GroupLayout DEFAULT SIZE Short MAX VALUE addContainerGap lt editor fold gt private void statusTF_ActionPerformed java awt event ActionEvent evt TODO add your handling code here pk Connect to serial port When connected button says Disconnect recButton_ enabled statusTF_ and connectionlabel_ display status throws PortInUseException throws UnsupportedCommOperationException throws IOException a private void connectButton_ActionPerformed java awt event ActionEvent evt throws IOException UnsupportedCommOperationException PortInUseException if connectButton_ getText equals Connect statusTF_ setText Connecting 52 Wireless Digital Video Camera connectionLabel setBackground java awt Color yellow change connection color to yellow isConnected serialManager enableSerial else if isRecording_ isRecording_ false recorder Stop stop recordi
8. case TWI_MT_ADR_ACK FOR break case TWI MT ADR NACK NACK gt retry goto retry case TWI_ARB_LOST goto begin default error gt STOP goto error TWDR regAddress send register address TWCR TWINT TWEN clear interrupt start tx while TWCR amp TWINT wait for tx TWINT switch TWSR amp TWSR_MASK check status case TWI_MT DATA ACK OK gt break break case TWI MT DATA NACK NACK gt quit goto quit case TWI ARB LOST goto begin default error gt STOP EE goto error Stop pause TWI interface TWCR 0 delay_us 2 TWCR TWINT TWSTA TWEN send START while TWCR amp TWINT wait for tx Switch TWSR amp TWSR_MASK check status case TWI_START case TWI REP START break case TWI_ARB LOST goto begin default 38 Wireless Digital Video Camera goto error sla slaveReadAddress regAddress gt gt 8 amp 0x07 lt lt 1 TWDR sla TWI READ send SLA R TWCR TWINT TWEN clear interrupt start tx while TWCR amp TWINT wait for tx switch TWSR amp TWSR_MASK check status case TWI MR ADR ACK break case TWI MR ADR NACK goto quit case TWI ARB LOST goto begin default goto error for i 0 i lt length i get content of register if i length 1 TWCR TWINT TWEN else TWCR TWINT TWEN TWEA while TWCR TWINT Switch TWSR amp TWSR MASK case T
9. 5a amp amp preambleByteCount_ 7 preambleByteCount_ 8 trackLatch_ 0 reset trackLatch System out println Found subsequent preamble else if preambleByteCount lt 3 preambleByteCount_ 8 preambleByteCount_ 0 if preambleByteCount_ 0 track baten else preambleByteCount_ 4 3 3 2 4 Panel java package host NES import java awt image BufferedImage p import java io File 4 import java io IOException a mport javax swing ImagelIcon Ja mport javax comm PortInUseException AE mport javax comm UnsupportedCommOperationException mport javax imageio HE mport javax swing JOptionPane H H H H H Panel java Created on Jul 20 2008 1 13 12 PM e per Panel class GUI author bentzx public class Panel extends javax swing JPanel private static final long serialVersionUID 11 private SerialManager serialManager_ private Recorder recorder_ private boolean isConnected_ false private boolean isRecording_ false private boolean isPlaying_ false Creates new form Panel throws IOException public Panel SerialManager sM throws IOException serialManager_ sM initComponents addListeners Imagelcon display new Imagelcon startupImg jpg Display video picWindowLabel setIcon display recorder new Recorder this This method is called from within th
10. DATABITS gt SerralPort DATABITS 8 pk x Constructor param hM HostManager EJ public SerialManager HostManager hM hostManager_ hM pk To select a port param msg The message to display in pop up window return The selected port el private String selectPort String msg Object list listPorts true String port null if list length gt 0 port String JOptionPane showInputDialog null JOptionPane INFORMATION_MESSAGE else System out println Must connect a serial port if port null I System out printin Exiting else port port substring 0 port indexof System out println port return port pk Searches for serial ports param available return The list of ports LS private Object listPorts boolean available Vector lt String gt result new Vector lt String gt list 0 43 Wireless Digital Video Camera Enumeration portEnum CommPortIdentifier getPortIdentifiers while portEnum hasMoreElements CommPortldentifier com CommPortIdentifier portEnum nextElement if available Switch com getPortType case CommPortIdentifier PORT SERIAL try Test open port to see if it s available CommPort thePort com open commtest 50 thePort close result add new String com getName getPortTypeName com getPortType catch PortInUseException e System err println e ca
11. JER Recursively delete folders in the directory given param dir Folder to be deleted return A boolean if deletion is successful y private boolean deleteDir File dir if dir isDirectory String children dir list for int i 0 i lt children length i boolean success deleteDir new File dir children i if success return false 98 Wireless Digital Video Camera delete empty directory return dir delete pk Generate a time based unique identifier for photo return A string containing the unique identifier E private String getUniqueldentifier Create a unique identifier based upon time DateFormat format new SimpleDateFormat ddMMMyyyy_hhmmss_SSSa System out println check uniqueldentifier format format new Date return format format new Date pk Copy file from source file to destination file param src source file param dst destination file E private void copyFile File src File dst try InputStream in new FilelnputStream src OutputStream out new FileOutputStream dst Transfer bytes from an to out byte buf new byte 1024 int len while len in read buf gt 0 out write buf 0 len in close out close catch FileNotFoundException e TODO Auto generated catch block e printStackTrace catch IOException e TODO Auto generated catch block e printStackTrace 99
12. SerialPortEventListener serialEvent gnu io SerialPortEvent ai public void serialEvent SerialPortEvent event switch event getEventType 45 Wireless Digital Video Camera dE case SerialPortEvent Bl case SerialPortEvent OE case SerialPortEvent FE case SerialPortEvent PE case SerialPortEvent CD case SerialPortEvent CTS case SerialPortEvent DSR case SerialPortEvent RI System out println Bad data Ignore most recent received data packet break case SerialPortEvent OUTPUT BUFFER EMPTY break case SerialPortEvent DATA AVAILABLE try while inputStream available gt 0 int i inputStream read System out printlind intToHex i hostManager_ getDataAnalyzer rxData i catch IOException e System err println IO Exception occurred reading fr inputStream System err println e break Disconnects serial connection x return Boolean false for disconnected serial i public boolean disconnect serialPort close return false false for disconnection Automatically disconnects and reconnects serial with previous settings x7 public void autoReconnect AutoReconnectThread aRecon new AutoReconnectThread this use new thread otherwise program freezes aRecon start pk Converts int to hex param i Int to be converted return Hex in String format a private String intToHex int i String hex Integer toHexString i Str
13. This involves creating a folder in local memory to store all valid image files collected while recording is enabled The folder s naming convention is chosen to easily distinguish between recordings It uses the Java s SimpleDateFormat which I define its format to be ddMMMyyyy hhmmss SSSa whereby dd is the day of the month in 2 digits MMM is the name of the month spelled with 3 letters yyyy is the year in 4 digits hhmmss is the hour minute and second in the standard 12 hour notation SSS is millisecond and a is either AM or PM An example of a folder name is 10Dec2008 094730 291PM which represents a recording that started at 9 47pm on 10 December 2008 The names of the recording folders are directly listed in the user selectable drop down box on the GUI as shown in Figure 19 Besides a uniquely identifiable recording folder named accordingly to the start time of the recording each recorded image stored in the recording folder is uniquely identifiable as well using a 13 digit computer system time in milliseconds System currentTimeMillis as its name when the image is recorded Recording is disabled when the Stop button on the GUI 1s clicked and Recorder calls updatePlaylist to update the list of recordings on the GUI 22 Wireless Digital Video Camera The Recorder class 1s also responsible for retrieving recordings and displaying them during playback The retrieve folder name funct
14. e Turn on power for both systems 24 Wireless Digital Video Camera 3 1 2 2 Software e Install and set up the RXTX plug ins for your computer s Java system according to the instructions given at www rxtx org e Double click on the WiDiVCam jar file to execute the GUI The program starts up as shown below Wireless Video Camera File Help Display Wireless Digital Video Camera Controls Select and play v Figure 22 GUI at start up 3 1 3 Video stream e To start video stream click the Connect button and the select from a pop up window the COM Port to which the PC side hardware system is connected as shown in Figure 18 e The connection status bar turns green upon successful connection and the video will start streaming once the program locks onto the camera data stream 3 1 4 Recording e Recording is only enabled when serial connection is active Otherwise the Rec button 1s disabled e Click the Rec button to start recording and the button changes to Stop Recordings are automatically saved in local memory e To stop recording click the Stop button 25 Wireless Digital Video Camera 3 1 5 Playback e Playback is only enabled when a recording is selected from the drop down playlist box that displays the text Select and play e Once a recording 1s selected click the Play button to start playback The Play button changes to Stop e To
15. not modify private javax swing JButton connectButton_ private javax swing JLabel connectionLabel private javax swing JPanel controlsPanel_ private javax swing JButton deleteButton_ private javax swing JLabel picWindowLabel_ priva te javax swing JButton playButton_ priva priva priva a te javax swing JPanel statusPanel_ pe te javax swing JComboBox playlistComboBox_ private javax swing JTextField statusTF_ te javax swing JButton recButton_ private javax swing JPanel topPanel_ End of variables declaration Requires this thread for play otherwise GUI freezes x author bentzx 7 class PlayThread extends Thread private Recorder recorder private String playlistSelected_ public PlayThread Recorder rec String s recorder_ rec playlistSelected_ s public void run recorder_ retrieve playlistSelected_ 3 3 2 5 Recorder java package host import java io File import java io FileFilter import java io FileInputStream import java io FileNotFoundException import java io FileOutputStream import java io IOException import java io InputStream import java io OutputStream import java text DateFormat import java text SimpleDateFormat import java util Date per Recorder class handles all recording and retrieving author bentzx a functions 56 Wireless Digital Video Camera public class Recorder pri
16. txFrame 36 0 txFrame 37 0 txFrame 38 0 txFrame 39 Oe txDataLength 40 rfSetTxMode rfSendFrame send color table void sendBmpTable void unsigned int i for i 0 142562144 4 Wireless Digital Video Camera txDataLength 4 rfSetTxMode rfSendFrame delay us 30 send start preamble void sendStartPreamble void unsigned long size unsigned long txFrame 0 size gt gt 24 txFrame 1 size lt lt 8 gt gt 24 txFrame 2 size lt lt 16 gt gt 24 txFrame 3 size lt lt 24 gt gt 24 txDataLength 4 rfsetTxMode rfSendFrame send end preamble and flusher void sendEndPreamble void first 4 bytes are end preamble txFrame 0 OxAA txFrame 1 0x55 txFrame 2 OxA5 txFrame 3 0x5A next 4 bytes are used to flush java serial so end preamble txFrame 4 0x01 txFrame 5 0x02 txFrame 6 0x03 txFrame 7 0x04 txDataLength 8 rfSetTxMode rfSendFrame capture photo and send void actCapture void unsigned int hort unsigned int vert unsigned int vertFull unsigned int bypass 0 unsigned int trackBypass 0 unsigned char wDiv2 PIC WIDTH gt gt 1 unsigned int count 0 unsigned char del 0 unsigned int i J rfsetTxMode for vertFull 0 vertFull lt NUM RECT FOR HEIGHT bypass vertFull lt lt LOG NRPF for del 0 del lt 1 del t whil
17. 0 sensor takes its register read address from the previous write cycle Therefore when reading from a camera register the microcontroller first performs a register write cycle that involves sending the camera write ID 0xC0 followed by the register read address Next the microcontroller sends the camera read ID 0xC1 which contains the read control bit 1 in its LSB bit before receiving the requested register data from the camera A more detailed TWI usage description can be obtained from the Atmega644P and OV6620 datasheets PGA Microsoft bitmap format The image data obtained from the camera is made into bitmap format and then sent to the PC Bitmap pictures are easily created by the microcontroller and easily converted into JPEG by the host software to be displayed on the PC The bitmap format consists of four 16 Wireless Digital Video Camera sections Header InfoHeader ColorTable and RasterData The following 1llustrates the bitmap format for a monochrome image of size 248x192 pixel Header 14 Bytes InfoHeader 40 Bytes ColorTable 1024 Bytes RasterData 248x192 Bytes Figure 14 Bitmap format 2 2 7 1 Header The Header consists of 14 bytes of data in the following sequence Signature 2 bytes FileSize 4 bytes Reserved 4 bytes and DataOffset 4 bytes The Signature section is by standard set to BM or 424D in hex The FileSize section describes the total size of the bitmap file in bytes
18. 1 Figure 6 PCB cutout for camera side board 11 Figure 7 PCB cutout for PC side board 11 Figure amera side UDS Ne 12 Figure PC Side SUD AID 12 Figure 10 Software architecture top level diagram rrnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn 13 Figure 11 PC side embedded state machine ia 13 Figure 12 Camera side embedded state machine rrrnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnenenn 14 Figure 13 Various methods for capturing image with limited buffer size From left Vertical capture horizontal capture and box Capture rrrrrrrrrrrnnnnnnnrrrrrrnnnnnnnnnnennre 16 Figure 1A Bitmap format sean daniel dde 17 Figure 15s One frame capt red Dy the Cameras vr 18 Figure 16 Host software state machine for main thread 18 Figure 17 Host software UML 19 Figure 18 Senter SAS 20 Figure 19 Playback selection and execution 22 Pigure 20 Delete confirmation tE quest ie 23 Figure 21 Left PC side system Right camera side system 24 Freire 22 GULat Start UP 4 45 25 Wireless Digital Video Camera List of Tables Tablet sG PIO COMM CHONS ae 8 Table 2 Bitcount section details essences esse secs success 17 Table Bl MN 26 Wireless Digital Video Camera 1 Abstract The objective of the project 1s to build a cheap wireless monitoring system for slowly varying environments The system can be used to monitor bee hives house solar panels and act
19. CK returned TWI SR GEN DATA NACK NACK returned TWI SR STOP RESTART status codes TWI START TWI REP START TWI ARB LOST TWI NO STATE TWI BUS ERROR on return status TWI_SUCCESS TWI_INVALID_STATUS_ERROR TWI_NO_ACK_ERROR TWI_INVALID_SLA ERROR TWI_ARB_LOST_ERROR TWI_NO_DATA ERROR Lize float temp if pullup_resistor A DDRC 0 0 DDRC 1 0 PORTC 0 1 PORIC 1 1 temp float cpu_freq 0x18 0x20 0x28 0x30 0x40 0x48 0x50 0x58 0x48 OxBO OxB8 UxCO 0xC8 0x60 0x68 0x70 0x78 0x80 0x88 0x90 0x98 OxAO 0x08 0x10 0x38 OxF8 0x00 O1 amp 0NR float E El jd El Ai El pl SLA W tramsmitted ACK received SLA W tramsmitted NACK received Data byte tramsmitted ACK received Data byte tramsmitted NACK received SLA R tramsmitted ACK received SLA R transmitted NACK received Data byte received ACK tramsmitted Data byte received NACK tramsmitted Own SLA R received ACK returned Arb lost in SLA R W as Master own SLA R received Data byte TWDR transmitted ACK received Data byte TWDR transmitted NACK received Last data byte in TWDR transmitted ACK received Own SLA W received ACK returned Lost arb in SLA R W as Master own SLA W received General call addr received ACK returned Lost arb in SLA R W as Master general call addr Previously addressed with own SLA W dat
20. CU as shown in Table 1 Data is transferred between the transceiver and the MCU via SPI The SPI control pins are SEL MOSI MISO and SCLK The MCU is the master whereas the transceiver is the slave in this SPI relationship The MCU supplies the clock signal via the SCLK pin To initialize communication the MCU pulls the SEL pin low and data is sent to the transceiver through the MOSI pin and received from the transceiver through the MISO pin A low signal on the RST pin resets the transceiver The SLP TR pin is used to start a wireless transmission of a frame of data 2 1 4 Camera The C3088 camera operates at a voltage of 5V It has a built in crystal that oscillates at 17 73MHz It is capable of taking relatively high resolution images at 101 376 pixels The difference in operating voltage between the camera at 5V and the rest of the circuit at 3 6V does not pose an issue because only the camera s digital IO pins are receiving signals from the rest of the system s circuit The camera s digital IO pins used for FC communication are able to accept lower range of voltage values at 3 6V from the MCU GPIO pins The image data received by the MCU no doubt has a maximum voltage level of SV can still be handled appropriately by the MCU The C3088 camera has 32 pins in a 2 by 16 pin arrangement A standard 2x16 connector is used to connect the camera s pins to the PCB 2 1 5 Power supply The system consists of three power supply sources
21. Digital Video Camera panel_ getStatusTF setText Played pctPlayed ery ii Thread sleep 3000 catch InterruptedException e TODO Auto generated catch block e printStackTrace else break break out of play mode when stop button pressed pk To get an array of folders directories as File in the recordings directory return An array containing folders File A4 protected File getRecFolders File dir new File recordings This filter only returns directories FileFilter fileFilter new FileFilter public boolean accept File file return file isDirectory y File files dir listFiles fileFilter return files JER To get an array of files bmp in the specified folder in the recordings directory param folderName The name of the folder in which to get files return An array containing the files bmp in the specified folder el private File getRecFiles String folderName File dir new File recordings folderName File files dir listFiles return files JR Delete the folder selected param folderName The name of the folder for deletion E protected void deleteFolder String folderName File dir new File recordings folderName boolean delSuccessful deleteDir dir if delSuccessful panel_ getStatusTF setText Delete successful else panel_ getStatusTF setText Unable to delete
22. GroupLayout PREFERRED SIZE addGroup controlsPanel_Layout createSequentialGroup addComponent connectButton_ javax swing GroupLayout PREFERRED_SIZE Swing GroupLayout DEFAULT_SIZE javax swing GroupLayout PREFERRED_SIZE addGap 30 30 30 addComponent connectionLabel_ javax swing GroupLayout PREFERRED SIZE 118 javax swing GroupLayout PREFERRED SIZE addComponent playlistComboBox 0 248 Short MAX VALUE addContainerGap controlsPanel_Layout setVerticalGroup controlsPanel_Layout createParallelGroup Javax swing GroupLayout Alignment LEADING addGroup controlsPanel_Layout createSequentialGroup addGroup controlsPanel_Layout createParallelGroup javax swing GroupLayout Alignment LEADING addGroup controlsPanel_Layout createSequentialGroup addContainerGap 51 Wireless Digital Video Camera addGroup controlsPanel_Layout createParallelGroup javax swing GroupLayout Alignment LEADING false addComponent connectionLabel_ javax swing GroupLayout DEFAULT SIZE jJavax swing GroupLayout DEFAULT_SIZE Short MAX VALUE addComponent connectButton_ Javax swing Grouplayout DEFAULT SIZE javax swing Grouplayout DEFAULT SIZE Short MAX VALUE addGroup controlsPanel_Layout createSequentialGroup addGap 52 52 52 addComponent playlistComboBox_ javax swing GroupLayout PREFERRED_SIZE javax swing GroupLayout DEFAULT SIZE javax swing GroupLayout PREFERRED_SIZE addGap 18 18
23. ImagelO read function to read in the JPEG file when updating the JLabel ie call setIcon ImagelO read jpeg file because ImagelO read does no caching and immediately outputs the file when set con function needs it If we call setIcon jpeg file instead without using the ImagelO read function the setIcon function fails to update even with JLabel s repaint validate or revalidate calls The playback feature needs to be executed on a separate thread from the current GUI thread that just fired the playback event The current GUI thread freezes when it is used to retrieve the image file from local memory reinitialize the JLablel and then repeat the process until the end of the recording None of JLabel s repaint validate or revalidate built in functions can solve the problem Refer to Panel java code in the Appendix section for implementation details 21 Wireless Digital Video Camera Display Wireless Digital Video Camera Status Played 85 Contrals 06Dec2008 035058 595AM DEDec2008 035058 595AM 10Dec2008 090352 337PM Rec Stop Delete 10Dec2008 0947 30 291PM Figure 19 Playback selection and execution 255 Recorder The Recorder class handles all functions involving storing and retrieving recordings to and from local memory When the Rec button on the GUI is clicked Panel calls the start function in Recorder to enable recording
24. Model new javax swing DefaultComboBoxModel new String Select and VW My VW VW E connectButton_ setText Connect connectButton_ setMaximumSize new java awt Dimension 100 connectButton setMinimumSize new java awt Dimension 100 ee connectButton_ setPreferredSize new java awt Dimension 100 23 23 23 deleteButton_ setText Delete deleteButton_ setEnabled false deleteButton_ setMaximumSize new java awt Dimension 60 deleteButton setMinimumSize new java awt Dimension 60 VALE deleteButton setPreferredSize new java awt Dimension 60 23 23 23 javax swing GroupLayout controlsPanel Layout new javax swing GroupLayout controlsPanel_ controlsPanel setLayout controlsPanel Layout controlsPanel Layout setHorizontalGroup controlsPanel Layout createParallelGroup javax swing GroupLayout Alignment LEADING addGroup controlsPanel_Layout createSequentialGroup addContainerGap addGroup controlsPanel_Layout createParallelGroup javax swing GroupLayout Alignment LEADING jJavax Short javax javax addGroup controlsPanel_Layout createSequentialGroup addComponent recButton_ javax swing GroupLayout PREFERRED_SIZE 71 swing GroupLayout PREFERRED_SIZE addGap 18 18 18 addComponent playButton_ Javax swing GroupLayout DEFAULT SIZE 71 MAX_VALUE addGap 18 18 18 addComponent deleteButton_ Javax swing GroupLayout PREFERRED_SIZE 70 swing
25. StatusIRO amp IRQ TRX END 0 checkStatusIRO 0 checks for incoming data then return boolean if any unsigned char rfRxListenNoWait void unsigned received 0 if IRQ 0 checkStatusIRQ rfReadRegister IRQ_ STATUS if checkStatusIRO IRO_TRX_END 0 received 1 else received 0 checkStatusIRQ 0 return received retrieve frame of data void rfRetrieveFrame void unsigned char i unsigned char data SEL 0 enable SPI transfer SPDRO 0600100000 frame receive command while SPSRO amp 0x80 0 wait till done SPDRO OxAA arbitrary data to rx a byte while SPSRO amp 0x80 0 rxDataLength SPDRO receive rxDataLength for i 0 i lt rxDataLength itt SPDRO OxAA while SPSRO amp 0x80 0 wait till done data SPDRO uart_send_byte data send to uart cxFrame i data SPDRO OxAA while SPSRO amp 0x80 0 wait till done LOI SPDRO uartsend byte LOT SEL 1 end SPI transfer clear IRQ void clearIRQ void checkStatusIRQ checkStatusIRQ rfReadRegister IRQ STATUS 0 read transceiver s register given address unsigned char rfReadRegister unsigned char addr unsigned char temp SEL 0 enable spi transfer SPDRO 128 addr amp 0b00111111 6 bit address while SPSRO amp Ox80 0 Wait till done temp SPDRO SPDRO OxAA send arbitrary data to receive back register data while SPSRO a
26. The Reserved section is unused and set to 0 The DataOffset section describes starting location of RasterData in the file 22 12 InfoHeader InfoHeader consists of 40 bytes of data in the following sequence size of InfoHeader 4 bytes which 1s set to 40 width of bitmap 4 bytes height of bitmap 4 bytes number of planes 2 bytes which 1s set to 1 Bitcount 2 bytes types of compression 4 bytes which is set to 0 for no compression compressed size of image 4 bytes which is set to 0 for no compression horizontal resolution 4 bytes vertical resolution 4 bytes number of colors used 4 bytes and number of important colors 4 bytes which 1s set to 0 to denote all colors are important The Bitcount section describes the number of bits to represent a pixel as follows 8 8 bitpalletized 256 colors Table 2 Bitcount section details The horizontal and vertical resolution sections are denoted in number of pixels per meter 2 2 7 3 ColorTable The size of ColorTable section is directly affected by the number of colors used and is calculated by multiplying number of colors by 4 This 1s because every color needs to have specifications in the following sequence for red intensity 1 byte green intensity 17 Wireless Digital Video Camera 1 byte and blue intensity 1 byte and reserved 1 byte Therefore for 256 colors 8 bits per pixel configuration in our case the size of the ColorT able section 1s 4x256 1024 b
27. WI MR DATA NACK case TWI MR DATA ACK data TWDR break default goto error TWCR TWINT TWSTO TWEN STOP while TWCR amp TWSTO return TWI SUCCESS return success status error CURE TWCR TWINT TWSTO TWEN STOP while TWCR TWSTO return TWI INVALID STATUS ERROR return error status send START send SLA W send register address write data STOP unsigned char twiWriteRegister unsigned char slaveWriteAddress unsigned int regAddress unsigned char length unsigned char data unsigned char sla i n 0 sla slaveWriteAddress regAddress gt gt 8 0x07 lt lt 1 retry if n gt TW_MAX_RETRY return TWI_NO_ACK_ERROR begin TWCR TWINT TWSTA TWEN send START while TWCR amp TWINT wait for tx TWINT Switch TWSR amp TWSR_MASK check status case TWI_REP_START case TWI_START OK break case TWI_ARB LOST goto begin default return TWI INVALID STATUS ERROR TWDR sla TWI_WRITE send SLA W TWCR TWINT TWEN clear interrupt start tx while TWCR amp TWINT wait for tx TWINT 39 Wireless Digital Video Camera Switch TWSR amp TWSR_MASK case TWI MT ADR ACK break case TWI MT ADR NACK JOCO Fetryv case TWI ARB LOST goto begin default goto error TWDR regAddress TWCR TWINT TWEN while TWCR amp TWINT switch TWSR amp TWSR_MASK case TWI_MT_DATA_ACK break ca
28. WIRELESS DIGITAL VIDEO CAMERA Design Document by Benjamin Tang Project Advisor Bruce R Land Degree Date January 2009 Wireless Digital Video Camera 4 2 Table of Contents Table of Contents List of Figures List of Tables Abstract Design and implementation 2 1 Hardware AleNteCiU E saa eee de NNN O 2 PE GE da EE RENEE EE tia 213 A Te eee ee 214 Camera 21 5 PW SUP ss PS NENNE 2 OEA Pu a a e a 21 8 ASS Sd ll 2 2 Embedded software architecture iii iii eeeeeeseeseeseeeeeeeses NOEN 2 2 2 PC side embedded software coccoccoccnnccnccnccnconccnconcnnnnnnonnonnnnnonnrnnnnnnnnrnnrnnennrnnnnnnnnss 2 2 3 Camera side embedded software iiiiiiiieeeieerceereeecereeeeces 224 RP60mmuncalbn m ususaanddasa none a ita 225 VAR I COMMUNICATIONS RE dida 226 A O A dn 227 INICrOSO Mt DIMap TO Mal LS od cias 2 3 FIOSE SO MAE Are NET UE id a 251 ROSIMANAGDCH ae 232 Sella MANAG SM mor dent ste ces 233 PA ACTES daa toc D PN PES E a RENE Appendix 3 1 USETT Na Sele DAM SNE SEN Cfo ro a A eee 312 RECON usada Ior PAET 5 sO VEN ee 3 2 Project budget allocation ss 3 3 TAO Sol Embedded Code VISION rra ica dad ene A NN Wireless Digital Video Camera List of Figures Figure t Hardware top ley el dive 6 Figure 2 MCU circuit DOOR 7 Hit S ROW CE SUD Dy EE EE EE EE T 9 Figure 4 Schematic diagram for transceiver camera board 9 FSSD Nay OU caesarean oia dt eco ons 1
29. a received Previously addressed with own SLA W data received data Previously addressed with general call Previously addressed with general call data STOP condition or repeated START condition received START transmitted Repeated START transmitted Arbitration lost No relevant state information Bus error with illegal START STOP conditions unsigned char pullup_resistor TWI FREQUENCY HZ 3 Wireless Digital Video Camera TWBR temp 16 2 TWI Bit Rate Register 12C Freq CPU Freq 16 2 TWBR 4 TWPS TWSR 0x00 prescaler 1 send START send SLA W send register address send START send SLA R grab data STOP unsigned char twiReadRegister unsigned char slaveWriteAddress unsigned char slaveReadAddress unsigned int regAddress unsigned char length unsigned char data unsigned char sla i n 0 sla slaveWriteAddress regAddress gt gt 8 0x07 lt lt 1 retry if n gt TW_MAX_RETRY return TWI_NO_ACK_ERROR begin TWCR TWINT TWSTA TWEN START while TWCR amp TWINT wait for tx TWINT switch TWSR amp TWSR_MASK check status case TWI REP START case TWI START TOR break case TWI_ARB LOST goto begin default return TWI INVALID STATUS ERROR TWDR sla TWI WRITE send SLA W TWCR TWINT TWEN clear interrupt start tx while TWCR amp TWINT wait for tx TWINT switch TWSR amp TWSR_MASK check status
30. al 10 Wireless Digital Video Camera ATOS DOLOLO LOS ITSO SEO TOP DE d AA ND JG AAA s I Bo sie uy CRE SS TI em KE GET Y RS eV ER NRS SSSR A y GE Figure 7 PCB cutout for PC side board 11 Wireless Digital Video Camera 2 1 8 Assembled system apaga TOUS LUE E Le L f rt 2 Figure 8 Camera side subsystem I ee 1022 Foz MERE 40d POT VA tee Figure 9 PC side subsystem 12 Wireless Digital Video Camera 2 2 Embedded software architecture 2 2 1 Overview The software architecture of the project consists of the embedded software architecture and the host software architecture The embedded software architecture consists of the PC side and the camera side embedded software architecture The PC side embedded subsystem sends a command to the camera side subsystem to request for data This command activates the camera and initiates the broadcast of image data via RF When the video data is received by the PC side embedded subsystem it transmits it to the PC Java host software to be processed The cycle is repeated for the next image stream PC side commands Camera side Java host embedded M embedded software program program Figure 10 Software architecture top level diagram 2 2 2 PC side embedded software The PC side embedded program radiopc c controls the camera side program With a video refresh rate of 32 seconds the PC side embedded
31. catch UnsupportedCommOperationException e TODO Auto generated catch block e printStackTrace catch PortInUseException e TODO Auto generated catch block e printStackTrace Hz recButton addActionListener new java awt event ActionListener public void actionPerformed java awt event ActionEvent evt recButton ActionPerformed evt er playButton_ addActionListener new java awt event ActionListener public void actionPerformed java awt event ActionEvent evt playButton_ActionPerformed evt HD playlistComboBox addPopupMenuListener new javax swing event PopupMenuListener I public void popupMenuWillBecomeVisible javax swing event PopupMenuEvent evt playlistComboBox Popup evt 54 Wireless Digital Video Camera public void popupMenuWillBecomelInvisible javax swing event PopupMenuEvent evt playlistComboBox PopupClosed evt public void popupMenuCanceled javax swing event PopupMenuEvent evt LIG deleteButton addActionListener new java awt event ActionListener public void actionPerformed java awt event ActionEvent evt deleteButton ActionPerformed evt JG EX Refreshes display param input Bitmap file 7 protected void initDisplay File input BufferedImage image ey it image flipV rotate90SX ImageIO read input image flipH Imagel0 read input File output new File recordings image jpg create a file for the output ImageIO write image jpg o
32. e CAM VSYNC while CAM VSYNC while CAM HREF while CAM HREF for trackBypass 0 trackBypass lt bypass while CAM HREF 14 40 1024 vertFull vertFull NUM ROWS PER FRAME PLC HETGHT PIC WIDTH wont get stuck delay to clear before consider next frame wait for next frame trackBypass 31 Wireless Digital Video Camera while CAM HREF for vert 0 vert lt NUM ROWS PER FRAME vert t while CAM HREF for hort 0 hort lt wDiv2 hort while CAM_PCLK buff count PINA while CAM PCLK while CAM PCLK buff count PINA while CAM_PCLK while CAM HREF count 0 txDataLength NUM_PER_SEND for i 0 i lt NUM_64B_IN_FRAME i for j 0 j lt NUM PER SEND j txFrame j buff i lt lt LOG_NPS j i 64 3 rfSendFrame delay ms 15 void main void initialize printf Nr Wireless Video Camera Version 1 0 r initTwiMaster CPU_FREQUENCY_HZ TWI_PULLUP_RESISTOR_ENABLE DDRA 0x00 defined as input signal from camera DDRD DDRD amp OxE3 signals from camera delay_ms 1500 resetCam delay_ms writeCam 0x11 0x25 slow down camera clock delay_ms 2 0x 2 while 1 rfSetRxMode rfRxListenAndWait PORTD 2 PORTD 2 LED indicator rfRetrieveFrame PLIAtE NERXD Sd r rxFrame 0 if rxFrame 0 ACT rfsetTxMode delay_us 4000 sendStartPreamble printt CEE
33. e at 3 6V as well At 3 6V the MCU is guaranteed to run properly below 10MHz Therefore the operating frequency of the MCU is set to 8MHz For convenience and ease of verification I started the design with Professor Land s MCU PCB as shown below The MCU GPIO ports as well as Vcc and Gnd pins are wired to pins along the edge of the PCB The order and layout of these pins are important in designing the PCB for the RF transceiver which will be discussed in the next section Figure 2 MCU circuit board The PCB 1s designed for 5V operation with the LM340 5V regulator I made a slight modification to the 5V regulator to provide 3 6V to the MCU The 5V output pin of the SV regulator is disconnected from the PCB and connected to the input pin of a 3 6V regulator which is on the RF transceiver PCB The output of the 3 6V regulator is then sent back to the MCU PCB via the VCC pins See Section 2 1 5 for power supply details The following table summarizes all the GPIO pins used There are 11 free GPIO ports that can still be used for other purposes Connected to the RF transceiver Wireless Digital Video Camera Connected to the camera Table 1 GPIO connections 2 1 3 RF transceiver The AT86RF230 transceiver operates at a voltage of 3 6V and frequency of I6MHz A Balun is used to convert its balanced output signal to unbalanced signal that is fed to the antenna The controls of the RF transceiver are connected to Port B of the M
34. e constructor to initialize the form WARNING Do NOT modify this code The content of this method is always regenerated by the Form Editor Bf SuppressWarnings unchecked lt editor fold defaultstate collapsed desc Generated Code gt 49 Wireless Digital Video Camera private void initComponents topPanel new javax swing JPanel picWindowLabel_ new Javax swing JLabel statusPanel_ new javax swing JPanel statusTF_ new javax swing JTextField controlsPanel_ new javax swing JPanel connectionLabel new javax swing JLabel recButton_ new javax swing JButton playButton_ new javax swing JButton playlistComboBox_ new javax swing JComboBox connectButton_ new javax swing JButton deleteButton_ new javax swing JButton topPanel_ setBorder javax swing BorderFactory createTitledBorder null Display javax swing border TitledBorder DEFAULT JUSTIFICATION javax swing border TitledBorder DEFAULT POSITION new java awt Font Tahoma 0 11 new Java art Colors 1593 2559 s 77 NOTLSN javax swing GroupLayout topPanel Layout new javax swing GroupLayout topPanel_ topPanel setLayout topPanel Layout topPanel Layout setHorizontalGroup topPanel Layout createParallelGroup javax swing GroupLayout Alignment LEADING addGroup topPanel_Layout createSequentialGroup addContainerGap addComponent picWindowLabel_ javax swing GroupLayout PREFERRED_SIZE 248 javax
35. ed is packaged up into a frame made up of a byte for frame transmit command 0x60 a byte for frame length and the data in the correct sequence To transmit the frame of packaged data from the RF transceiver the microcontroller pulls the SLP TR pin on the RF transceiver high which is taken care of by the function rfSendFrame as well For RF reception the RF transceiver has to be first set to receive mode with the rfSetRxMode function which sets the transceiver in RX ON state as described in the AT86RF230 datasheet Then the microcontroller can listen to incoming RF signals by 14 Wireless Digital Video Camera checking the IRQ STATUS register on the RF transceiver The complete reception of a frame of data 1s indicated by the TRX END bit of the IRQ STATUS register Next the microcontroller can start retrieving data from the RF transceiver with the rfRetrieveFrame function The frame of data is retrieved through SPI a byte at a time whereby the microcontroller sends a byte of junk arbitrary data just to receive a byte of data from the RF transceiver The frame of data is made up of a byte for frame receive command 0x20 a byte for frame length the data and a byte for LQI in the correct sequence The LQI information can be used to determine the quality of transmission and the suspected integrity of the data received For data integrity checks a header for RF frame transmission and reception 1s optionally implemented The header is s
36. ed program is 0x00 0x00 Oxbe 0x36 in hex The end preamble that marks the end of the image data frame is Oxaa 0x55 Oxa5 Ox5a The detectPreamble function tracks the data stream to find the start preamble incrementing the preambleByteCount_ variable by one with every matched preamble byte Once all four bytes of the start preamble are detected the preambleByteCount_ variable should have a value of 4 and we know that any subsequent data is the image data As long as the end preamble has not been detected yet DataAnalyzer puts all incoming data into a queue When the end preamble is detected the preambleByteCount_ variable would have been incremented up to 8 with all four matched end preamble bytes At this point we 20 Wireless Digital Video Camera would have all image data in the queue A quick check of the queue size allows DataAnalyzer to verify if the image data is valid A successful check of the queue size enables DataAnalyzer to extract the data from the queue to create a bitmap file to be sent to Panel for display with the function initDisplay bitmap file The DataAnalyzer is designed to handle non ideal situations Missing image data frames would not cause an error in processing the image file because of a image data queue size check mentioned above Corrupted image data that still has the correct size is beyond the host software s control but is handled by the PC side embedded program Besides that errors in the s
37. er portList nextElement if portld getPortType CommPortIdentifier PORT SERIAL Tests whether this is the com port we want if portId getName equals comPort_ I portFound true listen to serial port s events try if serialPort null serialPort close serialPort SerialPort portId open videoCam port 10000 wait up to 10 seconds for the port to open set the Serial Port parameters serialPort_ setSerialPortParams BAUD DATABITS STOPBELS PARITY set flow control hardware to none serialPort_ setFlowControlMode SerialPort FLOWCONTROL_NONE get the streams associated with serial port inputStream_ serialPort getInputStream outputStream_ serialPort_ getOutputStream start listening for events serialPort_ addEventListener this serialPort_ notifyOnDataAvailable true catch PortInUseException e System out println Serial Port already in use System err println e catch IOException e System out println An IO Exception occurred System err println e catch TooManyListenersException e System out println too many listeners System err println e catch UnsupportedCommOperationException e System out println Unknown comm Exception pa System err println e if portFound System out println Port comPort_ was not found return portFound non Javadoc see gnu io
38. er for each frame transmission unsigned char rfRxListenNoWait void void rfRetrieveFrame void void clearIR Q void unsigned char rfReadRegister unsigned char addr void rfWriteRegister unsigned char addr unsigned char RF_createChecksum unsigned char buff unsigned unsigned unsigned unsigned unsigned unsigned char char char char char char d KOL txFrame 64 txDataLength rxFrame 64 rxDatalength checkStatusIRQ FER butter to activate cam side receive checks for it unsigned char data unsigned char size to put data to be sent Length of data to be sent FLEX buffer can grab received data here length of data to be received can check quality of trx temp variable to check STATUS_IRQ 33 Wireless Digital Video Camera initialize SPI settings void initSPI void set directions for MCU SPI ports DDR_MOSI 1 DDR_MISO 0 DDR_SCLK 1 DDR_SEL 1 SPCRO 0601010000 enable SPI with MCU as master SPSRO 1 double speed initialize transceiver settings as receiver first void initTransceiver void set port directions DDR_IRO 0 DDR_SLP_TR DDR_RESET DDR_SEL 1 1 1 set signals SEL 1 RESET 1 SLP_TR 0 RESET 0 delay_us 1 RESET 1 rfWriteRegister TRX_CTRL_0 0b01001000 output current delay_us 800 rfWriteRegister IRQ MASK 0b00001000 TRX_END interrupt delay us 200 rfW
39. erial communication especially those involving missing start or end preambles will hamper DataAnalyzer s algorithm The variable trackLatch_ is used to detect this problem When preambleByteCount is stuck at 0 for a long period of time indicating errors in the serial communication DataAnalyzer will call the autoReconnect function to fix the problem 2 3 4 Panel The Panel class is the main graphical user interface of the host software It houses three subpanels Display Status and Controls The Display subpanel contains the video display which is set on a JLabel the Status subpanel displays the status of the program from serial connection status to recording playing stopping deleting and auto reconnect status the Controls subpanel allows users to connect and disconnect the serial communication record video and select from a list of recorded videos for playback or deletion The Panel class updates its video display using the initDisplay bitmap File function The function is also responsible for storing the bitmap file into local memory if recording is enabled This function is first called by the Panel class itself when initialized to display a start up screen Subsequent calls to this function are either made by the DataAnalyzer when valid image data is completely received or by the Recorder when playback is in use The function reads in a bitmap file and creates a JPEG file from it using Java s ImagelO class It is important to use
40. et to be Ox5A and is inserted between the frame length and the data in the rfSendFrame function for transmission Similarly the rfRetrieveFrame function would be modified to receive the header between the frame length and the data section in the frame 2 2 5 UART communication The project only requires UART transmit mode The serial communication settings are chosen to have a baud rate of 38400 bps 8 bits of data 2 stop bits and no parity When the PC side embedded system receives data via RF it immediately sends out the data via UART The UART communication speed is the main bottle neck in transmission of data Having a higher baud rate however increases transmission errors and this 1s caused by the MAX232 chip s series 2 2 6 Video The video stream consists of streaming bitmap images one after another The C3088 camera uses a progressive scan read out of data Important signals from the camera for the implementation of the project are VSYNC HREF PCLK and the Y bus For the default settings the VSYNC signal marks the start of the image scan when it goes from high to low a high HREF signal provides a guide for each horizontal line of image scan whereby image data for that particular line is valid at the rising clock edge of PCLK For an image of size 248x192 a naive and simple method to capture an image involves sampling the data at the Y bus 248 times for each line guided by each high HREF signal by the microcontroller and then re
41. he entire frame of image data is captured and transmitted A frame of bitmap image consists of 47616 bytes 248x192 of data or 24 subframes 8 lines per subframe which will be discussed in more detail in Section 2 2 6 Vate PREAMBLE 8 CAPTURE LISTEN BMP SUBFRAME HEADERS amp TRANSMIT frame_complete frame complete reset Figure 12 Camera side embedded state machine 2 2 4 RF communication The project implements the Basic Operating Mode of the RF transceiver The communication channel between the PC side transceiver and the camera side transceiver is RF Both transceivers take turns to operate as a transmitter or a receiver at different moments in time for synchronization purposes The communication between the RF transmitter and the microcontroller is through SPI whereby the microcontroller is the SPI master and the RF transmitter the slave To enable SPI communication the microcontroller pulls the SPI SEL pin low For RF transmission the RF transceiver has to be first set to transmit mode with the rfSetTxMode function which sets the transceiver in PLL ON state as described in the AT86RF230 datasheet Then the data to be transmitted is put into the transmit buffer txFrame with the data length specified in the txDataLength variable Then the function rfSendFrame is called to send the data over SPI from the microcontroller to the RF transceiver and packaged up for RF transmission The data to be transmitt
42. i h twi h define TW_MAX_RETRY 5 twi define define TWI FREQUENCY HZ 100000 define TWI_READ 1 define TWI_WRITE 0 define TWI GENERAL ADDRESS 0 define TWSR MASK OxF8 TWCR register constants define TWINT 0610000000 define TWEA 0b01000000 define TWSTA 0b00100000 define TWSTO 0b00010000 36 Wireless define define define twi ma define define define define twi ma define define define define twi sl define define ACK retu define define define twi sl define define ACK retu define define received define ACK retu define NACK ret define received define received define as slave other define define define define define EGNET define define define define define define FANTES void initTwiMaster unsigned long cpu freq Digital Video Camera 0600001000 0600000100 0600000001 TWWC TWEN TWIE ster tx status codes TWI_MT_ADR_ACK TWI MT ADR NACK TWI MT DATA ACK TWI MT DATA NACK ster rx status codes TWI MR ADR ACK TWI MR ADR NACK TWI MR DATA ACK TWI MR DATA NACK ave tx status codes TWI ST ADR ACK TWI ST ADR ACK M ARB LOST rned TWI ST DATA ACK TWI ST DATA NACK TWI ST DATA ACK LAST BYTE ave rx status codes TWI SR ADR ACK TWI SR ADR ACK M ARB LOST rned TWI SR GEN ACK TWI SR GEN ACK M ARB LOST ACK returned TWI SR ADR DATA ACK rned TWI SR ADR DATA NACK urned TWI SR GEN DATA ACK A
43. in Figure 18 A red connection status bar indicates a no connection yellow indicates connection in progress green indicates a successful connection File Help Display Wireless Digital Video Camera Wireless Digital Video Camere i Select Serial Port COM3 Serial Status Connecting Connected Serial connection is active Controls Controls Controls Connect Disconnect Select and play Select and play Select and play Figure 18 Serial connection status When data is received the SerialManager sends the data to DataAnalyzer using the function rxData data An important function in the SerialManager class is the autoReconnect function Some data can be stuck in the serial engine or go missing if not flushed out I realized that disconnecting and then re connecting the serial communication solves this problem Therefore I implemented the autoReconnect function to replace a manual disconnect and reconnect This function disconnects the current serial connection and reconnects it with the previously selected serial port However it requires a separate thread to execute because disconnecting the serial connection from the current thread and reconnecting it hangs the thread 2 3 3 DataAnalyzer The DataAnalyzer class analyzes the data received from the SerialManager using the private function detectPreamble The start preamble for the image data frame sent from the camera side embedd
44. ing hex Integer toHexString 0x100 Ox0Off 1 substring 1 if hex length 1 hex 0 hex return hex LEN Requires this thread for auto reconnect otherwise program freezes author bentzx 7 class AutoReconnectThread extends Thread private SerialManager serialManager_ 46 Wireless Digital Video Camera 3 3 2 3 public AutoReconnectThread SerialManager sM serialManager_ sM public void run System out println Auto reconnecting serialManager converse DataAnalyzer java package host As mport pr n mport mport d mport E mport H H H H H per java io File java io FileNotFoundException java io FileOutputStream java io IOException java util concurrent ConcurrentLinkedQueue DataAnalyzer class handles all data analysis author bentzx A public class DataAnalyzer Es private Panel panel_ E private SerialManager serialManager_ private int preambleByteCount_ 0 public static final int BMP_SIZE 48694 private ConcurrentLinkedQueue lt Integer gt queue_ null private int trackLatch_ 0 pk Constructor param p Panel param sM SerialManager Le public DataAnalyzer Panel p SerialManager sM panel p serialManager_ sM queue new ConcurrentLinkedQueue lt Integer gt REN Receives serial port data param i public void rxData int i detectP
45. ion is called by Panel when the Play button on the GUI is clicked This function retrieves all recorded images in the specified folder and displays them in sequence in a new thread as long as playback is still enabled Once the Stop button 1s clicked the function breaks returns and stops playback The heart of the recording deletion is also handled by Recorder When the Delete button on the GUI is clicked with a recording selected from the GUI s playlist a deletion confirmation message Is displayed requesting for user confirmation as shown in Figure 20 When user confirmation is obtained Panel calls Recorder s delete Folder folder name function and the folder together with 1ts content 1s deleted recursively Do you really want to delete selected recording Figure 20 Delete confirmation request 23 Wireless Digital Video Camera 3 Appendix 3 1 User manual 3 1 1 Components 3 1 1 1 Hardware e PC side unit e Camera side unit e 1 Serial cable e 2DC 9V wall wart 3 1 1 2 Software e Wireless Digital Video Camera JAR executable file W1D1VCam jar e RXTX plug ins 3 1 2 Set up 3 1 2 1 Hardware Figure 21 Left PC side system Right camera side system e Connect the power sockets on the PC side system and the camera side system to the DC wall wart e Connect the serial port on the PC side system to the serial port on the PC with the serial cable e Point camera to location of interest
46. ireless RF transceivers and a CMOS camera The MCUs used are the Atmel Atmega644P The transceivers used are the Atmel AT86RF230 chips The CMOS camera used 1s the C3088 video camera with Omnivision OV6620 image sensor The components can generally be grouped into PC side components and camera side components as shown in Figure 1 The PC side MCU is responsible for receiving data via SPI from the RF transceiver connected to 1t and then sends the data over to the PC via UART Reading and writing to the transceiver s registers are also done through SPI whereby the MCU 1s set as the master and the transceiver the slave The camera side MCU is responsible for controlling the RF transceiver and the camera connected to it and receiving image data from the camera The camera s image data is clocked out onto its output pins which are connected to the general purpose input output GPIO ports of the MCU The MCU retrieves the image data and sends it to the transceiver for transmission Image transmission will be discussed further in the embedded software architecture section Reading and writing to the camera s registers are done through IC or TWD Wireless Digital Video Camera 2 1 2 MCU The Atmega644P MCU is chosen because of its large SRAM capacity 4 KB which makes buffering of data easier It 1s capable of running at low voltages at low frequencies Because of the operating voltage of the RF transceiver is 3 6V the MCU is designed to operat
47. ivities in the compound The system consists of two IEEE802 15 4 Standard compliant wireless transceiver modules and microcontrollers a CMOS digital camera PC Graphical User Interface GUI and serial port modules The wireless transceiver modules communicate between the camera side embedded system and the PC side embedded system The sequence of images sent from the camera side transceiver Is received wirelessly by the PC side transceiver The PC side transceiver then transfers the images to the PC via the PC s serial port The sequence of images is displayed in the GUI The GUI also features recording playback of recording and deletion of recording functions controllable by the user through the GUI Wireless Digital Video Camera 2 Design and implementation This section 1s divided into hardware architecture embedded software architecture and host software architecture The hardware architecture section describes the functions and the interactions between the components of the system The embedded software architecture section describes the embedded software and protocols that handle wireless transmission and camera operation The host software architecture section describes the PC GUI program that handles user commands and video display 2 1 Hardware architecture 2 1 1 Overview PC side Camera side Camera Figure 1 Hardware top level diagram The major components of the system are the PC two microcontrollers MCU two w
48. mp Ox80 0 Wait till done 35 Wireless Digital Video Camera SEL 1 return SPDRO data read from register write transceiver s register given address and data to be written void rfWriteRegister unsigned char addr unsigned char data unsigned char temp SEL 0 enable spi transfer SPDRO 192 addr amp 0b00111111 while SPSR0 amp 0x80 0 Wait till done temp SPDRO SPDRO data while SPSR0 amp 0x80 0 Wait till done SEL 1 end spi transfer create simple checksum unsigned char RF_createChecksum unsigned char buff unsigned char size see wikipedia checksum unsigned char i 0 unsigned char chks 0 while i lt size sum up data chks chks buff chks chks amp 0xff chks chks 1 get 2 s complement flip bits add 1 D LI LOICORSES 5 Neil Cms o return chks 3 3 1 4 mega644_uart_tx h define UDREO 5 void uart_send_byte_array unsigned char data unsigned int length void uart_send_byte unsigned char data send byte array with specified length void uart_send_byte_array unsigned char data unsigned int length unsigned int counter 0 while counter lt length while UCSROA 1 lt lt UDREO Wait for buffer UDRO data Send out data send byte void uart_send_byte unsigned char data while UCSROA amp 1 lt lt UDREO Wait buffer UDRO data Send out data 3 3 1 5 tw
49. n in Figure 6 and Figure 7 2 1 7 1 Top layer All components except for the crystal for the RF transceiver circuitry and a capacitor are on the top layer Traces connected to the bypass capacitors are made as short as possible To minimize signal reflections caused by impedance mismatch traces from the RF transceiver to the balun and from the balun to the antenna are designed to be symmetric Besides that the traces connecting the RF output pins to the balun have an impedance of 100Q which is achieved by having trace width of about 0 030 inches for the given material http circuitcalculator com wordpress 2006 01 24 trace resistance calculator The trace between the antenna and the output of the balun is designed to have impedance of 50Q which 1s achieved by having trace width of about 0 1 inches for the given material Traces with high frequency signals such as clock signals are kept away from other signals to prevent coupling of the high frequency signals into the quieter signals 2 1 7 2 Bottom layer The bottom layer consists of the ground plane signal routing RF transceiver circuitry crystal and a capacitor The ground plane is carefully shaped so that the RF ground plane analog ground plane and the digital ground plane meet only at the star point of the RF transceiver chip as advised by the AT86RF230 datasheet To prevent the crystal from introducing noise to the ground planes a cutout of the ground plane is placed around the cryst
50. nd to be over exposed due to a longer minimum exposure time The box capture method is fast but difficult to implement because of the complexity in merging the boxes to form a bigger image either by merging individual box s bitmap data into a bigger image s bitmap data or displaying each box as separate bitmap image in the host software GUI Considering all the tradeoffs above I implemented the horizontal capture method for the project li lis AAA a I MU Figure 13 Various methods for capturing image with limited buffer size From left Vertical capture horizontal capture and box capture The C3088 camera with the OV6620 image sensor has a default system clock frequency of 8 86MHz Due to voltage constraints that affect the operation frequency the microcontroller is run at 8MHz For the microcontroller to be able to keep up with sampling the image data with the horizontal capture method and processing it the camera system clock frequency has to be adjusted to run at 119 8 kHz Writing and reading data to and from the camera registers are done via SCCB Serial Camera Control Bus which is compatible with IC Inter Integrated Circuit or TWI Two Wire Interface When writing to a camera register the microcontroller sends the camera write ID 0xC0 which contains the write control bit 0 in its LSB bit followed by the register address and then the data to be written It 1s important to note that the OV662
51. ng if still recording isConnected_ serialManager_ disconnect recButton_ setEnabled isConnected_ enabled only when serial connection is active if 1sConnected_ isConnected_ serialManager converse connectButton_ setText Disconnect statusTF_ setText Connected Serial connection is active connectionLabel_ setBackground java awt Color green recButton_ setText Rec else connectButton_ setText Connect statusTF_ setText Serial communication is disconnected connectionLabel setBackground java awt Color red isRecording false pk Handles rec button behavior param evt Action event FL private void recButton_ActionPerformed java awt event ActionEvent evt if isRecording recButton setText Rec statusTF setText Recording stopped isRecording false recorder stop else recButton setText Stop statusTF setText Recording isRecording true recorder start pk Handles play button behavior param evt Action event EL private void playButton ActionPerformed java awt event ActionEvent evt if isPlaying_ playButton_ setText Play statusTF_ setText Playback stopped isPlaying_ false else playButton_ setText Stop statusTF_ setText Playing isPlaying_ true String playSelected String playlistComboBox getSelectedItem PlayThread play new PlayThread recorder_ playSelected use new thread o
52. nt preambleByteCount when int i matches preamble Keep rxData running as long as preambleByteCount is 4 5 6 7 when reaches 8 know that reached end of second preamble then createPic and be sure to deduct the subsequent preamble from queue first param i integer data received I private void detectPreamble int 1 if intToHex i equals 00 amp amp preambleByteCount 0 preambleByteCount if intToHex i equals 00 amp amp preambleByteCount_ 1 else else else else else trackLatch_ gt 30000 else else preambleByteCount if intToHex i equals be preambleByteCount if intToHex i equals 36 preambleByteCount System out println Found preamble panel_ getStatusTF setText Capturing image if intToHex i equals aa amp amp preambleByteCount_ 4 preambleByteCount_ 5 if intToHex i equals aa get system out of latch preambleByteCount_ 5 serialManager_ autoReconnect panel_ getStatusTF setText Auto reconnect amp amp preambleByteCount_ 2 amp amp preambleByteCount_ 3 amp amp preambleByteCount 0 amp amp if intToHex i equals 55 amp amp preambleByteCount_ 5 preambleByteCount_ 6 if intToHex i equals a5 amp amp preambleByteCount_ 6 48 Wireless Digital Video Camera preambleByteCount _ 7 else if intToHex i equals
53. oheader void sendBmpInfoheader unsigned int height unsigned int width unsigned char height_low unsigned char height_high 29 Wireless Digital Video Camera unsigned char width_low unsigned char width_high height_low height lt lt 8 gt gt 8 height_high height gt gt 8 width_low width lt lt 8 gt gt 8 width_high width gt gt 8 4 Bytes InfoHeader size 40 txFrame 0 40 txFrame 1 0 txFrame 2 0 txFrame 3 0 4 Bytes width of the image in pixels txFrame 4 width_low txFrame 5 width_high txFrame 6 0 txFrame 7 0 4 Bytes height of the image in pixels txFrame 8 height_low txFrame 9 height_high txFrame 10 0 txFrame 11 0 2 Bytes Number of planes txFrame 12 1 txFrame 13 0 2 Bytes bitcount 8 txFrame 14 8 txFrame 15 0 4 bytes type of compression none txFrame 16 0 txFrame 17 0 txFrame 18 0 txFrame 19 0 4 bytes no compression txFrame 20 0 txFrame 21 0 txFrame 22 OF txFrame 23 0 4 bytes horizontal resolution txFrame 24 0 txFrame 25 0 txFrame 26 0 txFrame 27 0 4 bytes vertical resolution txFrame 28 0 txFrame 29 0 txFrame 30 0 txFrame 31 0 4 bytes num of colors used 256 txFrame 32 Oly txFrame 33 l txFrame 34 0 txFrame 35 0 14 bytes num of important colors all
54. ommand line argument throws IOException throws PortInUseException throws UnsupportedCommOperationException A ER 6 HF E public static void main String argv throws IOException UnsupportedCommOperationException PortInUseException new HostManager 3 3 2 2 SerialManager java package host J import java io IOException import java util TooManyListenersException aes import java io InputStream 4 import java io OutputStream import java util Enumeration import java util Vector 42 Wireless Digital Video Camera import gnu io CommPortIdentifier import gnu io CommPort import gnu io PortInUseException import gnu io SerialPort mport gnu io SerialPortEvent mport gnu io SerialPortEventListener mport gnu io UnsupportedCommOperationException H H H E import javax swing JOptionPane per SerialManager class handles all serial communication author bentzx public class SerialManager implements SerialPortEventListener private HostManager hostManager_ private SerialPort serialPort_ null private String comPort_ null private InputStream inputStream_ null private OutputStream outputStream_ null Serial port settings private static final int PARITY SerialPort PARITY_NONE private static final int STOPBITS SerialPort STOPBITS_2 private static final int BAUD 38400 38400 57600 115200 private static final int
55. ompare match A asm sei enable interrupts endasm void initUART void UBRROL 12 baud rate 38400 for 8 MHz UCSROB 1 lt lt 4 1 lt lt 3 enable receiver and transmit UCSROC 1 lt lt 7 1 lt lt 3 1 lt lt 2 1 lt lt 1 register select void fetch votada 1 timer TIMEOUT rfSetTxMode txDataLength 1 txFrame 0 ACT rfSendFrame reset timer rfSetRxMode clearIRQ tCransceiver set to receive while timer gt 0 if rfRxListenNoWait 1 PORTD 2 PORTD 2 rfRetrieveFrame retrieve frame 2 stop bits 8 bits Wireless Digital Video Camera void main void initialize delay_ms 5000 while 1 if timer 0 fetch 3 3 1 2 radiocam c radiocam c include lt mega644 h gt include lt rf h gt include lt stdio h gt include lt twi h gt RF transmission frame constants define RF FRAME LIMIT define PIC WIDTH define PIC HEIGHT define NUM ROWS PER FRAME define LOG NRPF define LENGTH FR NUM ROWS PER FRAME x WIDTH define NUM RECT FOR HEIGHT define NUM 64B IN FRAME define NUM PER SEND clearing sram buffer define LOG NPS cwi camera constants define CPU FREQUENCY HZ define TWI PULLUP RESISTOR ENABLE define TWI CAMERA WRITE ADDRESS define TWI CAMERA READ ADDRESS define TWI DATA BUFFER LENGTH define CAM HREF define CAM VSYNC define CAM PCLK define TRUE define FALSE global ini
56. onUID 11 private Panel panel_ Panel private DataAnalyzer dataAnalyzer_ DataAnaylzer private SerialManager serialManager_ SerialManager private JMenultem helpMenuAbout_ private JMenultem fileMenuExit_ private JMenu fileMenu_ private JMenu helpMenu_ private JMenuBar menuBar_ public static final String PROJECT_NAME Wireless Video Camera ER HostManager constructor throws IOException throws UnsupportedCommOperationException throws PortInUseException e public HostManager throws IOException UnsupportedCommOperationException PortInUseException super create in correct sequence serialManager_ new SerialManager this panel_ new Panel serialManager_ dataAnalyzer_ new DataAnalyzer panel_ serialManager_ initComponents pk Initialize components on frame ef private void initComponents setDefaultCloseOperation javax swing WindowConstants EXIT ON CLOSE setBackground new j v awt Color 255 255 255 setResizable false setTitle HostManager PROJECT NAME getContentPane add panel_ java awt BorderLayout CENTER initMenu initList nersi pack set Location 250 250 setVisible true JER Initialize menu bar items Ey private void initMenu menuBar_ new javax swing JMenuBar fileMenu_ new javax swing JMenu fileMenuExit_ new Javax swing JMenultem helpMenu_ new javax swing JMenu helpMenuAbout_ new Javax swing JMen
57. p statusPanel_Layout createParallelGroup javax swing GroupLayout Alignment LEADING addGroup javax swing GroupLayout Alignment TRAILING statusPanel_Layout createSequentialGroup addContainerGap javax swing GroupLayout DEFAULT_SIZE Short MAX VALUE addComponent statusTF_ javax swing GroupLayout PREFERRED SIZE jJavax swing GroupLayout DEFAULT_SIZE javax swing GroupLayout PREFERRED_SIZE addContainerGap 50 Wireless Digital Video Camera jJavax jJavax controlsPanel setBorder javax swing BorderFactory createTitledBorder null Controls swing border TitledBorder DEFAULT JUSTIFICATION swing border TitledBorder DEFAULT POSITION new java awt Font Tahoma 0 11 new lav sancicolon d 153 gt 25599 777 NOLIN play connectionLabel setBackground java awt Color red connectionLabel setForeground java awt Color red JL connectionLabel setOpaque true recButton setText Rec recButton_ setEnabled false recButton_ setMaximumSize new java awt Dimension 60 recButton_ setMinimumSize new java awt Dimension 60 eee recButton_ setPreferredSize new java awt Dimension 60 23 23 23 playButton setText Play playButton setEnabled false playButton setMaximumSize new java awt Dimension 60 playButton setMinimumSize new java awt Dimension 60 playButton_ setPreferredSize new java awt Dimension 60 23 23 23 playlistComboBox_ set
58. peated for 192 lines when the VSYNC signal goes low However to work with the limited size of the microcontroller memory 4KB for Atmega644P the capturing process has to be modified unless external memory modules are added Buffering of data is needed because of the inherent delay in transmitting the image data By using only the amount of memory available in the microcontroller as an image buffer three methods of capturing an image can be used vertical capture horizontal capture and box capture as shown in Figure 13 Each rectangle bounded by red lines in the figure represents an image data section that can be captured at any one time for the limited size buffer and transmitted to the PC side before the next rectangle can be captured The vertical capture method is slow because for every horizontal scan only one byte of data is taken However the camera can be set to run at a higher frequency without having to worry about missing camera sync signals because there will 15 Wireless Digital Video Camera be plenty of time for the microcontroller to do processing The image will not be over exposed because higher camera system frequency results in shorter exposure time The horizontal capture method 1s fast and simple to implement However the camera has to run at a lower frequency so that the microcontroller can keep up with the sync signals as more processing is performed between the sync signals At a lower operation frequency images te
59. program runs a microcontroller timer that creates interrupts to give the start command every 36 seconds The time period of 36 seconds is chosen because of ease of implementation with just a timer that creates an interrupt every 4 seconds and a modulo 9 counter In the COMMAND state the RF transceiver 1s set to transmit mode and issues a command activate via RF to the camera side receiver The activate command is set as OxA5 Then the RF transceiver Is set to receive mode to listen to incoming data from the camera side When received the data is downloaded from the RF transceiver to the microcontroller via SPI and sent to the Java host software immediately via UART start lincoming COMMAND Activate LISTEN Ista reset start DOWNLOAD Figure 11 PC side embedded state machine 13 Wireless Digital Video Camera 2 2 3 Camera side embedded software When the camera side embedded program radiocam c runs the RF transceiver 1s set to receive mode to listen for the activate command from the PC side When the activate command is received the RF transceiver 1s set to transmit mode to transmit the start preamble and the bitmap header info header and color table The start preamble has a size of 4 bytes and 1s set as the size of the bitmap file Section 2 2 7 describes the bitmap format more thoroughly Next the camera captures a subframe of image data and transmits it via RF to the PC side and this process repeats itself until t
60. reamble i System out println preambleByteCount_ if preambleByteCount_ gt 4 amp amp preambleByteCount_ lt 8 queue_ add new Integer i if preambleByteCount 8 System out println qs queue_ size if queue_ size BMP_SIZE 5 createPic preambleByteCount_ 0 queue clear System out println qs queue_ size JAR x Converts int to hex 47 Wireless Digital Video Camera param i int x return hex a private String intToHex int i String hex Integer toHexString i String hex Integer toHexString 0x100 OXOFE amp i substring 1 if hex length 1 hex 0 hex return hex pk Creates bitmap file from image data Af private void createPic FileOutputStream fos File tempFile new File recordings temp bmp try fos new FileOutputStream tempFile remove the first element since not needed the last preamble byte queue_ poll Integer queueArray queue_ toArray new Integer 0 for int i 0 i lt queueArray length 4 i ignore subsequent preamble stored fos write queueArray i intValue panel initDisplay tempFile fos close fos gt null System dut printin iTnttDispl ay carried out catch FileNotFoundException e e printStackTrace catch IOException e e printStackTrace preambleByteCount 0 queue clear pk Checks for preamble start increme
61. riteRegister TRX STATE FORCE TRX OFF delay_us 1880 rfWriteRegister TRX_STATE RX_ON init as rx delay_us 200 set transceiver in receive mode void rfSetRxMode void rfWriteRegister TRX_STATE FORCE TRX OFF delay us 1880 rfWriteRegister TRX STATE RX ON delay us 200 set transceiver in transmit mode void rfSetTxMode void rfWriteRegister TRX_STATE FORCE TRX OFF delay us 1880 rfWriteRegister TRX STATE PLL ON delay us 200 send out frame with txFrame and txDataLength filled void rfSendFrame void send out frame unsigned char 1 rfWriteRegister TRX STATE PLL ON SEL 0 enable SPI transfer SPDRO 0b01100000 frame tx command while SPSRO amp Ox80 0 wait till done SPDRO txDataLength send frame length while SPSROS 0x80 0 wait till done for i 0 i lt txDataLength i send out data SPDRO txFrameli while SPSRO amp 0x80 0 wait till done SEL 1 end SPI transfer SLP_TR 1 release frame via RF 34 Wireless Digital Video Camera delay us 1 SLP TR Q make sure transmit is complete do I if IRQ 0 checkStatusIRQ rfReadRegister IRQ_ STATUS while checkStatusIRO IRQ TRX END 0 checkStatusIRO 0 listen and won t return until detected incoming data void rfRxListenAndWait void do if IRQ 0 checkStatusIRQ rfReadRegister IRQ_ STATUS while check
62. se TWI_MT DATA NACK goto quit case TWI_ARB_LOST goto begin default goto error for i 0 i lt length i TWDR data check status OK NACK gt retry error gt STOP send register address clear interrupt start tx wait for tx TWINI check status OK NACK gt quit error gt STOP write data TWCR TWINT TWEN while TWCR amp TWINT switch TWSR amp TWSR_MASK check status case TWI MT DATA ACK OK break case TWI_MT_DATA_NACK write protected gt quit fen goto quit case TWI_ARB LOST da goto begin default d error gt STOP goto error TWCR TWINT TWSTO TWEN while TWCR TWSTO return TW SUCCESS error quit TWCR TWINT TWSTO TWEN while TWCR TWSTO return TWI_INVALID SLA ERROR 3 3 2 Java 3 3 2 1 HostManager java package host import java awt event ActionEvent E import java io IOException AE import javax comm PortInUseException import javax swing JFrame import javax swing JMenu import javax swing JMenuBar m ae import Javax swing JMenultem import javax swing JOptionPane STOP STOP import javax comm UnsupportedCommOperationException 40 Wireless Digital Video Camera per HostManager class Main author bentzx ay public class HostManager extends JFrame private static final long serialVersi
63. stop playback click the Stop button 3 1 6 Deletion e Deletion of recording is only enabled when a recording is selected from the drop down playlist box e Once a recording is selected click the Delete button to delete the selected recording e A window pops up requesting for deletion confirmation Click the Yes button to continue with deletion 3 2 Project budget allocation Expenses Cost s PCB 1 of 3 used Total 8150 Table 3 Budget allocation 26 3 3 Code 3 3 1 Embedded CodeVision 3 3 1 1 radiopc c radiopc c pc side radio include include include include lt mega644 h gt lt rf h gt lt stdio h gt lt string h gt define TRUE define FALSE 0 define TIMEOUT 9 time to loop back for next photo unsigned char timer vold initialize void void initUART void void fetch void interrupt TIM1_COMPA if timer gt 0 void timerl_comp void timer void initialize void initSPI initTransceiver initUART set up SPI for MCU set up transceiver DDRD 2 1 led indicator PORTD 2 O coupled with TCCROB settings Timer set up to f 1024 9 of this yields 36s TCCRIA 0b00000000 Clear timer on compare match TCCRIB 0600001101 Clear timer on compare match OCRIAH 0x7A produce timer for 4s need to count to 31250 0x7A12 OCRIAL 0x12 TIMSK1 0b00000010 interrupt enable for c
64. swing GroupLayout PREFERRED SIZE addContainerGap javax swing GroupLayout DEFAULT SIZE Short MAX VALUE topPanel_Layout setVerticalGroup topPanel_Layout createParallelGroup javax swing GroupLayout Alignment LEADING addGroup topPanel_Layout createSequentialGroup addContainerGap addComponent picWindowLabel_ javax swing GroupLayout PREFERRED_ SIZE 192 javax swing GroupLayout PREFERRED SIZE addContainerGap javax swing GroupLayout DEFAULT SIZE Short MAX VALUE statusPanel setBorder javax swing BorderFactory createTitledBorder null Status javax swing border TitledBorder DEFAULT JUSTIFICATION javax swing border TitledBorder DEFAULT POSITION new java awt Font Tahoma 0 11 new j vasant Color10 153 2551 yr JP NOLLSN statusTF addActionListener new jJava awt event ActionListener public void actionPerformed java awt event ActionEvent evt statusTF ActionPerformed evt Hz javax swing GroupLayout statusPanel Layout new javax swing GroupLayout statusPanel_ statusPanel_ setLayout statusPanel Layout statusPanel Layout setHorizontalGroup statusPanel Layout createParallelGroup javax swing GroupLayout Alignment LEADING addGroup statusPanel_Layout createSequentialGroup addContainerGap addComponent statusTF_ javax swing GroupLayout PREFERRED SIZE 251 javax swing GroupLayout PREFERRED SIZE addContainerGap 7 Short MAX VALUE statusPanel_Layout setVerticalGrou
65. tch Exception e System err println e else result add new String com getName getPortTypeName com getPortType return result toArray pk Determines what type of port param portType return The type of port in String format ay private String getPortTypeName int portType I Switch portType case CommPortIdentifier PORT I2C ret rn TE case CommPortIdentifier PORT PARALLEL return Parallel case CommPortIdentifier PORT RAW return Raw case CommPortIdentifier PORT RS485 return RS485 case CommPortIdentifier PORT SERIAL return Serial default return unknown type pk Enables serial connection user chooses COM port x return Boolean whether connection is successful AG protected boolean enableSerial System out println Initializing serial comPort_ selectPort Select Serial Port if comPort_ null return false else return converse pk Sets up communication channel return boolean whether connection is successful SE Wireless Digital Video Camera protected boolean converse CommPortIdentifier portId null Enumeration portlist null boolean portFound false if serialPort_ null serialPort_ close Get a list of available ports portList CommPortIdentifier getPortIdentifiers while portList hasMoreElements amp amp portFound portld CommPortIdentifi
66. therwise button and awt hangs until completed initDisplay Playa stare pk Handles playlist comboBox pop up behavior 53 Wireless Digital Video Camera param evt Action event 4 private void playlistComboBox_Popup Javax swing event PopupMenuEvent evt updatePlaylist pk Handles playlist comboBox close behavior param evt Action event e private void playlistComboBox PopupClosed javax swing event PopupMenuEvent evt if playlistComboBox_ getSelectedItem equals Select and play disable the play and delete buttons if no recording selected playButton setEnabled false deleteButton setEnabled false else playButton_ setEnabled true deleteButton_ setEnabled true pk Handles delete button event param evt Action event private void deleteButton_ActionPerformed java awt event ActionEvent evt int proceed proceed JOptionPane showConfirmDialog null Do you really want to delete selected recording if proceed JOptionPane YES_OPTION recorder deleteFolder String playlistComboBox getSelectedItem pk Add remaining listeners to action listening components note statusTF_ already added Ey private void addListeners connectButton_ addActionListener new Java awt event ActionListener I public void actionPerformed java awt event ActionEvent evt try I connectButton ActionPerformed evt catch IOException e TODO Auto generated catch block e printStackTrace
67. tial one time delay camera side radio and cam 128 248 192 1984 24 31 64 8000000 TRUE OxCO OxC 1 1 PIND 3 PIND PIND 4 t 0 N pic height divisible by NUM ROWS PER FRAME log2 of NUM ROWS PER FRAME Length of rectangle frame containing HEIGHT NUM ROWS PER FRAME LENGTH FR 64 number of bytes sent in one subframe while log2 of NUM PER SEND unsigned char twiDataBuffer TWI DATA BUFFER LENGTH unsigned char buff LENGTH FR functions void initialize void void initUART void void resetCam void void writeCam unsigned int reg unsigned char readCam unsigned int reg void sendBmpHeader unsigned int height void sendBmpInfoheader unsigned int height void sendBmpTable void void sendStartPreamble void void sendEndPreamble void void actCapture void void initialize void initSPI initTransceiver ic rfSetTxMode initUART DORDA ed set up SPI for MCU set up transceiver initialize UART LED indicator declare huge arrays first memory allocation unsigned char value unsigned int width unsigned int width 28 Wireless Digital Video Camera PORTD 2 0 asm sei enable interrupts endasm initialize UART void initUART void UBRROL 12 baud rate 38400 for 8MHz UCSROB 1 lt lt 4 1 lt lt 3 enable receiver and transmit UCSROC 1 lt lt 7 1 lt lt 3 1 lt lt 2 1 lt lt 1
68. ultem fileMenu_ setText File fileMenuExit_ setText Exit fileMenu_ add fileMenuExit_ menuBar_ add fileMenu_ helpMenu_ setText Help helpMenuAbout_ setText About helpMenu_ add helpMenuAbout_ menuBar add helpMenu setJMenuBar menuBar 41 Wireless Digital Video Camera L R Initialize all listeners private void initListeners add action listener to exit menu item fileMenuExit addActionListener new java awt event ActionListener public void actionPerformed java awt event ActionEvent evt fileMenuExitActionPerformed evt Hz add action listener to about menu item helpMenuAbout_ addActionListener new java awt event ActionListener public void actionPerformed java awt event ActionEvent evt helpMenuAboutActionPerformed evt pk Handle action event concerning exit menu item param evt The ActionEvent E private void fileMenuExitActionPerformed ActionEvent evt I System exit 0 pk Handle action event concerning about menu item param evt The ActionEvent ay private void helpMenuAboutActionPerformed ActionEvent evt String msg HostManager PROJECT NAME Ver 1 0 JOptionPane showMessageDialog this msg About JOptionPane INFORMATION MESSAGE pk To get DataAnalyzer instance x return DataAnalyzer instance De public DataAnalyzer getDataAnalyzer return dataAnalyzer Main method called at start of program param argv C
69. utput write the image to the destination as jpg Imagelcon display new Imagelcon ImagelO read output use ImageIO read cos no caching otherwise JLabel setIcon won t update picWindowLabel setIcon display output delete if 1sRecording_ recorder store input catch IOException e TODO Auto generated catch block System out println cannot display e printStackTrace J pk Flip image horizontally param bi BufferedImage return The horizontally flipped image my private BufferedImage flipH BufferedImage bi int width bi getWidth int height bi getHeight BufferedImage biFlip new BufferedImage width height bi getType for int i 0 i lt width i for int 1980 j lt height J biFlip setRGB width 1 i jJ bi getRGB i GI return biFlip pk Updates recordings playlist 7 protected void updatePlaylist playlistComboBox_ removeAllltems playlistComboBox_ addItem Select and play File folders recorder_ getRecFolders for int i 0 i lt folders length itt String folderName folders i getName playlistComboBox addItem folderName pk Check if playing 99 Wireless Digital Video Camera return Boolean if it s playing my protected boolean getIsPlaying return isPlaying_ KEN To get statusTEP return statusTF_ le protected javax swing JTextField getStatusTF return StatusTE 5 Variables declaration do
70. vate Panel panel_ private String folderPathName_ private boolean isRecording_ false pk Constructor param p Panel a public Recorder Panel p panel p pk Start recording Capture the starting time dl public void start isRecording_ true create folder that has the name of rec start time folderPathName_ recordings getUniqueIdentifier File f new File folderPathName_ f mkdirs JRR Store file in the record folder in bmp using filename of time in ms param input The input file xy public void store File input note takes bmp if isRecording_ create destination file File fileSave new File folderPathName_ System currentTimeMillis DNO try boolean success fileSave createNewFile if success copyFile input fileSave catch IOException e TODO Auto generated catch block e printStackTrace NS Stop recording and update the playlist ene public void stop isRecording_ false panel_ updatePlaylist PES Retrieve recording and play public void retrieve String playFolderName File files getRecFiles playFolderName if files length 0 panel_ getStatusTF setText Invalid recording else int pctPlayed for int 190 i lt files length i if panel_ getIsPlaying panel initDisplay files i pctPlayed int Math ceil i 1 100 files length round up 57 Wireless
71. ytes with the intensity of each color adjusted accordingly 2 2 7 4 RasterData RasterData contains raw data from the camera Since image compression is not used the size of this section 1s equivalent to the size of the image itself Figure 15 One frame captured by the camera 2 3 Host software architecture The host software is programmed in Java The host software is capable of displaying streams of images on its display panel recording playing back or deleting any recordings selected by the user It receives incoming data from the PC side embedded system via UART and analyzes it When a full frame of image is received it updates the display panel with the latest image and if the recording function 1s enabled it stores a copy of the image in local memory The application organizes a main thread which executes from program start up and two minor threads that handle auto reconnect of serial connection and recording playback respectively lincoming connected ENQUEUE DATA Figure 16 Host software state machine for main thread 18 Wireless Digital Video Camera recorder panel start Stop retrieve folderName getRecFolders deleteFolder folderName recorder _ initDisplay bmp updatePlaylist Recorder getlsPlaying getStatusTF enableSerial HostManager disconnect JFrame initDisplay bmp getStatusTF rxData data DataAnalyzer SerialManager Serial port data
Download Pdf Manuals
Related Search
Related Contents
Manuale Istruzioni Atendimento - Plan Assiste 取扱説明書/6.3MB Schede Tecniche - 8973_100R_S_ist_2014 Sony MVC-CD500 Digital Camera User Manual INSTALLATION MANUAL - NV ECO Vision Sales Inc. Chauvet 330SR Indoor Furnishings User Manual English-US Copyright © All rights reserved.
Failed to retrieve file