예제 #1
0
void test_handle_message(struct cfw_message * msg, void * param)
{
	cfw_log("%s:%s for param: %s conn:%p id:%d\n", __FILE__, __func__,
			(char*) param, msg->conn, CFW_MESSAGE_ID(msg));
	//cfw_dump_message(msg);

	switch (CFW_MESSAGE_ID(msg)) {
	case MSG_ID_CFW_REGISTER_SVC_AVAIL_EVT_RSP:
		break;
	case MSG_ID_CFW_SVC_AVAIL_EVT: {
		int svc_id = ((cfw_svc_available_evt_msg_t *)msg)->service_id;
		if (svc_id == SOC_GPIO_SERVICE_ID) {
			cfw_open_service_conn(client, SOC_GPIO_SERVICE_ID, "Conn1");
		}
		break;
	}
	case MSG_ID_CFW_OPEN_SERVICE_RSP: {
		cfw_log("%s:%s for conn: %s\n", __FILE__, __func__,
				(char*) CFW_MESSAGE_PRIV(msg));
		cfw_open_conn_rsp_msg_t * cnf = (cfw_open_conn_rsp_msg_t*) msg;
		gpio_service_conn = cnf->service_conn;
		gpio_configure(gpio_service_conn, 26, 1, NULL);
		break;
	}
	case MSG_ID_GPIO_CONFIGURE_RSP:
		gpio_set_state(gpio_service_conn, 26, 1, NULL);
		break;

	case MSG_ID_GPIO_SET_RSP: {
		int val;
		void * next;
		if (!((int) CFW_MESSAGE_PRIV(msg))) {
			val = 0;
			next = (void*) 1;
		} else {
			val = 1;
			next = (void*) 0;
		}
		printf("Got response: %d %d \n", val, (int) next);
		if (count ++ > 100) {
			cfw_close_service_conn(gpio_service_conn, NULL);
		} else {
			gpio_set_state(gpio_service_conn, 26, val, next);
		}
	}
		break;

	case MSG_ID_CFW_CLOSE_SERVICE_RSP: {
		cfw_close_conn_rsp_msg_t * resp = (cfw_close_conn_rsp_msg_t*) msg;
		cfw_log("%s: res: %d\n", __func__, resp->rsp_header.status);
		exit(0);
	}
	break;

	default: {
		cfw_log("%s: Unhandled message: %d\n", __func__, CFW_MESSAGE_ID(msg));
		break;
	}
	}
	cfw_msg_free(msg);

}
예제 #2
0
int press_simulation(unsigned int service_id, unsigned int input_pin,
		     unsigned int output_pin)
{
	cfw_service_conn_t *gpio_service_conn = NULL;

	cfw_client_t *gpio_client = cfw_client_init(
		get_test_queue(), pwrbtn_tst_handle_msg, NULL);

	if (!cfw_service_registered(service_id)) {
		cu_print("TST_PWRBTN: ss gpio service not registered\n");
		return DRV_RC_FAIL;
	}

	cfw_open_service_conn(gpio_client, service_id, &gpio_service_conn);
	SRV_WAIT((!gpio_service_conn), 2000);
	CU_ASSERT("TST_PWRBTN: can not open ss gpio service",
		  (gpio_service_conn));
	if (gpio_service_conn == NULL) {
		return DRV_RC_FAIL;
	}

	/* The configuration put the pin to 0 => the pin have to be set to 1
	 * before first press simulation */
	TEST_PWRBTN(configure, "TST_PWRBTN: gpio configuration failed",
		    gpio_service_conn, output_pin, 1,
		    "SS pin 2 output");
	SRV_WAIT((!tst_pwrbtn_configure), 2000);
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)",
		    gpio_service_conn, output_pin, 1,
		    "set_output 1");
	/* wait state response */
	SRV_WAIT((!tst_pwrbtn_set_state), 2000);

	/* wait 3s */
	local_task_sleep_ms(3000);

	tst_step = VERY_SH_PRESS;
	cu_print("Start pattern with press_duration = 700ms\n");
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)",
		    gpio_service_conn, output_pin, 0,
		    "set_output 0");
	local_task_sleep_ms(700);
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)",
		    gpio_service_conn, output_pin, 1,
		    "set_output 1");

	/* wait pattern detection */
	SRV_WAIT((!tst_very_short), 2000);
	/* wait 3s */
	local_task_sleep_ms(3000);

	cu_print("Start pattern with press_duration = 2500ms\n");
	tst_step = SH_PRESS;
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)",
		    gpio_service_conn, output_pin, 0,
		    "set_output 0");
	local_task_sleep_ms(2500);
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)",
		    gpio_service_conn, output_pin, 1,
		    "set_output 1");

	/* wait pattern detection */
	SRV_WAIT((!tst_short), 2000);
	/* wait 3s */
	local_task_sleep_ms(3000);

	cu_print("Start pattern with press_duration = 4000ms\n");
	tst_step = SINGLE_PRESS;
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)",
		    gpio_service_conn, output_pin, 0,
		    "set_output 0");
	local_task_sleep_ms(4000);
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)",
		    gpio_service_conn, output_pin, 1,
		    "set_output 1");

	/* wait pattern detection */
	SRV_WAIT((!tst_single), 2000);
	/* wait 3s */
	local_task_sleep_ms(3000);

	cu_print("Start pattern with press_duration = 7000ms\n");
	tst_step = L_PRESS;
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)",
		    gpio_service_conn, output_pin, 0,
		    "set_output 0");
	local_task_sleep_ms(7000);
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)",
		    gpio_service_conn, output_pin, 1,
		    "set_output 1");

	/* wait pattern detection */
	SRV_WAIT((!tst_long), 2000);
	/* wait 3s */
	local_task_sleep_ms(3000);

	cu_print("Start pattern with press_duration = 12000ms\n");
	tst_step = VERY_L_PRESS;
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)",
		    gpio_service_conn, output_pin, 0,
		    "set_output 0");
	local_task_sleep_ms(12000);
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)",
		    gpio_service_conn, output_pin, 1,
		    "set_output 1");

	/* wait 3s */
	local_task_sleep_ms(3000);

	/* Start failed double press pattern : very_short_press + 550 ms delay max + short_press */
	cu_print("Start double pattern press failed...\n");
	tst_step = DBLE_PRESS_FAIL_1;
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)",
		    gpio_service_conn, output_pin, 0,
		    "set_output 0");
	local_task_sleep_ms(700);
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)",
		    gpio_service_conn, output_pin, 1,
		    "set_output 1");

	/* wait pattern detection */
	SRV_WAIT((!tst_double_fail_1), 2000);
	/* wait between the very short press */
	local_task_sleep_ms(550);

	tst_step = DBLE_PRESS_FAIL_2;
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)",
		    gpio_service_conn, output_pin, 0,
		    "set_output 0");
	local_task_sleep_ms(2700);
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)",
		    gpio_service_conn, output_pin, 1,
		    "set_output 1");

	/* wait pattern detection */
	SRV_WAIT((!tst_double_fail_2), 2000);
	/* wait 3s */
	local_task_sleep_ms(3000);

	cu_print("Start too short pattern with duration = 300ms\n");
	tst_step = TOO_SHORT_PRESS;
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)",
		    gpio_service_conn, output_pin, 0,
		    "set_output 0");
	local_task_sleep_ms(300);
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)",
		    gpio_service_conn, output_pin, 1,
		    "set_output 1");

	/* wait pattern detection */
	SRV_WAIT((!tst_double_fail_2), 2000);
	/* wait 3s */
	local_task_sleep_ms(3000);

	/* Start double press pattern : very_short_press + 350 ms delay max + very_short_press */
	cu_print("Start double pattern press...\n");
	tst_step = DBLE_PRESS;
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)",
		    gpio_service_conn, output_pin, 0,
		    "set_output 0");
	local_task_sleep_ms(700);
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)",
		    gpio_service_conn, output_pin, 1,
		    "set_output 1");

	/* wait between the very short press */
	local_task_sleep_ms(350);

	TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)",
		    gpio_service_conn, output_pin, 0,
		    "set_output 0");
	local_task_sleep_ms(900);
	TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)",
		    gpio_service_conn, output_pin, 1,
		    "set_output 1");

	/* wait pattern detection */
	SRV_WAIT((!tst_double), 2000);
	/* wait 2s */
	local_task_sleep_ms(2000);

	cfw_close_service_conn(gpio_service_conn, NULL);

	return DRV_RC_OK;
}