LoginSignup
0
0

More than 5 years have passed since last update.

MemoryEnhancer > UDPの受信処理を行い、"***"と"+++"を交互にbanner表示する | banner:指定の文字すべてを表示してくれない | banner:改行付きの表示

Last updated at Posted at 2018-01-17
動作環境
Raspberry Pi 2 Model B (以下RPi)
  - Raspbian Jessie
Ubuntu 16.04 LTS desktop amd64

処理概要

  • UDP通信を受信する
    • Port:7000
    • コマンド: trig
  • コマンド受信時に文字列を表示する
    • banner表示
    • ***+++を交互に表示

参考

code

udpTrigger_180117.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import socket as skt
import subprocess as sb
import sys

'''
v0.1 Jan. 18, 2018
  - show [***] and [+++] alternatively
  - check incoming command [trig]
'''

# on Python 2.7.12 (Ubuntu 16.04 LTS)
# on Python 2.7.9 (Raspbian)

RECV_TIMEOUT_MSEC = 300

def udpTrigger(port_in):
    inst = skt.socket(skt.AF_INET, skt.SOCK_DGRAM)
    inst.bind(('', port_in))
    inst.setblocking(0)
    updateText = True
    txt1 = "***"
    txt2 = "+++"

    while True:
        if updateText:
            updateText = False
            cmd = "banner " + txt1
            txt1, txt2 = txt2, txt1
            os_cmd = sb.call(cmd.split())
        try:
            data, adr = inst.recvfrom(RECV_TIMEOUT_MSEC)
        except skt.error:
            pass
        else:
            if "trig" in data:
                updateText = True


udpTrigger(7000)

動作環境

  • RPi: UDP送信側
  • Ubuntu: UDP受信側
    • udpTrigger_180117.pyを起動しておく

動作結果

RPi側

pi@raspberrypi ~ $ echo "trig" | nc -u 192.168.0.9 7000
^C
pi@raspberrypi ~ $ echo "trig" | nc -u 192.168.0.9 7000
^C
pi@raspberrypi ~ $ echo "trig" | nc -u 192.168.0.9 7000
^C
pi@raspberrypi ~ $ 

Ubuntu側

$ python2 udpTrigger_180117.py 

 #   #   #   #   #   #
  # #     # #     # #
### ### ### ### ### ###
  # #     # #     # #
 #   #   #   #   #   #



   #       #       #
   #       #       #
 #####   #####   #####
   #       #       #
   #       #       #



 #   #   #   #   #   #
  # #     # #     # #
### ### ### ### ### ###
  # #     # #     # #
 #   #   #   #   #   #



   #       #       #
   #       #       #
 #####   #####   #####
   #       #       #
   #       #       #

Bannerを使う意図

27インチモニタでRPiを表示すると、通常のテキストが小さすぎて読めない。
以下のような使い方をするため、bannerを試してみた。

  • ESP8266を搭載したグローブ(+加速度センサ搭載)の動きを検知し、UDPコマンドを送信する
    • グローブを動かした: High
    • グローブを動かさない: Low
  • RPi側でUDPコマンドに応じて、英語フレーズの表示を更新する
    • 英語の復習ツールとして(記憶のEnhancer)

Bannerコマンドの制限?

$ banner "AAA BBB CCC DDD"
   #       #       #            ######  ######  ######           #####   #####
  # #     # #     # #           #     # #     # #     #         #     # #     #
 #   #   #   #   #   #          #     # #     # #     #         #       #
#     # #     # #     #         ######  ######  ######          #       #
####### ####### #######         #     # #     # #     #         #       #
#     # #     # #     #         #     # #     # #     #         #     # #     #
#     # #     # #     #         ######  ######  ######           #####   #####

指定の文字が全部表示されないようだ。
UbuntuとRPiで同じ結果になった。

bannerの-wオプションも使えない。

二重引用符の文字列を適度に区切れば、文字が改行付きで表示されるようだ。

$ banner "Verify tha" "t the guar" "ded area i" "s clear of" "personnel and"
#     #
#     #  ######  #####      #    ######   #   #           #####  #    #    ##
#     #  #       #    #     #    #         # #              #    #    #   #  #
#     #  #####   #    #     #    #####      #               #    ######  #    #
 #   #   #       #####      #    #          #               #    #    #  ######
  # #    #       #   #      #    #          #               #    #    #  #    #
   #     ######  #    #     #    #          #               #    #    #  #    #


  #####           #####  #    #  ######           ####   #    #    ##    #####
    #               #    #    #  #               #    #  #    #   #  #   #    #
    #               #    ######  #####           #       #    #  #    #  #    #
    #               #    #    #  #               #  ###  #    #  ######  #####
    #               #    #    #  #               #    #  #    #  #    #  #   #
    #               #    #    #  ######           ####    ####   #    #  #    #


 #####   ######  #####             ##    #####   ######    ##               #
 #    #  #       #    #           #  #   #    #  #        #  #              #
 #    #  #####   #    #          #    #  #    #  #####   #    #             #
 #    #  #       #    #          ######  #####   #       ######             #
 #    #  #       #    #          #    #  #   #   #       #    #             #
 #####   ######  #####           #    #  #    #  ######  #    #             #


  ####            ####   #       ######    ##    #####            ####   ######
 #               #    #  #       #        #  #   #    #          #    #  #
  ####           #       #       #####   #    #  #    #          #    #  #####
      #          #       #       #       ######  #####           #    #  #
 #    #          #    #  #       #       #    #  #   #           #    #  #
  ####            ####   ######  ######  #    #  #    #           ####   #


 #####   ######  #####    ####    ####   #    #  #    #  ######  #
 #    #  #       #    #  #       #    #  ##   #  ##   #  #       #
 #    #  #####   #    #   ####   #    #  # #  #  # #  #  #####   #
 #####   #       #####        #  #    #  #  # #  #  # #  #       #
 #       #       #   #   #    #  #    #  #   ##  #   ##  #       #
 #       ######  #    #   ####    ####   #    #  #    #  ######  ######
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0