Beispiel #1
0
 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()
Beispiel #2
0
    def get_humidity(self, input):
        result = {}
        result['value'] = self.sensor.get_humidity()
        result['value'] = int(result['value'])
        result['unit'] = "%"

        return ActionResult(production=(result, ))
Beispiel #3
0
 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()
Beispiel #4
0
 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'], ))
Beispiel #5
0
 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()
Beispiel #6
0
 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()
Beispiel #7
0
 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()
Beispiel #8
0
 def open_file(self, filename):
     try:
         self.file = self['file'].open(filename, "r")
     except:
         self.file = None
         self.file_not_found = True
     return ActionResult()
Beispiel #9
0
 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()
Beispiel #10
0
 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()
Beispiel #11
0
    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()
Beispiel #12
0
 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, ))
Beispiel #13
0
 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()
Beispiel #14
0
    def tree(self, temperature):
        if (temperature[1] == 'train'):
            self.train(temperature[0])
            self.mode = 'train'
        else:
            self.validate(temperature[0])

        return ActionResult(production=('', ))
Beispiel #15
0
 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, ))
Beispiel #16
0
 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, ))
Beispiel #18
0
 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, ))
Beispiel #19
0
 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, ))
Beispiel #20
0
 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()
Beispiel #21
0
 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,))
Beispiel #22
0
 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()
Beispiel #23
0
 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], ))
Beispiel #24
0
 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, ))
Beispiel #25
0
 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],))
Beispiel #26
0
 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
Beispiel #27
0
 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, ))
Beispiel #28
0
    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, ))
Beispiel #29
0
 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=())
Beispiel #30
0
 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()