Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BufferedSerial FatFileSystemCpp mbed
Diff: main.cpp
- Revision:
- 69:47f800793d00
- Parent:
- 68:9e68287f0ab7
- Child:
- 71:7305a35cee58
--- a/main.cpp Thu Jan 27 12:56:13 2022 +0000 +++ b/main.cpp Thu Feb 03 11:50:12 2022 +0000 @@ -1,4 +1,4 @@ -#define APP_VERSION 0.22 +#define APP_VERSION 0.24 /* Settings file options @@ -815,58 +815,66 @@ void settingsNetUpdate(void const* netInterface) { - FILE *LSFile; - const int rxBufferSize = 512; // making this 1024 causes a crash. Probably out of memory somewhere. + //FILE *LSFile; + const int rxBufferSize = MaxBuffSize; // making this 1024 causes a crash. Probably out of memory somewhere. + //char settingsOutBuffer[rxBufferSize]; char settingsInBuffer[rxBufferSize]; - - const char filename[] = "/local/NewSet.txt"; + int bytesToSend = 0; + unsigned char *bufferToSend; + bool validated_connection = false; Thread::wait(1000); - pc.puts("Starting network listen server\r\n"); + pc.puts("Starting TCP network listen server\r\n"); Thread::wait(50); - int fileSize = 0; +// int fileSize = 0; TCPSocketServer server; server.bind(UserSettings.SettingsPort); server.listen(); while (true) { TCPSocketConnection connection; - pc.puts("Waiting for connections\r\n"); + pc.puts("Waiting for TCP connection\r\n"); server.accept(connection); - pc.puts("Connected\r\n"); - fileSize = 0; - LSFile = fopen(filename,"w"); - // connection.set_blocking(true,0); + pc.puts("TCP Connected\r\n"); + connection.set_blocking(false,50); + int bytesIn = 0; do { bytesIn = connection.receive(settingsInBuffer,rxBufferSize); - fwrite(settingsInBuffer,bytesIn,1,LSFile); - printf("For %d bytes\r\n",bytesIn); - fileSize+=bytesIn; - if (fileSize > 1024*20) // 20k settings file? I think not. - bytesIn=0; // force close. - } while (bytesIn > 0); + if (bytesIn > 0) { + if (!validated_connection) { + printf("Recieved %d bytes on unvalidated connection\r\n",bytesIn); + if ((settingsInBuffer[0] == 0x07) && + (settingsInBuffer[1] == 0x05) && + (settingsInBuffer[2] == 0x02)) { + validated_connection = true; + printf("Validated Connection - Sending 'set quiet' command\r\n"); + VIPS.sendQuiet(); + Thread::wait(50); + VIPS.EnableDirectTX(true); + VIPS.sendDirectTX((unsigned char *)settingsInBuffer, bytesIn); + printf("Sent first %d bytes to VIPS\r\n",bytesIn); //also a set-quiet command but good to send twice + } else { + printf("Invalid: %X %X %X", settingsInBuffer[0], settingsInBuffer[1], settingsInBuffer[2]); + } + } else if (validated_connection) { + VIPS.sendDirectTX((unsigned char *)settingsInBuffer, bytesIn); + printf("Sent %d bytes to VIPS\r\n",bytesIn); + } + } + if (VIPS.getWaitingBuffer(&bufferToSend, &bytesToSend)) { + connection.send((char *)bufferToSend, bytesToSend); + printf("Recieved %d bytes from VIPS\r\n",bytesIn); + } + } while (connection.is_connected()); - pc.puts("Closing new settings file\r\n"); - fclose(LSFile); + VIPS.EnableDirectTX(false); + validated_connection = false; + pc.puts("Disconnected TCP \r\n"); connection.close(); - // sanitycheck file. - if ((fileSize > 512) && (fileSize < 1024*10)) { - pc.puts("Settings valid. Changing file new settings file\r\n"); - if (rename("/local/settings.txt","/local/oldSet.txt") == 0) - pc.puts("Old file moved\r\n"); - else - pc.puts("Old file move failed\r\n"); - - if (rename(filename,"/local/settings.txt") == 0) - pc.puts("new file moved\r\n"); - else - pc.puts("new file move failed\r\n"); - - } } } @@ -917,7 +925,7 @@ } pc.puts("Ethernet connect complete\r\n"); Thread::wait(100); - + printf("IP Address is %s\r\n", eth.getIPAddress()); if (ListenTask) delete ListenTask; if (settingsPtr->SettingsPort) {