void process_input(char *recvbuf, int recv_buf_cnt, int* csock) 
{

	char replybuf[1024]={'\0'};
	printf("%s",recvbuf);
	//printf("mahendar Reddy\n");
	int Arr_decode[200];
	int length = DecodeBuffer(recvbuf, Arr_decode);
	loadtoMazeValues(Arr_decode, length);
	printf("m=%d\tn=%d\n", m, n);
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			printf("%d\t", Arr[i][j]);
		}
		printf("\n");
	}
	printf("a1=%d\tb1=%d\ta2=%d\tb2=%d\n", a1, b1, a2, b2);
	int flag = ispathexist(a1, b1, a2, b2);
	char buffer[256];
	if (flag == 1)
	{
		converStringtoresultBuffer(buffer);
	}
	else{
		addnumber(0, buffer);
	}
	printf("%s", buffer);
	replyto_client(buffer, csock);
	replybuf[0] = '\0';
}
Ejemplo n.º 2
0
CSyncPipeInBuffer::EProcessRecvDataResult CSyncPipeInBuffer::InBufferTellAddedDataSize(size_t stNewDataSize)
{
	if( m_bDecompressData )
	{
		if( !DecodeBuffer( m_CompressedBuffer, stNewDataSize ) )
			return ePRDR_Nothing;

		return DecompressedData();
	}
	else
	{	
		if( !DecodeBuffer( m_Buffer, stNewDataSize ) )
			return ePRDR_Nothing;

		return m_Buffer.m_stDataSize > 0 ? ePRDR_NewData : ePRDR_Nothing;
	}
}
Ejemplo n.º 3
0
//---------------------------------------------------------------------------
void TfrmExport::WorkEvent(int aEvIndex, TBEvent *aBaseEvent, TBEvent *aEvent)
{
    // ----- Имя ескпортируемой директории ------
    aEvent->ExportFolderName = IntToStr(aBaseEvent->year ) + "." + IntToStr(aBaseEvent->month) + "." + IntToStr(aBaseEvent->day  ) + "_" +
                               IntToStr(aBaseEvent->hour ) + "." + IntToStr(aBaseEvent->min  ) + "." + IntToStr(aBaseEvent->sec  );


    int  CountTryReadData  = 0;
    int  CountTryIDCorrect = 0;
    char MessBuff[1024];

gRepeat:
    aEvent->isCorrectEvent = true;
    // ----- Читаем поток данных ----
    frmMain->eCOMText->Text = "bin_read " + IntToStr(aEvIndex);
    frmMain->bSendCommandClick(NULL);

    // ------------------------------
    if ( DecodeBuffer(aEvent, BlackBox->ReadBuffer) == false )
    {
        CountTryReadData++;
        aEvent->isCorrectEvent = false;
        if ( CountTryReadData >= 3 ) {
            sprintf(MessBuff, "Packet length error! Try to export event %d again!", aEvIndex);
            MessageBox(Handle, MessBuff, "MDRS - Error", MB_OK|MB_ICONERROR|MB_TASKMODAL);
            return;
        }
        goto gRepeat;
    }

    // коррекция входного буферра данных ----
    Correct_DataBuffer(aEvent);

    CountTryReadData = 0;

    // ------ Проверка на последовательность индексов в пакете данных --------
    if ( CheckCorrectIDCounter(aEvent) == false )
    {
        FILE *h_file = fopen(LogFileName, "at");
        fprintf(h_file, "\t\t\t\t\t\t\t\t\tStep number check error!\n");
        fclose(h_file);
        // -----------
        aEvent->isCorrectEvent = false;
        // -----------
        CountTryIDCorrect++;
        if ( CountTryIDCorrect >= 2 ) {
            sprintf(MessBuff, "Step number check error!  Try to export event %d again!", aEvIndex);
            MessageBox(Handle, MessBuff, "MDRS - Error", MB_OK|MB_ICONERROR|MB_TASKMODAL);
            return;
        }
        goto gRepeat;
    }

    // сохранняем данные на диск ----
    Save_DataEvent_to_Disk(aEvent, aEvIndex);
}
JNIEXPORT jint JNICALL Java_com_example_raspmusicstationclient_IPDecodeFromAudio_DecodeAudioBuffer
  (JNIEnv *env, jclass, jshortArray buffer)
{
	jshort *array;
	array = env->GetShortArrayElements( buffer, NULL);
	if(array == NULL){
		return -1;
	}

  short values[2];
  values[0]=DecodeBuffer(array);
  values[1]=DecodeBuffer(array+Dec_Window);

  env->ReleaseShortArrayElements(buffer, array, 0);

  int value=*(int*)(values);

  return value;
}
bool Ms3dxFileStreamDecoder::Read(void* bBuffer, DWORD dwMaxBufferLength, DWORD& dwBytesRead)
{
    bool bRet = m_spStream->Read(bBuffer, dwMaxBufferLength, dwBytesRead);

    if (!bRet || dwBytesRead == 0)
        return bRet;

    // decode
    BYTE* pBuffer = reinterpret_cast<BYTE*>(bBuffer);
    DecodeBuffer(pBuffer, dwBytesRead);

    return bRet;
}
LLFloaterMessageLogItem::LLFloaterMessageLogItem(LLMessageLogEntry entry)
:	LLMessageLogEntry(entry.mType, entry.mFromHost, entry.mToHost, entry.mData, entry.mDataSize)
{
	if(!sTemplateMessageReader)
	{
		sTemplateMessageReader = new LLTemplateMessageReader(gMessageSystem->mMessageNumbers);
	}
	mID.generate();
	mSequenceID = 0;
	if(mType == TEMPLATE)
	{
		BOOL decode_invalid = FALSE;
		S32 decode_len = mDataSize;
		std::vector<U8> DecodeBuffer(MAX_PACKET_LEN,0);
		memcpy(&(DecodeBuffer[0]),&(mData[0]),decode_len);
		U8* decodep = &(DecodeBuffer[0]);
		mFlags = DecodeBuffer[0];
		gMessageSystem->zeroCodeExpand(&decodep, &decode_len);
		if(decode_len < 7)
			decode_invalid = TRUE;
		else
		{
			mSequenceID = ntohl(*((U32*)(&decodep[1])));
			sTemplateMessageReader->clearMessage();
			if(!sTemplateMessageReader->validateMessage(decodep, decode_len, mFromHost, TRUE))
				decode_invalid = TRUE;
			else
			{
				if(!sTemplateMessageReader->decodeData(decodep, mFromHost, true))
					decode_invalid = TRUE;
				else
				{
					LLMessageTemplate* temp = sTemplateMessageReader->mCurrentRMessageTemplate;
					mName = temp->mName;
					mSummary = "";
					
					if(mFlags)
					{
						mSummary.append(" [ ");
						if(mFlags & LL_ZERO_CODE_FLAG)
							mSummary.append(" Zer ");
						if(mFlags & LL_RELIABLE_FLAG)
							mSummary.append(" Rel ");
						if(mFlags & LL_RESENT_FLAG)
							mSummary.append(" Rsd ");
						if(mFlags & LL_ACK_FLAG)
							mSummary.append(" Ack ");
						mSummary.append(" ] ");
					}
					
					LLMessageTemplate::message_block_map_t::iterator blocks_end = temp->mMemberBlocks.end();
					for (LLMessageTemplate::message_block_map_t::iterator blocks_iter = temp->mMemberBlocks.begin();
						 blocks_iter != blocks_end; ++blocks_iter)
					{
						LLMessageBlock* block = (*blocks_iter);
						const char* block_name = block->mName;
						S32 num_blocks = sTemplateMessageReader->getNumberOfBlocks(block_name);
						if(!num_blocks)
							mSummary.append(" { } ");
						else if(num_blocks > 1)
							mSummary.append(llformat(" %s [ %d ] { ... } ", block_name, num_blocks));
						else for(S32 i = 0; i < 1; i++)
						{
							mSummary.append(" { ");
							LLMessageBlock::message_variable_map_t::iterator var_end = block->mMemberVariables.end();
							for (LLMessageBlock::message_variable_map_t::iterator var_iter = block->mMemberVariables.begin();
								 var_iter != var_end; ++var_iter)
							{
								LLMessageVariable* variable = (*var_iter);
								const char* var_name = variable->getName();
								BOOL returned_hex;
								std::string value = getString(sTemplateMessageReader, block_name, i, var_name, variable->getType(), returned_hex, TRUE);
								mSummary.append(llformat(" %s=%s ", var_name, value.c_str()));
							}
							mSummary.append(" } ");
							if(mSummary.length() > 255) break;
						}
						if(mSummary.length() > 255)
						{
							mSummary.append(" ... ");
							break;
						}
					} // blocks_iter
				} // decode_valid
			}
		}
		if(decode_invalid)
		{
			mName = "Invalid";
			mSummary = "";
			for(S32 i = 0; i < mDataSize; i++)
				mSummary.append(llformat("%02X ", mData[i]));
		}
	}
	else // not template
	{
		mName = "SOMETHING ELSE";
		mSummary = "TODO: SOMETHING ELSE";
	}
}
std::string LLFloaterMessageLogItem::getFull(BOOL show_header)
{
	std::string full("");
	if(mType == TEMPLATE)
	{
		BOOL decode_invalid = FALSE;
		S32 decode_len = mDataSize;
		std::vector<U8> DecodeBuffer(MAX_PACKET_LEN,0);
		memcpy(&(DecodeBuffer[0]),&(mData[0]),decode_len);
		U8* decodep = &(DecodeBuffer[0]);
		gMessageSystem->zeroCodeExpand(&decodep, &decode_len);
		if(decode_len < 7)
			decode_invalid = TRUE;
		else
		{
			sTemplateMessageReader->clearMessage();
			if(!sTemplateMessageReader->validateMessage(decodep, decode_len, mFromHost, TRUE))
				decode_invalid = TRUE;
			else
			{
				if(!sTemplateMessageReader->decodeData(decodep, mFromHost, TRUE))
					decode_invalid = TRUE;
				else
				{
					LLMessageTemplate* temp = sTemplateMessageReader->mCurrentRMessageTemplate;
					full.append(isOutgoing() ? "out " : "in ");
					full.append(llformat("%s\n", temp->mName));
					if(show_header)
					{
						full.append("[Header]\n");
						full.append(llformat("SequenceID = %u\n", mSequenceID));
						full.append(llformat("LL_ZERO_CODE_FLAG = %s\n", (mFlags & LL_ZERO_CODE_FLAG) ? "True" : "False"));
						full.append(llformat("LL_RELIABLE_FLAG = %s\n", (mFlags & LL_RELIABLE_FLAG) ? "True" : "False"));
						full.append(llformat("LL_RESENT_FLAG = %s\n", (mFlags & LL_RESENT_FLAG) ? "True" : "False"));
						full.append(llformat("LL_ACK_FLAG = %s\n", (mFlags & LL_ACK_FLAG) ? "True" : "False"));
					}
					LLMessageTemplate::message_block_map_t::iterator blocks_end = temp->mMemberBlocks.end();
					for (LLMessageTemplate::message_block_map_t::iterator blocks_iter = temp->mMemberBlocks.begin();
						 blocks_iter != blocks_end; ++blocks_iter)
					{
						LLMessageBlock* block = (*blocks_iter);
						const char* block_name = block->mName;
						S32 num_blocks = sTemplateMessageReader->getNumberOfBlocks(block_name);
						for(S32 i = 0; i < num_blocks; i++)
						{
							full.append(llformat("[%s]\n", block->mName));
							LLMessageBlock::message_variable_map_t::iterator var_end = block->mMemberVariables.end();
							for (LLMessageBlock::message_variable_map_t::iterator var_iter = block->mMemberVariables.begin();
								 var_iter != var_end; ++var_iter)
							{
								LLMessageVariable* variable = (*var_iter);
								const char* var_name = variable->getName();
								BOOL returned_hex;
								std::string value = getString(sTemplateMessageReader, block_name, i, var_name, variable->getType(), returned_hex);
								if(returned_hex)
									full.append(llformat("%s =| ", var_name));
								else
									full.append(llformat("%s = ", var_name));
								// llformat has a 1024 char limit!?
								full.append(value);
								full.append("\n");
							}
						}
					} // blocks_iter
				} // decode_valid
			}
		}
		if(decode_invalid)
		{
			full = isOutgoing() ? "out" : "in";
			full.append("\n");
			for(S32 i = 0; i < mDataSize; i++)
				full.append(llformat("%02X ", mData[i]));
		}
	}
	else // not template
	{
		full = "FIXME";
	}
	return full;
}
Ejemplo n.º 8
0
int mainprog(void)
{	int res=0,return_len;
	TMxMsg *msg=NULL,*msg5=NULL,*msg6=NULL;
	int nfds;
	fd_set rfds, afds;
	struct timeval to;

	nfds = getdtablesize();
	FD_ZERO(&afds);
	FD_SET(MXsock, &afds);

	res=OpenDb(DBHOST,USER,PASS,DB);
	if (res<0) {Log(LOG_CRIT,"OpenDb (%d) : %s\n",res,MysqlErrorMsg);return(res);}
	else
	{
		res=BuildTags(&Tags);
		if (res<=0)
		{
			Log(LOG_WARNING,"Nothing to do\n");
			Terminated=1;
		} else
		{
			int i;
			TAGSimplex *Tag;
			for(i=0;i<Tags.Count;i++)
			{
				Tag=Tags.Data[i];
				Log(LOG_DEBUG,"%d : %s adresse : %d (%d)\n",i,Tag->TagName,Tag->Address,Tag->Bobine);
			}
		}
		//Terminated=1;
		bzero(&mybuffer,sizeof(mybuffer));
		while (!Terminated)
		{
			if (MXsock<0)
			{
				Log(LOG_INFO,"Attempting reconnection (%d connections lost)\n",connlost);
				MXsock=OpenSock(MXADDRESS,MXPORT);
				if (MXsock>=0)
				{
					Log(LOG_NOTICE,"Reconnection OK\n");
				}else
				{
					sleep(WAITTORECONNECT);
					Log(LOG_NOTICE,"Waiting before attempting reconnection (connections retries %d)\n",++connretries);
					continue;
				};
			}
			memcpy(&rfds, &afds, sizeof(rfds));
			to.tv_sec=UPDATERATE;
			to.tv_usec=0;
			switch (select(nfds, &rfds, 0, 0,&to))
			{
				case -1:if(errno == EINTR) continue;
					else Log(LOG_WARNING,"surveillance des descripteurs\n");
				case 0:	continue; // timeout
				default:
					if( FD_ISSET(MXsock, &rfds) )
					{
						return_len=read(MXsock,&inbuf,sizeof(inbuf));
						Log(LOG_DEBUG,"Recu  : %d\n",return_len);
						if (return_len>0)
						{	Addbuffer(&mybuffer,&inbuf,return_len);
							Log(LOG_DEBUG,"Com recu : %d buffersize =%d\n",return_len,mybuffer.Size);
							if (MsgInBuffer(&mybuffer)==0) // get a message
							{	if (CheckMsgOk(&mybuffer)==0) // Message well formatted
								{
									Log(LOG_DEBUG,"Entering DecodeBubber\n");
									msg=DecodeBuffer(&mybuffer);
									/*   */
									Affiche(msg);
									switch (msg->Funct)
									{
										case 3:
											Update(&Tags,msg);
											free(msg);
											break;
										case 4:
											switch (msg->SubFunct)
											{
												case 5:
												case 6:
													if ((msg->SubFunct==5)&&(msg5!=NULL))
													{
														Log(LOG_WARNING,"Reliquat de bobine\n");
														InsBobine(&Tags,msg5,msg6);
														if (msg5!=NULL) {free(msg5);msg5=NULL;};
														if (msg6!=NULL) {free(msg6);msg6=NULL;};
													}
													if (msg->SubFunct==5) msg5=msg;
													if (msg->SubFunct==6) msg6=msg;
													if ((msg5!=NULL)&&(msg6!=NULL))
													{
														Log(LOG_INFO,"Recu bobine\n");
														InsBobine(&Tags,msg5,msg6);
														if (msg5!=NULL) {free(msg5);msg5=NULL;};
														if (msg6!=NULL) {free(msg6);msg6=NULL;};
													}
													break;
												default:
													free(msg);
													break;
											}
											break;
										default:
											free(msg);
											break;
									}
									bzero(&mybuffer,sizeof(mybuffer));
									msg_ACK++;
									Log (LOG_INFO,"Msg recu OK : %d\n",msg_ACK);
								}else
								{
									bzero(&mybuffer,sizeof(mybuffer));
									Reply(MXsock,NAK);
									Log (LOG_NOTICE,"Msg recu mauvais: %d\n",msg_NACK++);
								}
							}else
							{ /* Erreur ?? */
								if (mybuffer.Size>=BufferMaxSize)
								{
									Log(LOG_WARNING,"******** Buffer sature ************\n");
									bzero(&mybuffer,sizeof(mybuffer));
								}
							}
						} else
						{
							close(MXsock);
							FD_CLR(MXsock,&afds);
							MXsock=-1;
							Log(LOG_WARNING,"Server connection lost !\n");
							continue;
						}
					}
			}
		}
		return(0);
		CloseDb;
	}
}
Ejemplo n.º 9
0
uint32 IFF8SVXFibonnaci::DecodeSampleData(PFile *file, PFile *file2, float *buffer, uint32 length, const APConverter_SampleFormat *convInfo)
{
	uint32 filled = 0;
	uint32 bufSize;
	uint32 todo;

	if (file2 == NULL)
		bufSize = BUFFER_SIZE;
	else
		bufSize = BUFFER_SIZE / 2;

	while (length > 0)
	{
		// Do we need to load some data from the file?
		if (samplesLeft < 2)
		{
			// Yes, do it
			if (file2 != NULL)
			{
				samplesLeft = GetFileData2(file2, decodeBuffer + bufSize, bufSize);

				if (samplesLeft == 0)
					break;			// End of file, stop filling

				samplesLeft += GetFileData1(file, decodeBuffer, samplesLeft);
			}
			else
			{
				samplesLeft = GetFileData1(file, decodeBuffer, bufSize);

				if (samplesLeft == 0)
					break;			// End of file, stop filling
			}

			offset = 0;
		}

		// Copy the sample data
		if (file2 == NULL)
		{
			// Mono sample
			//
			// Find the number of bytes to decode
			todo = min(length / 2, samplesLeft);

			// Should we get the start value?
			if (loadFirstBuf)
			{
				loadFirstBuf = false;
				startVal1    = decodeBuffer[offset + 1];
				offset      += 2;
				todo        -= 2;
				samplesLeft -= 2;
				*buffer++    = startVal1 / 128.0f;		// Store the value twice, so we get an even number to store in the buffer
				*buffer++    = startVal1 / 128.0f;
				length      -= 2;
				filled      += 2;
			}

			startVal1 = DecodeBuffer((uint8 *)decodeBuffer + offset, buffer, todo, startVal1, false);
			offset   += todo;
			buffer   += todo * 2;
		}
		else
		{
			// Stereo sample
			//
			// Find the number of bytes to decode
			todo = min(length / 2, samplesLeft) / 2;

			// Should we get the start value?
			if (loadFirstBuf)
			{
				loadFirstBuf = false;
				startVal1    = decodeBuffer[offset + 1];
				startVal2    = decodeBuffer[bufSize + offset + 1];
				offset      += 2;
				todo        -= 4;
				samplesLeft -= 4;
				*buffer++    = startVal1 / 128.0f;		// Store the value twice, so we get an even number to store in the buffer
				*buffer++    = startVal2 / 128.0f;
				*buffer++    = startVal1 / 128.0f;
				*buffer++    = startVal2 / 128.0f;
				length      -= 4;
				filled      += 4;
			}

			startVal1 = DecodeBuffer((uint8 *)decodeBuffer + offset, buffer, todo, startVal1, true);
			startVal2 = DecodeBuffer((uint8 *)decodeBuffer + bufSize + offset, buffer + 1, todo, startVal2, true);
			offset   += todo;
			todo     *= 2;
			buffer   += todo * 2;
		}

		// Update the counter variables
		length      -= todo * 2;
		filled      += todo * 2;
		samplesLeft -= todo;
	}

	return (filled);
}