gcvdata.extend ???? Please help !!!
5 posts
• Page 1 of 1
gcvdata.extend ???? Please help !!!
Hi,
I try to send 2 values to gpc scripts but it failed on the second value and I don't now why :(
This What I do on CV script:
And in my gpc2 script:
This is my print output in gtunerIV:
value2 should be 120 not -64000, What I'm doing wrong ?
I try to send 2 values to gpc scripts but it failed on the second value and I don't now why :(
This What I do on CV script:
- Code: Select all
class GCVWorker:
def __init__(self, width, height):
os.chdir(os.path.dirname(__file__))
self.gcvdata = bytearray([0x00])
def __del__(self):
del self.gcvdata
def process(self, frame):
gcvdata = bytearray()
gcvdata.extend(int(-250).to_bytes(4, byteorder='big', signed=True))
gcvdata.extend(int(120).to_bytes(4, byteorder='big', signed=True))
print("gcvdata = ", gcvdata)
return (frame, gcvdata)
And in my gpc2 script:
- Code: Select all
#pragma METAINFO("test", 1, 0, "<author_name>")
fix32 value1, value2;
main {
if (gcv_ready()){
gcv_read(0, &value1);
gcv_read(1, &value2);
printf("gpc value1 = %d", value1);
printf("gpc value2 = %d", value2);
}
}
This is my print output in gtunerIV:
- Code: Select all
GCV Output: gcvdata = bytearray(b'\xff\xff\xff\x06\x00\x00\x00x')
GVM Output: gpc value1 = -250
GVM Output: gpc value2 = -64000
value2 should be 120 not -64000, What I'm doing wrong ?
-
nabs - Corporal
- Posts: 4
- Joined: Tue Sep 28, 2021 4:39 pm
Re: gcvdata.extend ???? Please help !!!
Looks up data types and their sizes.
https://www.consoletuner.com/wiki/index ... data_types
you need to take the size of the variables send by your py script into account and tell the correct byte offset to be read from.
And take a look at the apex anti recoil script how it does end values in the correct format and read it back into the correct data type variables (at the start of the py script there is a source gpc example included)
In apex anti recoil something like this is used to send float values over to gpc:
gcvdata.extend(int(123.45*0x10000).to_bytes(4, byteorder='big', signed=True))
gcvdata.extend(int(67.89*0x10000).to_bytes(4, byteorder='big', signed=True))
to read the first value you point your gpc fix32 val1 to byteoffset 0 : gcv_read(0, &val1);
to read the second value you point your gpc fix32 val2 to byteoffset 4 : gcv_read(4, &val2);
as each of your float values above are using 4 bytes.
https://www.consoletuner.com/wiki/index ... data_types
you need to take the size of the variables send by your py script into account and tell the correct byte offset to be read from.
And take a look at the apex anti recoil script how it does end values in the correct format and read it back into the correct data type variables (at the start of the py script there is a source gpc example included)
In apex anti recoil something like this is used to send float values over to gpc:
gcvdata.extend(int(123.45*0x10000).to_bytes(4, byteorder='big', signed=True))
gcvdata.extend(int(67.89*0x10000).to_bytes(4, byteorder='big', signed=True))
to read the first value you point your gpc fix32 val1 to byteoffset 0 : gcv_read(0, &val1);
to read the second value you point your gpc fix32 val2 to byteoffset 4 : gcv_read(4, &val2);
as each of your float values above are using 4 bytes.
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: gcvdata.extend ???? Please help !!!
Very clear Scachi !! Thank you very very much ! It will help me a lot
For information, when i use your exemple with float:
This what I get:
Without float it work but when you use float, it doesn't.
It's ok for what i want to do but if you have an explanation, i will appreciate too ;)
For information, when i use your exemple with float:
- Code: Select all
class GCVWorker:
def __init__(self, width, height):
os.chdir(os.path.dirname(__file__))
self.gcvdata = bytearray([0x00])
def __del__(self):
del self.gcvdata
def process(self, frame):
gcvdata = bytearray()
gcvdata.extend(int(123.45 * 0x10000).to_bytes(4, byteorder='big', signed=True))
gcvdata.extend(int(67.89 * 0x10000).to_bytes(4, byteorder='big', signed=True))
print("gcvdata = ", gcvdata)
return (frame, gcvdata)
- Code: Select all
fix32 value1, value2;
main {
if (gcv_ready()){
gcv_read(0, &value1);
gcv_read(4, &value2);
printf("gpc value1 = %d", value1);
printf("gpc value2 = %d", value2);
}
}
This what I get:
- Code: Select all
GCV Output: gcvdata = bytearray(b'\x00{s3\x00C\xe3\xd7')
GVM Output: gpc value1 = 8090419
GVM Output: gpc value2 = 4449239
Without float it work but when you use float, it doesn't.
It's ok for what i want to do but if you have an explanation, i will appreciate too ;)
-
nabs - Corporal
- Posts: 4
- Joined: Tue Sep 28, 2021 4:39 pm
Re: gcvdata.extend ???? Please help !!!
you have to use %f for fix32 or you see the wrong values.
printf("%f <- this is for fix32", value1);
printf("%f <- this is for fix32", value1);
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: gcvdata.extend ???? Please help !!!
You are a king Scachi !!!
You save me several days Thank you very much !
You save me several days Thank you very much !
-
nabs - Corporal
- Posts: 4
- Joined: Tue Sep 28, 2021 4:39 pm
5 posts
• Page 1 of 1
Return to Gtuner Computer Vision
Who is online
Users browsing this forum: No registered users and 50 guests