Esempio n. 1
0
/**
 * Test for advertising using an iBeacon
 */
void setupIBeaconTest(void)
{
    /* setup the iBeacon */
    const static uint8_t uuid[] = {0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4,
                                   0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61};
    uint16_t majorNumber = 1122;
    uint16_t minorNumber = 3344;
    uint16_t txPower     = 0xC8;
    iBeacon ibeacon(ble, uuid, majorNumber, minorNumber, txPower);

    uint16_t interval_value = 1000;
    ble.gap().setAdvertisingInterval(interval_value); /* 1000ms. */
    CHECK_EQUALS(ble.gap().getAdvertisingParams().getInterval(), interval_value);

    ble.gap().setAdvertisingTimeout(0);
    CHECK_EQUALS(ble.gap().getAdvertisingParams().getTimeout(), 0);

    ASSERT_NO_FAILURE(ble.gap().startAdvertising());
    printf("ASSERTIONS DONE\r\n");
}
Esempio n. 2
0
YArray* Array_find(YArray* arr, YValue* val, YThread* th) {
	arr->parent.o.linkc++;
	val->o.linkc++;
	YArray* out = newArray(th);
	out->parent.o.linkc++;
	for (size_t i = 0; i < arr->size(arr, th); i++) {
		YValue* v = arr->get(arr, i, th);
		if (CHECK_EQUALS(val, v, th))
			out->add(out, newInteger((int64_t) i, th), th);
	}
	out->parent.o.linkc--;
	val->o.linkc--;
	arr->parent.o.linkc--;
	return out;
}
Esempio n. 3
0
YArray* Array_unique(YArray* arr, YThread* th) {
	arr->parent.o.linkc++;
	YArray* out = newArray(th);
	out->parent.o.linkc++;

	for (size_t i = 0; i < arr->size(arr, th); i++) {
		YValue* val = arr->get(arr, i, th);
		bool cont = false;
		for (size_t j = 0; j < out->size(out, th); j++) {
			YValue* val2 = out->get(out, j, th);
			if (CHECK_EQUALS(val, val2, th)) {
				cont = true;
				break;
			}
		}
		if (!cont)
			out->add(out, val, th);
	}
	out->parent.o.linkc--;
	arr->parent.o.linkc--;
	return out;
}
Esempio n. 4
0
VOID CATOLECRList::PassCmd(BSTR ID, LPBYTE lpUncodedCmd, DWORD dwCmdLen, 
						   LPBYTE lpDecodedRsp, DWORD &dwRspLen, 
						   LONG *pErrorCode)
{
	BOOL bSuccess = FALSE;
	BYTE nResponse, nEncodedCmd[CMD_LEN], nEncodedRsp[CMD_LEN];
	DWORD dwRetry = 0;
	CECRConnection *pConnection = GetConnection(ID);
	
	if (pConnection == NULL)
	{
		*pErrorCode = E_NOT_FOUND;
		return;
	}

	// подготовка данных команды к отправке
	ZeroMemory(nEncodedRsp, CMD_LEN);
	EncodeCmd(lpUncodedCmd, nEncodedCmd, dwCmdLen);

	// отправка запроса ENQ
	SetTimeouts(pConnection, T_T1, T_TW);
	do
	{
		COMM_OPERATION(ClearError(pConnection, pErrorCode), 100);
		COMM_OPERATION(PurgeComm(pConnection->m_hCommPort, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR), 0);
		COMM_OPERATION(WriteByte(pConnection, ENQ), 1);
		if (ReadByte(pConnection, &nResponse))
		{
			if (nResponse == ACK)
				// приемник готов к установке связи
				break;

			if (nResponse == ENQ)
			{
				// конфликтная ситуация
				Sleep(T_T7);
				SaveDumpString("ENQ Conflict\n");
			}
			else
			{
				// неверный ответ на запрос установки связи
				Sleep(T_T1);
				SaveDumpString("Wrong ENQ answer\n");
			}
		}

		// увеличиваем счетчик попыток
		dwRetry++;
	}
	while (dwRetry < N_ENQ_RETRY);
	CHECK_EQUALS(dwRetry, N_ENQ_RETRY, 3);

	// отправка команды
	dwRetry = 1;
	SetTimeouts(pConnection, T_T3, T_TW);
	do
	{
		COMM_OPERATION(WriteBuffer(pConnection, nEncodedCmd, dwCmdLen), 4);
		COMM_OPERATION(ReadByte(pConnection, &nResponse), 5);
		if (nResponse == ACK)
			break;
		
		// увеличиваем счетчик попыток
		SaveDumpString("NAK received on command\n");
		dwRetry++;
	}
	while (dwRetry < N_CMD_RETRY);
	CHECK_EQUALS(dwRetry, N_CMD_RETRY, 6);

	// закрытие сеанса связи
	COMM_OPERATION(WriteByte(pConnection, EOT), 7);

	// определяем таймаут ожидания ответа
	DWORD dwResponseWaitTimeout = 0;
	switch (nEncodedCmd[3])
	{
		case 0x4A:
		case 0x62:
		case 0xA7:
		case 0xA6:
		case 0x8D:
		case 0x8E:
			dwResponseWaitTimeout = 20000;
			break;
		case 0xA8:
		case 0xA9:
		case 0xAA:
		case 0xAB:
		case 0xAC:
		case 0xAD:
		case 0x5A:
			dwResponseWaitTimeout = 120000;
			break;
		case 0x91:
			dwResponseWaitTimeout = 45000;
			break;
		default:
			dwResponseWaitTimeout = T_T5;
	}

	// ждем ответ
	SetTimeouts(pConnection, dwResponseWaitTimeout, T_TW);
	COMM_OPERATION(ReadByte(pConnection, &nResponse), 8);
	CHECK_NOT_EQUALS(nResponse, ENQ, 80);
	COMM_OPERATION(WriteByte(pConnection, ACK), 9);

	// принимаем ответ
	dwRetry = 1;
	do
	{
		ZeroMemory(nEncodedRsp, CMD_LEN);
		COMM_OPERATION(GetResponse(pConnection, nEncodedRsp, dwRspLen), 10);
		
		// проверяем CRC
		if (IsValidCRC(nEncodedRsp, dwRspLen))
			break;

		// отправляем отказ 
		COMM_OPERATION(WriteByte(pConnection, NAK), 11);

		// увеличиваем счетчик попыток
		SaveDumpString("Response CRC error\n");
		dwRetry++;
	}
	while (dwRetry < N_CMD_RETRY);
	CHECK_EQUALS(dwRetry, N_CMD_RETRY, 12);

	// отправка подтверждения получения ответа
	COMM_OPERATION(WriteByte(pConnection, ACK), 13);
	// завершение сеанса связи
	SetTimeouts(pConnection, T_T4, T_TW);
	COMM_OPERATION(ReadByte(pConnection, &nResponse), 14);

	// декодируем ответ
	DecodeRsp(nEncodedRsp, lpDecodedRsp, dwRspLen);

	// проверяем результат выполнения команды
	((lpDecodedRsp[0] == 'U') && (lpDecodedRsp[1] != 0)) ? 
		*pErrorCode = lpDecodedRsp[1] : *pErrorCode = E_SUCCESS;

	// если команда выполнена с ошибкой
	// и код команды отличен от 0x45 (запрос кода состояния)
	if ((*pErrorCode != E_SUCCESS) && (nEncodedCmd[3] != 0x45))
	{
		// сохраняем дамп команды и дамп ответа
		SaveCommandDump(nEncodedCmd, nEncodedRsp, CMD_LEN, 0xFF);
	}
}