-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsendr.py
More file actions
79 lines (62 loc) · 2.01 KB
/
sendr.py
File metadata and controls
79 lines (62 loc) · 2.01 KB
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
#!/usr/bin/python
#
"""This module sends packets to the named pipe /run/multicastr.pipe
The data must be *precisely* 4320 bytes in length.
If it isn't, forget it.
Homepage and documentation: http://dev.moorescloud.com/
Copyright (c) 2013, Mark Pesce.
License: MIT (see LICENSE for details)
"""
__author__ = 'Mark Pesce'
__version__ = '1.0a1'
__license__ = 'MIT'
import os, sys, stat, socket, logging, errno, time, random
import tolholiday
class TxDataPipe(object):
"""Class to handle writing to a named pipe sitting in /run"""
pipename = '/run/multicastr.pipe'
BUFFER_SIZE = 4320
def __init__(self):
"""Open the named pipe."""
try:
self.pipedesc = os.open(self.pipename, os.O_WRONLY)
except OSError, e:
logging.critical("Could not open named pipe. Reason: %s" % e)
self.pipedesc = None
return
def close(self):
"""Closes the named pipe"""
try:
os.close(self.pipedesc)
self.pipedesc = None
except OSError, e:
logging.critical("Could not close named pipe. Reason: %s" % e)
sys.exit(1)
return
def write(self, buffer):
"""Write to the named pipe."""
if (len(buffer) == self.BUFFER_SIZE): # Only if it's the right lenght, precisely
try:
count = os.write(self.pipedesc, buffer)
#printme("Wrote %d bytes to pipe" % count)
except OSError as e:
logging.critical("Could not write to named pipe. Reason: %s" % e)
return
def printme(str):
"""A print function that can switch quickly to logging"""
#print(str)
logging.debug(str)
if __name__ == '__main__':
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
printme('Logging initialized')
printme("Running sendr module from the command line.")
thePipe = TxDataPipe()
hol = tolholiday.tolHoliday()
# At this point we're free to do whatever tests our heart desires. Sorta.
while(True):
for i in range(27):
hol.fill(i, random.randint(0,255),random.randint(0,255),random.randint(0,255))
pkt = hol.render()
thePipe.write(pkt)
time.sleep(0.02)
printme("Should be clear now.")