Beispiel #1
0
def pre_run():
    afe = atm90e26()
    afe.setup('spi')
    afe.reset()
    ser = '12345678'

    server_config = {
        'provisioning_token_path': './provisioning_token.json',
        'url_base': 'http://192.168.0.102:9090/pwrmon',
        'credentials_path': './credentials.json',
        'params_path': './device_params.json',
        'device_name': 'pipowermeter_proto_0',
        'device_type': 'atm90e26_i2c_meter',
        'device_serial': ser.encode('ascii'),
    }

    sconn = ServerConnection.ServerConnection(server_config)

    cfg = {k: base_config[k] for k in base_config}

    cfg['afe'] = afe
    cfg['sconn'] = sconn

    if False:
        synchronizeSystemClock()

    return cfg
Beispiel #2
0
def unregister_host():
    """request that this machine get removed from the automation database"""
    print "\n>> Sending request to automation server to be removed from database"
    sc = ServerConnection.ServerConnection()
    msg = sc.remove_host_request()

    if msg.code == 'ack':
        print "success"
    else:
        print "WARNING: could not remove this host from the database: " + \
                str(msg.error)
Beispiel #3
0
 def __init__(self):
     self.capture = cv.CaptureFromCAM(0)
     if DEBUG:
         cv.NamedWindow("Target", 1)
     # set camera resolution
     cv.SetCaptureProperty( self.capture, cv.CV_CAP_PROP_FRAME_WIDTH, 640 )
     cv.SetCaptureProperty( self.capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 480 )
     
     self.display_image = None
     
     # create a connection to the server
     if CONNECT_TO_SERVER:
         self.server = ServerConnection('localhost', 8887)
         self.server.send_resolution(ROI_WIDTH, ROI_HEIGHT)
Beispiel #4
0
 def start(self):
     """
     This method is called to start a client or server service. This method allow to initialize and configure a
     client or server service and create a socket connection between several client to a server.
     """
     if self.configuration['role'] == "client":
         print("")
         self.client = ClientConnection.ClientConnection(self.configuration)
         self.client.connection()
         self.client.client()
     elif self.configuration['role'] == "server":
         print("")
         self.server = ServerConnection.ServerConnection(self.configuration)
         self.server.connection()
         self.server.server()
Beispiel #5
0
def pre_run():
    kdevs = kromek.discover()
    print('Discovered %s' % kdevs)
    if len(kdevs) <= 0:
        print('No devices?')
        return

    try:
        kconn = kromek.connect(kdevs[0])
    except:
        print('Could not connect to kromek device.')
        return None

    try:
        cconn = Camera.Camera()
    except:
        print('Could not create camera instance.')
        return None

    try:
        ser = kromek.get_value(kconn, param='serial')
    except:
        return None

    server_config = {
        'provisioning_token_path': './provisioning_token.json',
        'url_base': 'https://irc-dev.lbl.gov/demo1',
        'credentials_path': './credentials.json',
        'params_path': './device_params.json',
        'device_name': fileIntoString('device_name.txt'),
        'device_type': 'kromek_d3s+picamera',
        'device_serial': ser['serial'].encode('ascii'),
    }

    sconn = ServerConnection.ServerConnection(server_config)

    cfg = {k: base_config[k] for k in base_config}
    cfg['kconn'] = kconn
    cfg['sconn'] = sconn
    cfg['cconn'] = cconn
    cconn.setParams(cfg['camera'])

    if True:
        synchronizeSystemClock()

    return cfg
Beispiel #6
0
def register_host(module, testbed_id):
    """request that this machine get added to the automation database"""
    print "\n>> Sending request to automation server to be added to database"
    sc = ServerConnection.ServerConnection()
    msg = sc.add_host_request()

    if msg.code == 'ack':
        print "success"
        msg = sc.map_host_capability_request(module)
        if msg.code == 'ack':
            print("resource is mapped with capability %s" % module)
            if testbed_id:
                msg = sc.add_host_resourcepool_request()
                print msg.code
        else:
            print "WARNING: could not add this host to the database: " + \
                str(msg.error)

    else:
        print "WARNING: could not add this host to the database: " + \
                str(msg.error)
Beispiel #7
0
 def run(self):
   for x in xrange(self.thread_count):
     s = ServerConnection.initialize(self.url, self.port, self.gets, self.posts, self.logger, self.config, self.file).start()
Beispiel #8
0

def main_loop(replacer):
    active = True
    while active:
        print('Введите название кейса')
        case = input().upper()
        status = replacer.replace_file(case)
        if not status:
            active = True
        else:
            active = False


if __name__ == '__main__':
    connection_settings = ServerConnection.read_connection_settings()

    connect_to_sm = ServerConnection.SSConnection(connection_settings[0],
                                                  connection_settings[1],
                                                  connection_settings[2],
                                                  connection_settings[3],
                                                  connection_settings[4])

    connection = connect_to_sm.connect()

    ss_repos = ServerConnection.SSRepository(connection, '3DS', 'project')

    ss_replacer = ServerConnection.SSReplacer(
        ss_repos, 'C:\\Users\\User\\AppData\\Roaming\\Replacer')

    main_loop(ss_replacer)
Beispiel #9
0
import ServerConnection

run = True
while (run):
    num = ServerConnection.openConnection(
    )  #Create a connection with the frontend
    if (num == None):
        run = False
Beispiel #10
0
 def run(self):
     for x in xrange(self.thread_count):
         s = ServerConnection.initialize(self.url, self.port, self.gets,
                                         self.posts, self.logger,
                                         self.config, self.file).start()
Beispiel #11
0
 def __init__(self):
     self._connection = ServerConnection.ServerConnection()
     self._account = Account.Account()
Beispiel #12
0
class Target:

    def __init__(self):
        self.capture = cv.CaptureFromCAM(0)
        if DEBUG:
            cv.NamedWindow("Target", 1)
        # set camera resolution
        cv.SetCaptureProperty( self.capture, cv.CV_CAP_PROP_FRAME_WIDTH, 640 )
        cv.SetCaptureProperty( self.capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 480 )
        
        self.display_image = None
        
        # create a connection to the server
        if CONNECT_TO_SERVER:
            self.server = ServerConnection('localhost', 8887)
            self.server.send_resolution(ROI_WIDTH, ROI_HEIGHT)
    

    def run(self):
        # Capture first frame to get size
        frame = cv.QueryFrame(self.capture)
        cv.SetImageROI(frame, (ROI_X_POS, ROI_Y_POS, ROI_WIDTH, ROI_HEIGHT) )
        frame_size = cv.GetSize(frame)
        color_image = cv.CreateImage(cv.GetSize(frame), 8, 3)
        grey_image = cv.CreateImage(cv.GetSize(frame), cv.IPL_DEPTH_8U, 1)
        moving_average = cv.CreateImage(cv.GetSize(frame), cv.IPL_DEPTH_32F, 3)
        
        THRESHOLD = 70
        
        particles = []

        first = True

        while True:
            #get a frame to work with
            color_image = cv.QueryFrame(self.capture)
            
            # Set an ROI so that we can cut the tree branches from the FOV
            cv.SetImageROI(color_image, (ROI_X_POS, ROI_Y_POS, ROI_WIDTH, ROI_HEIGHT) )

            # Smooth to get rid of false positives
            cv.Smooth(color_image, color_image, cv.CV_GAUSSIAN, 3, 0)

            if first:
                difference = cv.CloneImage(color_image)
                temp = cv.CloneImage(color_image)
                cv.ConvertScale(color_image, moving_average, 1.0, 0.0)
                first = False
            else:
                cv.RunningAvg(color_image, moving_average, 0.020, None)

            # Convert the scale of the moving average.
            cv.ConvertScale(moving_average, temp, 1.0, 0.0)

            # Minus the current frame from the moving average.
            cv.AbsDiff(color_image, temp, difference)

            # Convert the image to grayscale.
            cv.CvtColor(difference, grey_image, cv.CV_RGB2GRAY)

            # Convert the image to black and white.
            cv.Threshold(grey_image, grey_image, THRESHOLD, 255, cv.CV_THRESH_BINARY)

            # Dilate and erode to get people blobs
            cv.Dilate(grey_image, grey_image, None, 18)
            cv.Erode(grey_image, grey_image, None, 10)
            
            #get the contours (segmented objects)
            storage = cv.CreateMemStorage(0)
            contour = cv.FindContours(grey_image, storage, cv.CV_RETR_CCOMP, cv.CV_CHAIN_APPROX_SIMPLE)
            
            if DEBUG:
                cv.DrawContours(color_image, contour, cv.CV_RGB(255,0,0), cv.CV_RGB(0,255,0), 9)#, cv.CV_FILLED)
            
            centroids = []
            
            while contour:
                #get the bounding box
                bound_rect = cv.BoundingRect(list(contour))
                #assume the centre of the box is the centre of the blob (roughly true)
                centroids.append((bound_rect[0] + bound_rect[2] /2, bound_rect[1] + bound_rect[3] /2))
                contour = contour.h_next()
                
            if DEBUG:
                for i in centroids:
                    #each new centroid is an array of:
                    centroid = []
                    centroid.append(i) #the point
                    centroid.append(1) #the life
                    
                    shortest_distance = 100
                    for j in centroids:
                        if i != j:
                            if self.calculateDistance(i,j) < shortest_distance:
                                shortest_distance = self.calculateDistance(i,j)
                    colour = self.chooseColour(shortest_distance) 
                    
                    centroid.append(colour) #and the colour based on distance
                    particles.append(centroid) #and gets added to our list of particles
                
                    #cv.Circle(color_image, i, 10, self.chooseColour(), 30)
             
            #now that we have these nice coloured particles    
            """
            for i in particles:
                #if they aren't too old, draw them
                if i[1] < 20:
                    cv.Circle(color_image, i[0], i[1], i[2], -1)
                    i[1] += 2 #and age them
                else:
                    #otherwise kill them
                    particles.remove(i)
            """
            # send latest data to server
            if CONNECT_TO_SERVER:
                self.server.send_points(centroids)
                
            # save latest image
            cv.CvtColor(color_image, color_image, cv.CV_BGR2RGB)
            bgImage = cv2array(color_image)
            bgImageSize = cv.GetSize(color_image)
            self.display_image = bgImage
            self.display_image_width = bgImageSize[0]
            self.display_image_height = bgImageSize[1]
            
            
            if DEBUG: # only show window when we are debugging
                cv.ShowImage("Target", color_image)
            

            # Listen for ESC key
            c = cv.WaitKey(10) % 0x100
            if c == 27:
                sys.exit()
            # For adjustable thresholding based on ambient contrast
            elif c == 171:
                if THRESHOLD < 255:
                    THRESHOLD += 10
                else:
                    THRESHOLD = 255
            elif c == 173:
                if THRESHOLD > 0:
                    THRESHOLD -= 10
                else:
                    THRESHOLD = 0


    def calculateDistance(self, position_a, position_b):
        dist = sqrt( (position_b[0] - position_b[0])**2 + (position_b[1] - position_a[1])**2 )
        return dist
                
    def chooseColour(self, distance):
#        red = 255
#        green = 255
#        blue = 255
#        red = randint(0,255)
#        green = randint(0,255)
#        blue = randint(0,255)
#        red = 255 - randint(distance *2 - 30, distance *2 +30)
#        blue = 0 + randint(distance *2 - 30, distance *2 +30)
#        green = 0 + (randint(distance *2 - 30, distance *2 +30))
        red = 255 - (distance * 2)
        green = 0 + (distance * 2)
        blue = 0 + (distance * 2)
        return cv.CV_RGB(red, green, blue)
Beispiel #13
0
import datetime
import unittest
from ServerConnection import *
from NoDataFoundError import *
from DailyScores import *

date = datetime.date(2017, 12, 12)
server = ServerConnection("http://data.nba.net/data/10s/prod/v1", date)


class TestDailyScores(unittest.TestCase):
    def test_init_correct(self):
        self.assertIsNotNone(DailyScores(" ", " "))

    def test_get_scores_correct(self):
        self.assertIsNotNone(
            DailyScores(server.get_daily_scores(),
                        server.get_date()).get_scores())

    def test_get_scores_wrong_scores(self):
        try:
            DailyScores(" ", server.get_date()).get_scores()
        except TypeError:
            pass

    def test_show_wrong_date(self):
        try:
            a = DailyScores(server.get_daily_scores(), 21)
            a.show(a.get_scores())
        except AttributeError:
            pass