-
-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
105 changed files
with
3,233 additions
and
995 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,18 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
IMPORTANT NOTICE: BrainFlow uses SimpleBLE, | ||
which is owned by The California Open Source Company LLC and used under license. | ||
As an End User of BrainFlow, you are prohibited from using, modifying, or | ||
distributing SimpleBLE, or any part thereof, except as incorporated in this | ||
Project. Specifically, you may not: | ||
|
||
a) Extract, isolate, or separate SimpleBLE from BrainFlow; | ||
b) Modify, adapt or translate SimpleBLE; | ||
c) Distribute, sublicense, rent, lease, lend, or transfer SimpleBLE to any third party; | ||
d) Remove, obscure, or alter any copyright, trademark, or other proprietary rights | ||
notices contained within SimpleBLE. | ||
Your use of this Application is subject to your compliance with these restrictions. | ||
If you have any questions about these terms, please contact | ||
The California Open Source Company LLC [[email protected]]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import logging | ||
import threading | ||
import time | ||
from random import randint | ||
|
||
class Listener(threading.Thread): | ||
|
||
def __init__(self, port, write, read): | ||
# for windows write and read are methods from Serial object, for linux - os.read/write it doesnt work otherwise | ||
threading.Thread.__init__(self) | ||
self.port = port | ||
self.writer_process = None | ||
self.write = write | ||
self.read = read | ||
self.need_stop = False | ||
|
||
def run(self): | ||
self.writer_process = KnightBoardWriter(self.port, 0.005, self.write) | ||
self.writer_process.daemon = True | ||
self.writer_process.start() | ||
time.sleep(10) | ||
self.writer_process.need_data = False | ||
self.writer_process.join() | ||
|
||
|
||
class KnightBoardWriter(threading.Thread): | ||
|
||
def __init__(self, port, delay, write): | ||
threading.Thread.__init__(self) | ||
self.port = port | ||
self.write = write | ||
self.delay = delay | ||
self.package_size = 21 | ||
self.package_num = 0 | ||
self.need_data = True | ||
|
||
def run(self): | ||
while self.need_data: | ||
if self.package_num % 256 == 0: | ||
self.package_num = 0 | ||
|
||
package = list() | ||
package.append(0xA0) | ||
package.append(self.package_num) | ||
for i in range(2, self.package_size - 1): | ||
package.append(randint(0, 255)) | ||
package.append(0xC0) | ||
logging.info(bytes(package)) | ||
self.write(self.port, bytes(package)) | ||
|
||
self.package_num = self.package_num + 1 | ||
time.sleep(self.delay) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import logging | ||
import os | ||
import pty | ||
import subprocess | ||
import sys | ||
|
||
from brainflow_emulator.emulate_common import TestFailureError, log_multilines | ||
from brainflow_emulator.knightboard_emulator import Listener | ||
|
||
|
||
def write(port, data): | ||
return os.write(port, data) | ||
|
||
|
||
def read(port, num_bytes): | ||
return os.read(port, num_bytes) | ||
|
||
|
||
def get_ports_pty(): | ||
master, slave = pty.openpty() | ||
s_name = os.ttyname(slave) | ||
return master, slave, s_name | ||
|
||
|
||
def test_serial(cmd_list, master, slave, s_name): | ||
listen_thread = Listener(master, write, read) | ||
listen_thread.daemon = True | ||
listen_thread.start() | ||
|
||
cmd_to_run = cmd_list + [s_name] | ||
logging.info('Running %s' % ' '.join([str(x) for x in cmd_to_run])) | ||
process = subprocess.Popen(cmd_to_run, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
stdout, stderr = process.communicate() | ||
|
||
log_multilines(logging.info, stdout) | ||
log_multilines(logging.info, stderr) | ||
|
||
if process.returncode != 0: | ||
raise TestFailureError('Test failed with exit code %s' % str(process.returncode), process.returncode) | ||
|
||
return stdout, stderr | ||
|
||
|
||
def main(cmd_list): | ||
if not cmd_list: | ||
raise Exception('No command to execute') | ||
master, slave, s_name = get_ports_pty() | ||
test_serial(cmd_list, master, slave, s_name) | ||
|
||
|
||
if __name__ == '__main__': | ||
logging.basicConfig(level=logging.INFO) | ||
main(sys.argv[1:]) |
Oops, something went wrong.