def create_objects(self): ## DEFINE PARAMETERS ########### self.CharSet = 'lowerCaseLiterals' self.CharactersPerMessage = 5 self.SourceEncodeMethod = 'basic' self.errorCorrection = 'HardHamming' # NOTE: Only use frequencies From the following Set: # [23.26, 23.81, 24.39, 25, 25.64, 26.36, 27.03, 27.78, 28.57, 29.41, 30.30, 31.25, 32.26, 33.33, # 34.48, 35.71, 37.04, 38.46 ] self.TransmissionFrequenciesIdeal = [ 23.26, 25, 26.36, 27.78, 28.57, 30.30, 31.25, 33.33 ] self.TimePerSymbolSeconds = 4 self.ValidDictionary = IL.loadCharacterSet(self.CharSet) self.InputValidationObject = IL.InputValidation( self.ValidDictionary, self.CharactersPerMessage) self.SrcEncoder = IL.SrcEncoder(self.ValidDictionary, self.SourceEncodeMethod) self.FEC = IL.ChannelEncoder(self.errorCorrection, 7, 4) self.Chan = IL.Channel('FixedFrequencyAndDuty', self.TransmissionFrequenciesIdeal, self.TimePerSymbolSeconds, True, 28.57, 30.30)
def RunSender(file_name, config_parameters, test_option): # function which will execute on the sender sendHeader = True if config_parameters["SYNC_METHOD"] == "KeyPress": sendHeader = False characterSet = Sender.loadCharacterSet(config_parameters["CHARACTER_SET"]) sourceEncoder = Sender.SrcEncoder(characterSet, config_parameters["SOURCE_ENCODER"]) channelEncoder = Sender.ChannelEncoder(config_parameters["ERROR_CORRECTION"],\ config_parameters["FEC_BLOCK_SIZE"],\ config_parameters["FEC_MESSAGE_SIZE"]) channel = Sender.Channel('FixedFrequencyAndDuty',\ config_parameters["TRANSMISSION_FREQUENCIES"],\ config_parameters["TIME_PER_SYMBOL"],\ sendHeader,\ HOLD_FREQUENCY,\ HEADER_FREQUENCY) # need to do the actual sending here symbols = [] if config_parameters["CHARACTERS_PER_MESSAGE"] != 0: message = raw_input("Enter a Message (" + str(config_parameters["CHARACTERS_PER_MESSAGE"]) + ") characters \n") sendBits = sourceEncoder.EncodeData(message) encodedBits = channelEncoder.EncodeData(sendBits) intBits = channelEncoder.interleave(encodedBits) symbols = Sender.SymbolMapping( intBits, len(config_parameters["TRANSMISSION_FREQUENCIES"])) print("Symbols to Transmit " + str(symbols)) raw_input("ready ... press Enter to Start") if sendHeader: channel.sendHeaderV2() sendStartTime = time.time() print("Starting to Send message at time " + str(sendStartTime)) for symbol in symbols: channel.send(symbol) channel.re_header() results = {} results["CONFIGURATION"] = config_parameters results["SEND_START_TIME"] = sendStartTime if test_option != 'protocol_only': results["SENT_SYMBOLS"] = symbols results["INTERLEAVED_BITS"] = intBits results["ENCODED_BITS"] = encodedBits results["BINARY_MESSAGE"] = sendBits results["STRING_MESSAGE"] = message print(results) with open(file_name, 'w') as outfile: json.dump(results, outfile)
# this file will be used merely to determine properties of the # header it should be deleted. # create a detector # roll values into the detector import Source.InputLib as IL import time Channel = IL.Channel('FixedFrequencyAndDuty', [23.26, 25], 1) time.sleep(2) Channel.setSingleFreq(28.57) time.sleep(20) Channel.setSingleFreq(30.30) time.sleep(4) Channel.setSingleFreq(28.57) time.sleep(20) Channel.setSingleFreq(23.26) time.sleep(20)
'TimeSet variation Not yet Implemented - default will be for 3 and 4 seconds' ) FrequencySet = [ 23.26, 23.81, 24.39, 25, 25.64, 26.36, 27.03, 27.78, 28.57, 29.41, 30.30, 31.25, 32.26, 33.33, 34.48, 35.71, 37.04, 38.46 ] SymbolVector = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] ElectrodesForCCA = ['O1', 'O2', 'P7', 'P8'] NumRuns = 4 # how many detection loops should be performed # ================= ######### #===Collect Data ====== TransmissionFrequencies4s = FD.mapToClosestFrequencies(FrequencySet, 512) Sender = SendLib.Channel('FixedFrequencyAndDuty', None, None) Receiver = Channel.Channel('Emokit', ElectrodesForCCA, False, False) CCADetector4s = RecvLib.DetectionObject('CCA', TransmissionFrequencies4s, None, ElectrodesForCCA, 4, 'HARD') PSDADetector4s = RecvLib.DetectionObject('PSDA', TransmissionFrequencies4s, None, ['O1'], 4, 'HARD') CombinedDetector4s = RecvLib.DetectionObject('Combined', TransmissionFrequencies4s, None, ElectrodesForCCA, 4, 'HARD') ResultsCCA4s = numpy.zeros([len(SymbolVector), NumRuns]) ResultsPSDA4s = numpy.zeros([len(SymbolVector), NumRuns]) ResultsCombined4s = numpy.zeros([len(SymbolVector), NumRuns]) time.sleep(2) Receiver.flushBuffer() for i in range(NumRuns):
# change this for each participant user = raw_input('Enter Subject ID :') option = raw_input("1 - wholeSystem; 2 - transmissionOnly; 3 - timingOnly \n") if option == "1": testType = 'WithSync' CharSet = 'lowerCaseLiterals' CharactersPerMessage = 5 SourceEncodeMethod = 'basic' errorCorrection = 'HardHamming' transFrequencies = [23.26, 25, 26.36, 27.78 ,28.57, 30.30, 31.25, 33.33] period = 4 ValidDictionary = IL.loadCharacterSet(CharSet) SrcEncoder = IL.SrcEncoder(ValidDictionary , SourceEncodeMethod) FEC = IL.ChannelEncoder(errorCorrection,7,4) Chan = IL.Channel('FixedFrequencyAndDuty',transFrequencies,period, True, 28.57,30.30) while True: run = raw_input('Enter Run Number: ') path = TL.makePath(user, testType, run) TL.quickRunSender(path,Chan, FEC, SrcEncoder,transFrequencies,option) elif option == "2": testType = 'SelfSync' CharSet = 'lowerCaseLiterals' CharactersPerMessage = 5 SourceEncodeMethod = 'basic' errorCorrection = 'HardHamming'