Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rig_send_raw not working #1157

Closed
PianetaRadio opened this issue Nov 22, 2022 · 22 comments
Closed

rig_send_raw not working #1157

PianetaRadio opened this issue Nov 22, 2022 · 22 comments
Labels
bug fixed Issue has been fixed
Milestone

Comments

@PianetaRadio
Copy link
Contributor

Code example:

RIG *my_rig;
(my_rig open... etc)
unsigned char sendCmd[] = "xyz;";
int sendCmdSize = 4;
unsigned char term[] = ";";
unsigned char rcvdCmd[100];
int rcvdCmdLen = 0;

rig_send_raw(my_rig, sendCmd, sendCmdLen, rcvdCmd, rcvdCmdLen, term);

The program crashes after calling rig_send_raw, the last line in debug is "1:rig.c(7401):rig_send_raw entered", nothing else.
Tested with 991A (serial or netrigctl) and dummy.

@PianetaRadio
Copy link
Contributor Author

int rig_send_raw(rig, const unsigned char *send, int send_len, unsigned char *reply, int reply_len, unsigned char *term)

Also, looking into the code, int reply_len is not used and unsigned char *reply not returned.

@mdblack98 mdblack98 added the bug label Nov 22, 2022
@mdblack98 mdblack98 added this to the 4.5.1 milestone Nov 22, 2022
@mdblack98 mdblack98 added the needs test Patches have been submitted but need testing to close issue label Nov 22, 2022
@mdblack98
Copy link
Contributor

This works with the simpowersdr.c emulator

#include <stdio.h>
#include <stdlib.h>
#include <hamlib/rig.h>

int
main()
{
RIG *my_rig;
unsigned char sendCmd[] = "FA;";
int sendCmdLen = 3;
unsigned char term[] = ";";
unsigned char rcvdCmd[100];
int rcvdCmdLen = sizeof(rcvdCmd);
int retcode;

my_rig = rig_init(2048);
strcpy(my_rig->state.rigport.pathname, "/dev/pts/4");

retcode = rig_open(my_rig);

if (retcode != RIG_OK)
{
    printf("rig_open: error = %s\n", rigerror(retcode));
    exit(2);
}
freq_t f;
rig_get_freq(my_rig, RIG_VFO_A, &f);

int nbytes = rig_send_raw(my_rig, sendCmd, sendCmdLen, rcvdCmd, rcvdCmdLen, term);
if (nbytes >= 0) printf("Response(%d bytes): %s\n", nbytes, rcvdCmd);
else printf("Error occurred = %s\n", rigerror(retcode));
return retcode;

}

mdblack98 added a commit that referenced this issue Nov 22, 2022
mdblack98 added a commit that referenced this issue Nov 22, 2022
@PianetaRadio
Copy link
Contributor Author

I don't know, still not working for me...

@mdblack98 mdblack98 reopened this Nov 24, 2022
@mdblack98
Copy link
Contributor

mdblack98 commented Nov 24, 2022 via email

@PianetaRadio
Copy link
Contributor Author

Mike, let me setup a clean code in the next days to test it and I will be back.
Anyway, the error is the same, when the function is called, immediately crashes, in the log I find only 1:rig.c(7401):rig_send_raw entered and nothing else.

I have a question, what happens if rig_send_raw is called for dummy rig or net rictl rig?

@mdblack98
Copy link
Contributor

mdblack98 commented Nov 24, 2022 via email

@PianetaRadio
Copy link
Contributor Author

PianetaRadio commented Nov 25, 2022

Ok, now if I use with dummy, doesn't crash and reports the right error message.
Still problem with real rig, maybe some issue with char, unsigned char, pointer, array, conversion, etc. It's a nightmare!

@mdblack98
Copy link
Contributor

mdblack98 commented Nov 25, 2022 via email

@PianetaRadio
Copy link
Contributor Author

Yaesu FT-991

@PianetaRadio
Copy link
Contributor Author

I suggest to temporary insert some verbose messages for each step, reporting also variables content to better understand the issue.

mdblack98 added a commit that referenced this issue Nov 25, 2022
@PianetaRadio
Copy link
Contributor Author

Tested on my Yaesu FT-991 using rigctl

Rig command: \send_raw FA;
rigctl_parse: cmd=send_raw handle=0
rigctl_parse: rig_powerstat is not on = 0
  2:rig.c(5856):rig_get_powerstat entered
   3:newcat.c(3470):newcat_get_powerstat entered
newcat.c(7427):newcat_valid_command returning2(1)
    4:newcat.c(10251):newcat_get_cmd entered
    4:newcat.c(10473):newcat_get_cmd returning(0)
   3:newcat.c(3503):newcat_get_powerstat returning(0)
  2:rig.c(5878):rig_get_powerstat returning(0)
  2:rig.c(7415):rig_send_raw entered
rig_send_raw: writing 3 bytes

Then it returns to command prompt!
Something is strange, "rig_powerstat is not on = 0", but the radio is on.

@mdblack98
Copy link
Contributor

mdblack98 commented Nov 26, 2022 via email

@PianetaRadio
Copy link
Contributor Author

Ok. I will test tomorrow with the last daily snapshot.

Concerning rig_powerstat is not on = 0, is just a misunderstanding, = 0 means false, so "is not on = false" means radio is on.

General question out of theme: how to use the simulators? Can you provide a socat command example to link them to a virtual serial port.

@mdblack98
Copy link
Contributor

mdblack98 commented Nov 26, 2022 via email

@PianetaRadio
Copy link
Contributor Author

PianetaRadio commented Nov 27, 2022 via email

@mdblack98
Copy link
Contributor

mdblack98 commented Nov 27, 2022 via email

@PianetaRadio
Copy link
Contributor Author

Yes, is the Windows 10 command shell.

mdblack98 added a commit that referenced this issue Nov 28, 2022
@PianetaRadio
Copy link
Contributor Author

Progress, send works well. Get takes some extra bytes in the answer.

Rig command: \send_raw ; FA;
rigctl_parse: cmd=\(5c) handle=0
rigctl_parse: cmd=send_raw handle=0
rigctl_parse: vfo_opt=0
  2:rig.c(5856):rig_get_powerstat entered
rig.c(5876) trace
   3:newcat.c(3470):newcat_get_powerstat entered
newcat_valid_command PS
newcat.c(7427):newcat_valid_command returning2(1)
    4:newcat.c(10251):newcat_get_cmd entered
rig_flush: called for serial device
read_string_generic called, rxmax=4095 direct=1, expected_len=1
0000    ff fb 03 ff fb 01 ff fe 01 ff fd 00 ff fb 03 ff     ................
0010    fb 01 ff fe 01 ff fd 00                             ........
cmd_str = PS;
write_block(): TX 3 bytes, method=2
0000    50 53 3b                                            PS;
read_string_generic called, rxmax=129 direct=1, expected_len=1
read_string_generic(): RX 4 characters, direct=1
0000    50 53 31 3b                                         PS1;
newcat_get_cmd: read count = 4, ret_data = PS1;
    4:newcat.c(10473):newcat_get_cmd returning(0)
   3:newcat.c(3503):newcat_get_powerstat returning(0)
  2:rig.c(5878):rig_get_powerstat returning(0)
rigctl_send_raw:
  2:rig.c(7415):rig_send_raw entered
rig_send_raw: writing 3 bytes
write_block(): TX 3 bytes, method=2
0000    46 41 3b                                            FA;
rig_send_raw: reading frame terminated by ';'
read_string_generic called, rxmax=200 direct=1, expected_len=1
read_string_generic(): RX 12 characters, direct=1
0000    46 41 30 30 37 31 35 36 30 30 30 3b                 FA007156000;
  2:rig_send_raw: elapsed=534ms
  2:rig.c(7490):rig_send_raw returning(12)
Send raw answer: FA007156000;
rigctl_parse: called, interactive=1
Rig command: \send_raw ; ID;
rigctl_parse: cmd=\(5c) handle=0
rigctl_parse: cmd=send_raw handle=0
rigctl_parse: vfo_opt=0
rigctl_send_raw:
  2:rig.c(7415):rig_send_raw entered
rig_send_raw: writing 3 bytes
write_block(): TX 3 bytes, method=2
0000    49 44 3b                                            ID;
rig_send_raw: reading frame terminated by ';'
read_string_generic called, rxmax=200 direct=1, expected_len=1
read_string_generic(): RX 79 characters, direct=1
0000    ff fb 03 ff fb 01 ff fe 01 ff fd 00 ff fb 03 ff     ................
0010    fb 01 ff fe 01 ff fd 00 ff fb 03 ff fb 01 ff fe     ................
0020    01 ff fd 00 ff fb 03 ff fb 01 ff fe 01 ff fd 00     ................
0030    ff fb 03 ff fb 01 ff fe 01 ff fd 00 ff fb 03 ff     ................
0040    fb 01 ff fe 01 ff fd 00 49 44 30 36 37 30 3b        ........ID0670;
  2:rig_send_raw: elapsed=1476ms
  2:rig.c(7490):rig_send_raw returning(79)
Send raw answer:  ¹♥ ¹☺ ■☺ ²
rigctl_parse: called, interactive=1
Rig command: \send_raw ; FA007155000;
rigctl_parse: cmd=\(5c) handle=0
rigctl_parse: cmd=send_raw handle=0
rigctl_parse: vfo_opt=0
rigctl_send_raw:
  2:rig.c(7415):rig_send_raw entered
rig_send_raw: writing 12 bytes
write_block(): TX 12 bytes, method=2
0000    46 41 30 30 37 31 35 35 30 30 30 3b                 FA007155000;
rig_send_raw: reading frame terminated by ';'
read_string_generic called, rxmax=200 direct=1, expected_len=1
0000    ff fb 03 ff fb 01 ff fe 01 ff fd 00 ff fb 03 ff     ................
0010    fb 01 ff fe 01 ff fd 00 ff fb 03 ff fb 01 ff fe     ................
0020    01 ff fd 00 ff fb 03 ff fb 01 ff fe 01 ff fd 00     ................
0030    ff fb 03 ff fb 01 ff fe 01 ff fd 00 ff fb 03 ff     ................
0040    fb 01 ff fe 01 ff fd 00 ff fb 03 ff fb 01 ff fe     ................
0050    01 ff fd 00 ff fb 03 ff fb 01 ff fe 01 ff fd 00     ................
0060    ff fb 03 ff fb 01 ff fe 01 ff fd 00 ff fb 03 ff     ................
0070    fb 01 ff fe 01 ff fd 00 ff fb 03 ff fb 01 ff fe     ................
0080    01 ff fd 00 ff fb 03 ff fb 01 ff fe 01 ff fd 00     ................
0090    ff fb 03 ff fb 01 ff fe 01 ff fd 00                 ............
read_string_generic(): Timed out 5.964 seconds after 156 chars, direct=1
  2:rig_send_raw: elapsed=6049ms
  2:rig.c(7490):rig_send_raw returning(-8) Protocol error

Send raw answer:  ¹♥ ¹☺ ■☺ ²
rigctl_parse: called, interactive=1
Rig command: \send_raw ; FA;
rigctl_parse: cmd=\(5c) handle=0
rigctl_parse: cmd=send_raw handle=0
rigctl_parse: vfo_opt=0
rigctl_send_raw:
  2:rig.c(7415):rig_send_raw entered
rig_send_raw: writing 3 bytes
write_block(): TX 3 bytes, method=2
0000    46 41 3b                                            FA;
rig_send_raw: reading frame terminated by ';'
read_string_generic called, rxmax=200 direct=1, expected_len=1
read_string_generic(): RX 96 characters, direct=1
0000    ff fb 03 ff fb 01 ff fe 01 ff fd 00 ff fb 03 ff     ................
0010    fb 01 ff fe 01 ff fd 00 ff fb 03 ff fb 01 ff fe     ................
0020    01 ff fd 00 ff fb 03 ff fb 01 ff fe 01 ff fd 00     ................
0030    ff fb 03 ff fb 01 ff fe 01 ff fd 00 ff fb 03 ff     ................
0040    fb 01 ff fe 01 ff fd 00 ff fb 03 ff fb 01 ff fe     ................
0050    01 ff fd 00 46 41 30 30 37 31 35 35 30 30 30 3b     ....FA007155000;
  2:rig_send_raw: elapsed=1657ms
  2:rig.c(7490):rig_send_raw returning(96)
Send raw answer:  ¹♥ ¹☺ ■☺ ²
rigctl_parse: called, interactive=1

@mdblack98
Copy link
Contributor

mdblack98 commented Nov 29, 2022 via email

@PianetaRadio
Copy link
Contributor Author

Sorry, I'm using virtual serial port, configured in Telnet from server side, raw in the client side, so service commands weren't filtered. Now I put it in full raw mode and "bingo" is ok, let me try with my software CatRadio if I manage the same good results.

Instead using NET rigctl, no answer:

Rig command: \send_raw ; FA;
rigctl_parse: cmd=\(5c) handle=0
rigctl_parse: cmd=send_raw handle=0
rigctl_parse: vfo_opt=1
rigctl_send_raw:
 1:rig.c(7415):rig_send_raw entered
rig_send_raw: writing 3 bytes
write_block(): TX 3 bytes, method=2
0000    46 41 3b                                            FA;
rig_send_raw: reading frame terminated by ';'
read_string_generic called, rxmax=200 direct=1, expected_len=1
read_string_generic(): Timed out 10.010 seconds after 0 chars, direct=1
 1:rig_send_raw: elapsed=10011ms
 1:rig.c(7490):rig_send_raw returning(-8) Protocol error

Send raw answer:
rigctl_parse: called, interactive=1

@mdblack98 mdblack98 removed the needs test Patches have been submitted but need testing to close issue label Nov 29, 2022
@mdblack98
Copy link
Contributor

Works from rigctl but not rigctld

@PianetaRadio
Copy link
Contributor Author

I confirm that is also ok from my application, using rig_send_raw function, tested with Yaesu.

Now the only remaining issue is with rigctld.

@mdblack98 mdblack98 added needs test Patches have been submitted but need testing to close issue fixed Issue has been fixed and removed needs test Patches have been submitted but need testing to close issue labels Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fixed Issue has been fixed
Projects
None yet
Development

No branches or pull requests

2 participants