Skip to content

Commit

Permalink
#424 stdio serial plugin added
Browse files Browse the repository at this point in the history
  • Loading branch information
davetcc committed Nov 22, 2023
1 parent 15defd4 commit cd7e239
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public class GenerateCodeDialog {
private TextField namespaceField;
private ToggleButton useModuleButton;
private TableView<TcMenuFormPersistenceWithOptionality> formTable;
private VBox remotesPane;

public GenerateCodeDialog(CodePluginManager manager, CurrentProjectEditorUI editorUI,
CurrentEditorProject project, CodeGeneratorRunner runner,
Expand Down Expand Up @@ -160,6 +161,8 @@ public void showCodeGenerator(Stage stage, boolean modal) {
centerPane.getChildren().add(titleLbl);

List<String> remoteIds = genOptions.getLastRemoteCapabilitiesUuids();
remotesPane = new VBox();
centerPane.getChildren().add(remotesPane);
if(remoteIds != null && !remoteIds.isEmpty()) {
int count = 0;
for(var remoteId : remoteIds) {
Expand All @@ -169,7 +172,7 @@ public void showCodeGenerator(Stage stage, boolean modal) {
String pluginId = "remotePlugin" + count;
var currentRemote = new UICodePluginItem(manager, itemRemote, CHANGE, this::onRemoteChange, editorUI, allItems, count, pluginId);
currentRemote.getStyleClass().add("uiCodeGen");
centerPane.getChildren().add(currentRemote);
remotesPane.getChildren().add(currentRemote);
count++;
currentRemotes.add(currentRemote);
}
Expand All @@ -180,7 +183,7 @@ public void showCodeGenerator(Stage stage, boolean modal) {
String pluginId = "remotePlugin0";
var currentRemote = new UICodePluginItem(manager, itemRemote, CHANGE, this::onRemoteChange, editorUI, allItems, 0, pluginId);
currentRemote.getStyleClass().add("uiCodeGen");
centerPane.getChildren().add(currentRemote);
remotesPane.getChildren().add(currentRemote);
}

Button addRemoteCapabilityButton = new Button(MenuEditorApp.getBundle().getString("code.gen.remote.add"));
Expand Down Expand Up @@ -284,7 +287,7 @@ private void produceAnotherRemoteCapability(ActionEvent actionEvent) {
currentRemote.setId("currentRemoteUI-" + currentRemotes.size());
currentRemote.getStyleClass().add("uiCodeGen");
currentRemotes.add(currentRemote);
centerPane.getChildren().add(currentRemote);
remotesPane.getChildren().add(currentRemote);
}

private Label addTitleLabel(Pane vbox, String text) {
Expand Down Expand Up @@ -608,7 +611,7 @@ private void onRemoteChange(UICodePluginItem uiPlugin, CodePluginItem item) {
if(item == null) {
logger.log(INFO, "Remove fired on remote");
currentRemotes.remove(uiPlugin);
centerPane.getChildren().remove(uiPlugin);
remotesPane.getChildren().remove(uiPlugin);
changeProperties();

for(int i=0; i<currentRemotes.size(); i++) {
Expand Down
44 changes: 44 additions & 0 deletions xmlPlugins/core-remote/remoteStdio.xml
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>
36 changes: 36 additions & 0 deletions xmlPlugins/core-remote/serialSrc/StdioTransport.cpp
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();
}
39 changes: 39 additions & 0 deletions xmlPlugins/core-remote/serialSrc/StdioTransport.h
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
3 changes: 2 additions & 1 deletion xmlPlugins/core-remote/tcmenu-plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
<Plugin>remoteSerialESP.xml</Plugin>
<Plugin>remoteWifiESP.xml</Plugin>

<!-- mbed specific -->
<!-- true cpp specific -->
<Plugin>remoteMbedEthernet.xml</Plugin>
<Plugin>remoteStdio.xml</Plugin>

<!-- simhub connector -->
<Plugin>simhubConnector.xml</Plugin>
Expand Down

0 comments on commit cd7e239

Please sign in to comment.