def main(): """ Main function. """ # initialise objects serial_port = serial.Serial(port='COM4', baudrate=57600) ble_builder = BLEBuilder(serial_port) ble_parser = BLEParser(serial_port, callback=analyse_packet) # initialise the device print("COMMAND: Initialising device") print(print_output(ble_builder.send("fe00"))) # get an operating parameter value print("COMMAND: Getting operating parameter value") print(print_output(ble_builder.send("fe31", param_id="\x15"))) # start a device discovery scan print("COMMAND: Starting device scan") print(print_output(ble_builder.send("fe04", mode="\x03"))) # sleep main thread for 15 seconds - allow results of device scan to return time.sleep(15) #close device ble_parser.stop()
def test_parser(): ble_parser = BLEParser() print(print_output(ble_parser._split_response("\x04\xFF\x2C\x00\x06\x00\x06\x30\x85\x31\x18\x00\x1B\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x09\x09\x09\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x09\x09\x09\x09\x00\x00"))) print(print_output(ble_parser._split_response("\x04\xFF\x08\x7F\x06\x00\x31\xFE\x02\xD0\x07"))) print(print_output(ble_parser._split_response("\x04\xFF\x0C\x01\x06\x00\x01\x00\x00\x57\x6A\xE4\x31\x18\x00"))) print(print_output(ble_parser._split_response("\x04\xFF\x14\x01\x06\x00\x01\x00\x00\x57\x6A\xE4\x31\x18\x00\x11\x11\x11\x11\x11\x11\x11\x11"))) print(print_output(ble_parser._split_response("\x04\xFF\x07\x01\x06\x00\x00")))
def __init__(self, port, baudrate, callback): self.serial_port = serial.Serial(port=port, baudrate=baudrate) super(TIConnection, self).__init__(self.serial_port) self.parser = BLEParser(self.serial_port, callback=self.analyse_packet) self.callback = callback self.GAP_DeviceInit() self.state = State.DISCONNECTED self.desiredName = "" self.macAddr = "" self.name = "" self.notifications = list() self.wasSuccess = False self.cv = threading.Condition()
def test_parser(): ble_parser = BLEParser() print( ble_parser._split_response( "\x04\xFF\x2C\x00\x06\x00\x06\x30\x85\x31\x18\x00\x1B\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x09\x09\x09\x09\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x09\x09\x09\x09\x00\x00" )) print( ble_parser._split_response( "\x04\xFF\x08\x7F\x06\x00\x31\xFE\x02\xD0\x07")) print( ble_parser._split_response( "\x04\xFF\x0C\x01\x06\x00\x01\x00\x00\x57\x6A\xE4\x31\x18\x00")) print( ble_parser._split_response( "\x04\xFF\x14\x01\x06\x00\x01\x00\x00\x57\x6A\xE4\x31\x18\x00\x11\x11\x11\x11\x11\x11\x11\x11" )) print(ble_parser._split_response("\x04\xFF\x07\x01\x06\x00\x00"))
def executeQRSerialSequence(serialNumber): global testStatus global link_established global is_rssi_retrieved global serial_done global serial_failed global serialFromShine global ieee global ieeeLog global ieeeLogReverse global scan_done global rssi global serialReceived global shineSelectedScanOne global shineSelectedScanTwo global current_scan global zData1 global zData2 global zData3 global zDataStatus global serialQR global fw_rev_read global testFailures global files_erased global got_file global erase_count global streamCount global ble_builder global serialNumberX global operatingCurrent global avgOperatingCurrent global accelCurrent global avgAccelCurrent global serialFromShine global fw_rev global adv_samples ################## ADDED BY GABE ########### FORCE ALL VARS TO INIT STATE resetState() serialQR = '' ######################################################################### stationTwoTests = [] if not MDapi.internet_on(): resetState() return -2 #SERIAL NUMBER CLEANING serialNumberX = serialNumber average = 0 ieeeLogReverse = '' b = 1 for letter in serialNumber: hex = letter.encode('hex') hex = hex.upper() serialQR += hex if b < len(serialNumber): serialQR += '.' b += 1 #initialize success = initializeSourceMeter() if not success: return -1 #connect to USB radio serial_port = serial.Serial(USB_RADIO_PATH) #setup bt module ble_builder = BLEBuilder(serial_port) ble_parser = BLEParser(serial_port, callback=__analysePacket) testFailures[TIMEOUT_FAIL] = 0 #test sequence while (testStatus < FINAL_PHASE): print "Phase " + str(testStatus) testStatus = executeNextStepReturn(testStatus) #close port and stop ble parsing ble_parser.stop() serial_port.close() #### NEW (FROM QR SERIAL) CODE totalFailures = 0 print "Failures: %s" % testFailures for each in testFailures: if each != -1: totalFailures += each print "TOTAL FAILURES: " + str(totalFailures) if not totalFailures: global_pass = True else: global_pass = False #BUILD STATION TEST OBJECT timestamp = time.time() if testFailures[SCAN_FAIL] != -1: stationTwoTests.append( ScanTest(not testFailures[SCAN_FAIL], timestamp, shineSelectedScanTwo['rssi'])) print stationTwoTests if testFailures[CHECK_FW_FAIL] != -1: stationTwoTests.append( FirmwareCheckTest(not testFailures[CHECK_FW_FAIL], timestamp, "", fw_rev)) print stationTwoTests if testFailures[ACCEL_STREAM_FAIL] != -1: stationTwoTests.append( AccelZDataTest(not testFailures[ACCEL_STREAM_FAIL], timestamp, zData)) print stationTwoTests if testFailures[SN_DEFAULT_FAIL] != -1: print "SN DEFAULT TEST" print serialNumber stationTwoTests.append( DefaultSNCheckTest(not testFailures[SN_DEFAULT_FAIL], timestamp, serialNumber)) if testFailures[SN_MISMATCH_FAIL] != -1: stationTwoTests.append( SNMismatchTest(not testFailures[SN_MISMATCH_FAIL], timestamp, serialFromShine, serialNumberX)) if testFailures[TIMEOUT_FAIL] != -1: stationTwoTests.append( StationTwoTimeoutTest(not testFailures[TIMEOUT_FAIL], timestamp, timeout[0])) if testFailures[AVG_CURRENT_FAIL] != -1: stationTwoTests.append( OperCurrentTest(not testFailures[AVG_CURRENT_FAIL], timestamp, operatingCurrent, avgOperatingCurrent)) if testFailures[SN_DUPLICATE_FAIL] != -1: stationTwoTests.append( DuplicateSNTest(not testFailures[SN_DUPLICATE_FAIL], timestamp, serialFromShine)) if testFailures[RECENTLY_SYNCED_FAIL] != -1: stationTwoTests.append( RecentSyncTest(not testFailures[RECENTLY_SYNCED_FAIL], timestamp)) if testFailures[BATTERY_PLOT_FAIL] != -1: stationTwoTests.append( BatteryPlotTest(not testFailures[BATTERY_PLOT_FAIL], timestamp)) st = StationTest("3." + str(ATE_ID), global_pass, "log_format_7", fw_rev, stationTwoTests, timestamp) #initialize log stuff post_success = False update_success = False duplicate = '' ieee_db = '' entry = {} #POST STATION TEST TO MANUFACTURING DATABSE if ieeeLogReverse: ieee_db = str(ieeeLogReverse).translate(None, '.') print "Serial from Shine: " + serialFromShine print "SerialQR: " + serialQR (post_success, update_success, duplicate) = testToMFGDB(ieee_db, serialFromShine, st) print duplicate global_pass = global_pass and not duplicate #if it passed log to the unlink list if global_pass: writeSNUnlinkList(serialFromShine) finalIEEE = '' for each in shineSelectedScanTwo['ieee']: finalIEEE += each + '.' finalIEEE = finalIEEE[:-1] #Log all data writeSerialNumberLog(shineSelectedScanTwo['rssi'], operatingCurrent, avgOperatingCurrent, finalIEEE, zData, shineSelectedScanTwo['currentSN'], serialNumber, serialFromShine, fw_rev, testFailures, timeout[0], global_pass) entry['ieee'] = ieee_db entry['station_two_test'] = my_dict(st) #OBJECT -> DICTIONARY entry['final_serial'] = serialFromShine #did we fail or pass the unit in the factory? entry['global_pass'] = global_pass #what was the format? entry['station_two_log_format'] = 'log_format_7' #did we successfully post the test? entry['mfg_db_post_success'] = post_success #did we update serial/pass, physicals, and update/check duplicate? entry['mfg_db_update_success'] = update_success # was it a duplicate? entry['duplicate'] = duplicate #makes it easier to manage logs if post_success and update_success: print "Entry Successfully posted and updated in database" logPostedEntry(entry) else: print "Failed to log into database. Entry logged for future upload" logUnpostedEntry(entry) #UPDATE UI FOR FACTORY OPERATOR temp = testFailures if global_pass: resetState() return temp else: resetState() return temp
def executeTestSequence(dut_parameters, log_queue): global current_state global output output = 0 current_state = 0 setupSuccess = False overallPass = False logentry = {} if not MDapi.internet_on(): resetState() return -2 #reset globals resetState() #SET UP KEITHLEY POWER worked = powerSetup() if not worked: return -3 #INSTALL CORRECT FIRMWARE ON DEVICE FOR TESTING results = programmingSequence(dut_parameters, log_queue) stationOneTests = [] if 'programEFM' in results: unlockEFM = results['unlock'] programCC = results['programCC'] programEFM = results['programEFM'] setupSuccess = (unlockEFM.is_passed and programCC.is_passed and programEFM.is_passed) stationOneTests.append(unlockEFM) stationOneTests.append(programCC) stationOneTests.append(programEFM) else: unlockEFM = results['unlock'] logentry['unlocked'] = unlockEFM.is_passed if 'programCC' in results: programCC = results['programCC'] logentry['ieee_read'] = programCC.is_passed if programCC.is_passed: logentry['ieee'] = results['ieee'].translate(None, '.') #DEVICE CORRECTLY SET UP FOR TESTING if setupSuccess: ieee = results['ieee'] logentry['unlocked'] = True logentry['ieee_read'] = True logentry['test_began'] = True logentry['ieee'] = ieee.translate(None, '.') powerCycle() ledTests = singleLEDCurrentTests() stationOneTests.append(ledTests['mcu']) stationOneTests.append(ledTests['led']) sixLEDTest = sixLEDCurrentTest() stationOneTests.append(sixLEDTest) accelSelf = accelerometerSelfTest() stationOneTests.append(accelSelf) lowPower = lowPowerTest() stationOneTests.append(lowPower) flashFinal = flashFinalFirmware(dut_parameters, log_queue) stationOneTests.append(flashFinal) #initialise BT module and USB Dongle serial_port = serial.Serial(port=COM_PORT, baudrate=57600) ble_builder = BLEBuilder(serial_port) ble_parser = BLEParser(serial_port, callback=__analysePacket) timeout1 = connectToShineDUT(ble_builder, ieee) timeout2 = False if not timeout1: btTests = measureAverageRSSI(ble_builder) timeout2 = btTests['timeout'] #if we timed out, we didn't complete these tests, so don't include them. if not timeout2: if 'rssi' in btTests: #check to make sure we completed the rssi test stationOneTests.append(btTests['rssi']) stationOneTests.append( btTests['invalid'] ) #this one will always be in there if there wasn't a timeout #close link ble_builder.send("fe0a") #close device ble_parser.stop() serial_port.close() ieee = ieee.translate(None, '.') timeoutPass = True if timeout1 or timeout2: timeoutPass = False map_timeout = {'True': 1, 'False': 0} timeoutTest = StationOneTimeoutTest( isPassed=timeoutPass, timestamp=time.time(), timeouts=[map_timeout[str(timeout1)], map_timeout[str(timeout2)]]) stationOneTests.append(timeoutTest) #TEST DONE #create the overall station test object overallPass = True for each in stationOneTests: if not each.is_passed: overallPass = False #CREATED STATION ONE TEST OBJECT stationOneTest = StationTest("1." + str(ATE_ID), overallPass, "log_format_7", "0.0.21.ht03", stationOneTests, time.time()) #CREATE MISFIT DEVICE OBJECT misfitDevice = Device(serial_number="", ieee=ieee, manufacturer='MisfitVS', creation_time=time.time()) misfitDevice.physical['mechanical_revision'] = "1.0" misfitDevice.physical['pcb_revision'] = "0.9" misfitDevice.physical['pcba_revision'] = "0.9" misfitDevice.physical['color'] = "TBD" misfitDevice.physical['model_number'] = "TBD" misfitDevice.addStationTest(stationOneTest) #ADD ENTRY TO MFG DATABASE post_success = postTestEntryToMFGdb(stationOneTest, misfitDevice) # if this is false, it failed 5 times so ostensibly the internet is down. do we fail the unit? or pass and wait to import later? st = my_dict(stationOneTest) logentry['station_test'] = st logentry['mfg_db_post_success'] = post_success else: logentry['test_began'] = False logentry['station_test'] = {} logentry['mfg_db_post_success'] = False logentry['station_one_log_format'] = 'log_format_7' if logentry['mfg_db_post_success'] == True: logPostedEntry(logentry) else: logUnpostedEntry(logentry) #return UI to show operator if overallPass: return 0 else: return 1
def executeQRSerialSequence(serialNumber): global testStatus global link_established global is_rssi_retrieved global serial_done global serial_failed global serialFromShine global ieee global ieeeLog global ieeeLogReverse global scan_done global rssi global serialReceived global shineSelectedScanOne global shineSelectedScanTwo global current_scan global zData1 global zData2 global zData3 global zDataStatus global serialQR global fw_rev_read global testFailures global files_erased global got_file global erase_count global streamCount global ble_builder global serialNumberX global operatingCurrent global avgOperatingCurrent global accelCurrent global avgAccelCurrent global serialFromShine global fw_rev global adv_samples ################## ADDED BY GABE ########### FORCE ALL VARS TO INIT STATE resetState() ######################################################################### stationTwoTests = [] if not MDapi.internet_on(): resetState() return -2 #SERIAL NUMBER CLEANING serialNumberX = serialNumber average = 0 ieeeLogReverse = '' b = 1 for letter in serialNumber: hex = letter.encode('hex') hex = hex.upper() serialQR += hex if b < len(serialNumber): serialQR += '.' b += 1 #initialize success = initializeSourceMeter() if not success: return -1 #connect to USB radio serial_port = serial.Serial(port=COM_PORT, baudrate=57600) #setup bt module ble_builder = BLEBuilder(serial_port) ble_parser = BLEParser(serial_port, callback=__analysePacket) #test sequence while (testStatus < 10): testStatus = executeNextStep(testStatus) #close port and stop ble parsing ble_parser.stop() serial_port.close() #return pass or fail to screen totalFailures = 0 print "Failures: %s" % testFailures for each in testFailures: if each != -1: totalFailures += each print "TOTAL FAILURES: " + str(totalFailures) if not totalFailures: global_pass = True else: global_pass = False #BUILD STATION TEST OBJECT initialSerial = cleanSN(shineSelectedScanTwo['currentSN']) timestamp = time.time() if testFailures[SCAN_FAIL] != -1: stationTwoTests.append( ScanTest(not testFailures[SCAN_FAIL], timestamp, shineSelectedScanTwo['rssi'])) if testFailures[ADV_SAMPLES_FAIL] != -1: stationTwoTests.append( AdvSamplesTest(not testFailures[ADV_SAMPLES_FAIL], timestamp, adv_samples)) ### WTF??? What is testFailures[OPCURTEST]????? if testFailures[AVG_CURRENT_FAIL] != -1: stationTwoTests.append( OperCurrentTest(not testFailures[AVG_CURRENT_FAIL], timestamp, operatingCurrent, avgOperatingCurrent)) ### WTF??? What is testFailures[CHECK_FW_REV]????? CHECK_FW_FAIL ???? if testFailures[CHECK_FW_FAIL] != -1: stationTwoTests.append( FirmwareCheckTest(not testFailures[CHECK_FW_FAIL], timestamp, "0.0.28x.boot2_prod", fw_rev)) if testFailures[ACCEL_STREAM_FAIL] != -1: stationTwoTests.append( AccelZDataTest(not testFailures[ACCEL_STREAM_FAIL], timestamp, zData)) if testFailures[CONFIRM_LED_FAIL] != -1: stationTwoTests.append( ConfirmLEDCurrentTest(not testFailures[CONFIRM_LED_FAIL], timestamp, accelCurrent, avgAccelCurrent)) if testFailures[SN_PROGRAM_FAIL] != -1: stationTwoTests.append( WriteSerialTest(not testFailures[SN_PROGRAM_FAIL], timestamp, serialNumber)) if testFailures[SN_READ_FAIL] != -1: stationTwoTests.append( ReadSerialTest(not testFailures[SN_READ_FAIL], timestamp, initialSerial, serialFromShine)) if testFailures[TIMEOUT_FAIL] != -1: stationTwoTests.append( StationTwoTimeoutTest(not testFailures[TIMEOUT_FAIL], timestamp, timeout[0])) st = StationTest("2." + str(ATE_ID), global_pass, "log_format_7", fw_rev, stationTwoTests, timestamp) #initialize log stuff post_success = False update_success = False duplicate = '' ieee_db = '' entry = {} #POST STATION TEST TO MANUFACTURING DATABSE if ieeeLogReverse: ieee_db = str(ieeeLogReverse).translate(None, '.') print "Serial from Shine: " + serialFromShine print "SerialQR: " + serialQR (post_success, update_success, duplicate) = testToMFGDB(ieee_db, serialFromShine, st) print duplicate global_pass = global_pass and not duplicate entry['ieee'] = ieee_db entry['station_two_test'] = my_dict(st) #OBJECT -> DICTIONARY entry['final_serial'] = serialFromShine #did we fail or pass the unit in the factory? entry['global_pass'] = global_pass #what was the format? entry['station_two_log_format'] = 'log_format_7' #did we successfully post the test? entry['mfg_db_post_success'] = post_success #did we update serial/pass, physicals, and update/check duplicate? entry['mfg_db_update_success'] = update_success # was it a duplicate? entry['duplicate'] = duplicate #makes it easier to manage logs if post_success and update_success: print "Entry Successfully posted and updated in database" logPostedEntry(entry) else: print "Failed to log into database. Entry logged for future upload" logUnpostedEntry(entry) #UPDATE UI FOR FACTORY OPERATOR if global_pass: resetState() return 1 else: resetState() return 0