Top > calendar - 日記

2014年 07月 の 日記

<< 2014.7 >>
[日記]
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

21
July, 2014Edit

しゃべらすシリーズ(その2)

リフレクターに接続しているときに、そのリフレクターにLINK / UNLINK してくる局名をしゃべらす。*1
今回は、php とtext2speech.shを使う。

  1. Link/Unlink局の切り出し
    /usr/bin/php を利用するので、Raspberry Piに apache2、php5 をInstallしておく。最初に以下のphpファイルを/var/www/htmlに作成し、ブラウザで開けることを確認し、OKであれば、/rootに置く。ここで作ったphpを利用。
    ---- h2t_REF047.php ---
    <html>
    <head>
    <!--<meta http-equiv="refresh" content="12">-->
    <meta http-equiv="Content-Type" content="text/html; charset=x-sjis">
    <title>REF047_IN/OUT STATUS</title>
    </head>
    <body>
    
    <?php
    $tmp_f = "/home/pi/call_o.txt"; //現時点での接続局リスト
    $con_f = "/home/pi/conn.txt";   //今接続してきた局リスト
    $discon_f = "/home/pi/discon.txt"; //今切断した局リスト
    $str_n = "";
    $call_t = "";
    
    if (file_exists($tmp_f)){
      $call_t = file($tmp_f);
      unlink($tmp_f);
    }
    
    //print "Old_file = " . $call_t[0] . "<BR>";
    
    $source_file = "http://ref047.dstargateway.org/";
    $fp_in  = fopen($source_file, "r");
    $i = 0;
    $j = 0;
    $k = 0;
    
    //$call_o = array("JL3ZBS","JJ1YEG","JQ1ZKF","JH1BLT");
    //print "debug::" ; print_r ($call_o); print "<BR>";
    
    while (! feof($fp_in)) {
      $str[$i] = trim(fgetss($fp_in, 1000));
    //      print $i . ")" . $str[$i] . ":::" . strrpos($str[$i],"ype") . "<BR>";
      if (strrpos($str[$i],"ype") == 1) {
        $j = $i;
      }
      if (strrpos($str[$i],"ast Heard") == 1) {
        $k = $i;
      }
      $i++;
    }
    fclose($fp_in);
    array_shift ($str);
    //print_r($str);
    
    $j = $j + 2;
    $k = $k - 7;
    //print $j.":".$k."<BR>";
    
    for($i = $j; $i < $k; $i++){
        $str_a = substr($str[$i],0,6) . ",";
        $str_n = $str_n . $str_a;
        $i = $i + 5;
    }
    
    //print "New_file= " . $str_n . "<BR>";
    
    $fno = fopen($tmp_f, "w");// call_o.txt
    fwrite($fno, $str_n);
    fclose($fno);
    
    $call = split(",",$str_n);// to array $call
    sort($call);
    //print "New(Sort): "; print_r ($call);
    //print "<BR>\r\n";
    
    $call_o = split(",",$call_t[0]);
    sort($call_o);
    //print "Old&nbsp;&nbsp;(Sort): "; print_r ($call_o);
    //print "<BR>\r\n";
    
    $fo_con = fopen($con_f, "w");
    $diff1 = array_diff($call, $call_o);
    while(list($key,$val) = each($diff1)) {
      if(strlen($val) > 0){
        print $val . " Connected<br>";
        fwrite($fo_con, $val." ");
      }
    }
    print "<BR>";
    fclose($fo_con);
    
    $fo_discon = fopen($discon_f, "w");
    $diff2 = array_diff($call_o, $call);
    while(list($key,$val) = each($diff2)) {
      if(strlen($val) > 0){
        print $val . " disconnected<br>";
        fwrite($fo_discon, $val." ");
      }
    }
    print "<BR>";
    fclose($fo_discon);
    ?>
  2. text2speech.shで発声させる
    上記phpを/usr/bin/php で実行し、discon.txtかconn.txtが0バイトでなければtext2speechで発声する。
    --- inout.sh ---
    #!/bin/bash
    
    while :
    do
      /usr/bin/php /root/h2t_REF47.php > /dev/null
      sleep 1
      if [ -s /home/pi/conn.txt ]; then
         MSG=`cat /home/pi/conn.txt`
         echo $MSG
         /home/pi/bin/text2speech.sh "$MSG connected."
         rm -f /home/pi/conn.txt
         touch /home/pi/conn.txt
      fi
      if [ -s /home/pi/discon.txt ]; then
         MSG=`cat /home/pi/discon.txt`
         echo $MSG
         /home/pi/bin/text2speech.sh "$MSG disconnected."
         rm -f /home/pi/discon.txt
         touch /home/pi/discon.txt
      fi
    sleep 2
    done
  3. inout.shを自動起動させる
    --- /etc/ ---
    # Print the IP address
    _IP=$(hostname -I) || true
    if [ "$_IP" ]; then
      printf "My IP address is %s\n" "$_IP"
      /home/pi/bin/atk "IPアドレスは,$_IPです"
    fi
    /root/inout.sh &  # ← 追加 
    exit 0
     
    2015 8/1 からgoogle tts が利用できなくなった

    google tts が利用できなくなったので、AquesTalkを使うことにした。日記10月1日に載せた/root/henkan を通すと数字が英語読みになる。


    URL B I U SIZE Black Maroon Green Olive Navy Purple Teal Gray Silver Red Lime Yellow Blue Fuchsia Aqua White

08
July, 2014Edit

Mobile DstarRepeater

HOMEにircDDBGatewayを置き、屋外でDstarRepeaterのみで運用するためのircDDBGateway側の設定。

  1. GIP*2変動に対応
    Mobile回線でGIPが変化しても、ircDDBGatewayを追従させるスクリプト
    ---- ipget.sh ----
    #!/bin/bash
    
    while :
    do
    if [ ! -e /root/rpt_gip.txt ]; then
      echo "192.168.xxx.yyy" > /root/rpt_gip.txt #何でもよいが、localnet内で使う場合のIPにしておくとよい。
    fi
    NDT=`tcpdump -i eth0 -nAs0 udp port 20014 -c1` #Gateway portに20014を使用する場合
    FL1=`echo "$NDT" | grep -e "20014 >"`
    if test "$FL1" != ""; then
      OGIP=`tail -1 /root/rpt_gip.txt`
      NGIP=`echo $NDT | cut -d" " -f3 | cut -d"." -f1-4`
      echo "GIP of Repeater = $NGIP"
      if test "$OGIP" != "$NGIP"; then
        echo "$NGIP" >> /root/rpt_gip.txt
        PIRC=`pgrep -f ircddbgatewayd`
        kill -9 $PIRC
        sleep 2
        /bin/sed -e "s/repeaterAddress4=.*$/repeaterAddress4=$NGIP/" /etc/ircddbgateway > /etc/irc_new.txt
        mv -f /etc/ircddbgateway /etc/ircddbgateway.bak
        mv /etc/irc_new.txt /etc/ircddbgateway
        /usr/local/bin/ircddbgatewayd &
      fi
    fi
    sleep 23
    pkill tcpdump
    done
  2. ネットワーク環境の切り替え
    HOMEと屋外回線で使用する際、簡単に切り替えを行うために、DstarRepeater側で実行する(もちろんsshでリモートにて)スクリプト
     ただし、今回は各interfaces_car/interfaces_home はeth0をstaticで設定し利用している。*3
    --- h2m.sh ---
    #!/bin/bash
    
    PDS=dstarrepeaterd
    kill `pgrep -f $PDS`
    sleep 2
    cp -p /etc/dstarrepeater_car /etc/dstarrepeater
    cp -p /etc/network/interfaces_car /etc/network/interfaces
    cp -p /etc/resolv_car /etc/resolv.conf
    /sbin/shutdown -h now
     
    --- m2h.sh ---
    #!/bin/bash
    
    PDS=dstarrepeaterd
    kill `pgrep -f $PDS`
    sleep 2
    cp -p /etc/dstarrepeater_home /etc/dstarrepeater
    cp -p /etc/network/interfaces_home /etc/network/interfaces
    cp -p /etc/resolv_home /etc/resolv.conf
    /sbin/shutdown -h now
     以下作成中




*1 拡張子は含まない
*2 グローバルIPアドレス
*3 もちろんWiFiのdhcpを利用してもよいがそれも固定IPを設定した方が、WiFi ルーターのポート割り当てが楽

    ホーム 一覧 検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS