Ejemplo n.º 1
0
    def __init__(self, dwf, hdwf):
        self.dwf = dwf
        self.hdwf = hdwf

        self.ch1 = Channel.Channel(self.dwf, self.hdwf, 0)
        self.ch2 = Channel.Channel(self.dwf, self.hdwf, 1)

        self.frequency = 100000.00
        self.buffersize = 512
        self.trigger = Trigger.Trigger(self.dwf, self.hdwf)
Ejemplo n.º 2
0
 def __init__(self,
              callbackFunction=None,
              channels={},
              progressStepSeconds=0.1,
              progressStepSize=15):
     self.status = WScannerStatus.NOTSTARTED
     self.callbackFunction = callbackFunction
     self.channels = channels
     self.newChannels = {1: Channel('A'), 2: Channel('B'), 3: Channel('C')}
     self.progress = WScanner._WScanner__MINCHANNEL
     self.progressStepSeconds = progressStepSeconds
     self.progressStepSize = progressStepSize
Ejemplo n.º 3
0
 def copyChannel(self, ch, labels):
     # making all labels 10/1 or 10/20 system
     label = self.system10_20.testLabel(labels[self.i])
     if label is None:
         '''This a label not in the system so we add
         it as additional information'''
         channel = Channel(labels[self.i], ch)
         self.additionalData.append(channel)
     else:
         channel = Channel(label, ch)
         self.channels.append(channel)
     self.i += 1
Ejemplo n.º 4
0
    def add_channels_to_server(self):

        with open(self.channels_file, 'r') as f:
            for line in f:
                if line != "":
                    channel_name = line.strip().split()[0]
                    self.channels[channel_name] = Channel.Channel(channel_name)
Ejemplo n.º 5
0
def test_pushMessage_to_all():
    c = Channel(apiKey, secretKey)
    push_type = 3
    optional = dict()
    optional[Channel.MESSAGE_TYPE] = 1
    ret = c.pushMessage(push_type, message, message_key, optional)
    print ret
Ejemplo n.º 6
0
    def join(self, clientSocket, chatMessage, clientName):
        isInSameRoom = False

        if len(chatMessage.split()) >= 2:
            channelName = chatMessage.split()[1]

            if clientName in self.channels_client_map:  # Here we are switching to a new channel.
                if self.channels_client_map[clientName] == channelName:
                    clientSocket.sendall(("\n> You are already in channel: " +
                                          channelName + "\n").encode('utf8'))
                    isInSameRoom = True
                else:  # switch to a new channel
                    oldChannelName = self.channels_client_map[clientName]
                    self.channels[oldChannelName].remove_client_from_channel(
                        clientName)  # remove them from the previous channel

            if not isInSameRoom:
                if not channelName in self.channels:
                    newChannel = Channel.Channel(channelName)
                    self.channels[channelName] = newChannel

                self.channels[channelName].clients[clientName] = clientSocket
                self.channels[channelName].welcome_client(clientName)
                self.channels_client_map[clientName] = channelName
        else:
            self.help(clientSocket)
Ejemplo n.º 7
0
    def join_invite(self, client, channelName):
        isInSameRoom = False

        if client.get_clientName() in self.channels_client_map:
            if channelName in self.channels_client_map[
                    client.client.get_clientName()]:
                # User already on that channel
                client.send_message("\n> You are already in channel: " +
                                    channelName)
                isInSameRoom = True
            elif not channelName in self.channels_client_map[
                    client.client.get_clientName(
                    )] and channelName in self.channels:
                self.channels[channelName].clients[
                    client.get_clientName()] = client
                self.channels_client_map[client.get_clientName()].append(
                    channelName)

        if not isInSameRoom:
            if not channelName in self.channels:
                newChannel = Channel.Channel(channelName)
                self.channels[channelName] = newChannel
            self.channels[channelName].clients[
                client.get_clientName()] = client
            self.channels[channelName].welcome_client(client.get_clientName())
            self.channels_client_map[client.get_clientName()].append(
                channelName)
Ejemplo n.º 8
0
 def _manage_channels(self):
     assert self.state_lock.locked()
     for cid, channel in self.active_channels.items():
         message = 'Location channel management removing %r from active.'
         if not channel.accepting_requests():
             self.debugout(message % channel, 1)
             self.active_channels.pop(cid)
             self.parallel_channels.decrement()
     maxchannels = self.MAXPARALLELCHANNELS
     numpending = len(self.pending_transactions)
     numchannels = self.parallel_channels.value
     if numchannels == 0:
         createchannel = True
     elif numchannels >= maxchannels:
         createchannel = False
     elif (numpending / numchannels) > self.IDEALBACKLOG:
         createchannel = True
     else:
         createchannel = False
     if createchannel:
         channel = Channel(self.monitor, self.debug)
         channel.setup_connection(self.host, self.port, self.protocol)
         self.free_channels.append(channel)
         self.parallel_channels.increment()
     return
Ejemplo n.º 9
0
def pushMsgToTag(tagName, msg, type, opts):

    c = Channel()
    try:
        ret = c.pushMsgToTag(tagName, msg, type, opts)
    except ChannelException as e:
        print e.getLastErrorMsg()
Ejemplo n.º 10
0
 def load_channel_catalog(self, channel_catalog_filename):
     if self.VERBOSE:
         print("* %s" % Channel.get_header_caps())
     with open(channel_catalog_filename, "r") as channel_file:
         for line in channel_file:
             channel_line = line.strip()
             # Skip empty lines.
             if not channel_line:
                 continue
             # Skip comments.
             if (channel_line[0] == ';') or (channel_line[0] == '#'):
                 continue
             # Retrieve the values from the file.
             try:
                 label, id, cost, size, energy, df_energy, energy_cost, delay, error, wireless, point_to_point = channel_line.split(
                 )
             except ValueError:
                 print("Error: Wrong line format '%s'" % channel_line)
                 return False
             # Create a new Channel.
             new_channel = Channel(label, int(id), int(cost), int(size),
                                   int(energy), int(df_energy),
                                   float(energy_cost), int(delay),
                                   int(error), int(wireless),
                                   int(point_to_point))
             # Append the channel to the list of channels.
             self.add_channel(new_channel)
             # Print the channel.
             if self.VERBOSE:
                 print("* %s" % new_channel.to_string())
     return True
Ejemplo n.º 11
0
    def join(self, user, chatMessage):
        isInSameRoom = False

        if len(chatMessage.split()) >= 2:
            channelName = chatMessage.split()[1]

            if user.username in self.users_channels_map:  # Here we are switching to a new channel.
                if self.users_channels_map[user.username] == channelName:
                    user.socket.sendall(
                        "\n> You are already in channel: {0}".format(
                            channelName).encode('utf8'))
                    isInSameRoom = True
                else:  # switch to a new channel
                    oldChannelName = self.users_channels_map[user.username]
                    self.channels[oldChannelName].remove_user_from_channel(
                        user)  # remove them from the previous channel

            if not isInSameRoom:
                if not channelName in self.channels:
                    newChannel = Channel.Channel(channelName)
                    self.channels[channelName] = newChannel

                self.channels[channelName].users.append(user)
                self.channels[channelName].welcome_user(user.username)
                self.users_channels_map[user.username] = channelName
        else:
            self.help(user.socket)
Ejemplo n.º 12
0
 def ReDo(self, actions, es):
     # this redo's the filtering after forward
     self.GetParent().setStatus("Filtrando...", 1)
     self.eegs = es
     eegs = self.eegs
     new = []
     flag = False
     for eeg in eegs:
         # applying for each band
         bands = actions
         self.actions = bands
         if len(bands) > 0:
             flag = True
         for band in bands:
             channels = eeg.channels
             neweeg = deepcopy(eeg)
             neweeg.channels = []
             for ch in channels:
                 fourier = np.fft.rfft(ch.readings, len(ch.readings))
                 for i in range(len(fourier)):
                     if i < band.lowFrequency or i > band.hiFrequency:
                         fourier[i] = 0.0
                 # adding new filtered channel
                 filtered = np.fft.irfft(fourier)
                 fl = Channel(ch.label, filtered)
                 neweeg.channels.append(fl)
             # adding band limits to name
             neweeg.name += "~" + str(band.lowFrequency) + "~" + str(band.hiFrequency)
             new.append(neweeg)
     self.eegs.extend(new)
     self.pbutton.eegs = self.eegs
     self.GetParent().setStatus("", 0)
     if flag:
         self.exportButton.Enable()
Ejemplo n.º 13
0
def main():
    global client, host, username, password, channel

    load_parameters()
    try:
        client = Client(host, username, password)
    except:
        print("Could not connect to remote host.")
    grid = ScreenGrid.ScreenGrid(2, 2)

    chans = []

    for counter, channel in enumerate(channels):
        chans.append(Channel.Channel(channel, counter, client, grid))

    while True:
        for chan in chans:
            chan.run()
            time.sleep(1)

        for event in pygame.event.get():
            if (event.type == pygame.KEYUP and event.key == pygame.K_c
                    and event.mod & pygame.KMOD_CTRL):
                pygame.quit()
                sys.exit()
Ejemplo n.º 14
0
def get_section_channels(modeType):
    channelUrl = VVVVID_BASE_URL + getChannelsPath(modeType)
    response = getJsonDataFromUrl(channelUrl)
    data = json.loads(response.read().decode(
        response.info().getparam('charset') or 'utf-8'))
    channels = data['data']
    listChannels = []
    for channelData in channels:
        filter = ''
        path = ''
        listCategory = []
        listFilters = []
        listExtras = []
        if (channelData.has_key('filter')):
            for filter in channelData['filter']:
                listFilters.append(filter)
        if (channelData.has_key('category')):
            for category in channelData['category']:
                channelCategoryElem = ChannelCategory(category['id'],
                                                      category['name'])
                listCategory.append(channelCategoryElem)
        if (channelData.has_key('extras')):
            for extra in channelData['extras']:
                channelExtrasElem = ChannelExtra(extra['id'], extra['name'])
                listExtras.append(channelExtrasElem)

        channel = Channel(unicode(channelData['id']), channelData['name'],
                          listFilters, listCategory, listExtras)
        listChannels.append(channel)
    return listChannels
Ejemplo n.º 15
0
def pushMsgToSingleDevice(channel_id, msg, opts):

    c = Channel()
    try:
        ret = c.pushMsgToSingleDevice(channel_id, msg, opts)
    except ChannelException as e:
        print e.getLastErrorMsg()
Ejemplo n.º 16
0
    def join(self, chatMessage, client):
        isInSameRoom = False

        if len(chatMessage.split()) >= 2:
            channelName = chatMessage.split()[1]

            if client.get_clientName() in self.channels_client_map:
                if channelName in self.channels_client_map[
                        client.client.get_clientName()]:
                    # User already on that channel
                    client.send_message("\n> You are already in channel: " +
                                        channelName)
                    isInSameRoom = True
                elif not channelName in self.channels_client_map[
                        client.client.get_clientName(
                        )] and channelName in self.channels:
                    self.channels[channelName].clients[
                        client.get_clientName()] = client
                    self.channels_client_map[client.get_clientName()].append(
                        channelName)

            if not isInSameRoom:
                if not channelName in self.channels:
                    newChannel = Channel.Channel(channelName)
                    self.channels[channelName] = newChannel
                self.channels[channelName].clients[
                    client.get_clientName()] = client
                self.channels[channelName].welcome_client(
                    client.get_clientName())
                self.channels_client_map[client.get_clientName()].append(
                    channelName)
        else:
            self.help(client.get_clientSocket())
Ejemplo n.º 17
0
def pushMsgToAll(msg, opts):

    c = Channel()
    try:
        ret = c.pushMsgToAll(msg, opts)
    except ChannelException as e:
        print e.getLastErrorMsg()
Ejemplo n.º 18
0
 def concatenateWindows(self):
     if len(self.windows) == 0:
         return self
     self.SortWindows()
     channels = []
     for ch in self.channels:
         channels.append(Channel(ch.label, []))
     if len(self.windows) == 1:
         for i in range(len(channels)):
             reads = self.windows[0].readings[i]
             channels[i].readings.extend(reads)
     else:
         for w in range(len(self.windows)):
             for i in range(len(channels)):
                 reads = self.windows[w].readings[i]
                 if w < len(self.windows) - 1:
                     start, end = self.windows[w].GetSE()
                     s, e = self.windows[w+1].GetSE()
                     if start <= s <= end:
                         # there's overlapping
                         reads = self.windows[w].GetReadsUpTo(s)
                 channels[i].readings.extend(reads)
     concatenated = copy(self)
     concatenated.channels = channels
     concatenated.duration = len(channels[0].readings) / self.frequency
     return concatenated
Ejemplo n.º 19
0
def test_pushMessage_to_tag():
    c = Channel(apiKey, secretKey)
    push_type = 2
    optional = dict()
    optional[Channel.TAG_NAME] = tagname
    optional[Channel.MESSAGE_TYPE] = 1
    #	print 'hi:::::', push_type, message, message_key, optional
    ret = c.pushMessage(push_type, message, message_key, optional)
Ejemplo n.º 20
0
def test_pushMessage_to_tag():
    c = Channel(apiKey, secretKey)
    push_type = 2
    tag_name = 'push'
    optional = dict()
    optional[Channel.TAG_NAME] = tag_name
    ret = c.pushMessage(push_type, message, message_key, optional)
    print ret
Ejemplo n.º 21
0
    def add_channel(self, channelName):
        targetChnl = Channel(channelName)
        self.channels[channelName] = targetChnl

        #send update
        for client in self.clients.values():
            client.send("/channel add {0}".format(targetChnl.name))

        return targetChnl
Ejemplo n.º 22
0
def test_queryBindList():

    c = Channel(apiKey, secretKey)

    #optional = dict()

    #optional[Channel.CHANNEL_ID] =  channel_id

    c.queryBindList()
Ejemplo n.º 23
0
    def join(self, user, chatMessage):
        print("Join executed")
        if len(chatMessage.split()) >= 2:
            channelName = chatMessage.split()[1]


            try:
                # detect if user is in the channel mentioned
                if channelName in self.users_channels_map2[user.username]:
                    print('inside')
                    # detect if user is currently in that channel
                    if self.users_channels_map[user.username] == channelName:
                        user.socket.sendall("\n> You are already in channel: {0}".format(channelName).encode('utf8'))
                    else:  # switch to channel the user is already in
                        # switch to channel
                        print('inside2')
                        self.users_channels_map[user.username] = channelName
                        self.channels[channelName].welcome_user(user.username)
                elif channelName not in self.users_channels_map2[user.username]:
                    print("not inside")
                    if not channelName in self.channels:
                        newChannel = Channel.Channel(channelName)
                        self.channels[channelName] = newChannel

                    self.channels[channelName].users.append(user)
                    self.channels[channelName].welcome_user(user.username)
                    self.users_channels_map[user.username] = channelName
                    self.users_channels_map2[user.username].append(channelName)
                    self.channels[channelName].update_channels(user, self.users_channels_map2[user.username])
            except:
                print('inside except')
                # if the user is not in any channel, do the next
                # if the channel does not exist, create a new one
                if not channelName in self.channels:
                    newChannel = Channel.Channel(channelName)
                    self.channels[channelName] = newChannel

                # append the user object in the channel object
                self.channels[channelName].users.append(user)
                # change GUI ??###
                self.channels[channelName].welcome_user(user.username)
                self.users_channels_map[user.username] = channelName
                self.users_channels_map2[user.username] = [channelName]
                self.channels[channelName].update_channels(user, self.users_channels_map2[user.username])
Ejemplo n.º 24
0
 def send_request(self):
     channel = Channel(self.tm._monitor)
     self.set_channel(channel)
     channel.socket = None
     channel.setup_connection(self.request.get_host(),
                              self.request.get_port(),
                              self.request.get_type())
     channel.send_request(self.request)
     self.send_time = uptime.secs()
     return
Ejemplo n.º 25
0
def test_pushMessage_to_user():
    c = Channel(apiKey, secretKey)
    push_type = 1
    optional = dict()
    optional[Channel.USER_ID] = user_id
    optional[Channel.CHANNEL_ID] = channel_id
    #推送通知类型
    optional[Channel.MESSAGE_TYPE] = 1
    ret = c.pushMessage(push_type, message, message_key, optional)
    print ret
Ejemplo n.º 26
0
	def handler_client_create_proc(self, response):
		proc_id, uses_channels, ch_stdin, ch_stdout, ch_stderr = struct.unpack("!IBIII", response)

		uses_channels = bool(uses_channels) # convert bool

		if uses_channels:
			P4wnP1.print_debug("Process created channels, PID: {0}, CH_STDIN: {1}, CH_STDOUT: {2}, CH_STDERR: {3}".format(proc_id, ch_stdin, ch_stdout, ch_stderr))
			
			# we keep track of the process channels in client state, thus we create and add channels

			# create STDIN channel
			ch_stdin = Channel(ch_stdin, Channel.TYPE_OUT, Channel.ENCODING_UTF8) # from our perspective, this is an OUT channel (IN on client)
			# create STDOUT channel
			ch_stdout = Channel(ch_stdout, Channel.TYPE_IN, Channel.ENCODING_UTF8) # from our perspective, this is an IN channel (OUT on client)
			# create STDERR channel
			ch_stderr = Channel(ch_stderr, Channel.TYPE_IN, Channel.ENCODING_UTF8) # from our perspective, this is an IN channel (OUT on client)

			self.client.addChannel(ch_stdin)
			self.client.addChannel(ch_stdout)
			self.client.addChannel(ch_stderr)

			proc = ClientProcess(proc_id, ch_stdin, ch_stdout, ch_stderr)

			self.client.addProc(proc)
			
			
			#self.client.callMethod("core_inform_channel_added", struct.pack("!I", ch_stdin.id), self.handler_core_inform_channel_added, waitForResult = False)
			#self.client.callMethod("core_inform_channel_added", struct.pack("!I", ch_stdout.id), self.handler_core_inform_channel_added, waitForResult = False)
			#self.client.callMethod("core_inform_channel_added", struct.pack("!I", ch_stderr.id), self.handler_core_inform_channel_added, waitForResult = False)
			
			self.client_call_inform_channel_added(ch_stdin)
			self.client_call_inform_channel_added(ch_stderr)
			self.client_call_inform_channel_added(ch_stdout)
		
			print "Process with ID {0} created".format(proc_id)
			return proc
		else:
			print "Process created without channels, PID: {0}".format(proc_id)
Ejemplo n.º 27
0
    def __init__(self, team_id, token=config.BOT_API_KEY, post=True):
        super(BrolyBot, self).__init__()
        self.team_id = team_id
        self.headers = {
            "Authorization": "Bearer {token:s}".format(token=token)
        }
        self.post = post

        self.channel = Channel.Channel(self.team_id)
        channels = self.channel.get_list()
        for c in channels:
            if c[1] == "town-square":
                self.report_channel_id = c[0]
            if c[1] == "off-topic":
                self.social_channel_id = c[0]
Ejemplo n.º 28
0
    def setChannel(self, *args):
        args_len = len(args)
        if (args_len == 1):
            BER = 0.0
            pDelay = 0
        elif (args_len == 2):
            BER = args[1]
            pDelay = 0
        elif (args_len == 3):
            BER = args[1]
            pDelay = args[2]
        else:
            print "Unknown condition"

        channelNumber = args[0]

        ch = self._channels.get(channelNumber)
        if ch is None:
            ch = Channel(channelNumber, BER, pDelay)
            self._channels[channelNumber] = ch
        else:
            ch.setBER(BER)
Ejemplo n.º 29
0
 def applyFilter(self, event):
     self.GetParent().setStatus("Filtrando...", 1)
     eegs = self.eegs
     flag = False
     new = []
     tmp = None
     if len(eegs) > 0:
         tmp = deepcopy(eegs[0])
         tmp.clear()
     for eeg in eegs:
         # applying for each band
         bands = self.GetSelected()
         self.pbutton.actions = bands
         if len(bands) > 0:
             flag = True
         for band in bands:
             channels = eeg.channels
             neweeg = eeg_copy(eeg, tmp)
             neweeg.channels = []
             for ch in channels:
                 fourier = np.fft.rfft(ch.readings, len(ch.readings))
                 for i in range(len(fourier)):
                     if i < band.lowFrequency or i > band.hiFrequency:
                         fourier[i] = 0.0
                 # adding new filtered channel
                 filtered = np.fft.irfft(fourier)
                 fl = Channel(ch.label, filtered)
                 neweeg.channels.append(fl)
             # adding band limits to name
             neweeg.name += "~" + str(band.lowFrequency) + "~" + str(band.hiFrequency)
             new.append(neweeg)
     self.eegs.extend(new)
     self.pbutton.eegs = self.eegs
     self.GetParent().ForwardChanges(self.pbutton)
     self.GetParent().setStatus("", 0)
     if flag:
         self.exportButton.Enable()
Ejemplo n.º 30
0
        # coded1,2 = string of 7 bits
        coded1 = Hamming.hamming7_4(halfCodedWord1)
        coded2 = Hamming.hamming7_4(halfCodedWord2)

        # codedAudio1,2 = list of strings (7bits long)
        codedAudio1.append(coded1)
        codedAudio2.append(coded2)

    # Q11
    # get the audio values coded on 8 bits through the channel
    # with a bit error probability of 'errorRate' percent
    errorRate = 1

    # reminder :audioCodedValue : list of 8 bits strings
    channel = Channel.Channel(audioCodedValue, errorRate)
    # print("audioCodedValue : ")
    # print(audioCodedValue)
    # print("audioCodedValue uncorrupted message : ")
    # print(channel.getMessage())
    # print("audioCodedValue corrupted message :")
    # print(channel.getCorruptedMessage())

    corruptedMsg = channel.getCorruptedMessage()

    # translation of the corrupted msg from bits to integers
    for i in range(len(corruptedMsg)):
        corruptedMsg[i] = int(corruptedMsg[i], 2)

    # plot of the corrupted msg
    plt.plot(corruptedMsg[0:33100])