Last active
March 14, 2023 05:18
-
-
Save spiritedRunning/532d2fba2610545cbdb27f9376c03c08 to your computer and use it in GitHub Desktop.
implemation serial HAL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Step 4 | |
// test client | |
#include <vendor/labworks/serialport/1.0/ISerialPort.h> | |
using vendor::labworks::serialport::V1_0::ISerialPort; | |
int main(int argc, char *argv[]) | |
{ | |
android::sp<ISerialPort> ser; | |
ser = ISerialPort::getService({); | |
if (!ser) { | |
std::cout << "Error requesting service handler!" << std::endl; | |
return 1; | |
} | |
// TX | |
ser->tx('0'); | |
// RX | |
printf("RX: %c\n", ser->rx()); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Step 1 | |
interface ISerialPort { | |
oneway tx(uint8_t data); | |
rx() generates (uint8_t data); | |
}; | |
// SerialPort.h - generated by hidl-gen | |
struct SerialPort : public V1_0::ISerialPort { | |
// Methods from ::vendor:: labworks::serialport::V1 0::ISerialPort follow. | |
Return<void> tx(uint8_t data) override; | |
Return<uint8_t> rx() override; | |
// Methods from ::android::hidl::base::V1_0::IBase follow. | |
}; | |
// SerialPort.cpp - generated by hidl-gen | |
Return<void> SerialPort::tx(uint8_t data) { | |
// TODO implement | |
return Void(); | |
} | |
Return<uint8_t> SerialPort::rx() { | |
// TODO implement | |
return uint8_t {}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Step 2 | |
$ cat device/generic/goldfish/manifest. xml | |
<manifest version="1.0" type="device" target-level="3"> | |
<hal format="hidl"> | |
<name>vendor.labworks.serialport</name> | |
<transport>hwbinder</transport> | |
<version>1.0</version> | |
<interface> | |
<name>ISerialPort</name> | |
<instance>default</instance> | |
</interface> | |
</hal> | |
<hal format="hid1"> | |
<name>android.hardware.drm</name> | |
<transport>hwbinder</transport> | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Step 3 | |
#include "SerialPort .h" | |
using vendor::labworks::serialport::implementation::SerialPort; | |
using android::hardware::configureRpcThreadpool; | |
using android::hardware::joinRpcThreadpool; | |
int main() | |
{ | |
configureRpcThreadpool(16, true); | |
android::sp<SerialPort> serialport = new SerialPort(); | |
if (serialport->registerAsService() != ::android::OK) { | |
ALOG(LOG_ERROR, TAG, “Error registering service!"); | |
return 1; | |
} | |
ALOG(LOG_INFO, TAG, "Successfully initialized!"); | |
joinRpcThreadpool(); | |
return 0; // should never get here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment