-
Notifications
You must be signed in to change notification settings - Fork 2
/
Modem.py
98 lines (91 loc) · 3.41 KB
/
Modem.py
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
import serial
import time
import utils
import Process
import RemoteProcess
vuBinh = "+841655155918"
dungChuot = "+841697448948"
ngoc = "+84962202323"
SMSC = "+84980200030"
class Modem():
modem = ""
def __init__(self):
port = "/dev/ttyUSB2"
baudrate = 115200
self.modem = serial.Serial(port, baudrate, timeout = 5, bytesize = serial.EIGHTBITS)
if self.modem.isOpen():
print ("port " + self.modem.name + ' is open...')
self.modem.write('AT&F\r\n')
time.sleep(1)
self.modem.write('AT+CMGD=1,2\r\n')
time.sleep(0.5)
def test(self):
while True:
cmd = raw_input("Enter command or 'exit':")
if cmd == 'exit':
self.modem.close()
exit()
elif cmd == 'unread':
self.modem.write('AT+CMGL="REC UNREAD"\r')
elif 'send' in cmd:
message = cmd.split(':')[1]
utils.send(self.modem, vuBinh, message)
elif cmd == 'listen':
self.modem.write('AT+CNMI=2,1,0,0,0\r');
while True:
out = self.modem.readline();
#print(out)
if "+CMTI" in out:
utils.getMessage(self.modem, utils.getMessageIndex(out))
elif "REC UNREAD" in out:
body = self.modem.readline()
print(body)
else:
print "wrong cmd"
def run(self):
process = Process.Process()
response = ''
authorized = False
username = ""
password = ""
host = "127.0.0.1"
self.modem.write('AT+CMGF=1\r')
time.sleep(1)
self.modem.write('AT+CNMI=2,1,0,0,0\r\n');
time.sleep(1)
#self.modem.write('AT+CMGL="ALL"r\r');
while True:
out = self.modem.readline();
if (out != ''):
print(out)
if "+CMTI" in out:
utils.getMessage(self.modem, utils.getMessageIndex(out))
elif "REC UNREAD" in out:
#else:
body = self.modem.readline()
if (not authorized):
try:
username = body.split(' ')[0]
password = body.split(' ')[1]
response = process.process.authorize(username, password)
except:
response = "Please send your username and password, split by a whitespace"
if (process.process.authorized):
authorized = True
host = process.getUserInfo(username)[1]
else:
if host != '127.0.0.1':
process = RemoteProcess.RemoteProcess('root', 'v@(qbU7Cx7T7', "112.78.3.74")
host = '127.0.0.1'
response = process.execute(body.splitlines()[0])
if (response==''):
response = body.splitlines()[0] + " was successfully called"
utils.sendLongMessage(self.modem, ngoc, response)
# count = 0
# while True:
# count += 160
# if (count > len(response)):
# break
# clear mem
self.modem.write('AT+CMGD=1,2\r\n')
time.sleep(0.5)