示例#1
0
 def _v6ToInternet_notif(self,sender,signal,data):
     '''
     Called when receiving data from the EventBus.
     
     This function forwards the data to the the TUN interface.
     Read from tun interface and forward to 6lowPAN
     '''
     
     # abort if not tun interface
     if not self.tunIf:
         return
     
     # add tun header
     data  = VIRTUALTUNID + data
     
     # convert data to string
     data  = ''.join([chr(b) for b in data])
     
     try:
         # write over tuntap interface
         os.write(self.tunIf, data)
         if log.isEnabledFor(logging.DEBUG):
             log.debug("data dispatched to tun correctly {0}, {1}".format(signal,sender))
     except Exception as err:
         errMsg=u.formatCriticalMessage(err)
         print errMsg
         log.critical(errMsg)
示例#2
0
    def _v6ToInternet_notif(self, sender, signal, data):
        '''
        Called when receiving data from the EventBus.
        
        This function forwards the data to the the TUN interface.
        Read from tun interface and forward to 6lowPAN
        '''

        # abort if not tun interface
        if not self.tunIf:
            return

        # add tun header
        data = VIRTUALTUNID + data

        # convert data to string
        data = ''.join([chr(b) for b in data])

        try:
            # write over tuntap interface
            os.write(self.tunIf, data)
            if log.isEnabledFor(logging.DEBUG):
                log.debug("data dispatched to tun correctly {0}, {1}".format(
                    signal, sender))
        except Exception as err:
            errMsg = u.formatCriticalMessage(err)
            print errMsg
            log.critical(errMsg)
示例#3
0
 def _cycleDIO(self):
     """
     Send DIO and schedule next send.
     """
     try:
         self._sendDIO()
     except Exception as err:
         errMsg = u.formatCriticalMessage(err)
         print errMsg
         log.critical(errMsg)
     finally:
         # Must ensure next send is scheduled
         self._scheduleSendDIO(self.DIO_PERIOD)
示例#4
0
 def _cycleDIO(self):
     '''
     Send DIO and schedule next send.
     '''
     try:
         self._sendDIO()
     except Exception as err:
         errMsg = u.formatCriticalMessage(err)
         print errMsg
         log.critical(errMsg)
     finally:
         # Must ensure next send is scheduled
         self._scheduleSendDIO(self.DIO_PERIOD)
示例#5
0
    def cmd_setCompare(self,compareValue):
        '''
        emulates
        void sctimer_setCompare(PORT_TIMER_WIDTH compareValue)
        '''
        
        try:
            # enable interrupt
            self.cmd_enable()

            # log the activity
            if self.log.isEnabledFor(logging.DEBUG):
                self.log.debug('cmd_setCompare compareValue=' + str(compareValue))

            # get current counter value
            counterVal = self.hwCrystal.getTicksSince(self.timeLastReset)

            # how many ticks until compare event
            if counterVal - compareValue > 0 and counterVal - compareValue < self.LOOP_THRESHOLD:
                # we're already too late, schedule compare event right now
                ticksBeforeEvent = 0
            else:
                ticksBeforeEvent = compareValue - counterVal
                
            # print "compareValue {0} counterVal {1}  self.timeLastReset {2}".format(compareValue,counterVal, self.timeLastReset)

            # calculate time at overflow event
            compareTime = self.hwCrystal.getTimeIn(ticksBeforeEvent)

            # schedule compare event
            self.timeline.scheduleEvent(compareTime,
                                        self.motehandler.getId(),
                                        self.intr_compare,
                                        self.INTR_COMPARE)

            # the compare is now scheduled
            self.compareArmed = True
        
        except Exception as err:
            errMsg=u.formatCriticalMessage(err)
            print errMsg
            self.log.critical(errMsg)
示例#6
0
 def _v6ToInternet_notif(self,sender,signal,data):
     '''
     Called when receiving data from the EventBus.
     
     This function forwards the data to the the TUN interface.
     '''
     
     # convert data to string
     data  = ''.join([chr(b) for b in data])
     # write over tuntap interface
     try:
         win32file.WriteFile(self.tunIf, data, self.overlappedTx)
         win32event.WaitForSingleObject(self.overlappedTx.hEvent, win32event.INFINITE)
         self.overlappedTx.Offset = self.overlappedTx.Offset + len(data)
         if log.isEnabledFor(logging.DEBUG):
             log.debug("data dispatched to tun correctly {0}, {1}".format(signal,sender))
     except Exception as err:
         errMsg=u.formatCriticalMessage(err)
         print errMsg
         log.critical(errMsg)
示例#7
0
 def _v6ToInternet_notif(self,sender,signal,data):
     '''
     Called when receiving data from the EventBus.
     
     This function forwards the data to the the TUN interface.
     '''
     
     # convert data to string
     data  = ''.join([chr(b) for b in data])
     # write over tuntap interface
     try:
         win32file.WriteFile(self.tunIf, data, self.overlappedTx)
         win32event.WaitForSingleObject(self.overlappedTx.hEvent, win32event.INFINITE)
         self.overlappedTx.Offset = self.overlappedTx.Offset + len(data)
         if log.isEnabledFor(logging.DEBUG):
             log.debug("data dispatched to tun correctly {0}, {1}".format(signal,sender))
     except Exception as err:
         errMsg=u.formatCriticalMessage(err)
         print errMsg
         log.critical(errMsg)
示例#8
0
 def cmd_scheduleIn(self,delayTicks):
     '''
     emulates
     void bsp_timer_scheduleIn(PORT_TIMER_WIDTH delayTicks)
     '''
     
     try:
     
         # log the activity
         if self.log.isEnabledFor(logging.DEBUG):
             self.log.debug('cmd_scheduleIn delayTicks='+str(delayTicks))
         
         # get number of ticks since last compare
         ticksSinceCompare         = self.hwCrystal.getTicksSince(self.timeLastCompare)
         
         # how many ticks until compare event
         if ticksSinceCompare>delayTicks:
             # we're already too late, schedule compare event right now
             
             ticksBeforeEvent      = 0
         else:
             ticksBeforeEvent      = delayTicks-ticksSinceCompare
         
         # calculate time at overflow event (in 'period' ticks)
         compareTime               = self.hwCrystal.getTimeIn(ticksBeforeEvent)
         
         # schedule compare event
         self.timeline.scheduleEvent(
             atTime = compareTime,
             moteId = self.motehandler.getId(),
             cb     = self.intr_compare,
             desc   = self.INTR_COMPARE,
         )
         
         # the compare is now scheduled
         self.compareArmed         = True
     
     except Exception as err:
         errMsg=u.formatCriticalMessage(err)
         print errMsg
         log.critical(errMsg)