[olug] OT? C programming question.

Obi-Wan obiwan at jedi.com
Wed Sep 1 16:42:03 UTC 2010


I write C code for a living, but I'm not quite sure what you're asking
from us or what the current problem is.  Can you elaborate?

Is the "receiver" just a socket connection to some other program that's
expecting ASCII commands?

> I've been asked by a tech at an affiliate to post his code written in C below:
> 
> He is trying to find a command that will do the same as the WRITE command he is using...
> 
> One of the parameters has an extra character in it so the program fails......
> 
> He is using Ubuntu 10.04 as his OS.
> 
> This is the simpler of two programs he wrote:
> 
> Thanks,
> Joe
> 
> (code start)
> 
> 
> #include <stdio.h>
> #include <string.h>
> #include <unistd.h>
> #include <fcntl.h>
> #include <errno.h>
> #include <termios.h>
> #include <time.h>
> 
> int main(void)
> {
> time_t     now;
> struct tm  *ts;
> int fd = 0;
> int n = 0;
> int i = 0;
> int counter = 0;
> int number = 15;
> 
> 
> 
> //If I omit the \r the receiver won't receive anything until a \r is sent
> //while (n >= 0)  
> //{ 
>   /* Get the current time */
> now = time(NULL);
> ts = localtime(&now);
> 
> //if((ts->tm_hour == 16) && (ts->tm_min == 59) && (ts->tm_sec == 59) && (counter == 0))
> 
>       fd = open( "/dev/ttyS0", O_RDWR | O_NDELAY);
>       /*if( fd == -1 )
>          {
>              perror( "open_port: Unable to open /dev/ttyS0 - " );
>          } */
>       //counter = 1;
>       n = write(fd, "permch 1\r", 9);
>       //printf("It is 5:00 PM, so channel has been changed to 4. \n");
>       close(fd);
> 
> /*
> 
> //if((ts->tm_hour == 4) && (ts->tm_min == 59) && (ts->tm_sec == 59) && (counter == 0))
> {
>       fd = open( "/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
>       if( fd == -1 )
>          {
>              perror( "open_port: Unable to open /dev/ttyS0 - " );
>          }       
>       printf("%d",fd);
>       counter = 1;
>       n = write(fd, "permch 1\r", 9);
>       printf("It is 5:00 AM, so channel has been changed to 7. \n");
>       close(fd);
> }
> 
> 
> if((ts->tm_hour == 5) && (ts->tm_min == 0) && (ts->tm_sec == 0) && (counter == 1))
> {      
> printf("Counter changed to 0 \n");
> counter = 0;
> }
> 
> if((ts->tm_hour == 17) && (ts->tm_min == 0) && (ts->tm_sec == 0) && (counter == 1))
> {      
> printf("Counter changed to 0 \n");
> counter = 0;
> }
> 
> //} */
> printf("***PROGRAM FAIL*** will now terminate. \n");
> return 0;
> }
> 
> 
> (code end)
> 
> This is from the user guide of the receiver (using a terminal emulator):
> 
> Using the PERMCH Command to dynamically change channels on the receiver. NOTE: all four FREQ CMD dip switches must be in the up position.
> PERMCH (spacebar) 8 & Enter – dynamically selects Channel 1 
> PERMCH (spacebar) 12 & Enter – dynamically selects Channel 2 
> PERMCH (spacebar) 14 & Enter – dynamically selects Channel 3 
> PERMCH (spacebar) 15 & Enter – dynamically selects Channel 4 
> PERMCH (spacebar) 7 & Enter – dynamically selects Channel 5 
> PERMCH (spacebar) 3 & Enter – dynamically selects Channel 6 
> PERMCH (spacebar) 1 & Enter – dynamically selects Channel 7 
> PERMCH (spacebar) 5 & Enter – dynamically selects Channel 8
> 
> 
> 
>       
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> https://lists.olug.org/mailman/listinfo/olug
> 


-- 
Ben "Obi-Wan" Hollingsworth                             obiwan at jedi.com
   The stuff of earth competes for the allegiance I owe only to the
     Giver of all good things, so if I stand, let me stand on the
       promise that You will pull me through.  -- Rich Mullins



More information about the OLUG mailing list