Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_Scripting: added socket network bindings #25687

Merged
merged 33 commits into from
Dec 11, 2023

Conversation

tridge
Copy link
Contributor

@tridge tridge commented Dec 3, 2023

This adds some simple socket bindings for scripting and a web server example script.

update: added server side scripting support
for example, this file "test.shtml":

<html>
  <head>
       <meta http-equiv="refresh" content="1">
  </head>
  <body>
    <h1>Server Side Scripting Test</h1>
    <table>
      <tr><th>Roll</th><th>Pitch</th><th>Yaw</th></tr>
      <tr>
      <td><?lua return tostring(math.deg(ahrs:get_roll()))?></td>
      <td><?lua return tostring(math.deg(ahrs:get_pitch()))?></td>
      <td><?lua return tostring(math.deg(ahrs:get_yaw()))?></td>
      </tr>
    </table>
  </body>
</html>

gives this:
image

@IamPete1
Copy link
Member

IamPete1 commented Dec 3, 2023

Garbage collect doesn't work because of the trick we used to move bindings from memory to flash. So the garbage collect function is not added in the correct place by the binding loader. You might find you can add it as a operator rather than a method. If that doesn't work we will have to mess with the generator to special case it.

@tridge tridge force-pushed the pr-scripting-sockets branch from 24221a1 to 0d431ed Compare December 3, 2023 23:13
@tridge
Copy link
Contributor Author

tridge commented Dec 3, 2023

@IamPete1 for now I've added a close() method and user will run out of sockets if they don't use it. Hopefully we can fix gc as well for automatic close

@tridge tridge force-pushed the pr-scripting-sockets branch 5 times, most recently from 69cbae5 to 91b6ab6 Compare December 4, 2023 19:57
@tridge tridge added DevCallTopic and removed WIP labels Dec 4, 2023
@Ryanf55 Ryanf55 added WikiNeeded needs wiki update and removed DevCallTopic labels Dec 5, 2023
@Ryanf55
Copy link
Collaborator

Ryanf55 commented Dec 5, 2023

For wiki, want youtube video or dev documentation for the simple web server.

@tridge tridge force-pushed the pr-scripting-sockets branch 2 times, most recently from 92030c4 to 63f2a62 Compare December 9, 2023 03:14
@tridge tridge force-pushed the pr-scripting-sockets branch from 2af64b8 to 648731c Compare December 9, 2023 21:55
libraries/AP_Scripting/AP_Scripting.cpp Show resolved Hide resolved
libraries/AP_Scripting/docs/docs.lua Outdated Show resolved Hide resolved
libraries/AP_Scripting/lua_bindings.cpp Outdated Show resolved Hide resolved
libraries/AP_Scripting/lua_bindings.cpp Show resolved Hide resolved
libraries/AP_Scripting/lua_bindings.cpp Outdated Show resolved Hide resolved
we no longer allow open() on directories so that we match ChibiOS
FATFS
Copy link
Contributor

@peterbarker peterbarker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only looked at that AP_FileSystem changes

if (fs.stat(pathname, &st) != 0) {
return false;
}
stbuf.size = st.st_size;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memset

@tridge tridge merged commit 75fca4c into ArduPilot:master Dec 11, 2023
89 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Networking WikiNeeded needs wiki update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants