-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpilberry_modes
executable file
·65 lines (53 loc) · 2.17 KB
/
pilberry_modes
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Pilberry runs a car radio based on Raspberry Pi
# Copyright 2014 Olivier Cecillon <[email protected]>
# and Nicolas Hainaux <[email protected]>
# This file is part of Pilberry.
# Pilberry 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 3 of the License, or
# any later version.
# Pilberry 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 Pilberry; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# Python packages|modules imports
import sys
import pickle
import RPIO
# Pilberry packages|modules imports
from lib.globals import modes_list, cmd_match_list, current_mode, MODES_PORT
from lib.globals import current_state
from lib.states.memory.StateMemory_A import State_A as MState_A
from lib.states.memory.StateMemory_B import State_B as MState_B
from lib.states.memory.StateMemory_C import State_C as MState_C
from lib.states.memory.StateMemory_D import State_D as MState_D
from lib.states.memory.StateMemory_E import State_E as MState_E
##
# @todo At startup, get the last data...
current_state[current_mode] = MState_A()
def socket_callback(socket, data):
raw_cmd = pickle.loads(data)
if raw_cmd == 'QUIT':
print("Shutting down server")
sys.exit()
else:
cmd = cmd_match_list[raw_cmd]
print(cmd)
if cmd == 'CMD_CHMOD':
##
# @todo Implement changing mode
print("Now we change the mode")
elif cmd == 'QUIT':
sys.exit()
else:
current_state[current_mode].handle(cmd)
# TCP socket server callback on port 8080
RPIO.add_tcp_callback(MODES_PORT, socket_callback)
print("Waiting for TCP interrupts...\n")
# Blocking main epoll loop
RPIO.wait_for_interrupts()