Hi.
I'm modifying a non-published pvrinput variation which sends IR commands to a set box box - specifically, the channel number stored in channels.conf.
12345J2:6:C12:C:0:301:300:305:A1:62006:0:1009:0 FOODJ2:63:C12:C:0:301:300:305:A1:62008:0:1019:0 ^^ - channel number to send to external digi-box
It works fine, sending single-digit channel numbers but fails to send double digit. i.e. channels 1-9 are ok, but 10+ fail.
This fails because there are only codes in the lircd.conf for 0-9.
Here's an excerpt from the plugin which sends the commands:
redremote.h <snip> class cRedRemote : public cThread { public: cRedRemote(); ~cRedRemote();
int Open(); void Tune(int channel); void Send(char *text); <snip>
redremote.c <snip> void cRedRemote::Send(char *text) {
char buf[100]; snprintf(buf,sizeof(buf), "SEND_ONCE ADB_ICAN3000 %s\n",text);
write(fd,buf,strlen(buf)); close(fd); fd = -1; } <snip>
My question is this. I need to modify the channel sent, so that double (or triple) channel numbers are sent as '6 3' or '1 1 7' rather than '63' or '117'. i.e. put spaces between the letters.
I'm really out of my depth - can anyone point me in the right direction?
Thanks
Simon
El Viernes, 13 de Abril de 2007, Simon Baxter escribió:
Hi.
I'm modifying a non-published pvrinput variation which sends IR commands to a set box box - specifically, the channel number stored in channels.conf.
12345J2:6:C12:C:0:301:300:305:A1:62006:0:1009:0 FOODJ2:63:C12:C:0:301:300:305:A1:62008:0:1019:0 ^^ - channel number to send to external digi-box
It works fine, sending single-digit channel numbers but fails to send double digit. i.e. channels 1-9 are ok, but 10+ fail.
This fails because there are only codes in the lircd.conf for 0-9.
Here's an excerpt from the plugin which sends the commands:
redremote.h
<snip> class cRedRemote : public cThread { public: cRedRemote(); ~cRedRemote();
int Open(); void Tune(int channel); void Send(char *text);
<snip>
redremote.c
<snip> void cRedRemote::Send(char *text) {
char buf[100]; snprintf(buf,sizeof(buf), "SEND_ONCE ADB_ICAN3000 %s\n",text); write(fd,buf,strlen(buf));
close(fd); fd = -1; }
<snip>
My question is this. I need to modify the channel sent, so that double (or triple) channel numbers are sent as '6 3' or '1 1 7' rather than '63' or '117'. i.e. put spaces between the letters.
I'm really out of my depth - can anyone point me in the right direction?
Thanks
Simon
You can try something like that:
char txt2[strlen(txt) * 2]; int i = 0; int j = 0; while (i < strlen(txt) - 1) { txt2[j] = txt[i]; i++; j++; txt2[j] = ' '; j++; } txt2[j] = txt[i]; j++; txt2[j] = '\0';
Jose Alberto
El Viernes, 13 de Abril de 2007, Simon Baxter escribió:
My question is this. I need to modify the channel sent, so that double (or triple) channel numbers are sent as '6 3' or '1 1 7' rather than '63' or '117'. i.e. put spaces between the letters.
You can try something like that:
char txt2[strlen(txt) * 2]; int i = 0; int j = 0; while (i < strlen(txt) - 1) { txt2[j] = txt[i]; i++; j++; txt2[j] = ' '; j++; } txt2[j] = txt[i]; j++; txt2[j] = '\0';
Thanks!
One more thing - how do I convert a %d variable to a %s string first?
My 'txt' variable is currently an integer.
One more thing - how do I convert a %d variable to a %s string first?
My 'txt' variable is currently an integer.
Strike that - works a treat:
<snip> void cRedRemote::Tune(int channel) { char buf[10]; sprintf(buf,"%d",channel); log(1,"Setting digibox to channel %d",channel); char *p = buf;
/* SBB Fudge */ char txt2[strlen(buf) * 2]; int i = 0; int j = 0; while (i < strlen(buf) - 1) { txt2[j] = buf[i]; i++; j++; txt2[j] = ' '; j++; } txt2[j] = buf[i]; j++; txt2[j] = '\0';
log(0,"SBB Channel Produced by Fudge '%s'",txt2);
Send(txt2); <snip>
El Viernes, 13 de Abril de 2007, Simon Baxter escribió:
One more thing - how do I convert a %d variable to a %s string first?
My 'txt' variable is currently an integer.
Strike that - works a treat:
<snip> void cRedRemote::Tune(int channel) { char buf[10]; sprintf(buf,"%d",channel); log(1,"Setting digibox to channel %d",channel); char *p = buf;
/* SBB Fudge */ char txt2[strlen(buf) * 2]; int i = 0; int j = 0; while (i < strlen(buf) - 1) { txt2[j] = buf[i]; i++; j++; txt2[j] = ' '; j++; } txt2[j] = buf[i]; j++; txt2[j] = '\0';
log(0,"SBB Channel Produced by Fudge '%s'",txt2);
Send(txt2);
<snip>
If you like more compact code:
char txt2[strlen(buf) * 2]; int i = 0; int j = 0; while (i < strlen(buf) - 1) { txt2[j++] = buf[i++]; txt2[j++] = ' '; } txt2[j++] = buf[i]; txt2[j] = '\0';
Jose Alberto