Debug arudino runtime exceptions.

This commit is contained in:
Starbeamrainbowlabs 2016-10-20 20:06:41 +01:00
parent 2304c6e338
commit c4bdac2e60
4 changed files with 38 additions and 12 deletions

View file

@ -104,19 +104,27 @@ void findServer()
char* datagramStr = (char*)datagramBuffer; char* datagramStr = (char*)datagramBuffer;
// Find the positions of the key characters // Find the positions of the key characters
//int atPos = getPosition(datagramStr, datagramSize, '@');
//int colonPos = getPosition(datagramStr, datagramSize, ':');
int atPos = findChar(datagramStr, '@'); int atPos = findChar(datagramStr, '@');
int colonPos = findChar(datagramStr, ':'); int colonPos = findChar(datagramStr, ':');
char* role; char role[7];
char* serverIp; char serverIp[16];
char* portNumberText; char portNumberText[7];
memset(role, '\0', 7);
memset(serverIp, '\0', 16);
memset(portNumberText, '\0', 7);
strncpy(role, datagramStr, atPos); strncpy(role, datagramStr, atPos); Serial.print("R: "); Serial.println(role);
strncpy(serverIp, datagramStr + atPos + 1, colonPos); strncpy(serverIp, datagramStr + atPos + 1, colonPos - atPos - 1);
strncpy(portNumberText, datagramStr + colonPos + 1, datagramSize - 1); strncpy(portNumberText, datagramStr + colonPos + 1, datagramSize - colonPos - 1);
Serial.println("complete."); Serial.println("complete.");
Serial.print("atPos: "); Serial.println(atPos);
Serial.print("colonPos: "); Serial.println(colonPos);
Serial.print("Role: "); Serial.print(role); Serial.print(" "); Serial.print("Role: "); Serial.print(role); Serial.print(" ");
Serial.print("Remote IP: "); Serial.print(serverIp); Serial.print(" "); Serial.print("Remote IP: "); Serial.print(serverIp); Serial.print(" ");
Serial.print("Port number: "); Serial.print(portNumberText); Serial.print("Port number: "); Serial.print(portNumberText);

View file

@ -1,9 +1,19 @@
#include <string.h> //#include <string.h>
//#include <algorithm>
int findChar(char* str, char targetChar) int findChar(char* str, char targetChar)
{ {
for(int i = 0; strcmp(&str[i], "\0") == 0; i++) { for(int i = 0; str[i] != '\0'; i++) {
if(str[i] == targetChar) return i; if(str[i] == targetChar) return i;
} }
} }
/*
int getPosition(const char *array, size_t size, char c)
{
const char* end = array + size;
const char* match = std::find(array, end, c);
return (end == match)? -1 : (match-array);
}
*/

View file

@ -8,3 +8,6 @@
*/ */
int findChar(char* str, char targetChar); int findChar(char* str, char targetChar);
int getPosition(const char *array, int size, char c);

View file

@ -2,8 +2,13 @@
A combination of a C# server and an arduino program that allows the control of a Hull Pixelbot. A combination of a C# server and an arduino program that allows the control of a Hull Pixelbot.
## Credits
- Debugging:
- Andrew C, Karen van Eck, Mike C
## Useful Links ## Useful Links
### For Multicast networkinterface blog post ### For Multicast networkinterface blog post
- [NetworkInterface class](https://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface(v=vs.110).aspx)) - [NetworkInterface class](https://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface(v=vs.110).aspx))
- [Sockoverflow answer](http://stackoverflow.com/questions/2192548/specifying-what-network-interface-an-udp-multicast-should-go-to-in-net) - [Sockoverflow answer](http://stackoverflow.com/questions/2192548/specifying-what-network-interface-an-udp-multicast-should-go-to-in-net)
- [IPv4InterfaceProperties](https://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipv4interfaceproperties(v=vs.110).aspx) - [IPv4InterfaceProperties](https://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipv4interfaceproperties(v=vs.110).aspx)