I'm trying to send an AnalogInput signal from my Arduino via wifi to a PC with Simulink. I've created two models, one which runs on an Arduino Due with a Wifi Shield and one that receives the data and plots it onto a scope in Simulink.
The problem is that the Wifi TCP\UDP Send blocks are only able to send 1 Byte of data (uint8) per call. In the Code Generation Report it shows that the uint16 data of the AnalogInput will be explicitly casted to uint8:
uint16_T rtb_AnalogInput_0;MW_WifiTCPFinalWrite(untitled_P.TCPSend_p1, (uint8_T)rtb_AnalogInput_0, untitled_P.TCPSend_p2);
This will chop off any leading bits which won't fit into the uint8 datatype. The implementation of the MW_WifiTCPFinalWrite method can be found in the io_wrappers.cpp and looks like this:
extern "C" void MW_WifiTCPFinalWrite(uint8_t wifitcpindex, uint8_t data, uint32_t serverport) { server[wifitcpindex].write(data); }
It calls the write method implemented in the class EthernetServer which then passes the address of that parameter and the length of 1 byte:
size_t EthernetServer::write(uint8_t b) { return write(&b, 1); }
This leads to an overloaded write(const uint8*, size_t) method, is then passed to a write method in EthernetClient until it eventually reaches the send method defined in socket.cpp.
These last two methods both use pointers and a length parameter meaning that these are able to process and send more than just 8 bits of data.
Long story short…
I could now just extend the framwork by myself but it raises the question why this has been so poorly implemented. Maybe I missed something and I'm not right about this conclusion?
Is there any good reason that the method MW_WifiTCPFinalWrite used by Simulink only allows 8-Bit of data which it copies instead of passing a pointer and a size?
Best Answer