1 /* 2 * Copyright 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef USB_SERIAL_TYPE_H 17 #define USB_SERIAL_TYPE_H 18 #include <string> 19 #include "parcel.h" 20 #include "usb_common.h" 21 22 namespace OHOS { 23 namespace USB { 24 struct UsbSerialPort : public Parcelable { 25 int portId_; 26 uint8_t busNum_; 27 uint8_t devAddr_; 28 int vid_; 29 int pid_; 30 std::string serialNum_; 31 MarshallingUsbSerialPort32 bool Marshalling(Parcel &parcel) const override 33 { 34 WRITE_PARCEL_AND_RETURN_FALSE_WHEN_FAIL(Int32, parcel, this->portId_); 35 WRITE_PARCEL_AND_RETURN_FALSE_WHEN_FAIL(Uint8, parcel, this->busNum_); 36 WRITE_PARCEL_AND_RETURN_FALSE_WHEN_FAIL(Uint8, parcel, this->devAddr_); 37 WRITE_PARCEL_AND_RETURN_FALSE_WHEN_FAIL(Int32, parcel, this->vid_); 38 WRITE_PARCEL_AND_RETURN_FALSE_WHEN_FAIL(Int32, parcel, this->pid_); 39 WRITE_PARCEL_AND_RETURN_FALSE_WHEN_FAIL(String, parcel, this->serialNum_); 40 return true; 41 } 42 UnmarshallingUsbSerialPort43 static UsbSerialPort *Unmarshalling(Parcel &data) 44 { 45 UsbSerialPort *serialPort = new (std::nothrow) UsbSerialPort; 46 if (serialPort == nullptr) { 47 return nullptr; 48 } 49 50 serialPort->portId_ = data.ReadInt32(); 51 serialPort->busNum_ = data.ReadUint8(); 52 serialPort->devAddr_ = data.ReadUint8(); 53 serialPort->vid_ = data.ReadInt32(); 54 serialPort->pid_ = data.ReadInt32(); 55 serialPort->serialNum_ = data.ReadString(); 56 return serialPort; 57 } 58 }; 59 60 struct UsbSerialAttr : public Parcelable { 61 uint32_t baudRate_; 62 uint8_t stopBits_; 63 uint8_t parity_; 64 uint8_t dataBits_; 65 MarshallingUsbSerialAttr66 bool Marshalling(Parcel &parcel) const override 67 { 68 WRITE_PARCEL_AND_RETURN_FALSE_WHEN_FAIL(Uint32, parcel, this->baudRate_); 69 WRITE_PARCEL_AND_RETURN_FALSE_WHEN_FAIL(Uint8, parcel, this->stopBits_); 70 WRITE_PARCEL_AND_RETURN_FALSE_WHEN_FAIL(Uint8, parcel, this->parity_); 71 WRITE_PARCEL_AND_RETURN_FALSE_WHEN_FAIL(Uint8, parcel, this->dataBits_); 72 return true; 73 } 74 UnmarshallingUsbSerialAttr75 static UsbSerialAttr *Unmarshalling(Parcel &data) 76 { 77 UsbSerialAttr *usbSerialAttr = new (std::nothrow) UsbSerialAttr; 78 if (usbSerialAttr == nullptr) { 79 return nullptr; 80 } 81 82 usbSerialAttr->baudRate_ = data.ReadUint32(); 83 usbSerialAttr->stopBits_ = data.ReadUint8(); 84 usbSerialAttr->parity_ = data.ReadUint8(); 85 usbSerialAttr->dataBits_ = data.ReadUint8(); 86 return usbSerialAttr; 87 } 88 }; 89 90 } 91 } 92 #endif //USB_SERIAL_TYPE_H