bool Receiver::receiveData() { waitForBeginMessage(); rType = getMessageType(); bool endFlag= 0; if(strchr(validMessageTypes, rType) == NULL) { return false; } Serial.print(" Received valid type message "); Serial.print(rType); rCount = getMessageLength(); Serial.print (" message length is ") ; Serial.println(rCount); if(rCount < 0 || rCount > maxRL) { return false; } endFlag = getDataValues(); return endFlag; }
void Message::initialize(char *serializedMessage){ char *initialIndex = serializedMessage; readHeader(&serializedMessage); readData(&serializedMessage); #ifndef AVR if(serializedMessage - initialIndex != getMessageLength()) throw MESSAGE_LENGTH_ERROR; #endif }
MM::VOID MM::Assertion::toString(MM::String * buf, MM::UINT32 indent) { buf->space(indent); buf->append((MM::CHAR*)MM::Assertion::ASSERT_STR, MM::Assertion::ASSERT_LEN); buf->space(); name->toString(buf); buf->space(); buf->append(MM::Assertion::COLON_CHAR); buf->space(); exp->toString(buf); buf->space(); buf->append(msg, getMessageLength()); }
/* Fill tcpData array, return message length */ uint16_t waitTCPMessage_blocking() { uint16_t len; wait_for_message("+IPD,",0); wait_for_message(",",0); len = getMessageLength(); uint16_t t16; for(t16=0;t16 < len;t16++) { while(RingBuffer_GetCount(&Buffer) == 0); tcpData[t16] = RingBuffer_Remove(&Buffer); } wait_for_message("OK\r\n",10000); return len; }
bool Packet::deserialize(ByteArray& buffer) { _header = 0; _id = 0; _lengthType = 0; _length = 0; _data.clear(); BinaryReader reader(buffer); uint countReadedBytes = 0; if (reader.bytesAvailable() < sizeof(_header)) { return false; } _header = reader.readUShort(); _id = getMessageId(_header); _lengthType = getMessageLengthType(_header); countReadedBytes += sizeof(_header); if (reader.bytesAvailable() < _lengthType) { return false; } _length = getMessageLength(_lengthType, reader); countReadedBytes += _lengthType; if (reader.bytesAvailable() < _length) { return false; } _data = reader.readBytes(_length); countReadedBytes += _length; buffer.erase(buffer.begin(), buffer.begin() + countReadedBytes); return true; }
// Serialize the message struct into a string containing the RTSP message char* serializeRtspMessage(PRTSP_MESSAGE msg, int* serializedLength) { int size = getMessageLength(msg); char* serializedMessage; POPTION_ITEM current = msg->options; char statusCodeStr[16]; serializedMessage = malloc(size); if (serializedMessage == NULL) { return NULL; } if (msg->type == TYPE_REQUEST) { // command [space] strcpy(serializedMessage, msg->message.request.command); strcat(serializedMessage, " "); // target [space] strcat(serializedMessage, msg->message.request.target); strcat(serializedMessage, " "); // protocol \r\n strcat(serializedMessage, msg->protocol); strcat(serializedMessage, "\r\n"); } else { // protocol [space] strcpy(serializedMessage, msg->protocol); strcat(serializedMessage, " "); // status code [space] sprintf(statusCodeStr, "%d", msg->message.response.statusCode); strcat(serializedMessage, statusCodeStr); strcat(serializedMessage, " "); // status str\r\n strcat(serializedMessage, msg->message.response.statusString); strcat(serializedMessage, "\r\n"); } // option content\r\n while (current != NULL) { strcat(serializedMessage, current->option); strcat(serializedMessage, ": "); strcat(serializedMessage, current->content); strcat(serializedMessage, "\r\n"); current = current->next; } // Final \r\n strcat(serializedMessage, "\r\n"); // payload if (msg->payload != NULL) { int offset; // Find end of the RTSP message header for (offset = 0; serializedMessage[offset] != 0; offset++); // Add the payload after memcpy(&serializedMessage[offset], msg->payload, msg->payloadLength); *serializedLength = offset + msg->payloadLength; } else { *serializedLength = (int)strlen(serializedMessage); } return serializedMessage; }
void Message::writeHeader(char **serializedMessageIndex){ sprintf(*serializedMessageIndex,"%s%04d%04d%03d%01d%04d%04d", MESSAGE_HEAD_VALUE, getMessageLength(), messageID, revision, flags, to, from); (*serializedMessageIndex) = (*serializedMessageIndex) + MESSAGE_HEADER_LENGTH; }
BitmapPtr IEToolbar::generateShareBitmap(bool isHot) { const int textMargin = 3; const int bitmapHeight = 16; const int bitmapMargin = 2; const COLORREF grey = RGB(227, 232, 240); const COLORREF blue = RGB(57, 86, 149); // Set colors and plus bitmap UINT plusIconId = (isHot) ? IDB_SHARE_PLUS : IDB_SHARE_HOT_PLUS; COLORREF bkColor = (isHot) ? blue : grey; COLORREF bkFrameColor = (isHot) ? grey : blue; COLORREF txtColor = (isHot) ? grey : blue; // Load Plus bitmap and get its properties BITMAP bm; BitmapPtr plusIcon = loadBitmap(plusIconId); plusIcon->GetBitmap(&bm); int plusIconWidth = bm.bmWidth; int plusIconHeight = bm.bmHeight; // Create destination context CDC memDC; CFont font; CDC* deviceContext = CDC::FromHandle(::GetDC(0)); memDC.CreateCompatibleDC(deviceContext); setFont(&memDC, 14, _T("Sans Serif"), font); // Get message length in pixels String message = ResourceMessages::getMessage(kToolbarButtonShare); SIZE textSize = getMessageLength(message, font); // Create destination bitmap BitmapPtr bitmap(new CBitmap()); int bitmapWidth = 2 * textMargin + textSize.cx + 2 * bitmapMargin + plusIconWidth; bitmap->CreateCompatibleBitmap(deviceContext, bitmapWidth, bitmapHeight); memDC.SelectObject(getPtr(bitmap)); // Draw background with frame CRect frame(0, 0, bitmapWidth, bitmapHeight) ; memDC.FillSolidRect(&frame , bkFrameColor); CRect rectangle(1, 1, bitmapWidth - 1, bitmapHeight - 1) ; memDC.FillSolidRect(&rectangle , bkColor); // Draw message memDC.SetTextColor(txtColor); CRect textRect(1 + textMargin, 1, bitmapWidth - 1, bitmapHeight - 1) ; memDC.DrawText(message.c_str(), message.length(), textRect, DT_SINGLELINE | DT_VCENTER); // Draw plus bitmap CDC srcDC; srcDC.CreateCompatibleDC(NULL); srcDC.SelectObject(getPtr(plusIcon)); const BOOL bitBltResult = memDC.BitBlt(bitmapWidth - bitmapMargin - plusIconWidth, bitmapMargin, plusIconWidth, plusIconHeight, &srcDC, 0, 0, SRCCOPY); if (FALSE == bitBltResult) { throw Error("Failed to draw share button image/n"); } // Delete resources font.DeleteObject(); DeleteDC(srcDC); DeleteDC(memDC); return bitmap; }