-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
128 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<TcMenuPlugin name="EmbedControl/API using C++ stdio functions" id="DFE97583-1897-4F87-BEFA-10CB72C43F0E" subsystem="REMOTE" requiresDesigner="4.2" | ||
xmlns="https://www.thecoderscorner.com/libraries/tcmenuPluginItem" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="https://www.thecoderscorner.com/libraries/tcmenuPluginItem https://www.thecoderscorner.com/products/arduino-libraries/libraries/tcmenu-plugin-item.xsd"> | ||
<SupportedPlatforms> | ||
<PlatformGroup>TrueCpp</PlatformGroup> | ||
</SupportedPlatforms> | ||
<Description>An EmbedControl/API connection using stdio functions such as printf() and gets(). This assumes you have stdio available and configured on your board.</Description> | ||
<Documentation link="https://www.thecoderscorner.com/products/arduino-libraries/tc-menu/tcmenu-iot/serial-remote-plugin/"/> | ||
<RequiredLibraries/> | ||
<ImageFile>serial-connection.jpg</ImageFile> | ||
|
||
<Properties/> | ||
|
||
<ApplicabilityDefs/> | ||
|
||
<SourceFiles> | ||
<SourceFile name="serialSrc/StdioTransport.cpp"/> | ||
<SourceFile name="serialSrc/StdioTransport.h"/> | ||
</SourceFiles> | ||
|
||
<IncludeFiles> | ||
<Header name="RemoteConnector.h" inSource="false"/> | ||
<Header name="StdioTransport.h" inSource="true"/> | ||
</IncludeFiles> | ||
|
||
<GlobalVariables> | ||
<Variable name="stdioInitializer" type="NoInitialisationNeeded"/> | ||
|
||
<Variable name="stdioTransport" type="StdioTransport"> | ||
<Param value="255"/> | ||
</Variable> | ||
|
||
<Variable name="stdioConnection" type="TagValueRemoteServerConnection"> | ||
<Param value="stdioTransport"/> | ||
<Param value="stdioInitializer"/> | ||
</Variable> | ||
</GlobalVariables> | ||
|
||
<SetupFunctions> | ||
<Function name="addConnection" object="remoteServer"> | ||
<Param ref="stdioConnection"/> | ||
</Function> | ||
</SetupFunctions> | ||
</TcMenuPlugin> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
#include "StdioTransport.h" | ||
|
||
int StdioTransport::writeStr(const char *data) { | ||
auto dl = strlen(data); | ||
for(size_t i = 0; i<dl; ++i) { | ||
putchar_raw(data[i]); | ||
} | ||
return (int)dl; | ||
} | ||
|
||
uint8_t StdioTransport::readByte() { | ||
if (inputBuffer.available()) { | ||
return inputBuffer.get(); | ||
} | ||
return -1; | ||
} | ||
|
||
void StdioTransport::close() { | ||
currentField.msgType = UNKNOWN_MSG_TYPE; | ||
currentField.fieldType = FVAL_PROCESSING_AWAITINGMSG; | ||
} | ||
|
||
int StdioTransport::writeChar(char data) { | ||
putchar_raw(data); | ||
return 1; | ||
} | ||
|
||
|
||
bool StdioTransport::readAvailable() { | ||
int ch; | ||
while ((ch=getchar_timeout_us(0)) != PICO_ERROR_TIMEOUT) { | ||
inputBuffer.put(ch); | ||
} | ||
return inputBuffer.available(); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef STDIO_TRANSPORT_H | ||
#define STDIO_TRANSPORT_H | ||
|
||
#include <PlatformDetermination.h> | ||
#include <RemoteConnector.h> | ||
#include <remote/BaseRemoteComponents.h> | ||
#include "SCCircularBuffer.h" | ||
|
||
namespace tcremote { | ||
|
||
class StdioTransport : public TagValueTransport { | ||
private: | ||
SCCircularBuffer inputBuffer; | ||
public: | ||
explicit StdioTransport(int readBufferSize) : inputBuffer(readBufferSize), TagValueTransport(TVAL_UNBUFFERED) {} | ||
|
||
void flush() override { stdio_flush(); } | ||
|
||
int writeChar(char data) override; | ||
|
||
int writeStr(const char *data) override; | ||
|
||
uint8_t readByte() override; | ||
|
||
bool readAvailable() override; | ||
|
||
bool available() override { return true; } | ||
|
||
bool connected() override { return true; } | ||
|
||
void close() override; | ||
}; | ||
} | ||
|
||
#ifndef TC_MANUAL_NAMESPACING | ||
using namespace tcremote; | ||
#endif // TC_MANUAL_NAMESPACING | ||
|
||
#endif //STDIO_TRANSPORT_H |
This file contains 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