Skip to content

Commit 8be2cc7

Browse files
committed
Marvin's code checks
1 parent c0cfbc4 commit 8be2cc7

File tree

2 files changed

+95
-7
lines changed

2 files changed

+95
-7
lines changed

python-serial/src/thermoflex/network.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ def net_manager_thread():
3434
while NET_MANAGER_FLAG.is_set() == False:
3535

3636
checklist = NodeNet.netlist.copy()
37-
for net in checklist:
38-
# for cmd in net.rec_cmd_buff:
39-
# net.disperse(cmd)
40-
# del net.rec_cmd_buff[cmd]
41-
37+
for net in checklist:
4238
try:
4339
net.update_network()
4440
except TypeError:
@@ -106,7 +102,6 @@ def removeNode(self, id):
106102
D.debug(DEBUG_LEVELS['INFO'], self.debug_name, f"Removing node: {id}")
107103
for node in self.node_list:
108104
if node.id == id:
109-
self.node_list.remove(node)
110105
node.endself()
111106

112107
def getDevice(self, id):

test/muscle-cmd-test.py

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,96 @@
11
'''
22
Unit test for all muscle commands and status variables
3-
'''
3+
'''
4+
import thermoflex as tf
5+
import threading as th
6+
import time as t
7+
8+
COMMAND_CHANGE_INTERVAL = 5
9+
STATUS_THREAD_INTERVAL = 10
10+
END_TEST_FLAG = th.Event()
11+
END_TEST_FLAG.clear()
12+
13+
def threaded(func):
14+
global threadlist
15+
threadlist = []
16+
17+
def wrapper(*args, **kwargs):
18+
thread = th.Thread(target=func, args=args, kwargs=kwargs)
19+
threadlist.append(thread)
20+
thread.start()
21+
return thread
22+
23+
return wrapper
24+
25+
#Establish a connection to the testnet and testnode
26+
network = tf.discover()
27+
testnet = network[0]
28+
testnode = testnet.node_list[0]
29+
30+
#Test the muscle command and status variables
31+
32+
muscle1 = testnode.muscle0
33+
34+
# Test the Muscle class methods
35+
@threaded
36+
def test_muscle_cmd(muscle):
37+
38+
# Set the mode of the muscle
39+
muscle.setMode(conmode="amps")
40+
print(f"Muscle Mode: {muscle.cmode}")
41+
t.sleep(COMMAND_CHANGE_INTERVAL)
42+
43+
# Set a setpoint for the muscle
44+
muscle.setSetpoint(conmode="percent", setpoint=0.75)
45+
print("Setpoint set to 0.75 in percent mode.")
46+
t.sleep(COMMAND_CHANGE_INTERVAL)
47+
48+
# Enable the muscle
49+
muscle.setEnable(True)
50+
print("Muscle enabled.")
51+
t.sleep(COMMAND_CHANGE_INTERVAL)
52+
53+
# Disable the muscle
54+
muscle.setEnable(False)
55+
print("Muscle disabled.")
56+
t.sleep(COMMAND_CHANGE_INTERVAL)
57+
58+
@threaded
59+
def muscle_status_test(muscle):
60+
61+
while not END_TEST_FLAG.is_set():
62+
t.sleep(STATUS_THREAD_INTERVAL)
63+
# Get the current setpoint of the muscle
64+
setpoint = muscle.getSetpoint()
65+
print(f"Muscle Setpoint: {setpoint}")
66+
67+
# Get the current mode of the muscle
68+
mode = muscle.getMode()
69+
print(f"Muscle Mode: {mode}")
70+
71+
# Get the current current of the muscle
72+
current = muscle.getCurrent()
73+
print(f"Muscle Current: {current}")
74+
75+
# Get the current voltage of the muscle
76+
voltage = muscle.getVoltage()
77+
print(f"Muscle Voltage: {voltage}")
78+
# Get the muscle status
79+
80+
status = muscle.muscleStatus()
81+
print(f"Muscle Status: {status}")
82+
83+
# Get the resistance of the muscle
84+
resistance = muscle.getResistance()
85+
print(f"Muscle Resistance: {resistance}")
86+
87+
88+
89+
# Run the test
90+
muscle_status_test(muscle1)
91+
test_muscle_cmd(muscle1)
92+
93+
94+
95+
for thread in threadlist:
96+
thread.join()

0 commit comments

Comments
 (0)