I am currently experimenting with making a debugging interface to a Micropython implementation running on a NIOS2 processor. It is a very rudimentary way of during it by only sending and receiving register write or read commands to/from the device over ethernet.
However, I've got the bright idea that it could be nice if I, with a decorator, could set a whole function to be executed on the device. By sending the entire source code to the device and then uses exec().
This works just fine.
But I ran into the problem with function arguments. If the argument is an already created object how do I get this data to the device? Pickle does not exist in the version of Micropython I'm stuck at using.
I've found that getting the __dict__ information is the way to go. I am though stuck at how to create an object in micropython without running its __init__() method.
IE the object must not be initialized twice since it will corrupt itself.
Is this possible to do?
Regards
Related
I'm writting a Golang package to manage NFC tags on an embedded system.
The tag reader is based on a NXP chip and a library from NXP : https://github.com/NXPNFCLinux/linux_libnfc-nci/tree/NCI2.0_PN7160. NXP also provides an example to read tags with that library : https://github.com/NXPNFCLinux/linux_libnfc-nci_examples/blob/master/tag-read_example/main.c.
The example works as expected and I'm able to read tags' information.
My Golang package uses cgo to call the functions in that C library. To enable the NFC discovery mode the following sequence must be done (as in the example):
nfcManager_doInitialize()
nfcManager_registerTagCallback(...)
nfcManager_enableDiscovery(...)
My golang package is stuck in the function nfcManager_enableDiscovery(...). After some investigation I figured out that the function is blocked when waiting for an event coming from another thread (https://github.com/NXPNFCLinux/linux_libnfc-nci/blob/NCI2.0_PN7160/src/nxp_nci_hal_nfc/nci/jni/NativeNfcManager.cpp#L2461).
The code sNfaEnableDisablePollingEvent.wait() is waiting for a mutex to be notified. It is calling pthread_cond_wait.
I tried to use runtime.LockOSThread but it doesn't fix my issue. I have checked that all the C functions called from my Go package have their paremters set with the right values, and it is the case.
Any idea on how to fix it ?
Discretion: I would like a general guidance for an approach to a project I am working on, so the question is very broad.
I am currently trying to build a GUI to make serial communication with an arduino, a usb camera (the camera has its own python library for controls), and handle real-time data in .dat format that gets updated as this GUI is running.
Right now, I am using threading on python in order to do all of these simultaneously, and I only interact with the script by using input function on python. Once threads start running, I cannot really interact with this script.
I have 3 separate threads running: 1. thread that saves images from the camera 2. thread that sends signals to arduino in every given random timing. 3. thread that waits for an input to terminate the main thread.
Everything works as I desire, but I wish to add GUI to make things more straight forward for others to use the program.
I realized that Qt actually offers all the capabilities that I wish to implement as a part of this program. Yet, I cannot fully understand the scope of Qt library functions I will need to implement everything.
My understanding is that I could use a combination of QWidgets, QTimer and QThreads to try something, but I would like to have some guidance on a more conventional approach to designing such GUI interface to do multitasking. I would like to also display real-time data on graphs including images from the camera and recording voltage data from the data files that gets updated through another program (data gets written to another folder). The program requires tracking of time from finish to end, and I know that threading can be very confusing when it comes to tracking these times. Any reference will be greatly appreciated.
Thanks you all.
I have a complex application. There is a WM_MOUSEMOVE message coming from somewhere with the same coordinates as the last WM_MOUSEMOVE.
So I tried to iterate through all loaded modules to try and detour (using MS Detours 3.0) any ::PostMessageA() and ::PostMessageW() call from every one of them. When I did this, the only module that showed up as having these functions was C:\WINDOWS\SYSTEM32\USER32.dll (well duh!).
I had thought that every module would have it's own call jump table, which is why I thought I could detour on a per module basis, but this doesn't seem to be the case, or if it is, then it is not recognized by the DetourFindFunction() command. Detouring from the local module from C:\WINDOWS\SYSTEM32\USER32.dll will result in only the calls from the local module will be detoured (I think).
Is there some way to detour the same function in each module that is loaded from a common executable?
Might it be possible to have code execute from the POV of the loaded module?
Seems that I was wrong. I do appear to be intercepting all messages, which is awesome!
However, the message isn't the result of a PostMessage() command. Not exactly sure what is causing lower down as yet (or that I really need to know, probably there is some other internal windows mechanism used to add to the message queue), but it would appear that it is triggered by a DLL that is using SendMessage(hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(-1, -1)). This is making it appear to the system that the mouse is moving, and thus sending out another WM_MOUSEMOVE with the same position.
I need to make asynchronous HTTP call to my server in order to receive XML response.
After I get the response I will call a [previously specified] function if it is success or some other function if it's an error.
So what I thought about in the first place was coroutines. Unfortunately, after I make the http.get call I cannot yield, as it will wait for the whole thing to finish. I know I can use separate functions to read the response, however I have to wait at least for the first bytes of data in order for this function to be triggered which would allow me to yield. Anyway, for what I wan to do using coroutines doesn't look like the way to go.
Then I've tried calling a C function from lua, creating separate thread to get the XML and then call a function in Lua, however this doesn't work because of lua_state changing after a new thread is created. Before the thread is created I can see 3 parameters on the stack, and after creation of the new thread [I am passing lua_State as the argument] it has only one. Anyway, from what I understand lua_State will be closed once the original cfunction call is finished, so I won't be able to call back.
Since I'm just starting with lua and I'm even less familiar with lua to c bindings I can only hope I'm making some stupid mistakes and it will be easy to solve. For now however I'm stuck with no idea on how to progress further.
The story behind this issue:
I'm porting my game from Cocos2D objective C framework to Cocos2d-X C++ framework. I want to use Lua bindings as I think I will fail to port it to C++. Anyway I want to do it in Lua.
So I've got a scene where someone accesses a list of inventory they have in the game. If the response is immediate they will basically see a window opened with list of inventory. However, if it takes a tad bit longer to get the data [connection issues, sever overload... whatever] screen will fade out and some animation indicating data transfer will be shown on screen. At least this is how it works on the objc version of the game and I want the same thing.
Is there something I have missed during my research, is it possible to do it?
BTW I have seen Lua socket asynchronous calls and it doesn't help me because it still waits for the beginning of the transfer before it will start another one.
Something like Luvit ?
Luvit is an attempt to do something crazy by taking nodeJS's awesome
architecture and dependencies and seeing how it fits in the Lua
language.
This project is still under heavy development, but it's showing
promise. In initial benchmarking with a hello world server, this is
between 2 and 4 times faster than nodeJS.
I was able to do it using https://github.com/Neopallium/lua-llthreads
This seems to work fine on both iOS and Android platforms.
I am trying to communicate with an arduino using the code from,
http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/
which uses termios to open and talk to an arduino in a non blocking way which works fine. What I was wondering is when on Java using rxtx I can register a callback function that is called when ever there is data on the line so that I don't have to manually check. I googled but could not find any info on how to register a callback function?
I am on Linux/OS X and I am trying to avoid launching a new thread just to watch/read data on the line.
Posix itself does not define a way to assign a callback function to be called when serial data arrives. The standard way to do this type of processing if you don't want to use a seperate thread is to use the select library function. This allows you program to define a set of file descriptors your program is interested in and then go to sleep. Select will automatically wake up your process if something interesting happens to one of the file descriptors you've declared interest in (such as new data becoming available for reading). This avoids having to busy-wait and poll multiple descriptors for activity.
Another option would be to use a library like libevent which sits on top of the Posix layer and provides the callback infrastructure. http://monkey.org/~provos/libevent/
Boost.Asio can provide callback functionality when using serial ports. It runs on Linux and Mac OS X.