예제 #1
0
def send_func(  pdc         : PDC_server            , 
                pmu_IP      : str = '10.64.37.34'   , 
                pmu_port    : int = 12345           
            ):
    sqn_num = int(0)
    try :
        sqn_num = sqn_num + 1
        msg = str(sqn_num)
        pdc.send_to(pmu_IP=pmu_IP , pmu_port= pmu_port, payload = msg.encode() )

    except KeyboardInterrupt :
        print("exited by user")
예제 #2
0
def recv_common_frame(   th_Q        : TH_Queue              ,
            pmu34_db    : db_client             , 
            pdc         : PDC_server            , 
            pmu_IP      : str = '10.64.37.34'   , 
            pmu_port    : int = 12345               
        ):
    sqn_num = int(0)
    try :
        while True:
            #recv
            loop_start_time = time()
            data_recvd , addr_of_client = pdc.recv()
            print(extract_frame_type(data_recvd))
            #
            frame = DataFrame.convert2frame(data_recvd,ieee_cfg2_sample)
            server_ct = time()
            SOC_server = int(server_ct)
            FRASEC_server = int (  (server_ct - SOC_server) * (10**6) )

            #SOC_Client = struct.unpack('!HHHIIHIIIIHHIIIHH',data_recvd)[3]
            #FRASEC_Client = struct.unpack('!HHHIIHIIIIHHIIIHH',data_recvd)[4]
            #FRASEC_diff = FRASEC_server - FRASEC_Client
            #SOC_diff = SOC_server - SOC_Client
            #print( SOC_server , SOC_Client , FRASEC_server , FRASEC_Client , FRASEC_diff)
            #store over db
            '''
            db_start_time = time()
            entry = pmu34_db.create_me_json(measurement='comm_delay',
                                    tag_name='pmu_34',tag_field='fracsec_diff',
                                    field_name='pdc_pmu_diff',field_value=FRASEC_diff)
            pmu34_db.write_to_db(data_json=entry,verbose_mode=False)
            db_end_time = time()
            '''
            #push to queue
            '''
            db_start_time = time()
            entry = pmu34_db.create_me_json(measurement='comm_delay',
                        tag_name='pmu_34',tag_field='fracsec_diff',
                        field_name='pdc_pmu_diff',field_value=FRASEC_diff)
            th_Q.put_in_queue(item = entry)
            db_end_time = time()
            '''
            #send
            sqn_num = sqn_num + 1
            msg = str(sqn_num)
            pdc.send_to(pmu_IP=addr_of_client[0] , pmu_port=addr_of_client[1] , payload = msg.encode() )
            loop_end_time = time()

            #print( (loop_end_time-loop_start_time) , (db_end_time - db_start_time) , ((loop_end_time-loop_start_time) / (db_end_time - db_start_time)) )
    
    except KeyboardInterrupt :
        print("exited by user")
예제 #3
0
def recv_data_frame(th_Q: TH_Queue,
                    pmu34_db: db_client,
                    pdc: PDC_server,
                    pmu_IP: str = '10.64.37.34',
                    pmu_port: int = 9991,
                    table: dict = pmu_id_ip_table):
    sqn_num = int(0)
    while True:
        #recv
        #loop_start_time = time()
        data_recvd, addr_of_client = pdc.recv()
        #
        server_ct = time()
        SOC_server = int(server_ct)
        FRASEC_server = int((server_ct - SOC_server) * (10**6))

        #print(DataFrame.extract_frame_type(data_recvd))
        frame = DataFrame.convert2frame(data_recvd, ieee_cfg2_sample)
        #print(frame)
        #SOC_Client = frame.get_soc()
        FRASEC_Client = frame.get_frasec()[0]
        #print(SOC_server , SOC_Client , FRASEC_server , FRASEC_Client , FRASEC_server - FRASEC_Client )
        #push to queue
        FRASEC_diff = FRASEC_server - FRASEC_Client
        #db_start_time = time()
        entry = pmu34_db.create_me_json(measurement='comm_delay',
                                        tag_name='pmu_34',
                                        tag_field='fracsec_diff',
                                        field_name='pdc_pmu_diff',
                                        field_value=FRASEC_diff)
        th_Q.put_in_queue(entry)
        #db_end_time = time()
        #print(f"upload time -> {db_end_time - db_start_time}")
        #send
        sqn_num = sqn_num + 1
        msg = str(sqn_num)
        pmu_id = frame.get_id_code()
        pmu_ip_addr = table[pmu_id]
        pdc.send_to(pmu_IP=pmu_ip_addr, pmu_port=9991, payload=msg.encode())
예제 #4
0
def recv_func( pdc : PDC_server ):
    sqn_num = int(0)
    try :
        while True:
            #recv
            data_recvd , addr_of_client = pdc.recv()
            #
            server_ct = time() - 0
            SOC_server = int(server_ct)
            FRASEC_server = int (  (server_ct - SOC_server) * (10**6) )

            SOC_Client = struct.unpack('!HHHIIHIIIIHHIIIHH',data_recvd)[3]
            FRASEC_Client = struct.unpack('!HHHIIHIIIIHHIIIHH',data_recvd)[4]
            FRASEC_diff = FRASEC_server - FRASEC_Client
            SOC_diff = SOC_server - SOC_Client
            print( SOC_server , SOC_Client , FRASEC_server , FRASEC_Client , FRASEC_diff)
    except KeyboardInterrupt :
        print("exited by user")
예제 #5
0
                        set_deamon             = False         ,
                        sync_lock_precision    = (10**(-4))    ,
                        ntp_sync_wait          = 1.0           ,
                        to_log_syncer          = True          ,
                        sync_logging_level     = 'DEBUG'
                    )
    '''
    PDC = PDC_server (  ip_server_is_binding = IP_to_bind , 
                        port_opening         = port_opening       , 
                        buffer_size          = buffer_size        ,
                        trans_logging_level  = 'INFO'               ,
                        to_log_trans         = False        ,
                        
                        ntp_server_sync     = False        , 
                        set_deamon          = True        ,
                        sync_lock_precision = (10**(-4))  ,
                        ntp_sync_wait       = 1.0         ,
                        to_log_syncer       = False        ,
                        sync_logging_level  = 'DEBUG'     ,

                        ptp_server_sync     = True          ,
                        ptp_sync_wait       = 0.5           ,
                        to_log_ptp_syncer   = False          ,
                        ptp_sync_logging_level = 'DEBUG'       
                 )
    #creating RT time series DB
    pmu34_db = db_client(IFDbname='PMU_34')
    #TODO create thread safe queue
    th_Q = TH_Queue(BUF_SIZE=0 , to_log_queue=True)
    #TODO create analytics and main_thread
    analytic_TH = threading.Thread(target=upload_func , args=(pmu34_db , th_Q , ) )
    #analytic_TH.setDaemon(True)