Ejemplo n.º 1
0
/* simulate a relay module */
void module_sim_relay(struct microjs_vm * vm, struct slcdev_sim * sim, 
					  struct ss_device * dev, struct db_dev_model * model)
{
	uint32_t ctl = sim->ctls;

	DCC_LOG2(LOG_INFO, "addr=%d ctl=0x%04x", dev->addr, ctl);

	module_contorl_seq(dev, ctl);

	if ((ctl & 0x81) == 0) {
		/* 1.	Bit 10 = 0,  sent two consecutive times, 
		   will reset PW3 latches */
		DCC_LOG(LOG_INFO, "Reset PW3 latches.");
	}

	switch (ctl & CONTROL_OUT_MSK) {
	case CONTROL_OUT_ON:
		DCC_LOG(LOG_INFO, "Set");
		dev->pw2 = device_db_pw_lookup(model->pw2lst, 2);
		break;

	case CONTROL_OUT_OFF:
		DCC_LOG(LOG_INFO, "Reset");
		dev->pw2 = device_db_pw_lookup(model->pw2lst, 1);
		break;
	}

	module_pw4_default(dev, model);
}
Ejemplo n.º 2
0
static int shell_pw_sel(FILE * f, int argc, char ** argv, int n)
{
	struct db_dev_model * mod;
	struct ss_device * dev;
	int addr;
	int sel;

	if (argc < 3)
		return SHELL_ERR_ARG_MISSING;

	addr = strtoul(argv[1], NULL, 0);
	if (addr > 160)
		return SHELL_ERR_ARG_INVALID;

	sel = strtoul(argv[2], NULL, 0);
	if (sel > 16)
		return SHELL_ERR_ARG_INVALID;

	dev = sensor(addr);

	if ((mod = db_dev_model_by_index(db_info_get(), dev->model)) == NULL)
		return SHELL_ERR_ARG_INVALID;

	switch (n) { 
	case 1:
		dev->pw1 = device_db_pw_lookup(mod->pw1, sel);
		break;
	case 2:
		dev->pw2 = device_db_pw_lookup(mod->pw2, sel);
		break;
	case 3:
		dev->pw3 = device_db_pw_lookup(mod->pw3, sel);
		break;
	case 4:
		dev->pw4 = device_db_pw_lookup(mod->pw4, sel);
		break;
	case 5:
		dev->pw5 = device_db_pw_lookup(mod->pw5, sel);
		break;
	}

	return 0;
}
Ejemplo n.º 3
0
/* simulate a monitor module */
void module_sim_monitor(struct microjs_vm * vm, struct slcdev_sim * sim, 
						struct ss_device * dev, struct db_dev_model * model)
{
	uint32_t ctl = sim->ctls;

	DCC_LOG2(LOG_TRACE, "addr=%d ctl=%b", dev->addr, ctl);

	module_contorl_seq(dev, ctl);

	switch (ctl & CLASS_A_MSK) {
	case CLASS_A_SWITCHED:
		DCC_LOG1(LOG_TRACE, "M%d Class A switched ", dev->addr);
		dev->pw2 = device_db_pw_lookup(model->pw2lst, 2);
		break;
	case CLASS_A_NORMAL:
		DCC_LOG1(LOG_TRACE, "M%d Class A normal", dev->addr);
		dev->pw2 = device_db_pw_lookup(model->pw2lst, 1);
		break;
	}

	module_pw4_default(dev, model);
}
Ejemplo n.º 4
0
/* simulate a supervised cntrol module */
void module_sim_control(struct microjs_vm * vm, struct slcdev_sim * sim, 
						struct ss_device * dev, struct db_dev_model * model)
{
	uint32_t ctl = sim->ctls;

	DCC_LOG2(LOG_INFO, "addr=%d ctl=0x%04x", dev->addr, ctl);

	module_contorl_seq(dev, ctl);

	switch (ctl & CONTROL_OUT_MSK) {
	case CONTROL_OUT_ON:
		DCC_LOG(LOG_INFO, "Control ON");
		dev->pw2 = device_db_pw_lookup(model->pw2lst, 2);
		break;
	case CONTROL_OUT_OFF:
		DCC_LOG(LOG_INFO, "Control Off");
		dev->pw2 = device_db_pw_lookup(model->pw2lst, 1);
		break;
	}

	module_pw4_default(dev, model);
}
Ejemplo n.º 5
0
/* Default control bits processing for sensors */
void sensor_ctl_default(struct ss_device * dev, 
					   struct db_dev_model * model, uint32_t ctl)
{
	device_led_default(dev, ctl);

	/* Remote test */
	switch (ctl & REMOTE_TEST_MSK) {
	case REMOTE_TEST_ON:
		if (dev->tst) { 
			DCC_LOG(LOG_TRACE, "Remote test enabled");
			dev->tst = 1;
			dev->pw2 = device_db_pw_lookup(model->pw2lst, 2);
		}
		break;
	case REMOTE_TEST_OFF:
		if (dev->tst) { 
			DCC_LOG(LOG_TRACE, "Remote test disabled");
			dev->tst = 0;
			dev->pw2 = device_db_pw_lookup(model->pw2lst, 1);
		}
		break;
	}
}
Ejemplo n.º 6
0
void sensor_pw4_default(struct ss_device * dev, struct db_dev_model * model)
{
	int idx;
	int lvl;

	if (dev->tst) {
		idx = model->pw4lut.tst.idx;
	} else if ((lvl = dev->alm) > 0) {
		if (lvl > model->pw4lut.alm.cnt)
			lvl = model->pw4lut.alm.cnt;
		DCC_LOG1(LOG_TRACE, "Alarm %d", lvl);
		idx = model->pw4lut.alm.idx + lvl - 1;
	} else if ((lvl = dev->tbl) > 0) {
		if (lvl > model->pw4lut.tbl.cnt)
			lvl = model->pw4lut.tbl.cnt;
		DCC_LOG1(LOG_TRACE, "Trouble %d", lvl);
		idx = model->pw4lut.tbl.idx + lvl - 1;
	} else {
		idx = 1;
	}

	dev->pw4 = device_db_pw_lookup(model->pw4lst, idx);
}