<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][14759] </title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=14759">14759</a></dd>
<dt>Author</dt> <dd>trixter</dd>
<dt>Date</dt> <dd>2009-09-03 19:50:43 -0500 (Thu, 03 Sep 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>initial add of the ham radio interconnect to freeswitch.  </pre>

<h3>Added Paths</h3>
<ul>
<li><a href="#freeswitchtrunkcontribtrixterradiofs_rptpl">freeswitch/trunk/contrib/trixter/radio/fs_rpt.pl</a></li>
<li><a href="#freeswitchtrunkcontribtrixterradiohamradioREADME">freeswitch/trunk/contrib/trixter/radio/ham-radio.README</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunkcontribtrixterradiofs_rptpl"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/contrib/trixter/radio/fs_rpt.pl (0 => 14759)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/trixter/radio/fs_rpt.pl                                (rev 0)
+++ freeswitch/trunk/contrib/trixter/radio/fs_rpt.pl        2009-09-04 00:50:43 UTC (rev 14759)
</span><span class="lines">@@ -0,0 +1,267 @@
</span><ins>+#!/usr/bin/perl
+# -*- mode:perl; tab-width:4; c-basic-offset:4; c-indent-level:4; indent-tabs-mode:nil;  -*-
+# Copyright (C) 2009, Bret McDanel &lt;trixter AT 0xdecafbad.com&gt;
+#
+# Version: MPL 1.1 
+#
+# The contents of this file are subject to the Mozilla Public License Version 
+# 1.1 (the &quot;License&quot;); you may not use this file except in compliance with 
+# the License. You may obtain a copy of the License at 
+# http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an &quot;AS IS&quot; basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
+# for the specific language governing rights and limitations under the 
+# License.
+#
+# The Original Code is FreeSWITCH Radio Interface
+#
+# The Initial Developer of the Original Code is 
+# Bret McDanel &lt;trixter AT 0xdecafbad.com&gt;
+# Portions created by the Initial Developer are Copyright (C)
+# the Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#
+# Bret McDanel &lt;trixter AT 0xdecafbad.com&gt;
+
+# WARNING:
+#    Certain laws apply in virtually every jurisdiction to the use 
+#    of radio transmitters.  By connecting a radio transmitter to
+#    your system you assume all responsibility for its use, and the
+#    content that others may provide.
+#    Be aware of the laws, and follow them.
+
+# This script will connect to event socket and bridge a ham radio into
+# a conference via portaudio.  
+#
+# If anyone on the radio side presses DTMF it can react to that
+#    Autopatch
+#    Bring up a prespecified link (echolink or irlp type functionality)
+#    Announce some information
+#    Perform other actions like kicking people out of the conference
+#
+# If anyone on the internet side connects
+#    Their audio is relayed through the radio using the talking events
+
+
+
+
+
+
+use Device::SerialPins;
+use Getopt::Std;
+use strict;
+use FreeSWITCH::Client;
+use POSIX ':signal_h'; # used for alarm to ensure we get heartbeats 
+use Switch;
+use Data::Dumper; # used to print out myhash debug info                         
+use File::stat;
+
+
+my $password = &quot;ClueCon&quot;;    # event socket password
+my $host     = &quot;localhost&quot;;  # event socket host
+my $port     = 8021;         # event socket port
+my $device   = undef;        # radio control device (/dev/ttyS0, COM1, etc)
+my $baud     = 9600;         # radio control device baud rate
+my $timeout  = 30;           # seconds to expect a heartbeat or reconnect
+my $courtesy_tone = &quot;tone_stream://%(150,150,500);%(150,0,400)&quot;; # tone played before releasing PTT
+#my $courtesy_tone = &quot;/sounds/beep.wav&quot;; # play a sound file
+#my $courtesy_tone = undef; # disable courtesy tone
+my $confname = &quot;radio&quot;;      # the name of the conference
+my $extension = &quot;1337&quot;;      # this is the extension that portaudio will call to join
+my $callsign = &quot;kc2dwq&quot;;     # callsign for morse autoID
+#my $callsign = undef;        # disable callsign autoID
+my $callsign_interval = 600; # 10 minute intervals
+
+
+# for TTS anouncements played after CWID - undef to disable
+my $voice = &quot;Allison&quot;;
+my $swift = &quot;/opt/swift/bin/swift&quot;;
+my $filetime = 0;
+
+
+# normal users do not need to edit anything below here
+my %options;
+my $fs;
+my $lastheartbeat;
+my $lastcallsign;
+my $lasttx;
+my $releasePTT=0;
+my $ptt_port;
+
+
+
+sub pressPTT()
+{
+    $ptt_port-&gt;set_rts(1);
+}
+
+sub releasePTT()
+{
+    $ptt_port-&gt;set_rts(0);
+}
+
+
+# this connects to the event socket 
+sub es_connect()
+{
+    print &quot;Connecting to $host:$port\n&quot;;
+    eval {
+        $fs = init FreeSWITCH::Client {-password =&gt; $password, -host =&gt; $host, -port =&gt; $port};
+        if(defined $fs) {
+            $fs-&gt;sendmsg({'command' =&gt; 'event plain heartbeat CUSTOM conference::maintenance'});
+            $lastheartbeat = time;
+        }
+    } or do {
+        print &quot;Error connecting - waiting for retry\n&quot;;
+        sleep(10);
+    }
+}
+
+
+sigaction SIGALRM, new POSIX::SigAction sub { 
+    if ($lastheartbeat &lt; (time - $timeout)) {
+        print &quot;Did not receive a heartbeat in the specified timeout\n&quot;;
+        if (defined $fs) {
+            $fs-&gt;disconnect();
+            undef $fs;
+        }
+        es_connect();
+    }
+    
+    if(defined $callsign &amp;&amp; $lastcallsign &lt; (time - $callsign_interval) &amp;&amp; $lasttx &gt; $lastcallsign) {
+        pressPTT();
+        $fs-&gt;command(&quot;jsapi morse.js conference radio &quot;.$callsign);
+        $lastcallsign = time;
+        $releasePTT++;
+
+
+        if (-f &quot;announcement.txt&quot;) {
+            if(stat(&quot;announcement.txt&quot;)-&gt;mtime &gt; $filetime &amp;&amp; defined $voice $$ defined $swift) {
+                system(&quot;$swift -p audio/deadair=2000,audio/sampling-rate=8000,audio/channels=1,audio/encoding=pcm16,audio/output-format=raw -o /tmp/announcement.raw -f announcement.txt -n $voice&quot;);
+                $fs-&gt;command(&quot;conference &quot;.$confname.&quot; play /tmp/announcement.raw&quot;);
+            }
+        }
+    }
+
+    # reset the alarm 
+    alarm $timeout;
+} or die &quot;Error setting SIGALRM handler: $!\n&quot;;
+
+sub usage()
+{
+    print &quot;Usage: $0 [-p pass] [-P port] [-H host] [-d device] [-b baud]\n&quot;;
+    print &quot;example: $0 -p password -P 8021 -H localhost -d /dev/ttyS0 -b 38400\n&quot;;
+    exit;
+}
+
+
+sub checkArgs()
+{
+    getopts(&quot;p:P:H:d:b:h&quot;,\%options);
+    usage() if defined $options{h};
+    $password = $options{p} if defined $options{p};
+    $host = $options{H} if defined $options{H};
+    $port = $options{P} if defined $options{P};
+    $device = $options{d} if defined $options{d};
+    $baud = $options{b} if defined $options{b};
+    
+    if(! defined $device || ! defined $password || 
+       ! defined $host || ! defined $port) {
+        usage();
+        exit;
+    }
+}
+
+
+checkArgs();
+$ptt_port = Device::SerialPins-&gt;new($device);
+releasePTT();
+es_connect();
+alarm $timeout;
+
+
+
+$SIG{INT} = &quot;byebye&quot;;        # traps keyboard interrupt (^C)
+
+sub byebye {
+    if(defined $fs) {
+        $fs-&gt;command(&quot;pa hangup&quot;);
+    }
+    exit();
+}
+
+
+if(defined $fs) {
+    $fs-&gt;command(&quot;pa call &quot;.$extension);
+} else {
+    print &quot;Unable to start portaudio channel\n&quot;;
+}
+
+$lastcallsign = time;
+
+while (1) {
+    if(defined $fs) {
+        my $reply = $fs-&gt;readhash(undef);
+        if ($reply-&gt;{socketerror}) {
+            es_connect();
+        }
+
+        if($reply-&gt;{body}) {
+            my $myhash = $reply-&gt;{event};
+
+            if ($myhash-&gt;{'event-name'} eq &quot;HEARTBEAT&quot;) {
+                $lastheartbeat = time;
+            } elsif ($myhash-&gt;{'event-subclass'} eq &quot;conference::maintenance&quot;) {
+                if($myhash-&gt;{'conference-name'} eq $confname) {
+                    if($myhash-&gt;{'caller-channel-name'} =~ m/^portaudio/) {
+                        # this is from the radio
+                        if($myhash-&gt;{'action'} eq 'dtmf') {
+                            switch($myhash-&gt;{'dtmf-key'}) {
+                                # I will be adding some &quot;dial&quot; instructions for autopatch
+                                # and maybe some other settings here
+                            }
+                        }
+                    } else {
+                        # this is from everyone else
+                        if ($myhash-&gt;{'action'} eq 'start-talking') {
+                            print &quot;The port is talking! keying mic\n&quot;;
+                            $lasttx = time;
+                            pressPTT();
+                        } elsif ($myhash-&gt;{'action'} eq 'stop-talking') {
+                            print &quot;The port stopped talking! releasing mic\n&quot;;
+                            if(defined $courtesy_tone) {
+                                $fs-&gt;command(&quot;conference &quot;.$confname.&quot; play &quot;.$courtesy_tone);
+                                $releasePTT++;
+                            }
+                        }                           
+                    }
+                    
+                    if($myhash-&gt;{'action'} eq 'dtmf') {
+                        print &quot;conf: $myhash-&gt;{'conference-name'}\tmember: $myhash-&gt;{'member-id'}\tDTMF: $myhash-&gt;{'dtmf-key'}\n&quot;;
+                    } elsif ($myhash-&gt;{'action'} eq 'play-file') {
+                        print &quot;conf: $myhash-&gt;{'conference-name'}\taction: $myhash-&gt;{'action'}\tfile: $myhash-&gt;{'file'}\n&quot;;
+                    } elsif ($myhash-&gt;{'action'} eq 'play-file-done') {
+                        print &quot;conf: $myhash-&gt;{'conference-name'}\taction: $myhash-&gt;{'action'}\tfile: $myhash-&gt;{'file'}\n&quot;;
+                        if($releasePTT&gt;0) {
+                            $releasePTT--;
+                        }
+print &quot;release PTT: $releasePTT\n&quot;;
+                        if($releasePTT==0) {
+                            releasePTT();
+                        }
+                    } else {
+                        print &quot;conf: $myhash-&gt;{'conference-name'}\tmemid: $myhash-&gt;{'member-id'}\taction: $myhash-&gt;{'action'}\tCLID: $myhash-&gt;{'caller-caller-id-number'}\n&quot;;
+                    }
+                } else {
+                    print &quot;conf: $myhash-&gt;{'conference-name'}\tmemid: $myhash-&gt;{'member-id'}\taction: $myhash-&gt;{'action'}\tCLID: $myhash-&gt;{'caller-caller-id-number'}\n&quot;;
+                }
+            } else {
+                print Dumper $myhash;
+            }
+        }
+    } else {
+        es_connect();
+    }
+}
</ins><span class="cx">Property changes on: freeswitch/trunk/contrib/trixter/radio/fs_rpt.pl
</span><span class="cx">___________________________________________________________________
</span><span class="cx">Name: svn:executable
</span><span class="cx">   + *
</span></span></pre></div>
<a id="freeswitchtrunkcontribtrixterradiohamradioREADME"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/contrib/trixter/radio/ham-radio.README (0 => 14759)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/trixter/radio/ham-radio.README                                (rev 0)
+++ freeswitch/trunk/contrib/trixter/radio/ham-radio.README        2009-09-04 00:50:43 UTC (rev 14759)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+morse.js - lets you send audible morse code to a conference or uuid
+         cp to /usr/local/freeswitch/scripts  (or wherever it was installed)
+         see script for usage information.
+fs_rpt.pl - lets you bridge your ham radio (or other) into freeswitch. 
+          requires morse.js for CWID identification if you are using it 
+          like a repeater and your jurisdiction requires this.
+          requires a hardware adapter to key the mic.
+          I will be writing up exactly how to do this, somewhere under
+          &quot;radio&quot; on http://www.0xdecafbad.com is the circuit for a
+          Yaesu FT-897 radio (which works for many transceivers).
</ins></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>