Skip to content

Commit

Permalink
working solution for #181
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Jul 24, 2021
1 parent 1195151 commit aaa78a9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ build/
.vscode/
*CMakeUserPresets*.json
*.tar.gz
*env/
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
network = pyRF24Network.RF24Network(radio)
network.begin(90, this_node[0])

head_out = pyRF24Network.RF24NetworkHeader(other_node[0], 0)
head_in = pyRF24Network.RF24NetworkHeader()
header = pyRF24Network.RF24NetworkHeader(other_node[0], 0)

def master(count=1, interval=1):
for _ in range(count):
msg = bytes(range(count)) # using dynamic payload sizes
count -= 1
print("message", msg, end=" ")
if network.write(head_out, msg):
header = pyRF24Network.RF24NetworkHeader(other_node[0], 0)
if network.write(header, msg):
print("sent successfully")
else:
print("failed to transmit")
Expand All @@ -45,10 +45,10 @@ def slave(timeout=10):

def print_details():
radio.printPrettyDetails()
print("node address\t:", oct(this_node[0]))
print("node address\t\t=", oct(this_node[0]))

print("""\n
testing script for RF24Network python wrapper\n\n
run `master(<msg_count>)` to transmit\n
print("""
testing script for RF24Network python wrapper\n
run `master(<msg_count>)` to transmit
run `slave(<timeout_seconds>)` to receive"""
)
10 changes: 6 additions & 4 deletions RPi/pyRF24Network/examples/helloworld_rx.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@
print("payload length ", len(payload))
millis, number = struct.unpack('<LL', bytes(payload))
print(
"Received payload", number,
"at", millis,
"from", oct(header.from_node),
"to", oct(header.to_node)
"Received payload {} from {} to {} at (origin's timestamp) {}".format(
number,
oct(header.from_node),
oct(header.to_node),
millis,
)
)
start = time.monotonic()
time.sleep(0.05)
16 changes: 4 additions & 12 deletions RPi/pyRF24Network/pyRF24Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int get_bytes_or_bytearray_ln(bp::object buf)
return 0;
}

bp::tuple read_wrap(RF24Network &ref, size_t maxlen=MAX_PAYLOAD_SIZE)
bp::tuple read_wrap(RF24Network &ref, size_t maxlen)
{
RF24NetworkHeader header;

Expand All @@ -53,7 +53,7 @@ bp::tuple read_wrap(RF24Network &ref, size_t maxlen=MAX_PAYLOAD_SIZE)
return bp::make_tuple(header, py_ba);
}

bp::tuple peek_read_wrap(RF24Network &ref, size_t maxlen=MAX_PAYLOAD_SIZE)
bp::tuple peek_read_wrap(RF24Network &ref, size_t maxlen)
{
RF24NetworkHeader header;
char *buf = new char[maxlen + 1];
Expand Down Expand Up @@ -105,22 +105,14 @@ BOOST_PYTHON_MODULE(RF24Network)
}
{ //::RF24Network::peek
typedef bp::tuple (*peek_frame)(::RF24Network &, size_t);
RF24Network_exposer.def("peek", peek_frame(&peek_read_wrap), (bp::arg("maxlen")));
}
{ //::RF24Network::peek (using optional maxlen param's default value)
typedef bp::tuple (*peek_frame)(::RF24Network &, size_t);
RF24Network_exposer.def("peek", peek_frame(&peek_read_wrap));
}
{ //::RF24Network::read (using optional maxlen param's default value)
typedef bp::tuple (*read_function_type)(::RF24Network &, size_t);
RF24Network_exposer.def("read", read_function_type(&read_wrap));
RF24Network_exposer.def("peek", peek_frame(&peek_read_wrap), (bp::arg("maxlen")=MAX_PAYLOAD_SIZE));
}
{ //::RF24Network::read
typedef bp::tuple (*read_function_type)(::RF24Network &, size_t);
RF24Network_exposer.def(
"read",
// read_function_type( &::RF24Network::read ),
read_function_type(&read_wrap), (bp::arg("maxlen")));
read_function_type(&read_wrap), (bp::arg("maxlen")=MAX_PAYLOAD_SIZE));
}
{ //::RF24Network::update
typedef void (::RF24Network::*update_function_type)();
Expand Down

0 comments on commit aaa78a9

Please sign in to comment.