Using values from a UPD pkt as array address - help needed
Posted: Fri Jul 15, 2016 6:10 pm
Hi, if you can help with this I would appreciate it.
I receive a UDP packet as follows:
Bytes 17 to 24 contain a file name that I need to use to address an array. I extract the file name as follows (this is where I think I go wrong as I create a second array):
The problem comes when I come to use ‘NAME’, I want to use it to specify which array to read data from.
Arrays in this format: byte 1234 [ ] = { d, a, t, a, 0,};
When I try to read a value from the array called ‘NAME’ using the following:
It returns the value of the byte in NAME not the value of the byte in array.
Two examples:
The project; some wearables that display effects and text dependant on the UDP packet received. Guests at the party will be able to push one of ten buttons that will send a birthday message to the wearables. All the other bits are sorted, I’m just haven’t been able to sort this last bit to link the two up yet and time is getting short. So any help will be greatly appreciated.
I’m using 1.6.5 as it’s been an ongoing project for my wife’s 50th birthday on the 30th of this month and I don’t want to upgrade until after then.
Thanks in advance.
I receive a UDP packet as follows:
Code: Select all
int packetSize = Udp.parsePacket();
if (packetSize) {
int len = Udp.read(packetBuffer, 31);
Bytes 17 to 24 contain a file name that I need to use to address an array. I extract the file name as follows (this is where I think I go wrong as I create a second array):
Code: Select all
for (int i = 17; i < 25; i++) {
NAME [i -17] = (packetBuffer[i]);
}
The problem comes when I come to use ‘NAME’, I want to use it to specify which array to read data from.
Arrays in this format: byte 1234 [ ] = { d, a, t, a, 0,};
When I try to read a value from the array called ‘NAME’ using the following:
Code: Select all
Function ( NAME [ location in array 1234 ] );
It returns the value of the byte in NAME not the value of the byte in array.
Two examples:
Code: Select all
Arrays in this format: byte 1234 [ ] = { d, a, t, a, 0,};
Function (1234 [2]); // returns ‘t’ which is what I require.
Function (NAME [2]); returns ‘M’ which is not what I wanted but I understand why.
The project; some wearables that display effects and text dependant on the UDP packet received. Guests at the party will be able to push one of ten buttons that will send a birthday message to the wearables. All the other bits are sorted, I’m just haven’t been able to sort this last bit to link the two up yet and time is getting short. So any help will be greatly appreciated.
I’m using 1.6.5 as it’s been an ongoing project for my wife’s 50th birthday on the 30th of this month and I don’t want to upgrade until after then.
Thanks in advance.