def __init__(self, host, port): self.logger = logging.getLogger('FasitClient') self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.logger.debug('connecting to %s', (host, port)) self.sock.connect((host, port)) FasitHandler.__init__(self, sock=self.sock, name='FasitClient') return
def __init__(self, host, port, type, remote, local_ip, local_port): self.logger = logging.getLogger('FasitClient') self.sock = None self.target_type = type # check the type here, but don't assign __device__ # until after the socket has been successfully opened if ((type != fasit_packet_pd.PD_TYPE_NONE) and (type != fasit_packet_pd.PD_TYPE_SAT_LIGHT) and (type != fasit_packet_pd.PD_TYPE_SAT_HEAVY) and (type != fasit_packet_pd.PD_TYPE_SIT) and (type != fasit_packet_pd.PD_TYPE_MIT) and (type != fasit_packet_pd.PD_TYPE_MAT) and (type != fasit_packet_pd.PD_TYPE_SES)): raise ValueError( 'NONE, SIT, MIT and SES are only currently supported target types' ) self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.logger.debug('connecting to %s', (host, port)) self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) # keepalive will try to ensure a connection is valid and disconnect if it is not #self.sock.setsockopt(socket.SOL_SOCKET, socket.TCP_KEEPALIVE_INTVL, 10) -- these values set globally via sysctl #self.sock.setsockopt(socket.SOL_SOCKET, socket.TCP_KEEPALIVE_PROBES, 5) #self.sock.setsockopt(socket.SOL_SOCKET, socket.TCP_KEEPALIVE_TIME, 30) self.sock.connect((host, port)) if (type == fasit_packet_pd.PD_TYPE_NONE): self.__device__ = FasitPd.FasitPd() elif (type == fasit_packet_pd.PD_TYPE_SAT_LIGHT): self.__device__ = FasitPdSit.FasitPdSit(type) elif (type == fasit_packet_pd.PD_TYPE_SAT_HEAVY): self.__device__ = FasitPdSit.FasitPdSit(type) elif (type == fasit_packet_pd.PD_TYPE_SIT): self.__device__ = FasitPdSit.FasitPdSit(type) elif (type == fasit_packet_pd.PD_TYPE_MIT): if (remote == True): self.logger.debug('Remote connection specified') self.__device__ = FasitPdMitRemote.FasitPdMitRemote( local_ip, local_port) else: self.logger.debug('Local connection specified') self.__device__ = FasitPdMit.FasitPdMit() elif (type == fasit_packet_pd.PD_TYPE_MAT): self.__device__ = FasitPdMat.FasitPdMat() elif (type == fasit_packet_pd.PD_TYPE_SES): self.__device__ = FasitPdSes.FasitPdSes() else: raise ValueError( 'NONE, SIT, MIT, MAT and SES are only currently supported target types' ) FasitHandler.__init__(self, sock=self.sock, name='FasitClient')
def __init__(self, sock): self.logger = logging.getLogger('RemoteTargetServerHandler') self.command_ack_packet = None self.command_status_packet = None FasitHandler.__init__(self, sock, name='RemoteTargetServerHandler') device_status_request = fasit_packet_pd.FasitPacketPd() status_request = fasit_packet_pd.FasitPacketPd.EventCommand() status_request.command_id = fasit_packet_pd.EVENT_CMD_REQ_STATUS device_status_request.data = status_request self.push(device_status_request.pack())
def __init__(self, host, port, type, remote, local_ip, local_port): self.logger = logging.getLogger('FasitClient') self.sock = None self.target_type = type # check the type here, but don't assign __device__ # until after the socket has been successfully opened if ((type != fasit_packet_pd.PD_TYPE_NONE) and (type != fasit_packet_pd.PD_TYPE_SIT) and (type != fasit_packet_pd.PD_TYPE_MIT) and (type != fasit_packet_pd.PD_TYPE_MAT) and (type != fasit_packet_pd.PD_TYPE_SES)): raise ValueError( 'NONE, SIT, MIT and SES are only currently supported target types' ) self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.logger.debug('connecting to %s', (host, port)) self.sock.connect((host, port)) if (type == fasit_packet_pd.PD_TYPE_NONE): self.__device__ = fasit_pd.FasitPd() elif (type == fasit_packet_pd.PD_TYPE_SIT): self.__device__ = fasit_pd.FasitPdSit() elif (type == fasit_packet_pd.PD_TYPE_MIT): if (remote == True): self.logger.debug('Remote connection specified') self.__device__ = fasit_pd.FasitPdMitRemote( local_ip, local_port) else: self.logger.debug('Local connection specified') self.__device__ = fasit_pd.FasitPdMit() elif (type == fasit_packet_pd.PD_TYPE_MAT): self.__device__ = fasit_pd.FasitPdMat() elif (type == fasit_packet_pd.PD_TYPE_SES): self.__device__ = fasit_pd.FasitPdSes() else: raise ValueError( 'NONE, SIT, MIT, MAT and SES are only currently supported target types' ) FasitHandler.__init__(self, sock=self.sock, name='FasitClient')