def try_register(msg, own_port, reg_slave_f, check_slave_reg_f):
		hwa = msg[1][1]
		
		#if NORMAL msg:
		if ( (msg[1][3] == 0) | ((msg[1][4] != sys.Ids['HEARTBEAT']) & (msg[1][4] != sys.Ids['CONFIG'])) ):
			return (rc_ok)
		
		#if CONFIG msg:
		if (msg[1][4] == sys.Ids['CONFIG']):
			if (reg_states.get(hwa) == reg_state_req_sent):
				#send command to set slave regime to Normal
				packer_rc, data = sys.set_op_w_normal()
				if (packer_rc != 0):
					return (rc_packer_err, packer_rc)
				msg_setop = ("msg_lvl2", ("msg_metadata", hwa, own_port, 1, sys.Ids['SET_OP']), data)
				snd_rc = lnet.send(msg_setop)
				if (snd_rc != 0):
					return (rc_snd_err, snd_rc)
				
				reg_slave_f(msg)
				del reg_states[hwa]
				
				return (rc_processed)
			#else: unexpected config - panic
		
		#if HEARTBEAT msg:
		#else if already registered - quit:  (this way allows app to delete slaves without asking receive_message)
		if (check_slave_reg_f(hwa)):
			return (rc_processed)
		
		#send request for config (if it hvent been done already):
		if (reg_states.get(hwa) != reg_state_req_sent):
			packer_rc, data = sys.config_w_request()
			if (packer_rc != 0):
				return (rc_packer_err, packer_rc)
			msg_req = ("msg_lvl2", ("msg_metadata", hwa, own_port, 1, sys.Ids['CONFIG']), data)
			snd_rc = lnet.send(msg_req)
			if (snd_rc != 0):
				return (rc_snd_err, snd_rc)
			else:
				#quit - only one msg handling on one registration_handler call
				reg_states[hwa] = reg_state_req_sent
				return (rc_ok)
import can_net_sync as cn
import pmd_net_system as sys

cn.init(1, 100, 100, 100, 100)
msg = ("msg_lvl2", ("msg_metadata", 123, 1, 1, sys.Ids['SET_OP']), sys.set_op_w_normal()[1])
print msg
cn.send(msg)