Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 112

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jerdew5/orbworks.com/forum/includes/bbcode.php on line 472
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3368: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:112)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3370: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:112)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3371: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:112)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3372: Cannot modify header information - headers already sent by (output started at /includes/bbcode.php:112)
OrbWorks Community Forum • View topic - problem with unpack()

problem with unpack()

Discuss PocketC for Palm OS (including Desktop Edition)

Postby Doug on Tue Feb 24, 2004 8:03 pm

// The problem I am having is with the unpack() function.
// I can't get it to extract info to the data array
// Can someone point out the error in the following test code?
// TIA, Doug

//---------------- code below
//Unpack Test 1.0
@cid "UPAK";
@name "Upack";
@dbname "Upack";
@category "IR";
@ver "1.0";

string message="Upack 1.0\n";
// Signon message

#define SWITCH1 0
#define PACKETSIZE 2
#define BUFFSIZE 10

string csum1 = "90";
string csum2[3] = { "89\0" };
int sw1;

main() {
int data1[BUFFSIZE], data2[BUFFSIZE];
// # elements in the string

text(0,10, csum1 + " " + *csum2);
// Print test 'strings'

// unpack(data1, csum1, "1", PACKETSIZE);
// The previous statement should be the proper syntax
// but generates a Virtual Machine Error
// Addr:81,Func:main,Global ref out of range
// at run-time.

unpack(data1, &csum1, "2", PACKETSIZE);
// Should extract hex string to int
// does not error but computes incorrect result.
// Syntax does not seem correct.

sw1 = data1[SWITCH1];
text(0, 30, sw1);
// displays a '0'

// Following statement is a char array
// instead of string, results are the same
unpack(data2, csum2, "2", PACKETSIZE);
// Should extract hex string to int

sw1 = data2[SWITCH1];
text(0, 40, sw1);

while(!event(1));
}
Doug
 
Posts: 6
Joined: Tue Feb 17, 2004 2:42 pm
Location: USA

Postby dewey on Wed Feb 25, 2004 2:29 am

The second parameter to unpack, pSerData, is a pointer to either an array or ints or array of chars. You are passing it a string, which is what is causing the VM errors.

For example, the way csum1 should have been declared is:
char csum1[2] = { '9', '0' };

Jeremy
dewey
Site Admin
 
Posts: 749
Joined: Sun Oct 21, 2007 5:12 am

Postby Doug on Wed Feb 25, 2004 9:39 pm

Thanks Jeremy, that was the missing piece. I have since discovered that unpack() does not provide the format that I need. I am getting the 34 byte data packet (in ascii hex format) at 57,600 baud and need to convert to int as fast as possible to update a display every 60mS.

unpack() takes hex data and converts it to int so my '90' string becomes 0x39(57 decimal), 0x30(48) in successive array locations (for 1 byte ints) and 14,640 for a 2 byte int ((57 * 256) + 48). It should be 0x90 (144 decimal).

Right now I am converting each byte pair individually and adding them together i.e.: '91' = (('9' - '0') * 16) + ('1'-'0'). Doing this 17 times creates a lot of overhead not even counting the case of 'A'-'F'.

Anyone have any ideas on how to translate hex ascii byte pairs to an int array really fast?
Doug
 
Posts: 6
Joined: Tue Feb 17, 2004 2:42 pm
Location: USA

Postby Doug on Wed Feb 25, 2004 9:40 pm

>> It should be 0x90 (144 decimal).

Should read:
I need it to be 0x90 (144 decimal).
Doug
 
Posts: 6
Joined: Tue Feb 17, 2004 2:42 pm
Location: USA

Postby Vigon on Thu Feb 26, 2004 4:45 am

Some code may help...
(Best time in Palm IIIx was 230 millisecons)
(Best time in Sony Clie SJ20 was 140 millisecons)
Code: Select all
//HextoIntTest
//By Vigon (2004)
main(){
int i,Time;
int Integers[17];
string Hexstring;

//InBuffer is Filled for test purpose.
//Use serrecva(InBuffer,34) to fill it in your program;
char InBuffer[35]={   
'9','0',
'2','0',
'f','f',
'3','f',
'1','f',
'9','0',
'9','0',
'9','0',
'9','0',
'9','0',
'9','0',
'9','0',
'9','0',
'9','0',
'9','0',
'1','a',
'f','0',};

InBuffer[34]=0;      //append 0 at the end for the use of ctostr()


clear();
Time=ticks();

Hexstring=ctostr(InBuffer);
for(i=0;i<17;i++)Integers[i]=(int)("0x" + substr(Hexstring, i*2, 2));

puts("Execution Time="+(ticks()-Time)+"0 Millisecons\n");   //Elapsed Time.

for(i=0;i<6;i++) puts(Integers[i]+"\n");      //Show the first 6 results.
while(1);
}
Vigon
 
Posts: 43
Joined: Wed Apr 17, 2002 2:26 pm
Location: Venezuela

Postby Doug on Thu Feb 26, 2004 8:23 pm

Thanks Vigon,

The statement:
Integers[i]=(int)("0x" + substr(Hexstring, i*2, 2));

shows me a PocketC conversion trick that I didn't know and it helps me out. Thanks for the tip.

Doug
Doug
 
Posts: 6
Joined: Tue Feb 17, 2004 2:42 pm
Location: USA


Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 1 guest

cron