def consume_list(self, data): if type(data) is not list: self.data = [ExceptionToken()] self.has_data = True return ActionResult() if not data: # Empty list => no output return ActionResult() try: self.data = copy(data) self.has_data = True except: pass return ActionResult()
def get_humidity(self, input): result = {} result['value'] = self.sensor.get_humidity() result['value'] = int(result['value']) result['unit'] = "%" return ActionResult(production=(result, ))
def check_card(self): _log.info("check_card") self.timeout_timer.ack() if self.rfid.read_value(self.active_type) is None: self.timeout_timer.cancel() self._state = "card gone" return ActionResult()
def avg(self, temperature1, temperature2, temperature3): if (temperature1 != 'ignore' and temperature2 != 'ignore' and temperature3 != 'ignore'): self.result = (temperature1 + temperature2 + temperature3) / 3 else: self.result = 'ignore' return ActionResult(production=([self.result, 'validate'], ))
def open_file(self, filename): try: self.file = self.calvinsys.io.file.open(filename, "r") except: self.file = None self.file_not_found = True return ActionResult()
def close(self): for handle, connection in self.connections.items(): if connection.connection_lost: connection.connection_lost = False del self.connections[handle] break return ActionResult()
def start(self): try: self.server = self['server'].start(self.host, self.port, self.mode, self.delimiter, self.max_length) except Exception as e: _log.exception(e) return ActionResult()
def open_file(self, filename): try: self.file = self['file'].open(filename, "r") except: self.file = None self.file_not_found = True return ActionResult()
def exception_handler(self, action, args, context): # FIXME: Check that action is append and args is EOSToken # if not, call super's exception_handler # Similarly, if self.text is not None => raise self.text = self.delim.join(self.lines) self.lines = [] return ActionResult()
def add_entry(self, key, value): if isinstance(key, basestring): self._dict[key] = value self.done = bool(len(self._dict) == self.n) else: self._bail() return ActionResult()
def switch_state(self, state): data = self.databits data |= (state << 4) bits = [] # Start bits bits.append((self.startBit[0]["state"], self.startBit[0]["time"])) bits.append((self.startBit[1]["state"], self.startBit[1]["time"])) # Data bits for bit in range(0, 32): if data & 0x80000000: bits.append((self.oneBit[0]["state"], self.oneBit[0]["time"])) bits.append((self.oneBit[1]["state"], self.oneBit[1]["time"])) bits.append( (self.zeroBit[0]["state"], self.zeroBit[0]["time"])) bits.append( (self.zeroBit[1]["state"], self.zeroBit[1]["time"])) else: bits.append( (self.zeroBit[0]["state"], self.zeroBit[0]["time"])) bits.append( (self.zeroBit[1]["state"], self.zeroBit[1]["time"])) bits.append((self.oneBit[0]["state"], self.oneBit[0]["time"])) bits.append((self.oneBit[1]["state"], self.oneBit[1]["time"])) data <<= 1 # Stop bit bits.append((self.stopBit[0]["state"], self.stopBit[0]["time"])) bits.append((self.stopBit[1]["state"], self.stopBit[1]["time"])) # Output data self.gpio.shift_out(bits, self.repeat) return ActionResult()
def move(self, trigger): if self.pos == 2.5: # right self.pos = 12.5 else: # left self.pos = 2.5 return ActionResult(production=(self.pos, ))
def exception_handler(self, action, args, context): try: e = args[context['exceptions']['token'][0]] except: e = ExceptionToken() self.status = e self.token = EOSToken() return ActionResult()
def tree(self, temperature): if (temperature[1] == 'train'): self.train(temperature[0]) self.mode = 'train' else: self.validate(temperature[0]) return ActionResult(production=('', ))
def produce_list(self): if isinstance(self._list, list): res = (self.pre_list if self.pre_list else []) + self._list +(self.post_list if self.post_list else []) else: res = self._list self.done = False self._list = [] return ActionResult(production=(res, ))
def start(self): try: self.server = self.calvinsys.network.tcp_server.start( self.host, self.port, self.mode, self.delimiter, self.max_length) except Exception as e: _log.exception(e) return ActionResult()
def ok(self, status, body): header = self.HEADER_TEMPLATE.substitute(length=len(body)) response = self.RESPONSE_TEMPLATE.substitute(header=header, status=status, reason=self.STATUSMAP.get( status, "Unknown"), body=body) return ActionResult(production=(response, ))
def step_no_periodic(self): self.timer.ack() if self.count == 2: # now continue with periodic timer events self.timer = self['timer'].repeat(self.sleep) else: self.timer = self['timer'].once(self.sleep) self.count += 1 return ActionResult(production=(self.count, ))
def step_no_periodic(self): self.timer.ack() if self.count == 2: # now continue with periodic timer events self.timer = self.calvinsys.events.timer.repeat(self.sleep) else: self.timer = self.calvinsys.events.timer.once(self.sleep) self.count += 1 return ActionResult(tokens_produced=1, production=(self.count, ))
def new_request(self, trigger): url = "http://" + self.ip + "/axis-cgi/jpg/image.cgi" auth = "Basic " + self['base64'].b64encode( "%s:%s" % (self.credentials['username'], self.credentials['password'])) header = {'Authorization': auth} params = {} self.request = self['http'].get(url, params, header) return ActionResult()
def next_operation(self, operation): obj, var = operation['variable'].split(".") if operation.get('value', None) is not None: val = operation['value'] self['opc'].set_value(obj, var, val) else : val = self['opc'].get_value(obj, var) operation["value"] = val return ActionResult(production=(operation,))
def write_card(self, incoming): _log.info("write_card") data = incoming["data"] if not self.rfid.write_value(self.active_type, data): _log.info("could not write") self._state = "card gone" else: _log.info("write successful") return ActionResult()
def avg(self, temperature1, temperature2, temperature3): if (temperature1[0] != 'ignore' and temperature2[0] != 'ignore' and temperature3[0] != 'ignore'): self.result = (temperature1[0] + temperature2[0] + temperature3[0]) / 3 self.type = temperature3[1] else: self.result = 'ignore' self.type = 'train' return ActionResult(production=([self.result, self.type], ))
def card_gone(self): _log.info("card_gone") result = { "status": False, "data": None, "cardno": self.active_uid_string, "timestamp": str(now()) } self._state = "reset" return ActionResult(production=(result, ))
def trigger(self): self.low += 0.1 self.high += 0.1 if(self.high > 80): self.high = 10 self.high = 15 self.type = 'validate' result = self.rand_generator(self.low, self.high) self.started = False return ActionResult(production=([result, self.type],))
def fire_actors(self): total = ActionResult(did_fire=False) with traceback_context(): for actor in self.actor_mgr.enabled_actors(): try: action_result = actor.fire() total.merge(action_result) except: _log.error('\n'.join(format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))) self.idle = not total.did_fire
def get_value(self, data, key): keylist = key if type(key) is list else [key] try: res = data for key in keylist: if self._type_mismatch(res, key): raise Exception() res = res[key] except Exception as e: res = ExceptionToken() return ActionResult(production=(res, ))
def action(self, d): res = {} try: for fmtkey in self.fmtkeys: res[fmtkey] = value_for_key(d, fmtkey) except Exception: res = {} retval = self.fmt for key, value in res.iteritems(): retval = retval.replace('{' + key + '}', str(value)) return ActionResult(production=(retval, ))
def receive_control(self, token): if token[0] == "connect": if not self.cc: # TODO: validate these self.address = token[1]['addr'] self.port = token[0]['port'] self.connect() if token[0] == "disconnect": if self.cc: self.cc.disconnect() self.cc = None return ActionResult(production=())
def show(self, data): textcolor = data.get("textcolor", None) bgcolor = data.get("bgcolor", None) if not bgcolor: bgcolor = (0, 0, 0) if not textcolor: ave = 255 - sum(bgcolor) / 3 textcolor = (ave, ave, ave) text = data.get("text", "Text goes here") self.display.show(text, textcolor, bgcolor) print("Displaying %r using %r and %r" % (text, textcolor, bgcolor)) return ActionResult()