-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpacketcommslib_test.py
More file actions
169 lines (110 loc) · 4.15 KB
/
packetcommslib_test.py
File metadata and controls
169 lines (110 loc) · 4.15 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
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
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 27 20:12:20 2014
@author: john
==============================================================================
License
==============================================================================
Copyright 2016 John Bainbridge
This file is part of PacketComms.
PacketComms 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
(at your option) any later version.
PacketComms is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANY; 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 PacketComms. If not, see <http://www.gnu.org/licenses/>.
"""
#=================================================================
#%% Setup Server [Run in separate console]
#=================================================================
# Note : Runs best in standard Spyder console, not iPython
# Setup paths
# =============
# Adding to the system path
import sys
sys.path.append('/home/john/Documents/Python/Projects/packet_comms_checkouts/trunk')
# Imports
# ===========
import numpy as np
from packetcommslib import *
# Run server
# =============
testServer()
#=================================================================
#%% Setup Packet Server [Run in separate console]
#=================================================================
# Note : Runs best in standard Spyder console, not iPython
# Setup paths
# =============
# Adding to the system path
import sys
sys.path.append('/home/john/Documents/Python/Projects/packet_comms_checkouts/trunk')
# Imports
# ===========
import numpy as np
from packetcommslib import *
# Run server
# =============
server = PacketServer()
server.run()
#=================================================================
#%% Setup Client [Run in separate console]
#=================================================================
# Setup paths
# =============
# Adding to the system path
import sys
sys.path.append('/home/john/Documents/Python/Projects/packet_comms_checkouts/trunk')
# Imports
# ===========
import socket
import numpy as np
import packetcommslib as pcl
# Get IP address of host
hostIP = socket.gethostname()
#hostIP = socket.gethostbyname('raspberrypi')
#%% Send packet to server
dataPacket = "Hi Raspberry Pi, are you tasty"
pcl.sendPacket(hostIP,dataPacket)
#%% Shutdown server
pcl.serverShutdown(hostIP)
#%% Test sending text packets
data_label = "/Data/New_place"
text = "Some text to send"
text_list = ["Sending","some","text","in","a","list"]
text_packet = pcl.makeTextPacket(data_label,text)
text_list_packet = pcl.makeTextPacket(data_label,text_list)
pcl.sendPacket(hostIP,text_packet)
pcl.sendPacket(hostIP,text_list_packet)
#=================================================================
#%% Array Packet making/extracting test
#=================================================================
import sys,imp
sys.path.append('/home/john/Documents/Python/Projects/packet_comms_checkouts/trunk')
import packetcommslib as pcl
# Make an array packet
# -----------------------
array = np.array([[1,2,3],[4,5,6]]).transpose()
columns = ['col1','col2']
packet = pcl.makeArrayPacket('label',array,columns)
(label,array_out) = pcl.extractPacket(packet)
print("Packet: %s" % label)
print("Array :")
print(array_out)
#=================================================================
#%% Text Packet making/extracting test
#=================================================================
import sys,imp
sys.path.append('/home/john/Documents/Python/Projects/packet_comms_checkouts/trunk')
import packetcommslib as pcl
data_label = "/Data/New_place"
text = "Some text to send"
text_list = ["Sending","some","text","in","a","list"]
text_packet = pcl.makeTextPacket(data_label,text)
text_list_packet = pcl.makeTextPacket(data_label,text_list)
(label,text_out) = pcl.extractPacket(text_packet)
(list_label,text_list_out) = pcl.extractPacket(text_list_packet)