I was trying to capture 16 bit sound from a microphone. I wanted to use UDP to send the data to a pc for speech recognition. In the process I suspected bogus data in the UDP packets. Finally I made a test program to send a hundred integers. I started with 301 and added 200 each time. I was only able to reconstruct 90% of the integers. The other ten percent had bogus large numbers. (I do not see a pattern to the large numbers, but they are always the same.)
This reminded me of the spurious AnalogIn data. Soldering LED1 to a ground plane did not help.
Did static electricity fry my microcontroller? Before I learned to ground myself first, miniature lightening bolts jumped to a momentary switch next to my mbed.
I wish someone would use my code to see whether UDP packets have bogus data with their mbed.
Any assistance will be greatly appreciated.
Here is the c program that sends 200 bytes when loaded:
- include "mbed.h"
- include "EthernetNetIf.h"
- include "UDPSocket.h"
EthernetNetIf eth;
UDPSocket udp;
int main() {
printf("Setting up...\n");
EthernetErr ethErr = eth.setup();
if(ethErr)
{
printf("Error %d in setup.\n", ethErr);
return -1;
}
printf("Setup OK\n");
Use the IP of the client.
Host unicast(IpAddr(192,168,0,2), 21567, NULL);
udp.bind(unicast);
char sampleStr[256];
while(true)
{
Net::poll();
sampleIndex = 0;
uint16_t x = 301;
for (int i = 0; i < 200; i+=2) {
sampleStr[i + 1] = x & 0xff;
sampleStr[i] = (x >> 8) & 0xff;
printf("s[0] = %d s[1] = %d ", sampleStr[i], sampleStr[i+1]);
printf("%d ", x);
x += 200;
}
udp.sendto(sampleStr, 200, &unicast);
wait(10);
}
}
Here is the Java program for a pc that receives 200 bytes and reconstructs most of the hundred integers:
import java.net.DatagramPacket;
import java.net.DatagramSocket;
class Receive200 {
public static void main(String args[]) throws Exception {
int clientPort = 21567;
int bufferSize = 256;
byte buffer[] = new byte[bufferSize];
DatagramSocket ds = new DatagramSocket(clientPort);
String str;
while (true) {
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
ds.receive(packet);
str = new String(packet.getData(), 0, packet.getLength());
System.out.println("packet length = " + str.length());
if (str.length() == 200) {
for (int i = 0; i < str.length() - 1; i+=2) {
int anInt = ((int)(str.charAt(i))<<8)+(int)(str.charAt(i+1));
System.out.println(i + ":" + (int)(i + 1) + " " + anInt);
}
break; listen until a 200 byte packet is processed.
}
}
}
}
I was trying to capture 16 bit sound from a microphone. I wanted to use UDP to send the data to a pc for speech recognition. In the process I suspected bogus data in the UDP packets. Finally I made a test program to send a hundred integers. I started with 301 and added 200 each time. I was only able to reconstruct 90% of the integers. The other ten percent had bogus large numbers. (I do not see a pattern to the large numbers, but they are always the same.)
This reminded me of the spurious AnalogIn data. Soldering LED1 to a ground plane did not help.
Did static electricity fry my microcontroller? Before I learned to ground myself first, miniature lightening bolts jumped to a momentary switch next to my mbed.
I wish someone would use my code to see whether UDP packets have bogus data with their mbed.
Any assistance will be greatly appreciated.
Here is the c program that sends 200 bytes when loaded:
EthernetNetIf eth; UDPSocket udp;
int main() { printf("Setting up...\n"); EthernetErr ethErr = eth.setup(); if(ethErr) { printf("Error %d in setup.\n", ethErr); return -1; } printf("Setup OK\n");
Use the IP of the client. Host unicast(IpAddr(192,168,0,2), 21567, NULL);
udp.bind(unicast);
char sampleStr[256];
while(true) { Net::poll(); sampleIndex = 0; uint16_t x = 301; for (int i = 0; i < 200; i+=2) { sampleStr[i + 1] = x & 0xff; sampleStr[i] = (x >> 8) & 0xff; printf("s[0] = %d s[1] = %d ", sampleStr[i], sampleStr[i+1]); printf("%d ", x); x += 200; } udp.sendto(sampleStr, 200, &unicast); wait(10); } }
Here is the Java program for a pc that receives 200 bytes and reconstructs most of the hundred integers:
import java.net.DatagramPacket; import java.net.DatagramSocket;
class Receive200 { public static void main(String args[]) throws Exception {
int clientPort = 21567;
int bufferSize = 256; byte buffer[] = new byte[bufferSize];
DatagramSocket ds = new DatagramSocket(clientPort);
String str; while (true) {
DatagramPacket packet = new DatagramPacket(buffer, buffer.length); ds.receive(packet);
str = new String(packet.getData(), 0, packet.getLength()); System.out.println("packet length = " + str.length());
if (str.length() == 200) { for (int i = 0; i < str.length() - 1; i+=2) { int anInt = ((int)(str.charAt(i))<<8)+(int)(str.charAt(i+1)); System.out.println(i + ":" + (int)(i + 1) + " " + anInt); } break; listen until a 200 byte packet is processed. } } } }