コード例 #1
0
ファイル: cmsg-test.cpp プロジェクト: abelepereira/stcrypt
void EncodeAndDecodeMessage(LPWSTR pwszSignerName)
{
    CRYPT_DATA_BLOB EncodedBlob;

    if(EncodeMessage(&EncodedBlob, pwszSignerName))
    {
        DecodeMessage(&EncodedBlob, pwszSignerName);
    }
}
コード例 #2
0
ファイル: CCliReq.cpp プロジェクト: Ntels-sup/SRC_ATOM_BE
int CCliReq::DecodeMessage(std::vector<char>& a_vecData)
{
	int nRet = 0;
	std::string  strPayload;

	strPayload = &a_vecData[0];

	nRet = DecodeMessage(strPayload);

	return nRet;
}
コード例 #3
0
ファイル: decodeIMDoc.cpp プロジェクト: paulhiggs/decode1
BOOL CDecodeIMDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
	CUserInputDlg userInputDlg;
	userInputDlg.m_UserInput = getLastMessage();
	if (userInputDlg.DoModal() == IDOK)
		DecodeMessage(userInputDlg.m_UserInput);

	return TRUE;
}
コード例 #4
0
//--------------------------------------------------------------
//  Read list of actions
//---------------------------------------------------------------
void CGaugeAction::ReadActions(SStream *str)
{ char txt[128];
  int na = 0;
  ReadInt(&na,str);
  while (na--)
  { ReadString(txt,128,str);
    BASE_ACT *a = new BASE_ACT();
    vact.push_back(a);
    if (DecodeFrame  (txt,a))   continue;
    if (DecodeMessage(txt,a))   continue;
    gtfo("Bad Gauge action");
  }
  return;
}
コード例 #5
0
ファイル: cmsg-test.cpp プロジェクト: abelepereira/stcrypt
void msg_test(wchar_t const*const subject_str){



	CRYPT_DATA_BLOB data_blob = { 0 };

	EncodeMessage(&data_blob, const_cast<wchar_t*>( subject_str) );

	std::ofstream o_cert( "c:\\temp\\signed_message.p7b", std::ios_base::out | std::ios_base::binary );
	o_cert.write( reinterpret_cast<char const*>(data_blob.pbData), data_blob.cbData );
	o_cert.flush();
	assert( !o_cert.bad() );

	DecodeMessage(&data_blob, const_cast<wchar_t*>( subject_str) );


}
コード例 #6
0
ファイル: NazaGPS.cpp プロジェクト: racerxdl/openquadlog
uint8_t NazaGPS::CheckData()	{
#ifdef READ_NAZA
	if(Serial1.available())	{
		/*
		 *	Resets the current status pin states.
		 */
		digitalWrite(CHKSUM_ERROR_PIN, LOW);
		digitalWrite(PACKET_OK_PIN, LOW);


		if(buffpos < 2)		{												//	If we dont have the header bytes, we will just read.
			buffer[buffpos] = Serial1.read();
			buffpos ++;
		}else{
			if(buffer[0] == 0x55 && buffer[1] == 0xAA)	{					//	Checks if we have the correct heading
				if(buffpos < 4)	{											//	We need 4 bytes. Head + ID + Size
					buffer[buffpos] = Serial1.read();
					buffpos ++;
				}else{
					payloadsize = buffer[3];								//	Size is the 4th byte
					buffer[buffpos] = Serial1.read();
					buffpos ++;
					if(buffpos == payloadsize+6)	{						//	Ok, so we have all data
						CalcChecksum();										//	Calculate the checksum
						if(CompareChecksum(&buffer[buffpos-2]))		{		// 	Checksum OK
							DecodeMessage(&buffer[4], buffer[2], buffer[3]);//	Decode the message and save the data
							digitalWrite(PACKET_OK_PIN, HIGH);
							buffpos = 0;
							return 1;
						}else{												//	Invalid Checksum. Discard all data.
							buffpos = 0;
							digitalWrite(CHKSUM_ERROR_PIN, HIGH);
						}
					}
				}
			}else{															// Wrong head, lets clean and restart
				buffpos = 0;
				buffer[buffpos] = Serial1.read();
				buffpos++;
			}
		}
	}
#endif
	return 0;
}
コード例 #7
0
ファイル: GPS.cpp プロジェクト: jlwegene/Autonomous-Car
void GPS::RxIrqHandler(void)
{
    char in;
    while(RawSerial::readable())
    {
        in = RawSerial::getc();
        if(in == START_CHAR)
        {
            insertIndex = 0;
            RxMessageBuffer.data[(insertIndex++)%RX_BUFFER_SIZE] = in;
        }
        else if(in == END_CHAR)
        {
            RxMessageBuffer.data[(insertIndex++)%RX_BUFFER_SIZE] = 0;
            DecodeMessage(RxMessageBuffer,info);
        }
        else
            RxMessageBuffer.data[(insertIndex++)%RX_BUFFER_SIZE] = in;
    }
}
コード例 #8
0
char *getMsgString(int messageID) {
    char *value, *v2 = NULL;
    char *key = messages[0].key;
    char *defaultMessage = messages[0].message;
    int i, len, len2;
    twchar_t wArray[MAXPATHLEN];

    len = sizeof(messages)/sizeof(messages[0]);
    for (i=0; i<len; i++) {
	if (messages[i].id == messageID) {
	    key = messages[i].key;
	    defaultMessage = messages[i].message;
            break;
        }
    }

    if (msgs_inProgress) {
	/* double fault - error generating error msg return default*/
	return defaultMessage;
    }
    msgs_inProgress = TRUE;

    if (!msgs_initialized) {
	initializeMessages(sysGetLocaleStr());
	msgs_initialized = TRUE;
    }

    value = GetPropertyValue(MsgFileHead, key);
    if (value == NULL) {
	value = defaultMessage;
    }
    len2 = DecodeMessage(value, wArray);
    v2 = sysWideCharToMBCS(wArray, len2);
    msgs_inProgress = FALSE;

    if (v2 == NULL) {
      return defaultMessage;
    } else {
      return v2;
    }
}
コード例 #9
0
ファイル: DlgLogAndDecode.cpp プロジェクト: paulhiggs/decode1
/////////////////////////////////////////////////////////////////////////////
// CDlgLogAndDecode message handlers
DWORD WINAPI StartLogging(LPVOID lpParameter) 
{
	bool	loopDone = false;
	DWORD	dwWaitResult;
	char	rBuf[ 2048 ], tBuf[ 20 ];
	int		len;
	
	sLogThreadParams *p = (sLogThreadParams *)lpParameter;
	CDalsuRichEdit *eCtrl = p->m_pDalRich;

	while ( !loopDone ) {
		dwWaitResult = WSAWaitForMultipleEvents(cntEvents, p->events, FALSE, WSA_INFINITE, TRUE);
		switch ( dwWaitResult )
		{
			case (WSA_WAIT_EVENT_0 + eNetworkEvent):
				len = recvfrom( p->sRecv, rBuf, sizeof(rBuf), 0, NULL, NULL );
				rBuf[len] = '\0';
				StripCRLF( rBuf );
				time_t ltime;
				time( &ltime );
				struct tm now;
				memcpy( &now, localtime( &ltime ), sizeof(now) );
				sprintf( tBuf, "(%02d:%02d:%02d) ", now.tm_hour, now.tm_min, now.tm_sec );
	
				eCtrl->AddText(tBuf,crBlue);
				eCtrl->AddText(rBuf,crBlue);
				eCtrl->AddText("\n",crBlue);
//				cout << tBuf << rBuf << endl << flush;

#ifdef DO_MESSAGEPARSE
				if ( decode )
					DecodeMessage( rBuf );
#endif
				break;
			case (WSA_WAIT_EVENT_0 + eAbortEvent):
				eCtrl->AddText("Stopping...\n",crBlue);
				loopDone = true;
				break;
			case (WSA_WAIT_EVENT_0 + eKeypressEvent):
/*				switch ( toupper(chKeyHit) ) 
				{
					case 'L':
						// toggle program logging
						additionalLogging = !additionalLogging;
						cout << TIMEPAD << "Additional logging turned " << ( additionalLogging ? "ON" : "OFF" ) << endl;
						break;
					case 'M':
						// record a marker in the file
						break;
					case 'C':
						// close the log file
						break;
					case 'O':
						//open the log file
						break;
					case 'Q':
						// key press to quit the application
						loopdone = true;
						break;
				}*/
				break;
			default:
				sprintf(rBuf,"Error in event wait...(err=%d)",WSAGetLastError());
				eCtrl->AddText(rBuf,crRed);
				loopDone = true;
				break;
		}
	}
	return 0;
}
コード例 #10
0
void OneBitSliding(std::string message) {
	std::vector<std::string> incomingFrames;
	std::vector<bool> outgoingFrames = StringToBits(message);
	int outgoingFrameTotal = outgoingFrames.size();
	int outgoingFrame = 0;
	int incomingFramesLastSize = -1;
	int incomingFramesTotal = -1;
	int incomingFrame = -1;
	int incomingLastFrame = -1;
	int incomingAckFrame = -1;
	int pendingAck = -1;
	std::string incomingMessage = "";
	std::string incomingData = "";
	
	printf("Attempt To Send.\n");
	while (incomingLastFrame < incomingFramesTotal || outgoingFrame < outgoingFrameTotal) {
		bool isOutgoingData = false;
		printf("LastFrame: %d/%d Outgoing: %d/%d\n", incomingLastFrame, incomingFramesTotal, outgoingFrame, outgoingFrameTotal);
		
		// Send message. Wait for response.
		std::string outgoingData = "-1";
		if (outgoingFrame < outgoingFrameTotal - 1) {
			isOutgoingData = true;
			if (outgoingFrames[outgoingFrame]) outgoingData = "1";
			else outgoingData = "0";
		}
		
		if (isOutgoingData || pendingAck != -1) {
			Send(outgoingData, outgoingFrame, outgoingFrameTotal, pendingAck);
			pendingAck = -1;
		}
		
		incomingMessage = Listen();
		
		// If incoming message is empty, no message received. We must resend last message.
		if (incomingMessage.empty()) {
			// Only resend if we weren't already finished sending. Otherwise, we are just acknowledging incoming messages.
			//printf("Receive Failed.\n");
			continue;
		}
		else {
			// Decode message.
			DecodeMessage(incomingMessage, incomingFrame, incomingFramesTotal, incomingData, incomingAckFrame);
			//printf("Incoming Message: %s\nIncoming Frame #: %d/%d\nIncomingData: %s\nIncoming Ack Frame: %i\n\n\n", incomingMessage.c_str(), incomingFrame, incomingFramesTotal, incomingData.c_str(), incomingAckFrame);
			// If frame acknowledge is frame sent, increase outgoing frame
			if (incomingAckFrame != -1 && incomingAckFrame == outgoingFrame) {
				outgoingFrame++;
			}
			
			if (incomingFramesLastSize < incomingFramesTotal) {
				incomingFrames.resize(incomingFramesTotal);
				incomingFramesLastSize = incomingFramesTotal;
			}
			
			if (incomingFrame != -1 && incomingFrame < incomingFramesTotal) {
				incomingFrames[incomingFrame] = incomingData;
			}
			
			if (incomingFrame != -1) {
				incomingLastFrame = incomingFrame;
			}
			
			pendingAck = incomingFrame;
		}
	}
	
	// Convert message to string
	std::vector<bool> bits(32);
	int counter = 0;
	std::string output;
	std::string line = "";
	
	for (int i = 0; i < incomingFrames.size(); i++) {
		if (counter == 31) {
			//printf("Decoded: %s", (char)ToInt(bits));
			bits[counter++] = (incomingFrames[i] == "1");
			line += (incomingFrames[i] == "1") ? "1" : "0";
			printf("Char: %c %s %d\n", (char)ToInt(bits), line.c_str(), ToInt(bits));
			line = "";
			output += (char)ToInt(bits);
			counter = 0;
		}
		else {
			bits[counter++] = (incomingFrames[i] == "1");
			line += (incomingFrames[i] == "1") ? "1" : "0";
		}
	}
	//printf("Raw Message Received: \n%s \n", frames.c_str());
	printf("Message Received: %s \n", output.c_str());
}