def sendRejectRsp(self, system_id, s_type, reason): """Send a Reject Response to the remote host :param system_id: System of the request to reply for :type system_id: integer :param s_type: s_type of rejected message :type s_type: integer :param reason: reason for rejection :type reason: integer """ packet = hsmsPacket(hsmsRejectReqHeader(system_id, s_type, reason)) self.connection.send_packet(packet)
def on_connection_packet_received(self, packet): """Packet received by connection :param packet: received data packet :type packet: :class:`secsgem.hsmsPackets.hsmsPacket` """ if packet.header.sType > 0: self.logger.info("< %s\n %s", packet, hsmsSTypes[packet.header.sType]) # check if it is a select request if packet.header.sType == 0x01: # if we are disconnecting send reject else send response if self.connection.disconnecting: self.sendRejectRsp(packet.header.system, packet.header.sType, 4) else: self.sendSelectRsp(packet.header.system) # update connection state self.connectionState.select() # check if it is a select response elif packet.header.sType == 0x02: # update connection state self.connectionState.select() # queue packet to notify waiting threads self._queuePacket(packet) # check if it is a deselect request elif packet.header.sType == 0x03: # if we are disconnecting send reject else send response if self.connection.disconnecting: self.sendRejectRsp(packet.header.system, packet.header.sType, 4) else: self.sendDeselectRsp(packet.header.system) # update connection state self.connectionState.deselect() elif packet.header.sType == 0x04: # update connection state self.connectionState.deselect() # queue packet to notify waiting threads self._queuePacket(packet) # check if it is a linktest request elif packet.header.sType == 0x05: # if we are disconnecting send reject else send response if self.connection.disconnecting: self.sendRejectRsp(packet.header.system, packet.header.sType, 4) else: self.sendLinktestRsp(packet.header.system) else: # queue packet if not handeled self._queuePacket(packet) else: if not self.connectionState.isstate("SELECTED"): self.logger.info("< %s", packet) self.logger.warning("received message when not selected") self.connection.send_packet(hsmsPacket(hsmsRejectReqHeader(packet.header.system, packet.header.sType, 4))) return True # redirect packet to hsms handler if hasattr(self, '_onHsmsPacketReceived') and callable(getattr(self, '_onHsmsPacketReceived')): self._onHsmsPacketReceived(packet) else: self.logger.info("< %s", packet)