<commit_before>
# ProMotion board test utility
# (C) 2015 Motsai Research Inc.
# Author: <NAME> (<EMAIL>)

from __future__ import print_function
import os
import cmd
import time

import serial
import serial.tools.list_ports

import neblina as neb
import neblinaAPI as nebcomm
import binascii


class TestProMotion(cmd.Cmd):
    """docstring for StreamMenu"""
    
    def __init__(self):
        cmd.Cmd.__init__(self)

        self.bigLine = '-------------------------------------------------------------------\n'
        self.configFileName = 'streamconfig.txt'
        self.prompt = '>>'
        self.intro = "ProMotion Test Routine!"
        
        # Check if config file exists
        if(not os.path.exists(self.configFileName)):
            self.setCOMPortName()

        # Read the config file to get the name
        with open(self.configFileName, 'r') as configFile:
                comPortName = configFile.readline()
        
        # Try to open the serial COM port
        sc = None
        while sc is None:
            try:
                sc = serial.Serial(port=comPortName,baudrate=500000, timeout=1.5)
            except serial.serialutil.SerialException as se:
                if 'Device or resource busy:' in se.__str__():
                    print('Opening COM port is taking a little while, please stand by...')
                else:
                    print('se: {0}'.format(se))
                time.sleep(1)
        
        self.comm = nebcomm.NeblinaComm(sc)
        self.comm.sc.flushInput()
        # Make the module stream towards the UART instead of the default BLE
        self.comm.switchStreamingInterface(True)
        self.comm.motionStopStreams()

        thefile = open('ProMotionTestLog.txt', 'w')
        print(" ")
        dataString = "*** ProMotion Board Test Routine ***\n"
        print(dataString)
        thefile.write(dataString)
        thefile.write("\n")
        dataString = "=================================================================================="
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")

        dataString = "Test#1: Loopback test with KL26 by sending 1000 empty packets..."
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        dataString = "================================================================"
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        for x in range(1, 1001):
            print('Loopback test packet %d\r' % (x), end="", flush=True)
            self.comm.sendCommand(neb.Subsys_Debug, neb.DebugCmd_SetInterface, True)
            self.comm.waitForAck(neb.Subsys_Debug, neb.DebugCmd_SetInterface)
        print("")
        dataString = "Test#1 Passed!!!"
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n\n")
        print(" ")
        dataString = "Test#2: Checking communication with the LSM9DS1 chip by getting the temperature..."
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        dataString = "=================================================================================="
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        temp = self.comm.getTemperature()
        dataString = 'Board Temperature: {0} degrees (Celsius)'.format(temp)
        print(dataString)
        thefile.write(dataString)
        thefile.write("\n")

        dataString =  "Test#2 Passed!!!"
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n\n")
        print(" ")
        dataString = "================================================================================================="
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        dataString = "Test#3: Checking communication between Nordic and KL26 chips by getting the firmware versions..."
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        dataString = "================================================================================================="
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        versions = self.comm.debugFWVersions()
        apiRelease = versions[0]
        mcuFWVersion = versions[1]
        bleFWVersion = versions[2]
        deviceID = versions[3]
        print( "API Release: {0}\n\
        MCU Version: {1}.{2}.{3}\n\
        BLE Version: {4}.{5}.{6}\n\
        Device ID: {7}".format(apiRelease,\
            mcuFWVersion[0], mcuFWVersion[1], mcuFWVersion[2],\
            bleFWVersion[0], bleFWVersion[1], bleFWVersion[2],\
            binascii.hexlify(deviceID)))
        # print(versions)
        if (bleFWVersion[0]==255):
            dataString = "The Nordic firmware is still unknown."
            print( dataString )
            thefile.write(dataString)
            thefile.write("\n")
            dataString = "Try running the script again after 20 seconds to make sure that Nordic sends its firmware version!"
            print( dataString )
            thefile.write(dataString)
            thefile.write("\n")
            dataString = "If the problem persists, there is a communication problem between Nordic and KL26 chips..."
            print( dataString )
            thefile.write(dataString)
            thefile.write("\n")
            self.comm.switchStreamingInterface(False)
            dataString = "Exiting..."
            print( dataString )
            thefile.write(dataString)
            thefile.write("\n")
            return
        dataString = "Test#3 Passed!!!"
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n\n")
        print(" ")
        dataString = "=========================================================================="
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        dataString = "Test#4: Checking the EEPROM by issuing a write command followed by a read"
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        dataString = "=========================================================================="
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        dataString = "UnitTest"
        dataString = dataString.encode('utf-8')
        self.comm.EEPROMWrite(0, dataString)
        dataBytes = self.comm.EEPROMRead(0)
        if (dataBytes==dataString):
            dataString = "Test#4 Passed!!!"
            print( dataString )
            thefile.write(dataString)
            thefile.write("\n\n")
            print(" ")
            dataString = "=============================================="<commit_msg>minor revision to the testProMotion.py<commit_after>
# ProMotion board test utility
# (C) 2015 Motsai Research Inc.
# Author: <NAME> (<EMAIL>)

from __future__ import print_function
import os
import cmd
import time

import serial
import serial.tools.list_ports

import neblina as neb
import neblinaAPI as nebcomm
import binascii


class TestProMotion(cmd.Cmd):
    """docstring for StreamMenu"""
    
    def __init__(self):
        cmd.Cmd.__init__(self)

        self.bigLine = '-------------------------------------------------------------------\n'
        self.configFileName = 'streamconfig.txt'
        self.prompt = '>>'
        self.intro = "ProMotion Test Routine!"
        
        # Check if config file exists
        if(not os.path.exists(self.configFileName)):
            self.setCOMPortName()

        # Read the config file to get the name
        with open(self.configFileName, 'r') as configFile:
                comPortName = configFile.readline()
        
        # Try to open the serial COM port
        sc = None
        while sc is None:
            try:
                sc = serial.Serial(port=comPortName,baudrate=500000, timeout=1.5)
            except serial.serialutil.SerialException as se:
                if 'Device or resource busy:' in se.__str__():
                    print('Opening COM port is taking a little while, please stand by...')
                else:
                    print('se: {0}'.format(se))
                time.sleep(1)
        
        self.comm = nebcomm.NeblinaComm(sc)
        self.comm.sc.flushInput()
        # Make the module stream towards the UART instead of the default BLE
        self.comm.switchStreamingInterface(True)
        self.comm.motionStopStreams()

        thefile = open('ProMotionTestLog.txt', 'w')
        print(" ")
        dataString = "*** ProMotion Board Test Routine ***\n"
        print(dataString)
        thefile.write(dataString)
        thefile.write("\n")
        dataString = "================================================================"
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")

        dataString = "Test#1: Loopback test with KL26 by sending 1000 empty packets..."
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        dataString = "================================================================"
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        for x in range(1, 1001):
            print('Loopback test packet %d\r' % (x), end="", flush=True)
            self.comm.sendCommand(neb.Subsys_Debug, neb.DebugCmd_SetInterface, True)
            self.comm.waitForAck(neb.Subsys_Debug, neb.DebugCmd_SetInterface)
        print("")
        dataString = "Test#1 Passed!!!"
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n\n")
        print(" ")
        dataString = "Test#2: Checking communication with the LSM9DS1 chip by getting the temperature..."
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        dataString = "=================================================================================="
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        temp = self.comm.getTemperature()
        dataString = 'Board Temperature: {0} degrees (Celsius)'.format(temp)
        print(dataString)
        thefile.write(dataString)
        thefile.write("\n")

        dataString =  "Test#2 Passed!!!"
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n\n")
        print(" ")
        dataString = "================================================================================================="
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        dataString = "Test#3: Checking communication between Nordic and KL26 chips by getting the firmware versions..."
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        dataString = "================================================================================================="
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        versions = self.comm.debugFWVersions()
        apiRelease = versions[0]
        mcuFWVersion = versions[1]
        bleFWVersion = versions[2]
        deviceID = versions[3]
        print( "API Release: {0}\n\
        MCU Version: {1}.{2}.{3}\n\
        BLE Version: {4}.{5}.{6}\n\
        Device ID: {7}".format(apiRelease,\
            mcuFWVersion[0], mcuFWVersion[1], mcuFWVersion[2],\
            bleFWVersion[0], bleFWVersion[1], bleFWVersion[2],\
            binascii.hexlify(deviceID)))
        # print(versions)
        if (bleFWVersion[0]==255):
            dataString = "The Nordic firmware is still unknown."
            print( dataString )
            thefile.write(dataString)
            thefile.write("\n")
            dataString = "Try running the script again after 20 seconds to make sure that Nordic sends its firmware version!"
            print( dataString )
            thefile.write(dataString)
            thefile.write("\n")
            dataString = "If the problem persists, there is a communication problem between Nordic and KL26 chips..."
            print( dataString )
            thefile.write(dataString)
            thefile.write("\n")
            self.comm.switchStreamingInterface(False)
            dataString = "Exiting..."
            print( dataString )
            thefile.write(dataString)
            thefile.write("\n")
            return
        return
        dataString = "Test#3 Passed!!!"
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n\n")
        print(" ")
        dataString = "=========================================================================="
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        dataString = "Test#4: Checking the EEPROM by issuing a write command followed by a read"
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        dataString = "=========================================================================="
        print( dataString )
        thefile.write(dataString)
        thefile.write("\n")
        dataString = "UnitTest"
        dataString = dataString.encode('utf-8')
        self.comm.EEPROMWrite(0, dataString)
        dataBytes = self.comm.EEPROMRead(0)
        if (dataBytes==dataString):
            dataString = "Test#4 Passed!!!"
            print( dataString )
            thefile.write(dataString)
            thefile.write("\n\n")
            print(" ")
            dataString = "=============================================="
{'fraction_non_alphanumeric': 0.1992278554778555, 'fraction_numerical': 0.009761072261072262, 'mean_word_length': 2.208459920542183, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1527558', 'n_tokens_mistral': 3718, 'n_tokens_neox': 3514, 'n_words': 839}