/** * @param bValue - byte value to be written. * @param nCount - number of bytes to write. * @return number of written bytes. */ size_t COutputStream::WriteByte(unsigned char bValue, size_t nCount) { size_t nNumWritten = 0; while (nNumWritten < nCount) { if (! WriteByte(bValue)) break; ++nNumWritten; } return nNumWritten; }
void cProtocol132::SendBlockBreakAnim(int a_entityID, int a_BlockX, int a_BlockY, int a_BlockZ, char stage) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_BLOCK_BREAK_ANIM); WriteInt (a_entityID); WriteInt (a_BlockX); WriteInt (a_BlockY); WriteInt (a_BlockZ); WriteChar (stage); Flush(); }
void FileStream::SetLength(size_t Length) { #if defined(CPPEXCEPTIONS_ENABLED) if (_fileAccess == FileAccess::Read) throw CryptoProcessingException("FileStream:SetLength", "The file was opened as read only!"); #endif _fileStream.seekg(Length - 1, std::ios::beg); WriteByte(0); _fileStream.seekg(0, std::ios::beg); }
/** * @param arrBytes - array of bytes. * @param nCount - size of the array. * @return number of written bytes. */ size_t COutputStream::WriteBytes(const unsigned char* arrBytes, size_t nCount) { size_t nNumWritten = 0; while (nNumWritten < nCount) { if (! WriteByte(arrBytes[nNumWritten])) break; ++nNumWritten; } return nNumWritten; }
void cProtocol125::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_SPAWN_OBJECT); WriteInt (a_Vehicle.GetUniqueID()); WriteByte (a_VehicleType); WriteInt ((int)(a_Vehicle.GetPosX() * 32)); WriteInt ((int)(a_Vehicle.GetPosY() * 32)); WriteInt ((int)(a_Vehicle.GetPosZ() * 32)); WriteByte ((Byte)((a_Vehicle.GetPitch() / 360.f) * 256)); WriteByte ((Byte)((a_Vehicle.GetRotation() / 360.f) * 256)); WriteInt (a_VehicleSubType); if (a_VehicleSubType != 0) { WriteShort((short)(a_Vehicle.GetSpeedX() * 400)); WriteShort((short)(a_Vehicle.GetSpeedY() * 400)); WriteShort((short)(a_Vehicle.GetSpeedZ() * 400)); } Flush(); }
void cProtocol125::SendExplosion(double a_BlockX, double a_BlockY, double a_BlockZ, float a_Radius, const cVector3iArray & a_BlocksAffected, const Vector3d & a_PlayerMotion) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_EXPLOSION); WriteDouble (a_BlockX); WriteDouble (a_BlockY); WriteDouble (a_BlockZ); WriteFloat (a_Radius); WriteInt (a_BlocksAffected.size()); for (cVector3iArray::const_iterator itr = a_BlocksAffected.begin(); itr != a_BlocksAffected.end(); ++itr) { WriteByte ((Byte)(itr->x - a_BlockX)); WriteByte ((Byte)(itr->y - a_BlockY)); WriteByte ((Byte)(itr->z - a_BlockZ)); } WriteFloat ((float)a_PlayerMotion.x); WriteFloat ((float)a_PlayerMotion.y); WriteFloat ((float)a_PlayerMotion.z); Flush(); }
void cProtocol161::SendWindowOpen(char a_WindowID, char a_WindowType, const AString & a_WindowTitle, char a_NumSlots) { if (a_WindowType < 0) { // Do not send for inventory windows return; } cCSLock Lock(m_CSPacket); WriteByte (PACKET_WINDOW_OPEN); WriteByte (a_WindowID); WriteByte (a_WindowType); WriteString(a_WindowTitle); WriteByte (a_NumSlots); WriteByte (1); // Use title if (a_WindowType == 11) // horse / donkey { WriteInt(0); // Unknown value sent only when window type is 11 (horse / donkey) } Flush(); }
void cProtocol162::SendPlayerMaxSpeed(void) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENTITY_PROPERTIES); WriteInt(m_Client->GetPlayer()->GetUniqueID()); WriteInt(1); WriteString("generic.movementSpeed"); WriteDouble(m_Client->GetPlayer()->GetMaxSpeed()); WriteShort(0); Flush(); }
// // Write() // size_t JLSOutputStream::Write(BYTE* pdata, size_t cbyteLength) { _pdata = pdata; _cbyteLength = cbyteLength; WriteByte(0xFF); WriteByte(JPEG_SOI); for (size_t i = 0; i < _segments.size(); ++i) { _segments[i]->Write(this); } //_bCompare = false; WriteByte(0xFF); WriteByte(JPEG_EOI); return _cbyteOffset; }
Error i8250::write(s8 *buffer, Size size, Size offset) { Size bytes = 0; /* Write as much bytes as possible. */ while (ReadByte(base + LINESTATUS) & TXREADY && bytes < size) { WriteByte(base, buffer[bytes++]); } return bytes ? (Error) bytes : EAGAIN; }
/* WriteDataByte ** ** Synopsis: ** WriteDataByte(pBytes[idx]); ** Parameters: ** uint8_t bData - the data byte ** ** ** Return Values: ** void ** ** Errors: ** ** ** Description: ** Writes the specified byte as data. When the device is ready it sets the RS and writes byte. ** ** */ void LCDP::WriteDataByte(uint8_t bData) { // wait until LCD is not busy WaitUntilNotBusy(); // Set RS digitalWrite(m_rs_pin, HIGH); // Write command byte WriteByte(bData); }
/* WriteCommand ** ** Synopsis: ** WriteCommand(cmdLcdClear); ** Parameters: ** uint8_t bCmd - the command code byte ** ** ** Return Values: ** void ** ** Errors: ** ** ** Description: ** Writes the specified byte as command. When the device is ready it clears the RS and writes byte. ** ** */ void LCDP::WriteCommand(uint8_t bCmd) { // wait until LCD is not busy WaitUntilNotBusy(); // Clear RS digitalWrite(m_rs_pin, LOW); // Write command byte WriteByte(bCmd); }
void cProtocol125::SendThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ) { cCSLock Lock(m_CSPacket); WriteByte(PACKET_THUNDERBOLT); WriteInt (0x7fffffff); // Entity ID of the thunderbolt; we use a constant one WriteBool(true); // Unknown bool WriteInt (a_BlockX * 32); WriteInt (a_BlockY * 32); WriteInt (a_BlockZ * 32); Flush(); }
void cProtocol132::SendEncryptionKeyRequest(void) { cCSLock Lock(m_CSPacket); WriteByte(0xfd); WriteString(cRoot::Get()->GetServer()->GetServerID()); WriteShort((short)(cRoot::Get()->GetServer()->GetPublicKeyDER().size())); SendData(cRoot::Get()->GetServer()->GetPublicKeyDER().data(), cRoot::Get()->GetServer()->GetPublicKeyDER().size()); WriteShort(4); WriteInt((int)(intptr_t)this); // Using 'this' as the cryptographic nonce, so that we don't have to generate one each time :) Flush(); }
EdpPacket* PacketSavedataBinStr(const char* dst_devid, const char* desc_str, const uint8* bin_data, uint32 bin_len) { EdpPacket* pkg; uint32 remainlen; /* check arguments */ uint32 desc_len = mystrlen(desc_str); if (desc_len > (0x01 << 16) || bin_len > (3 * (0x01 << 20))) { /* desc < 2^16 && bin_len < 3M*/ return 0; } pkg = NewBuffer(); /* msg type */ WriteByte(pkg, SAVEDATA); if (dst_devid) { /* remain len */ remainlen = 1+(2+mystrlen(dst_devid))+1+(2+desc_len)+(4+bin_len); WriteRemainlen(pkg, remainlen); /* translate address flag */ WriteByte(pkg, 0x80); /* dst devid */ WriteStr(pkg, dst_devid); } else { /* remain len */ remainlen = 1+1+(2+desc_len)+(4+bin_len); WriteRemainlen(pkg, remainlen); /* translate address flag */ WriteByte(pkg, 0x00); } /* bin flag */ WriteByte(pkg, 0x02); /* desc */ WriteStr(pkg, desc_str); /* bin data */ WriteUint32(pkg, bin_len); WriteBytes(pkg, bin_data, bin_len); return pkg; }
STDMETHODIMP CScales::get_Weight(LONG* pVal) { // инициализируем возвращаемое значение *pVal = -1; // возвращаем текущее значение веса на индикаторе весов // если порт весов открыт if (m_CommPort != INVALID_HANDLE_VALUE) { // открываем лог-файл OpenLog(); // число попыток инициации обмена int nTryCount = 0; do { // отправляем запрос на начало обмена if (WriteByte(ENQ)) { // читаем и анализируем ответ BYTE nReq; if (ReadBytes(&nReq, 1) && (nReq == ACK)) { // посылаем команду запроса показаний веса if (WriteByte(DC1)) { // читаем ответ на команду BYTE nDc1Data[SCALES_ANSWER_LEN]; if (ReadBytes(nDc1Data, SCALES_ANSWER_LEN)) *pVal = DecodeScaleData(nDc1Data); } } } // увеличиваем счетчик попыток nTryCount++; } while ((nTryCount < MAX_TRY_COUNT) && (*pVal == -1)); // закрываем лог-файл CloseLog(); } return S_OK; }
void cProtocol132::SendSoundEffect(const AString & a_SoundName, int a_SrcX, int a_SrcY, int a_SrcZ, float a_Volume, float a_Pitch) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_SOUND_EFFECT); WriteString (a_SoundName); WriteInt (a_SrcX); WriteInt (a_SrcY); WriteInt (a_SrcZ); WriteFloat (a_Volume); WriteChar ((char)(a_Pitch * 63.0f)); Flush(); }
// all these sent values MUST have corresponding read values in CSQC (CSQC_Ent_Update() in main.c ) float Player_SendEntityToCSQC() { WriteByte(MSG_ENTITY, ENT_CSPLAYER); WriteByte(MSG_ENTITY, player.frame); //FIXME NEED COMPRESSION //WriteByte(MSG_ENTITY, player.movetype); -- not used, uncomment and delete this if needed //WriteByte(MSG_ENTITY, player.solid); -- not used, uncomment and delete this if needed //WriteString(MSG_ENTITY,player.model); -- not used, uncomment and delete this if needed //WriteByte(MSG_ENTITY, player.skeletonindex); -- DON'T SEND IT - it will break code driven animation WriteByte(MSG_ENTITY, player.modelindex); WriteByte(MSG_ENTITY, player.PersID); WriteShort(MSG_ENTITY, player.angles_x); WriteShort(MSG_ENTITY, player.angles_y); WriteShort(MSG_ENTITY, player.angles_z); WriteCoord(MSG_ENTITY, player.origin_x); WriteCoord(MSG_ENTITY, player.origin_y); WriteCoord(MSG_ENTITY, player.origin_z); WriteShort(MSG_ENTITY, player.velocity_x); WriteShort(MSG_ENTITY, player.velocity_y); WriteShort(MSG_ENTITY, player.velocity_z); return TRUE; }
void BeginStruct(const StructSig *sig) { WriteByte(Trace::TYPE_STRUCT); WriteUInt(sig->id); if (!lookup(structs, sig->id)) { WriteString(sig->name); WriteUInt(sig->num_members); for (unsigned i = 0; i < sig->num_members; ++i) { WriteString(sig->members[i]); } structs[sig->id] = true; } }
void cProtocol132::SendBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_BLOCK_ACTION); WriteInt (a_BlockX); WriteShort((short)a_BlockY); WriteInt (a_BlockZ); WriteChar (a_Byte1); WriteChar (a_Byte2); WriteShort(a_BlockType); Flush(); }
void cProtocol132::SendSoundEffect(const AString & a_SoundName, double a_X, double a_Y, double a_Z, float a_Volume, float a_Pitch) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_SOUND_EFFECT); WriteString (a_SoundName); WriteInt ((int)(a_X * 8.0)); WriteInt ((int)(a_Y * 8.0)); WriteInt ((int)(a_Z * 8.0)); WriteFloat (a_Volume); WriteChar ((char)(a_Pitch * 63.0f)); Flush(); }
void cProtocol125::SendEntityVelocity(const cEntity & a_Entity) { ASSERT(a_Entity.GetUniqueID() != m_Client->GetPlayer()->GetUniqueID()); // Must not send for self cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENTITY_VELOCITY); WriteInt (a_Entity.GetUniqueID()); WriteShort((short) (a_Entity.GetSpeedX() * 400)); //400 = 8000 / 20 WriteShort((short) (a_Entity.GetSpeedY() * 400)); WriteShort((short) (a_Entity.GetSpeedZ() * 400)); Flush(); }
uint8_t i2c_t::WriteBuf(uint8_t Addr, uint8_t *PW, uint16_t SzW) { if(Start() != 0) return 1; // Write Addr with Write bit (0) WriteByte(Addr<<1); if(!IsAcked()) { Stop(); Uart.Printf("Addr NACK\r"); return 2; } // Write data while(SzW--) { WriteByte(*PW++); if(!IsAcked()) { Stop(); Uart.Printf("NACK\r"); return 3; } } Stop(); return 0; }
void cProtocol125::SendWindowSlots(char a_WindowID, int a_NumItems, const cItem * a_Items) { WriteByte (PACKET_INVENTORY_WHOLE); WriteChar (a_WindowID); WriteShort((short)a_NumItems); for (int j = 0; j < a_NumItems; j++) { WriteItem(a_Items[j]); } Flush(); }
void cProtocol125::SendEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ) { ASSERT(a_Entity.GetUniqueID() != m_Client->GetPlayer()->GetUniqueID()); // Must not send for self cCSLock Lock(m_CSPacket); WriteByte(PACKET_ENT_REL_MOVE); WriteInt (a_Entity.GetUniqueID()); WriteChar(a_RelX); WriteChar(a_RelY); WriteChar(a_RelZ); Flush(); }
void cProtocol125::SendTeleportEntity(const cEntity & a_Entity) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_ENT_TELEPORT); WriteInt (a_Entity.GetUniqueID()); WriteInt ((int)(floor(a_Entity.GetPosX() * 32))); WriteInt ((int)(floor(a_Entity.GetPosY() * 32))); WriteInt ((int)(floor(a_Entity.GetPosZ() * 32))); WriteChar ((char)((a_Entity.GetYaw() / 360.f) * 256)); WriteChar ((char)((a_Entity.GetPitch() / 360.f) * 256)); Flush(); }
/** ****************************************************************************** ** Initialize the RTC's time registers and start counting operation (24 h mode). ** ** \pre I2C_Init() must be called before! ** ** \param punTime Pointer to initial time information (can be NULL to skip this) ** \param u8CtrlReg Value of the control register ** ** \retval ** - Ok Operation finished successfully ** - Error I²C error occurred *****************************************************************************/ en_result_t RtcExt_Init(un_rtc_ext_time_t* punTime, uint8_t u8CtrlReg) { en_result_t enResult; uint_fast8_t fu8Index; if (punTime != NULL) { for (fu8Index = 0; fu8Index < sizeof(punTime->au8TimeData); fu8Index++) { enResult = WriteByte(fu8Index, VALUE_TO_BCD8(punTime->au8TimeData[fu8Index])); if (enResult != Ok) { return enResult; } } } enResult = WriteByte(ADDRESS_CONTROL, u8CtrlReg); return enResult; }
// Write a word in little endian format bool CCPCBooster::WriteWord(const unsigned short val) { #if _WINDOWS unsigned long nbBytesSend = 0; BOOL fSuccess = WriteFile(_COMPortHandle, &val, 2, &nbBytesSend, NULL); return ((nbBytesSend == 2) && fSuccess); #else unsigned char byte1, byte2 ; byte1 = val / 256 ; byte2 = val % 256 ; WriteByte(byte1); WriteByte(byte2) ; return true ; #endif }
void cProtocol125::SendWeather(eWeather a_Weather) { cCSLock Lock(m_CSPacket); switch( a_Weather ) { case eWeather_Sunny: { WriteByte(PACKET_CHANGE_GAME_STATE); WriteByte(2); // Stop rain WriteByte(0); // Unused Flush(); break; } case eWeather_Rain: case eWeather_ThunderStorm: { WriteByte(PACKET_CHANGE_GAME_STATE); WriteByte(1); // Begin rain WriteByte(0); // Unused Flush(); break; } } }
//----handles the storage of data----// void swapFiles() { OpenWrite(hFileHandle2,nIoResultRead,sFileName2,nFileSize2); OpenRead(hFileHandle,nIoResult,sFileName1,nFileSize); float tempVar; char tempX, tempY, tempTheta, z; while(nIoResult != ioRsltEndOfFile) { for(z = 0; z<numNeuralUnits; z++) { ReadFloat(hFileHandle,nIoResult,tempVar); if(nIoResult == ioRsltEndOfFile) {break;} WriteFloat(hFileHandle2,nIoResultRead,tempVar); } if(nIoResult == ioRsltEndOfFile) {break;} ReadByte(hFileHandle, nIoResult, tempX); ReadByte(hFileHandle, nIoResult, tempY); ReadByte(hFileHandle, nIoResult, tempTheta); WriteByte(hFileHandle2,nIoResultRead,tempX); WriteByte(hFileHandle2,nIoResultRead,tempY); WriteByte(hFileHandle2,nIoResultRead,tempTheta); } char x; for(x = 0; x<numNeuralUnits; x++) { WriteFloat(hFileHandle2, nIoResult, localTemp.localArray[x]); } WriteByte(hFileHandle2, nIoResult, poseWorld.maxActivatedCell.x); WriteByte(hFileHandle2, nIoResult, poseWorld.maxActivatedCell.y); WriteByte(hFileHandle2, nIoResult, poseWorld.maxActivatedCell.theta); Close(hFileHandle2,nIoResultRead); Close(hFileHandle,nIoResult); Delete(sFileName1,nIoResult); Rename(sFileName1,nIoResult,sFileName2); }