def doTask(): cmd, trg = task.pop(0) if cmd == 'recalc': devices.update(trg) else: notify.error('task.doTask: Unknown command ' + str(cmd)) notify.info('task.doTask: ' + str(len(task)) + ' tasks left')
def setV(wire, value): notify.debug('wire.setV setting ' + str(wire) + ' to ' + str(value)) if wire in bus.keys(): if type(value) == type([]): V, S, out = bus[wire] if len(value) > S: notify.warn('wire.setV: ' + str(len(value)) + ' bit value ' + str(value) + 'is to big and it will be truncaded to LSB [' + str(S) + ' pin bus ' + str(wire) + ']') value = value[-S:] if value != V or GLOB.force_same_v_update: #extend MSB to value svalue = [0] * max(S - len(value), 0) svalue.extend(value) #write out bus[wire] = svalue, S, out #add task for updating connected devices for dev in out: task.addTask('recalc', dev) else: notify.info( 'wire.setV: New value is the same, no update. To ommit, set "force_same_v_update = True"' ) else: notify.error('wire.setV: value [' + str(value) + ' ' + str(type(value)) + '] is not a list [bus ' + str(wire) + ']') else: notify.error('wire.setV: Wrong wire name ' + str(wire))
def setBinary(wire, value): if wire in bus.keys(): if type(value) == type(0): busvalue = [] for bn in bin(value)[2:]: if bn == '1': busvalue.append(GLOB.digital_high) else: busvalue.append(GLOB.digital_low) setV(wire, busvalue) #if type(value) == type([]): # setV(wire, value) elif type(value) == type(''): busvalue = [] for bn in value: if bn == '1': busvalue.append(GLOB.digital_high) else: busvalue.append(GLOB.digital_low) else: notify.error('wire.setBinary: value [' + str(value) + ' ' + str(type(value)) + '] is not an integer or a string [bus ' + str(wire) + ']') else: notify.error('wire.setBinary: Wrong wire name' + str(wire))
def readV(wire): if wire in bus.keys(): out = [] v,_,_ = bus[wire] out.extend(v) return out else: notify.error('wire.readV: Wrong wire name '+str(wire))
def readV(wire): if wire in bus.keys(): out = [] v, _, _ = bus[wire] out.extend(v) return out else: notify.error('wire.readV: Wrong wire name ' + str(wire))
def connect(wire, device): if wire in bus.keys(): V, S, out = bus[wire] out.add(device) bus[wire] = V, S, out task.addTask('recalc', device) else: notify.error('wire.connect: Wrong wire name ' + str(wire))
def connect(wire, device): if wire in bus.keys(): V,S,out = bus[wire] out.add(device) bus[wire] = V,S,out task.addTask('recalc', device) else: notify.error('wire.connect: Wrong wire name '+str(wire))
def addDevice(dname, dtype, inset, outset): clear = True typein, typeout = logic[dtype]['data'] if len(inset) != typein: notify.error('devices.addDevice: Asked for ' + str(len(inset)) + ' inputs in inset, when ' + dtype + ' has only ' + str(typein)) clear = False if len(outset) != typeout: notify.error('devices.addDevice: Asked for ' + str(len(outset)) + ' inputs in outset, when ' + dtype + ' has only ' + str(typeout)) clear = False if dname in devices.keys(): notify.error('devices.addDevice: Device ' + dtype + ' already exists') clear = False if clear: devices[dname] = (dtype, inset, outset) notify.info('Device ' + dname + ' of type ' + dtype + ' added') if GLOB.autoconnect: #connect mentioned input buses wires = set() for w, i in inset: wires.add(w) for w in wires: wire.connect(w, dname) else: notify.error('Can\'t add device ' + dname + ' of type ' + dtype)
def readsettings(filename, Veridis): try: tasks = open(filename) t=tasks.read().rstrip("}").split("\n") tasks.close() Aliases={} def addAlias(fromToList): Aliases[fromToList[0]] = fromToList[1] t = [dict([[(Aliases[a] if a in Aliases else a) for a in list(value.split(":"))] for value in task.split(";")]) for task in "".join([val for val in [(addAlias(line.split(" ")[1:3]) if not line.find("Alias") else line) for line in t] if not val == None]).split("}")] return t except IOError as e: error("Could not read %s, aborting." % (filename)) Veridis.running = False return False
def giveReport(wire, full=True): out = '' if wire in bus.keys(): V,S,output = bus[wire] if S==1: out += wire+' ['+str(V[0])+' V] '+str(len(output))+' device(s) listen\n' if S>1: out += wire+' '+str(S)+' lines '+str(len(output))+' device(s) listen\n' for i in range(len(V)): out += ' '+str(i)+':['+str(V[i])+']\n' if full: out += ' listeners:\n' for o in output: out += ' '+o+'\n' else: out = 'Not a wire: '+str(wire)+'\n' notify.error('wire.giveReport: Wrong wire name '+str(wire)) return out
def giveReport(wire, full=True): out = '' if wire in bus.keys(): V, S, output = bus[wire] if S == 1: out += wire + ' [' + str(V[0]) + ' V] ' + str( len(output)) + ' device(s) listen\n' if S > 1: out += wire + ' ' + str(S) + ' lines ' + str( len(output)) + ' device(s) listen\n' for i in range(len(V)): out += ' ' + str(i) + ':[' + str(V[i]) + ']\n' if full: out += ' listeners:\n' for o in output: out += ' ' + o + '\n' else: out = 'Not a wire: ' + str(wire) + '\n' notify.error('wire.giveReport: Wrong wire name ' + str(wire)) return out
def setBinary(wire, value): if wire in bus.keys(): if type(value) == type(0): busvalue = [] for bn in bin(value)[2:]: if bn=='1': busvalue.append(GLOB.digital_high) else: busvalue.append(GLOB.digital_low) setV(wire, busvalue) #if type(value) == type([]): # setV(wire, value) elif type(value) == type(''): busvalue = [] for bn in value: if bn=='1': busvalue.append(GLOB.digital_high) else: busvalue.append(GLOB.digital_low) else: notify.error('wire.setBinary: value ['+str(value)+' '+str(type(value))+'] is not an integer or a string [bus '+str(wire)+']') else: notify.error('wire.setBinary: Wrong wire name'+str(wire))
def setV(wire, value): notify.debug('wire.setV setting '+str(wire)+' to '+str(value)) if wire in bus.keys(): if type(value) == type([]): V,S,out = bus[wire] if len(value) > S: notify.warn('wire.setV: '+str(len(value))+' bit value '+str(value)+'is to big and it will be truncaded to LSB ['+str(S)+' pin bus '+str(wire)+']') value = value[-S:] if value != V or GLOB.force_same_v_update: #extend MSB to value svalue = [0]*max(S-len(value),0) svalue.extend(value) #write out bus[wire] = svalue,S,out #add task for updating connected devices for dev in out: task.addTask('recalc', dev) else: notify.info('wire.setV: New value is the same, no update. To ommit, set "force_same_v_update = True"') else: notify.error('wire.setV: value ['+str(value)+' '+str(type(value))+'] is not a list [bus '+str(wire)+']') else: notify.error('wire.setV: Wrong wire name '+str(wire))
def addDevice(dname, dtype, inset, outset): clear = True typein,typeout = logic[dtype]['data'] if len(inset)!=typein: notify.error('devices.addDevice: Asked for '+str(len(inset))+' inputs in inset, when '+dtype+' has only '+str(typein)) clear = False if len(outset)!=typeout: notify.error('devices.addDevice: Asked for '+str(len(outset))+' inputs in outset, when '+dtype+' has only '+str(typeout)) clear = False if dname in devices.keys(): notify.error('devices.addDevice: Device '+dtype+' already exists') clear = False if clear: devices[dname] = (dtype, inset, outset) notify.info('Device '+dname+' of type '+dtype+' added') if GLOB.autoconnect: #connect mentioned input buses wires = set() for w,i in inset: wires.add(w) for w in wires: wire.connect(w, dname) else: notify.error('Can\'t add device '+dname+' of type '+dtype)
Veridis.day=sorted(Veridis.day) lst = [] """ FUNCTION SUMMARY 0:00->day[0][0] -> day[1][0] -> day[2][0] etc.. lst=(lst.insert(0,(0,0)) if not(lst[0][0]==0) else lst)#Insert a 'phantom' task at the beginning so the later logic notices the 0->day[1] space, if there is no task starting at 0:00. [(items[0][0]+items[0][1], items[1][0]) for items in zip(lst, (lst[1:] if (lst[-1][0]+lst[-1][1]==24*3600) else lst.append((24*3600,0))) if not(items[0][0]+items[0][1]>=items[1][0])] """ for i in range(len(Veridis.day)+1): #+1 to account for possible 0:00->task[0] n=i-1 if n==len(Veridis.day)-1: break elif (n<0) and (not(Veridis.day[i][0]==0)): lst.append((0, Veridis.day[i][0])) elif (n<0): pass else: start =Veridis.day[n][0]+Veridis.day[n][1] lst.append((Veridis.day[n][0]+Veridis.day[n][1], Veridis.day[i][0])) notify.error(str(lst)+ "\n|\n" + str(Veridis.day)) #for slot in Veridis.settings.day: # for prioritytask in [x for x in Veridis.settings.tasks if "Priority" in x]: while Veridis.running: #Screen.refresh() #update(Screen, Veridis) react(Screen.getch(), Screen, Veridis)
elif temp <= _too_cold: msgQueue.enqueue('Too cold, how did this happen?', level="ERROR") elif temp >= _too_hot: msgQueue.enqueue('Too hot, how did this happen?', level="ERROR") else: msgQueue.enqueue('Can''t tell if it''s hot or cold', level="ERROR") msgQueue.close() _actions = _actions + 1 time.sleep(int(config.SIMULATION_DELAY)) msg = hostname + ": Simulated " + str(config.SIMULATION_ACTIONS) + " actions and added them to the queue" log.debug(msg) notify.info(msg) def getQueueType(): return os.environ['ACS_LOGGING_QUEUE_TYPE'] if __name__ == "__main__": log = Log() log.debug("Started to simulate logs") try: simulate() except: e = sys.exc_info()[0] hostname = socket.gethostname() log.error("Unable to simulate logging") notify.error(hostname + ": ACS Logging simulation failed") mailhandler.send(hostname + ": ACS Logging simulation failed", "Check logs on " + hostname + " for details")
else: msgQueue.enqueue('ERROR - Can' 't tell if it' 's hot or cold') msgQueue.close() _actions = _actions + 1 time.sleep(int(config.SIMULATION_DELAY)) msg = hostname + ": Simulated " + str( config.SIMULATION_ACTIONS) + " actions and added them to the queue" log.debug(msg) notify.info(msg) def getQueueType(): return os.environ['ACS_LOGGING_QUEUE_TYPE'] if __name__ == "__main__": log = Log() log.debug("Started to simulate logs") try: simulate() except: e = sys.exc_info()[0] hostname = socket.gethostname() log.error("Unable to simulate logging", exc_info=True) notify.error(hostname + ": ACS Logging simulation failed") mailhandler.send(hostname + ": ACS Logging simulation failed", "Check logs on " + hostname + " for details")