Commit b187ecbc2b160e92aa74558b848ba36741a830e6
1 parent
8d0fc742
Exists in
dev
refactorisation goes on...
Showing
1 changed file
with
0 additions
and
115 deletions
Show diff stats
src/device_controller/concrete_component/gemini/server_udp_or_tcp_gemini.py deleted
@@ -1,115 +0,0 @@ | @@ -1,115 +0,0 @@ | ||
1 | -#!/usr/bin/env python3 | ||
2 | - | ||
3 | -from device_controller.concrete_component.device_simulator_common.server_udp_or_tcp import get_SocketServer_UDP_TCP | ||
4 | - | ||
5 | - | ||
6 | - | ||
7 | -###STAMP = '01000000' | ||
8 | -#STAMP = '0100000000000000' | ||
9 | -#HOST, PORT = "localhost", 11110 | ||
10 | -#HOST, PORT = "localhost", 9999 | ||
11 | -#HOST, PORT = "localhost", 20001 | ||
12 | - | ||
13 | -# stamp is 8 digits long | ||
14 | -STAMP_LENGTH = 8 | ||
15 | - | ||
16 | -# COMMON CONSTANTS WITH CLIENT | ||
17 | -TERMINATOR = '\x00' | ||
18 | -COMMAND5 = '050000' | ||
19 | -#COMMAND6_SIMPLE = '6' | ||
20 | -COMMAND6 = '\x00\x06\x00' | ||
21 | - | ||
22 | - | ||
23 | -class UnknownCommandException(Exception): | ||
24 | - pass | ||
25 | - | ||
26 | - | ||
27 | -class Memo: | ||
28 | - | ||
29 | - @classmethod | ||
30 | - def get(cls, var): | ||
31 | - return cls._variables[var] | ||
32 | - | ||
33 | - @classmethod | ||
34 | - def set(cls, var, value): | ||
35 | - cls._variables[var] = value | ||
36 | - | ||
37 | - _variables = { | ||
38 | - "C" : '10/10/19', | ||
39 | - "L" : '10:20:36', | ||
40 | - "g" : '+10', | ||
41 | - "t" : '+45:00:00', | ||
42 | - } | ||
43 | - | ||
44 | - | ||
45 | - | ||
46 | - | ||
47 | -# @override superclass method | ||
48 | -def make_answer_for_request(request_bytes:bytes): | ||
49 | - #if request == STAMP + ":GD#": return STAMP + "+12:28" | ||
50 | - #if request == b'0100000000000000:GD#': return bytes(STAMP + "+12:28", "utf-8") | ||
51 | - print("Request received is", request_bytes) | ||
52 | - | ||
53 | - ''' | ||
54 | - 3 types of commands: | ||
55 | - - TYPE1: '06' or '050000' | ||
56 | - - TYPE2: ':cde#' (mainly ':??#' - i.e : ':GD#', ':GR#', ...) | ||
57 | - - TYPE3: 'b?#' (bC# = Cold Start, bW# = selecting Warm Start, bR# = selecting Warm Restart) | ||
58 | - ''' | ||
59 | - | ||
60 | - # Convert to string | ||
61 | - request = request_bytes.decode("utf-8") | ||
62 | - if len(request) < STAMP_LENGTH+2+1: raise UnknownCommandException(request) | ||
63 | - | ||
64 | - # Remove TERMINATOR | ||
65 | - request = request[0:-1] | ||
66 | - | ||
67 | - # Remove leading stamp | ||
68 | - stamp = request[0:STAMP_LENGTH] | ||
69 | - command = request[STAMP_LENGTH:] | ||
70 | - print("Command received is", repr(command)) | ||
71 | - | ||
72 | - # TYPE1 | ||
73 | - if command not in (COMMAND5, COMMAND6): | ||
74 | - # TYPE2 or 3 | ||
75 | - if len(command) < 3: raise UnknownCommandException() | ||
76 | - if not (command[-1]=='#'): raise UnknownCommandException() | ||
77 | - if not (command[0]==':') and command not in ('bC#','bW#','bR#'): raise UnknownCommandException() | ||
78 | - | ||
79 | - command_start = command[1:3] | ||
80 | - if command == COMMAND6: answer = "G" | ||
81 | - elif command == COMMAND5: answer = COMMAND5 | ||
82 | - | ||
83 | - #gr_request = STAMP + ':GR#' + END | ||
84 | - #return bytes(stamp + "15:01:48#" + TERMINATOR, "utf-8") | ||
85 | - elif command == ':GR#': answer = "15:01:49" | ||
86 | - | ||
87 | - #gd_request = STAMP + ':GD#' + END | ||
88 | - #if request == bytes(gd_request, "utf-8"): return bytes(STAMP + "+12:28#", "utf-8") | ||
89 | - #elif useful_request == 'GD': answer = "+12:28" | ||
90 | - elif command == ':GD#': answer = "+12:29" | ||
91 | - elif command == ':SG+00#': answer = "1" | ||
92 | - elif command == ':GG#': answer = "+00" | ||
93 | - elif command_start == 'Gv': answer = 'T' | ||
94 | - elif command_start in ('GC','GL', 'Gg', 'Gt'): | ||
95 | - answer = Memo.get(command_start[1]) | ||
96 | - # Gemini telescope replaces "*" with ":" | ||
97 | - if command_start in ('Gg','Gt'): answer = answer.replace('*',':') | ||
98 | - else: | ||
99 | - # Remove ending '#' | ||
100 | - command = command[0:-1] | ||
101 | - if command_start in ('SC', 'SL', 'Sg', 'St'): Memo.set(command_start[1],command[3:]) | ||
102 | - if command[0] == ':': command = command[1:] | ||
103 | - answer = command.upper() | ||
104 | - | ||
105 | - full_answer_in_bytes = bytes(stamp + answer + '#' + TERMINATOR, "utf-8") | ||
106 | - #print("request str upper is", str(request).upper()) | ||
107 | - print("Answer sent is", full_answer_in_bytes) | ||
108 | - return full_answer_in_bytes | ||
109 | - | ||
110 | - | ||
111 | - | ||
112 | -def get_SocketServer_UDP_TCP_gemini(myhost:str="localhost", myport:int=11110, PROTOCOL:str="TCP"): | ||
113 | - #return get_SocketServer_UDP_TCP(myhost, myport, PROTOCOL) | ||
114 | - return get_SocketServer_UDP_TCP(myhost, myport, PROTOCOL, make_answer_for_request) | ||
115 | - |