def __init__(self,total=0,total_dtc=0):
        log.info("Starting geigercounter")
        threading.Thread.__init__(self)
        self.daemon = True
        self.socket = None
        self.totalcount=total
        self.totalcount_dtc=total_dtc

        if cfg.getboolean('entropy','enable'):
            self.entropygenerator = EntropyGenerator(cfg.get('entropy','filename'))
        else:
            self.entropygenerator = None

        self.reset()
        self.start()
Beispiel #2
0
    def __init__(self,total=0,total_dtc=0):
        log.info("Starting geigercounter")
        threading.Thread.__init__(self)
        self.daemon = True
        self.socket = None
        self.totalcount=total
        self.totalcount_dtc=total_dtc

        if cfg.getboolean('entropy','enable'):
            self.entropygenerator = EntropyGenerator(cfg.get('entropy','filename'))
        else:
            self.entropygenerator = None


        self.reset()
        self.start()
class Geigercounter (threading.Thread):
    def __init__(self,total=0,total_dtc=0):
        log.info("Starting geigercounter")
        threading.Thread.__init__(self)
        self.daemon = True
        self.socket = None
        self.totalcount=total
        self.totalcount_dtc=total_dtc

        if cfg.getboolean('entropy','enable'):
            self.entropygenerator = EntropyGenerator(cfg.get('entropy','filename'))
        else:
            self.entropygenerator = None

        self.reset()
        self.start()

    def reset(self):
        if gpio_available:
            i2c_addr = 0x19
            bus = smbus.SMBus(1)
            bus.write_byte(i2c_addr, 0x00)
        self.count=0
        self.cps=0
        self.cpm=0
        self.cps_dtc=0
        self.cpm_dtc=0
        self.edr=0

    def tick(self, pin=None):
        self.count += 1
        self.totalcount += 1
        self.totalcount_dtc += 1
        if self.entropygenerator:
            self.entropygenerator.tick()

    def run(self):
        if gpio_available:
            GPIO.setmode(GPIO.BCM)
            gpio_port = cfg.getint('geigercounter','gpio_port')
            GPIO.setup(gpio_port,GPIO.IN)
            GPIO.add_event_detect(gpio_port,GPIO.FALLING)
            GPIO.add_event_callback(gpio_port,self.tick)

            # I2C config for HV output
            i2c_addr = 0x19
            bus = smbus.SMBus(1) # I2C1 port
            bus.write_byte(i2c_addr, 0x71)
        else:
            TickSimulator(self).start()

        cpm_fifo = deque([],60)
        cpm_dtc_fifo = deque([],60)
        while True:
            time.sleep(1)

            # Statistical correction of tube dead-time
            if gpio_available:
                deadtime = cfg.getfloat('geigercounter','tube_dead_time')
                count_dtc = int(self.count/(1-(self.count*deadtime)))
            else:
                count_dtc = self.count
                
            cpm_fifo.appendleft(self.count)
            cpm_dtc_fifo.appendleft(count_dtc)

            self.cpm = int(sum(cpm_fifo)*60.0/len(cpm_fifo))
            self.cpm_dtc = int(sum(cpm_dtc_fifo)*60.0/len(cpm_dtc_fifo))
            self.cps = self.count
            self.cps_dtc = count_dtc
            
            ratefactor = cfg.getfloat('geigercounter','tube_rate_factor')
            self.edr = round(self.cpm_dtc * ratefactor,2)
            
            self.totalcount_dtc += (count_dtc - self.count)
            
            self.count = 0
            
            log.debug(self.get_state())

    def get_state(self):
        msg = {
                "type": "geigerjson",
                "node_uuid": cfg.get('node','uuid'),
                "timestamp": int(datetime.datetime.now().strftime("%s")),
                "geostamp": {
                    "lat": cfg.getfloat('node','lat'),
                    "lon": cfg.getfloat('node','lon'),
                    "alt": cfg.getfloat('node','alt')
                },
                "parameters": {
                    "tube_id": cfg.get('geigercounter','tube_id'),
                    "dead_time": cfg.getfloat('geigercounter','tube_dead_time'),
                    "tube_factor": cfg.getfloat('geigercounter','tube_rate_factor'),
                    "opmode": cfg.get('node', 'opmode'),
                    "window": cfg.get('geigercounter', 'window')
                },
                "data": {
                    "source": cfg.get('geigercounter', 'source') if gpio_available else "sim",
                    "cps": self.cps,
                    "cps_dtc": self.cps_dtc,
                    "cpm": self.cpm,
                    "cpm_dtc": self.cpm_dtc,
                    "totalcount": self.totalcount,
                    "totalcount_dtc": self.totalcount_dtc,
                    "edr": self.edr
                },
                "annotation": ""

            }
        return msg
Beispiel #4
0
class Geigercounter (threading.Thread):
    def __init__(self,total=0,total_dtc=0):
        log.info("Starting geigercounter")
        threading.Thread.__init__(self)
        self.daemon = True
        self.socket = None
        self.totalcount=total
        self.totalcount_dtc=total_dtc

        if cfg.getboolean('entropy','enable'):
            self.entropygenerator = EntropyGenerator(cfg.get('entropy','filename'))
        else:
            self.entropygenerator = None


        self.reset()
        self.start()

    def reset(self):
        self.count=0
        self.cps=0
        self.cpm=0
        self.cps_dtc=0
        self.cpm_dtc=0
        self.edr=0

    def tick(self, pin=None):
        self.count += 1
        self.totalcount += 1
        self.totalcount_dtc += 1
        if self.entropygenerator:
            self.entropygenerator.tick()

    def run(self):
        if gpio_available:
            GPIO.setmode(GPIO.BCM)
            gpio_port = cfg.getint('geigercounter','gpio_port')
            GPIO.setup(gpio_port,GPIO.IN)
            GPIO.add_event_detect(gpio_port,GPIO.FALLING)
            GPIO.add_event_callback(gpio_port,self.tick)
        else:
            TickSimulator(self).start()

        cpm_fifo = deque([],60)
        cpm_dtc_fifo = deque([],60)
        while True:
            time.sleep(1)

            # Statistical correction of tube dead-time
            if gpio_available:
                deadtime = cfg.getfloat('geigercounter','tube_dead_time')
                count_dtc = int(self.count/(1-(self.count*deadtime)))
            else:
                count_dtc = self.count
                
            cpm_fifo.appendleft(self.count)
            cpm_dtc_fifo.appendleft(count_dtc)

            self.cpm = int(sum(cpm_fifo)*60.0/len(cpm_fifo))
            self.cpm_dtc = int(sum(cpm_dtc_fifo)*60.0/len(cpm_dtc_fifo))
            self.cps = self.count
            self.cps_dtc = count_dtc
            
            ratefactor = cfg.getfloat('geigercounter','tube_rate_factor')
            self.edr = round(self.cpm_dtc * ratefactor,2)
            
            self.totalcount_dtc += (count_dtc - self.count)
            
            self.count = 0
            
            log.debug(self.get_state())

    def get_state(self):
        msg = {
                "type": "geigerjson",
                "node_uuid": cfg.get('node','uuid'),
                "timestamp": int(datetime.datetime.now().strftime("%s")),
                "geostamp": {
                    "lat": cfg.getfloat('node','lat'),
                    "lon": cfg.getfloat('node','lon'),
                    "alt": cfg.getfloat('node','alt')
                },
                "parameters": {
                    "tube_id": cfg.get('geigercounter','tube_id'),
                    "dead_time": cfg.getfloat('geigercounter','tube_dead_time'),
                    "tube_factor": cfg.getfloat('geigercounter','tube_rate_factor'),
                    "opmode": cfg.get('node', 'opmode'),
                    "window": cfg.get('geigercounter', 'window')
                },
                "data": {
                    "source": cfg.get('geigercounter', 'source') if gpio_available else "sim",
                    "cps": self.cps,
                    "cps_dtc": self.cps_dtc,
                    "cpm": self.cpm,
                    "cpm_dtc": self.cpm_dtc,
                    "totalcount": self.totalcount,
                    "totalcount_dtc": self.totalcount_dtc,
                    "edr": self.edr
                },
                "annotation": ""

            }
        return msg