• 沒有找到結果。

Chapter 2 Materials and Methods

2.6 System software design

2.6.3 PSG Client design

The software of our proposed system is used modular concept for program design. There are seven modules in PSG Client: 1) Bluetooth Search Module, 2) Network Connect Module, 3) Subject Info Get Module, 4) Stream Input Module, 5) Display Module, 6) Encryption Module and 7) Data Record Module. According to the different demand, these modules could be reused easily.

Procedure of PSG Client

The operation procedure of PSG Client is shown as Figure 2.23. The process is listed below:

1. When the start button of PSG Client is turned on, Bluetooth Search Module will start to search nearby Bluetooth device, find out our Bio-signal Acquisition Unit and establish connection with the device.

2. Network Connect Module at this step will establish network connection with remote PSG Server and exchange each other’s public key.

3. Subject Info Get Module will get some information needed for EDF: local subject identification, local recording identification, start recording time and others parameter. These informations will be writed into EDF header.

4. Stream Input Module start to receive signal from Bluetooth stream, and write into the buffer.

5. When the buffer is full, Display Module will read datas from the buffer and draw the waveform on the waveform panel according these datas.

6. Encryption Module read data from the buffer. These datas will be processed by a serial of encryption function

7. Network Connect Module will transmit the encrypted data to PSG Server.

8. Data Record Module will read data from the buffer, and write data into EDF and text file respectively.

9. When the stop button is pressed, Data Record Module at this step will get the end recording time and update the EDF header.

Figure 2.23: Procedure of PSG Client.

The following will explain function for each module in detail.

Bluetooth Search Module

y DeviceDiscover( ): Discover nearby Bluetooth device.

y KeySetting( ): Setting the key to Bio-signal Acquisition Unit.

y DeviceConnect( ): Establish connection with Bio-signal Acquisition Unit.

Figure 2.24: Bluetooth Search Module of PSG Client.

Network Connection Module

y Socket( ): Creates a new socket of a certain socket type, identified by an integer number, and allocates system resources to it.

y Connect( ): Assigns a free local port number to a socket. In case of a TCP socket, it causes an attempt to establish a new TCP connection.

y Send( ) / Receive( ): Used for sending and receiving data to/from a remote socket.

Figure 2.25: Network Connect Module of PSG Client.

Subject Info Get Module

y GetSubjectInfo( ): Get local subject identification and local recording identification from User Information field.

y GetTime( ): Get start recording time from system time.

y WriteEDFHeader( ): In Table 2.2 which there are four fields of the EDF header, and these 4 extreme values specify offset and amplification of the signal, the parameter of amplitude and offset is (phy_max-phy_min) / (dig_max-dig_min) ,as listed in Table 2.5. In data record, each sample value is represented as a 2-byte integer in 2's complement and little endian format.

Table 2.5: The parameter of EDF header Physical

Figure 2.26: Subject Info Get Module of PSG Client.

Stream Input Module

y ReadByte( ): Receive signal from Bluetooth stream. Per time read one byte.

In this function we can get the sampling rate and how much channel of bio-signal acquisition unit. When we receive “FF” the next byte is the crucial byte we want (refer to Figure 2-21).

y RestoreSignal( ): According to MSP430 packet format, we know per channel’s signal is divided into two parts: MSB (6 bits) and LSB (6bits), and fill “01” in front of MSB and “10” in front of LSB respectively (refer to Figure 2-22). In this function, we will restore original signal from divided two bytes by equation 2-1:

Φ(MSB,LSB) = (LSB - 64) * 64 + (LSB - 128) (2-1) y WriteBuffer( ): Write the restored signal into the buffer.

Figure 2.27: Stream Input Module of PSG Client.

Display Module

y ReadBuffer( ): Read the restored signal from the buffer.

y DrawLine( ): In bio-signal recording, the scientist and clinician need to know not only the bio-signal waveforms but also their amplitudes. Therefore, we restore the signal and mark the amplitude of bio-signals, the bio-signal waveform is circular drawn using Graphics 2D on waveform panel, the panel shows in right side of the windows. The sampling rate of screen display was down sampled to 128 Hz, and each page shows five-second bio-signals.

y IndicateSignal( ): When the cyclic and crucial functions are executed, we use light signal to indicate it’s process state. The following are the cyclic and crucial functions on PSG Client: a) Encrypt PSG signal, b) Encrypt AES Key, c) sign the Signature, d) Send Signature, e) Send Encrypted AES Key, f) Send Encrypted PSG signal.

y SystemLog( ): Record the system log.

Figure 2.28: Display Module of PSG Client.

Encryption Module

y GenerateKey( ): Random generate AES password as string and use MD5 Hash Function to compute AES key.

y AESEncrypt( ): Use AES algorithm encrypt plaintext.

y RSAEncrypt( ): Use RSA algorithm encrypt AES key.

y Signature( ): Use RSA and SHA-1 algorithm to sign the Signature.

Figure 2.29: Encryption Module of PSG Client.

Data Record Module

y ReadBuffer( ): Read data from buffer.

y WriteTextFile( ): Write data into text file according to following format:

Time Stamp CH1 CH2 CH3 CH4 CH5 CH6 CH7 CH8 Each row record 1/256 second data

y WriteEDF( ): Write data into EDF file according to EDF format.

y GetTime( ): Get the end recording time from system time.

y UpdateEDFHeader( ): The “Number of data records” field of EDF header will be updated.

Figure 2.30: Data Record Module of PSG Client.

相關文件