+ All Categories
Home > Documents > PARSE SOFTWARE DEVICES © Copyright 2007 PARSE Software Devices, all rights reserved. Home Security,...

PARSE SOFTWARE DEVICES © Copyright 2007 PARSE Software Devices, all rights reserved. Home Security,...

Date post: 24-Dec-2015
Category:
Upload: evangeline-wilkerson
View: 215 times
Download: 2 times
Share this document with a friend
Popular Tags:
48
PARSE SOFTWARE DEVICES © Copyright 2007 PARSE Software Devices, all rights reserved. Home Security, Monitoring, and Data Acquisition with FreeBSD Presented by: Robert Krten [email protected]
Transcript

PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Home Security, Monitoring, and Data Acquisition

withFreeBSD

Presented by:

Robert [email protected]

2PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

The Big Picture – Telecoms Section

Reverse DN Lookup

Database

CallAudio

Database

Software Modem (for Caller ID)

Voice-Activated Call Recorder

SMDR Parser

SMDR

Call RecordDatabase

Internal Extensions

PABXMitel SX-20

(12 x 72)

Phone Line

Phone Line

Soundcard

Adaptor

Adaptor

(left)

(right)

Telecom Event Server

Telecom Event Server

HardwareSoftwareDatabase CLID_logger

dbPhone

3PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

The Big Picture – Weather Section

HardwareSoftwareDatabase

N

S

W E

Wind Direction

Wind Speed 0 mm

5 mm

10 mm

Rainfall Meter

0o C

-10o C

-20o C

-30o C

-40o C

40o C

30o C

20o C

10o C

Temperature(indoor & outdoor)

PressureWMR981

Weather Station

Radio ReceiverBase Station

WeatherDatabase wx200d

RS-232

4PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

WeatherDisplay

The Big Picture – Video Section

LUX 220Driver

Caller IDDisplay

HardwareSoftwareDatabase

Internalcoax

camera(NTSC)

camera(NTSC)

3 x 8 x 8 video/audio

switch matrix

4 Channel RF Modulator

LUX 220 video cards

Console(80x25)

audiocard

audiocards

Antenna

TV

Video Recorder Database

Motion-Activated

Video Recorder

WinTV GO+ vidcap cards

mplayer

other apps…

switcher

5PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Audio Section

Let’s start with the audio section:– hardware– var – voice activated recorder– software modem– telecom event server– utilities

6PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Telephone Adaptor (hardware)

TIP and RING are the inputs from the phone line, and the AUDIO and GND are suitable to go to a line-in compatible input (like a sound card). If a 600 to 600 Ohm transformer isn’t available, other (similar) values will do, provided that the ratio is around 1:1.

Warning: connecting this equipment to your telephone line and your sound card is at your own risk, no warranties are expressed or implied, and all damage is your responsibility.

600 to 600 isolation transformer

TIP

RINGGND

AUDIO470

470

330nF

330nF

680pF

2k2

1N4148 (x2)

7PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Voice Activated Recorder

var -d/var/local -f10 -h10000 \

-l00l=8318 -l00r=8316 \

-L/var/local/var.log –v

Option Description

-d Root directory

-f Noise floor (absolute value %age of full-scale)

-h Hysterisis (milliseconds)

-l label (ccs=name; “cc” = channel, “s” = side, “l” for left or “r” for right)

-L logfile

-v verbose operation

8PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Voice Activated Recorder

Noise Floor (-f) parameter:– must be set so that var isn’t triggered by noise

that you don’t want recorded.– the selected value 10 (10%) means that we

need something over 10% of the maximum sample value in order to trigger a recording.

But lots of times there is a second or two or three of silence… we want that to be “part” of the recording.

9PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Voice Activated Recorder

Hysterisis (-h) parameter (milliseconds):– controls how long we record for once we’ve

started.– the selected value, 10000, means that once we

trigger a recording, we will continue recording for 10 seconds (10000 milliseconds)

Since there is always silence at the end of a recording (how else would we know it’s the end, except by the fact that the hysterisis value was exceeded?) we trim off the end silence.

10PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Voice Activated Recorder

To prevent spurious “pops” from triggering recordings, we have one last requirement – there must have been at least 1 second of recorded audio (this isn’t configurable from the command line). While a recording is actually made due to a spurious pop, the recording is deleted if there’s less than 1 second of actual audio.

11PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Voice Activated Recorder

Here’s a typical phone call (1 minute in duration):

20Hz Ringing (2 seconds)

Caller ID burst

Near side: “Hello?”

Far side: “Yes, this is…”

Beginning of second ring

(quiet spots)

0%

100%

10%

12PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Voice Activated Recorder

Finally, the label (-l, lowercase L) option gives the label for the recording. Recordings are saved to:

root/yyyy/mm/dd/hhMMss.label.wav– root is the –d option (/var/local)– yyyy, mm, dd, hh, MM, ss is the time– label is the value of –l– we had: -l00l=8318 -l00r=8316– which means channel “00” (the first sound card)

“left” (the “l” after the “00”) is called “8318”. Channel “00” “right” (the “r”) is called “8316”.

13PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Software Modem

The software modem:– gets raw 16-bit 8kHz samples from the voice-

activated recorder (it’s reading from the soundcard anyway)

– only gets values when we are recording– performs a 1200-baud FSK software decode

• has a 1200 Hz and 2200 Hz tone detector• has a software UART for assembling bytes

– passes assembled bytes to telecom event handler’s CLID decoder logic.

14PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Software Modem

one bit-cell time = 1/1200 of a second = 833 s.At 8 kHz sampling rate, that means 6.666 samples per bit.

1200 Hz = Mark (1) and 2200 Hz = Space (0)

0 0 1 1

At the analog signal level:

15PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Software Modem

sin @ 1200Hz cos @ 1200Hz

sin @ 2200Hz cos @ 2200Hz

To decode the waveform into a series of data bits, we start with four templates; a sin and a cosine of each frequency. These tables aren’t very big – after all, we have just under 7 samples per bit cell. These samples are stored in the “correlates” array.

16PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Software Modem// do the multiplication

memset (factors, 0, sizeof (factors));

for (i = 0; i < handle -> corrsize; i++) {// corrsize = 7 here

val = handle -> buffer [j]; // sample buffer

factors [0] += handle -> correlates [0][i] * val;

factors [1] += handle -> correlates [1][i] * val;

factors [2] += handle -> correlates [2][i] * val;

factors [3] += handle -> correlates [3][i] * val;

j++;

}

// compare the squares of the values

handle -> current_bit = factors [0] * factors [0]

+ factors [1] * factors [1]

> factors [2] * factors [2]

+ factors [3] * factors [3]);

// whichever squared value is bigger is the matched bit

17PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Software Modem

At the bit level:

1 1 1 1110 00 00… …

Start bit MSBLSB Stop bit

This shows the reception of 01100101, or 0x65, or the letter “e” in ASCII. Note the LSB-first ordering of the bits.

18PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Software Modem

This results in a stream of data bytes which are passed to the telecom event server’s CLID input function:55 55 55 55 55 55 55 55-55 55 55 55 55 55 55 55 UUUUUUUUUUUUUUUU55 55 F5 80 19 01 08 30-32 30 36 30 39 30 37 08 UU.....02060907.01 4F 03 0A 36 31 33 35-35 35 31 38 37 33 53 2C .O..6135551873S,10 84 20 08 0C 17 42 38-02 03 00 20 00 15 06 03 .. ...B8... ....

The “U” characters are a modem training sequence, and are interpreted as a “validation” of the CLID sequence. Next, we have the date (“02060907”, meaning Feb 06 09:07), followed by the reason for absence of name (the “O” character), followed by the phone number (“6135551873”). There are checksums and headers here as well…

19PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Other Software Modems

There’s also an off-line utility that takes a .wav file and decodes the DTMF (“Touch Tone”) information. It operates a little differently, it basically has 8 tuned filters (4 “row” filters and 4 “column” filters) and measure the energy in each band. When sufficient energy is detected, and it occurs in one row and one column only, a DTMF digit is declared.

20PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

SMDR Parser

Simple data format (1200 baud RS-232):

02/06 07:49 00:00:55 T003 009 163-02/06 08:34 00:05:08 131 9 6135557837 T003

Call length qualifier (calls > 5 minutes)

month/day hour:minute

call duration

trunk/extension

digits dialled

access code

This data stream is parsed, and sent off to the telecom event server as well.

21PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Telecom Event Server

Gets events:– incoming caller ID events– incoming SMDR events

Groks events– knows about the format of CLID and SMDR

records

Logs events internally

Allows apps to fetch events– so that they can be logged to a disk file– or displayed on the TV, etc.

22PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Telecom Database

I also have a huge (618 MB) database of phone numbers. It’s a digit tree off the root /data/static/telecom/phoneDB:

10

23456789

1 52

3 56.txt

2.txt3.txt4.txt5.txt

7.txt8.txt9.txt

…………

………

……

0 …2 …

4 ……

3 …4 …

6 ……

2 …3 …4 …

6…

2 ……

0.txt1.txt

/data/static/telecom/phoneDB/1/6/1/3/5/5/5.txt

23PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Telecom Database

Each file (.txt) contains station codes and flat ASCII text:…7300 MAPLE COURT DINING LOUNGE 9-A KAKULU RD KANATA7302 CONNOR SARAH J 22 DRESSLER DR KANATA7303 COSCAN DEVELOPMENT CORP CONST SITE BRID KANATA7304 MONTCHATEAU R H DR 68 HERSCHEL CR KANATA7312 DAVIDOVICH BART 34 RIDING WAY KANATA7313 SMYTH M 185 SALTER CSNT KANATA7314 BENTON W 519 DRAINIE DR KANATA…

Together with the path, the station code forms the full telephone directory number (DN). The flat ASCII text files are always sorted by station code. An index file (.i) contains offsets to the start of each line, for speed.

24PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Weather Station

The weather station is an Oregon Scientific “WMR-981” weather station.

The various probes transmit their data via radio (400-something MHz) to a base station, which spits it out a serial port.

Then, the public domain “wx200” program and friends is used to parse, log, and graph the data.

25PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Weather Station

I then display the data on my TV, by converting selected PNG files generated by the RRD tool into PNM, and then feeding the PNM graphics to the Lux220 card that’s connected to the 4 channel RF modulator.

pngtopnm filename.png | pbmluxLUX 220

video card

26PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Weather Station

27PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Weather Station

28PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

mar -c27 -c46 -r /var/local/mar

Option Description

-b /dev/bktr device # (default 0)

-c channel to monitor (can specify multiple, in which case it does round-robin)

-r database root

In the example above, I log to /var/local/mar, and I monitor channels 27 and 46 – this is where the 4-channel RF modulator puts the camera data from the back yard and the front door.

29PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

30PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

31PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

I capture using YUV (not RGB) because there’s a bug in FreeBSD 6.0 AMD64 that crashes the machine if I use RGB (6.2 is worse )

YUV is fine for this kind of thing; the Y plane is the intensity plane; no need to compare the U and V planes.

I use a “blob” technique to detect motion.

32PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

Here’s the setup (error checking removed):…

sprintf (buf, "/dev/bktr%d", optb);

fd_bktr = open (buf, O_RDONLY);

sprintf (buf, "/dev/tuner%d", optb);

fd_tuner = open (buf, O_RDONLY);

// specify tuner frequency set

u32 = 1; // North American Broadcast Frequencies

ioctl (fd_tuner, TVTUNER_SETTYPE, &u32);

33PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder// specify NTSC format

u32 = METEOR_FMT_NTSC;

ioctl (fd_bktr, METEORSFMT, &u32);

// mmap kernel data

data = (uint8_t *) mmap ((caddr_t) 0, nbytes,

PROT_READ, MAP_SHARED,

fd_bktr, (off_t) 0);

// set the first channel (contexts contains all –c)

u32 = contexts [0].channel;

ioctl (fd_tuner, TVTUNER_SETCHNL, &u32);

34PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder// wait for, and capture, the data

u32 = METEOR_CAP_SINGLE;

ioctl (fd_bktr, METEORCAPTUR, &u32);

At this point, the data is sitting in the buffer that we mmap()ed previously. It’s in YUV format. We now need to perform the blob analysis to see if there was a difference between the previous snapshot that we took.

35PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

The first thing to do is to see if there have been any changes that are greater than the threshold value:

for (i = 0; i < XSIZE * YSIZE; i++) {

// sufficient to look only at Y plane

*d++ = abs (*curr - *prev) > THRESHOLD_P;

curr++;

prev++;

}

This populates the “d” array with Boolean change values.

36PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

The d array now looks like this:

The red pixels indicate areas that have changed between the current image and the previous image.

37PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

We work with 3x3 matrices.

The first selected 3x3 matrix has one hot spot; we need at least 7 to consider it a blob. So, we reject it.

38PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

Moving on to the next 3x3 matrix

The second selected 3x3 matrix has three hot spots, still not enough, so reject it as well… This process continues until…

39PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

much later…

… we get to the blob at the bottom, which has 7 hot spots, which matches the criteria. We increment the count of blobs to one.

40PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

Counting the number of blobs is what determines if the picture has changed.

My settings are:

Image Size 640x480 (307kp)

Blob Size 3x3 (9p)

Y difference >= 20

Blob pixels >= 7

Screen change >=40 blobs

Previous image had 1 blob; therefore, I don’t count this as a change because it’s less than 40.

41PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

On the other hand, there might be lots of changes:

Performing the same blob analysis leads us to…

42PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

A lot more blobs!

27 + 13 + 1 > 40, so we declare this picture “different” from the previous one, and record it to disk.

27 blobs here

13 blobs here

43PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

Keep in mind:– 40 blobs isn’t a lot! It looked dense in the

previous picture because we had a MUCH smaller resolution (only 24x11 instead of 640x480!)

44PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

Once we’ve recognized a change:– I stamp the date, time, and channel on the

image.• this is done through homegrown tools; it was very

simple

– I write the image to disk

45PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

To record to disk, I use libjpeg:write_jpeg (FILE *fp, uint8_t *image){ int x, y;

JSAMPROW row_ptr [1];struct jpeg_compress_struct cjpeg;struct jpeg_error_mgr jerr;static uint8_t row [XSIZE * 3]; // *3 for YUV

cjpeg.err = jpeg_std_error (&jerr); // errors to stderr

jpeg_create_compress (&cjpeg);cjpeg.image_width = XSIZE;cjpeg.image_height= YSIZE;cjpeg.input_components = 3;cjpeg.in_color_space = JCS_YCbCr;jpeg_set_defaults (&cjpeg);

46PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Motion Activated Recorder

jpeg_set_quality (&cjpeg, 90, TRUE); // 90 is qualitycjpeg.dct_method = JDCT_FASTEST;jpeg_stdio_dest (&cjpeg, fp);jpeg_start_compress (&cjpeg, TRUE);

row_ptr [0] = row;for (y = 0; y < YSIZE; y++) {

for (x = 0; x < XSIZE; x++) {row [x * 3 + 0] = image [y * XSIZE + x];row [x * 3 + 1] = image [(y * XSIZE + x) / 2

+ XSIZE * YSIZE];row [x * 3 + 2] = image [(y * XSIZE + x) / 2

+ 3 * XSIZE * YSIZE / 2];}jpeg_write_scanlines (&cjpeg, row_ptr, 1);

}

jpeg_finish_compress (&cjpeg);jpeg_destroy_compress (&cjpeg);

}This stuff deals with the layout of planar YUV from the BKTR capture.

47PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Things that go bump in the night

At night, the following things happen:– audio files are compressed via LSF (Low

Sampling Frequency) MPEG to MP2 and gzip’d (yes, this does save space; ~10-15%)

– the individual JPEG files are converted into a movie via (two pass, only pass 1 shown):•nice mencoder mf://*-ch027*jpg -mf fps=30:type=jpg -forceidx -o ch27.avi –ovc lavc -lavcopts vcodec=mpeg4:mbd=2:v4mv:cmp=3:subcmp=3:mbcmp=3:vhq=4:vbitrate=1600:trell:subq=8:autoaspect:vpass=1:cbp:mv0 -ofps 30

• Isn’t mencoder wonderful?

48PARSE SOFTWAREDEVICES © Copyright 2007 PARSE Software Devices, all rights reserved.

Contact Info

Check out my other projects and website:– www.parse.com/~rk– www.parse.com/~museum

Email:– [email protected]

Slides available at:www.parse.com/slides

for 2 months after presentation.


Recommended