Exemple #1
0
//Handler to handle the receive(RXNE) interrupt,DA means Data Available here,the name
//inherites from COM driver implemented on X86 platform.
static VOID DAIntHandler(__USART_CONTROL_BLOCK* pCtrlBlock)
{
    CHAR                bt;
    DWORD               dwFlags;


    //Process data available interrupt.
    __ENTER_CRITICAL_SECTION(NULL,dwFlags);
    while(IsDataAvailable(pCtrlBlock->dwUsartBase))  //Data available.
    {
        bt = GetUsartByte(pCtrlBlock->dwUsartBase);  //Read the byte.
        pCtrlBlock->Buffer[pCtrlBlock->nBuffTail] = bt;
        pCtrlBlock->nBuffTail ++;
        if(COM_BUFF_LENGTH == pCtrlBlock->nBuffTail)  //Reach end of buffer.
        {
            pCtrlBlock->nBuffTail = 0;
        }
        if(pCtrlBlock->nBuffHeader == pCtrlBlock->nBuffTail)  //Buffer full.
        {
            break;
        }
    }
    while(IsDataAvailable(pCtrlBlock->dwUsartBase))  //Drain out all data from COM interface,since the buffer is full.
    {
        GetUsartByte(pCtrlBlock->dwUsartBase);
    }
    //Wake up all threads waiting for COM data.
    while(pCtrlBlock->pReadingList)
    {
        pCtrlBlock->pReadingList->OnCompletion((__COMMON_OBJECT*)pCtrlBlock->pReadingList);
        pCtrlBlock->pReadingList = pCtrlBlock->pReadingList->lpNext;
    }
    pCtrlBlock->pReadingListTail = NULL;
    __LEAVE_CRITICAL_SECTION(NULL,dwFlags);
}
Exemple #2
0
__int64 CTimeShiftUtil::GetAvailableFileSize() const
{
	if( this->filePath.empty() == false ){
		if( this->fileMode ){
			//単純にファイルサイズを返す
			if( this->seekFile == INVALID_HANDLE_VALUE ){
				WIN32_FIND_DATA findData;
				HANDLE find = FindFirstFile(this->filePath.c_str(), &findData);
				if( find != INVALID_HANDLE_VALUE ){
					FindClose(find);
					return (__int64)findData.nFileSizeHigh << 32 | findData.nFileSizeLow;
				}
			}else{
				LARGE_INTEGER liSize;
				if( GetFileSizeEx(this->seekFile, &liSize) ){
					return liSize.QuadPart;
				}
			}
		}else{
			//有効なデータのある範囲を調べる
			HANDLE file = this->seekFile;
			if( file == INVALID_HANDLE_VALUE ){
				file = CreateFile(this->filePath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
				                  NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
			}
			if( file != INVALID_HANDLE_VALUE ){
				LARGE_INTEGER liSize;
				CPacketInit packetInit;
				if( GetFileSizeEx(file, &liSize) == FALSE || liSize.QuadPart < 188 * 16 * 8 ){
					liSize.QuadPart = 0;
				}else if( IsDataAvailable(file, liSize.QuadPart - 188 * 16 * this->seekJitter, &packetInit) == FALSE ){
					//終端部分が無効なので有効なデータの境目を探す
					//seekJitterは調査箇所がたまたま壊れている場合への対処
					__int64 range = liSize.QuadPart - 188 * 16 * this->seekJitter;
					__int64 pos = range / 2 / 188 * 188;
					//ここは頻繁に呼ばれると高負荷に見えるが、ファイルキャッシュがよく効く条件なのでさほどでもない
					for( ; range > 256 * 1024; range /= 2 ){
						if( IsDataAvailable(file, pos, &packetInit) ){
							pos += range / 4 / 188 * 188;
						}else{
							pos -= range / 4 / 188 * 188;
						}
					}
					//安定のため有効なデータの境目からさらに512KBだけ手前にする
					liSize.QuadPart = max(pos - range / 2 - 512 * 1024, 0);
				}
				if( file != this->seekFile ){
					CloseHandle(file);
				}
				return liSize.QuadPart;
			}
		}
	}
	return 0;
}
// Registers a callback function
void WirelessDevice::RegisterWatcher(void *target, WirelessDeviceWatcher function, void *parameter)
{
    this->target = target;
    this->parameter = parameter;
    this->function = function;
    if ((function != NULL) && IsDataAvailable())
        NewData();
}
void MythSocket::CallReadyReadHandler(void)
{
    // Because the connection to this is a queued connection the
    // data may have already been read by the time this is called
    // so we check that there is still data to read before calling
    // the callback.
    if (IsDataAvailable())
    {
        LOG(VB_SOCKET, LOG_DEBUG, LOC +
            "calling m_callback->readyRead()");
        m_callback->readyRead(this);
    }
}
Exemple #5
0
/*
 * This method is used to wait for data to become available in incoming queue 
 * and then read all data into single Data object which is given as parameter
 */
DWORD IPCommPlugin::ReceiveWait(Data** data_out, long timeout)
{
    long elapsed = 0;
    while (elapsed < timeout && !IsDataAvailable())
    {
        elapsed += 25;
        Sleep(25);
    }
    if (elapsed >= timeout)
    {
        return ERR_DG_COMM_DATA_RECV_TIMEOUT;
    }
    return Receive(data_out, timeout);
}
Exemple #6
0
bool CLimitLess::GetV6BridgeID()
{
	m_BridgeID_1 = m_BridgeID_2 = 0;
	int totRetries = 0;
	sendto(m_RemoteSocket, (const char*)&V6_GetSessionID, sizeof(V6_GetSessionID), 0, (struct sockaddr*)&m_stRemoteDestAddr, sizeof(sockaddr_in));

	while (totRetries < v6_repeats)
	{
		if (!IsDataAvailable(m_RemoteSocket))
		{
			totRetries++;
			sendto(m_RemoteSocket, (const char*)&V6_GetSessionID, sizeof(V6_GetSessionID), 0, (struct sockaddr*)&m_stRemoteDestAddr, sizeof(sockaddr_in));
			continue;
		}
		uint8_t rbuffer[1024];
		sockaddr_in si_other;
		socklen_t slen = sizeof(sockaddr_in);
		int trecv = recvfrom(m_RemoteSocket, (char*)&rbuffer, sizeof(rbuffer), 0, (struct sockaddr*)&si_other, &slen);
		if (trecv < 1)
		{
			return false;
		}
		if (trecv != 0x16)
			return false;
		if ((rbuffer[0x00] != 0x28) || (rbuffer[0x15] != 0x00))
			return false;
		uint8_t mac_1 = rbuffer[0x07];
		uint8_t mac_2 = rbuffer[0x08];
		uint8_t mac_3 = rbuffer[0x09];
		uint8_t mac_4 = rbuffer[0x0A];
		uint8_t mac_5 = rbuffer[0x0B];
		uint8_t mac_6 = rbuffer[0x0C];
		m_BridgeID_1 = rbuffer[0x13];
		m_BridgeID_2 = rbuffer[0x14];
		return true;
	}
	return false;
}
bool ODDecodeBlockFile::IsSummaryAvailable()
{
    return IsDataAvailable();
}
FArchive* FHttpNetworkReplayStreamer::GetStreamingArchive()
{
	return ( StreamArchive.IsSaving() || IsDataAvailable() ) ? &StreamArchive : NULL;
}
Exemple #9
0
void Measure(OutputChannel *outputs,int numoutputs)
{
	DataSource *sources[numoutputs];
	int numsources=0;

	for(int i=0;i<numoutputs;i++)
	{
		bool found=false;
		for(int j=0;j<numsources;j++)
		{
			if(outputs[i].source==sources[j]) { found=true; break; }
		}

		if(!found)
		{
			sources[numsources]=outputs[i].source;
			numsources++;
		}
	}

	for(;;)
	{
		bool didupdate=false;
		while(!didupdate)
		{
			for(int i=0;i<numsources;i++)
			{
				if(IsDataAvailable(sources[i]))
				{
					SampleData(sources[i]);
					if(IsDataSourceImportant(sources[i])) didupdate=true;

					for(int j=0;j<numoutputs;j++)
					{
						if(outputs[j].source==sources[i] && outputs[j].accumulates)
						{
							double value=GetData(outputs[j].source,outputs[j].channel);
							outputs[j].accumulator+=value;
						}
					}
				}
			}
		}
		FILE *fp;
		fp = fopen("power.log","a");
		for(int i=0;i<numoutputs;i++)
		{
			if(i!=0) printf(",");

			if(outputs[i].accumulates)
			{
				printf(outputs[i].format,outputs[i].accumulator*outputs[i].scalefactor);
				fprintf(fp,outputs[i].format,outputs[i].accumulator*outputs[i].scalefactor);
			}
			else
			{
				double value=GetData(outputs[i].source,outputs[i].channel);
				printf(outputs[i].format,value*outputs[i].scalefactor);
				fprintf(fp,outputs[i].format,value*outputs[i].scalefactor);
			}
		}
		
		printf("\n");
		fprintf(fp,"\n");
		fclose(fp);
	}
}
Exemple #10
0
bool CLimitLess::SendV6Command(const uint8_t *pCmd)
{
	if (m_BridgeID_1 == 0)
	{
		//No Bridge ID received yet, try getting it
		if (!GetV6BridgeID())
			return false;
	}
	uint8_t OutBuffer[100];
	int wPointer = 0;
	memcpy(OutBuffer + wPointer, V6_PreAmble, sizeof(V6_PreAmble)); wPointer += sizeof(V6_PreAmble);
	OutBuffer[wPointer++] = m_BridgeID_1;
	OutBuffer[wPointer++] = m_BridgeID_2;
	OutBuffer[wPointer++] = 0x00;
	OutBuffer[wPointer++] = (uint8_t)(m_CommandCntr++);
	OutBuffer[wPointer++] = 0x00;

	int wPointerCmd = wPointer;
	memcpy(OutBuffer + wPointer, pCmd, 10); wPointer += 10;

	OutBuffer[wPointer++] = 0x00;

	//Calculate checksum
	uint8_t crc = 0;
	for (int ii = 0; ii < wPointer- wPointerCmd; ii++)
		crc = (crc + OutBuffer[wPointerCmd+ii]) & 0xFF;
	OutBuffer[wPointer++] = crc;

	sendto(m_RemoteSocket, (const char*)&OutBuffer, wPointer, 0, (struct sockaddr*)&m_stRemoteDestAddr, sizeof(sockaddr_in));
//	return true;
	int totRetries = 0;
	while (totRetries < v6_repeats)
	{
		if (!IsDataAvailable(m_RemoteSocket))
		{
			sendto(m_RemoteSocket, (const char*)&OutBuffer, wPointer, 0, (struct sockaddr*)&m_stRemoteDestAddr, sizeof(sockaddr_in));
			totRetries++;
			continue;
		}
		sockaddr_in si_other;
		socklen_t slen = sizeof(sockaddr_in);
		int trecv = recvfrom(m_RemoteSocket, (char*)&OutBuffer, sizeof(OutBuffer), 0, (struct sockaddr*)&si_other, &slen);
		if (trecv < 1)
			return false;
		if (OutBuffer[0x07] != 0x00)
		{
			//Maybe the Bridge was turned off, try getting the ID again
			if (GetV6BridgeID())
			{
				sendto(m_RemoteSocket, (const char*)&OutBuffer, wPointer, 0, (struct sockaddr*)&m_stRemoteDestAddr, sizeof(sockaddr_in));
				return (IsDataAvailable(m_RemoteSocket));
			}
			else
			{
				_log.Log(LOG_ERROR, "AppLamp: Invalid command send to Bridge!...");
			}
			return false;
		}
		return true;
	}
	_log.Log(LOG_ERROR, "AppLamp: Error sending command to Bridge!...");
	return false;
}