/usr/bin/ecamonitor is in ecatools 2.9.1-7+b2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | #! /usr/bin/python
# ------------------------------------------------------------------------
# ecamonitor: Ecasound monitor client implemented using NetECI
# Copyright (C) 2002-2003,2009 Kai Vehmanen
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# ------------------------------------------------------------------------
import curses
import re
import socket
import string
import sys
import time
ecamonitor_remote_host = "localhost"
ecamonitor_remote_port = 2868
ecamonitor_version = "v20090419-7"
# TODO:
# - nothing at the moment
# References:
# - http://www.python.org/doc/essays/styleguide.html
# - http://py-howto.sourceforge.net/curses/curses.html
# - http://www.python.org/doc/2.2.2/lib/module-curses.html
# - http://py-howto.sourceforge.net/regex/regex.html
# - http://www.python.org/doc/2.2.2/lib/module-re.html
# - http://py-howto.sourceforge.net/sockets/sockets.html
# - http://www.python.org/doc/2.2.2/lib/module-string.html
def connect_to_server(remote_host, remote_port):
"""Connects to the ecasound server.
@return Socket object for the connection.
"""
while 1:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((remote_host, remote_port))
s.setblocking(1)
return(s)
except Exception, e:
if e[0] == 111: # 111 = connection refused
time.sleep(1)
pass
else:
raise
def issue_eiam_command(s, cmd):
"""Sends a command to ecasound and waits for an response.
@param s socket for an active connection
@param cmd EIAM command to send
@return tuple of return value type and value
"""
tm = ''
counter = 0
s.send(cmd + '\r\n')
while counter < 16:
count = counter + 1
newdata = s.recv(4096)
if len(newdata) == 0:
return ('e','')
tm = tm + newdata
# lets test whether we have received a valid
# EIAM command
try:
m = expand_eiam_response(tm)
return parse_eiam_response(m, tm)
except Exception, e:
pass
return ('e','')
def expand_eiam_response(str):
"""Checks wheter 'str' is a valid EIAM response.
@return Regex match object.
"""
m = re.match('256 ([0-9]{1,5}) (.+)\r\n(.*)\r\n\r\n.*', str, re.MULTILINE | re.S)
return m
def parse_eiam_response(m, str):
"""Parses a valid EIAM response.
@param m Valid regex match object.
@param str The whole EIAM response.
@return tuple of return value type and value
"""
if not m:
m = re.match('256 ([0-9]{1,5}) (.+)\r\n(.*)', str, re.MULTILINE | re.S)
if not m:
raise Exception, 'Regexp failed!'
if m and len(m.groups()) == 0:
print "(ecamonitor) Matching groups failed: ", m.groups()
if m and len(m.groups()) == 3:
#print 'received=', len(m.group(3)), ', expected=', m.group(1)
if int(m.group(1)) != len(m.group(3)):
print "(ecamonitor) Response length error."
if m:
return (m.group(2), m.group(3))
return ('e','')
def main():
s = None
remote_host = ecamonitor_remote_host
remote_port = ecamonitor_remote_port
if not hasattr(sys, 'version_info') or (hasattr(sys, 'version_info') and sys.version_info[1] <2):
print 'Error! Ecamonitor requires python-2.0 or newer to run!'
return 1
if len(sys.argv) > 1:
destination = sys.argv[1]
address = string.split(destination, ':')
remote_host = address[0]
if len(address) > 1:
remote_port = int(address[1])
try:
stdscr = curses.initscr()
pad = curses.newpad(255, 80)
pad.nodelay(1) # to make getch() nonblocking
while 1:
try:
pad.erase()
pad.addstr(0, 0, "ecamonitor " + ecamonitor_version, curses.A_BOLD)
if s == None:
pad.addstr(2, 0, "No connection. Trying to connect to " + remote_host + ":" + str(remote_port) + ".\n")
pad.refresh(0, 0, 0, 0, stdscr.getmaxyx()[0]-1, stdscr.getmaxyx()[1]-1)
#time.sleep(3)
s = connect_to_server(remote_host, remote_port)
pad.addstr(3, 0, "Connection established.\n")
pad.refresh(0, 0, 0, 0, stdscr.getmaxyx()[0]-1, stdscr.getmaxyx()[1]-1)
pad.addstr(1, 0, "")
else:
pad.addstr("\n")
pad.addstr("\n------------------------------------------------------------")
pad.addstr("\nEngine status: ")
pad.addstr((issue_eiam_command(s, 'engine-status')[1]), curses.A_BOLD)
pad.addstr("\nConnected chainsetup: ")
pad.addstr(issue_eiam_command(s, 'cs-connected')[1], curses.A_BOLD)
pad.addstr("\nSelected chainsetup: ")
pad.addstr(issue_eiam_command(s, 'cs-selected')[1], curses.A_BOLD)
#pad.addstr("\nSelected chainsetup status:: ")
#pad.addstr(issue_eiam_command(s, 'cs-status')[1])
pad.addstr("\n\nPosition: ")
pad.addstr(issue_eiam_command(s, 'cs-get-position')[1] + "s", curses.A_BOLD)
pad.addstr(" / Length: ")
pad.addstr(issue_eiam_command(s, 'cs-get-length')[1] + "s", curses.A_BOLD)
pad.addstr("\nChains: ")
pad.addstr(str(len(string.split(issue_eiam_command(s, 'c-list')[1],','))), curses.A_BOLD)
pad.addstr(" / Inputs: ")
pad.addstr(str(len(string.split(issue_eiam_command(s, 'ai-list')[1],','))), curses.A_BOLD)
pad.addstr(" / Outputs: ")
pad.addstr(str(len(string.split(issue_eiam_command(s, 'ao-list')[1],','))), curses.A_BOLD)
pad.addstr("\n\n------------------------------------------------------------\n")
res = issue_eiam_command(s, 'aio-status')
pad.addstr(res[1])
pad.addstr("\n\n------------------------------------------------------------\n")
res = issue_eiam_command(s, 'cop-status')
pad.addstr(res[1])
pad.addstr("\n\n------------------------------------------------------------\n")
res = issue_eiam_command(s, 'ctrl-status')
pad.addstr(res[1])
pad.addstr("\n\n------------------------------------------------------------\n")
pad.refresh(0, 0, 0, 0, stdscr.getmaxyx()[0]-1, stdscr.getmaxyx()[1]-1)
time.sleep(1.0)
ch=pad.getch()
if ch == ord('q'):
break
except curses.error:
raise
except socket.error, e:
if e[0] == 32 or e[0] == 104 or e[0] == 111:
s = None
pass
else:
curses.endwin()
print "Exception!" , e
raise
except KeyboardInterrupt:
break
finally:
if s != None:
s.close()
curses.endwin()
if __name__ == '__main__':
main()
|