Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

Low points tough question please help!!! SYNCDRIVE

short transmit(char *pMss, int leng)
{

   char *pSS={"\x0b"};
   char *pLL;


   strncpy(pLL,pMss,leng);
   printf("%c",pLL);
   getch();
   *pLL=*pSS+*pLL
   strcpy ((char *)pTxBuffer->BitT.comm_buffer, pLL);



   // Initialize the transmit buffer comm_block

   pTxBuffer->BitT.buffer_length = strlen((char*)pTxBuffer->BitT.comm_buffer);
   pTxBuffer->BitT.buffer_status = 0;
   pTxBuffer->BitT.idle_flag =  0;

#ifdef __OS2__
   rc = sync_transmit (pMPA_cfg, pTxBuffer, 10000);
#elif defined _WINDOWS
   rc = sync_transmit (pMPA_cfg, pTxBuffer, 0);
#else  // DOS
   rc = sync_transmit (pMPA_cfg, pTxBuffer);
#endif

   if (rc)
      {
      printf("Error starting frame transmission %04x", rc);
      return(-1);
      }

   while (!(pTxBuffer->BitT.buffer_status & (TxDone | TxAbort | TxError)));

   if (pTxBuffer->BitT.buffer_status & TxError)
      printf("Transmitter Error\n");
   if (pTxBuffer->BitT.buffer_status & TxAbort)
      printf("Transmitter underrun\n");

   return(pTxBuffer->BitT.buffer_status);

}
#define MAXLEN 50
void split(char *pMessage)
{
  int slen, leng;

  char *pE, *pF;

  slen = strlen(pMessage) ;
  pE = pMessage;
  do
  {
            pF = pE;
        leng = slen > MAXLEN ? MAXLEN : slen ;

        pE = pF + leng;

        while (*pE != ' ')
        {
               if (*pE == 0)
         break ;
             pE--;
         leng-- ;
        }

          leng=pE-pF ;

      printf("%*.*s\n", leng, leng, pF) ;

      getch() ;

      transmit(pF, leng);

      slen -= leng;

  } while(slen>0);

}

this is a small part out of the syncdrive program. Syncdrive is the example program provided by quatech for their communication card. the split function is to segment the message which is very long into 50 characters by 50 characters. by right when i strncpy(pLL,pMss,leng) i am suppose to get the segmented message correctly. but i realise that when i printf it , there are lots of unwanted characters behind my message. Why is that so? Another problem is i want to add hexadecimal 0B in front of the segmented message. SO i use the above method *pLL=*pSS+*pLL it doesnt seem to be able to work. THe characters in the message transmitted was in a mess.hopefully people out there can help me on this.
0
bbtss
Asked:
bbtss
  • 10
  • 9
1 Solution
 
ozoCommented:
short transmit(char *pMss, int leng){

  char *pSS={"\x0b"};
  char pLL[100];
  if( leng >= 100 ){
     fprintf(stderr,"not enough space in string for %d chars\n",leng);
     exit(1);
  }


  strncpy(pLL,pMss,leng);
  pLL[leng]='\0';

  printf("%c",pLL);
  getch();
  *pLL=*pSS+*pLL
  strcpy ((char *)pTxBuffer->BitT.comm_buffer, pLL);
0
 
bbtssAuthor Commented:
wow thanks. the message i send dun have rubbish behind it anymore. but i didnt get OB in front. instead i have a + sign in front which is equal to 2B?
how come?
0
 
bbtssAuthor Commented:
wow thanks. the message i send dun have rubbish behind it anymore. but i didnt get OB in front. instead i have a + sign in front which is equal to 2B?
how come?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Mayank SAssociate Director - Product EngineeringCommented:
He used \x - which is an escape sequence for hexadecimal value. Anyways, \x0b will evaluate to 11 decimal, so the character shown should be different. '+' has an ASCII value of 43, so that should not be displayed. Might have something to do with encoding and might also depend upon the platform on which you are working.

You can try:

char * str = "\x0b" ;
printf ( "%s", str ) ;

printf ( "%c", ( (char) 11 ) ) ;

printf ( "%d", ( ( int ) '+' ) ) ;


Mayank.
0
 
bbtssAuthor Commented:
ya i do get ob now. but my programming is really lousy. i do not know how i can put it in front of my segmented message. what am i suppose to declare or what am i suppose to do?
0
 
bbtssAuthor Commented:
ya i do get ob now. but my programming is really lousy. i do not know how i can put it in front of my segmented message. what am i suppose to declare or what am i suppose to do?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
I am sorry I don't quite understand your question..

Mayank.
0
 
bbtssAuthor Commented:
hm... i want to add hexadecimal 0B in front of my string pLL. How can i do this?
i tried char *pSS="\x0B";
        *pSS=*pSS+*pLL;
i cant get the the hexadecimal infront. is there any other way to do it?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
If you want to get it in front of pLL (I think this is supposed to mean - first characater of string pLL), then why are you assigning it to * pSS? Make it: * pLL = '\x0b' ; // single-quotes

Mayank.
0
 
bbtssAuthor Commented:
i got a % symbol instead of a symbol that represent 0b in front. is there any other way to put this 0b as the first character?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
If pLL is pointing to the first character, then * pLL = '\x0b' will modify the first character, otherwise which-ever character it is pointing to will be modified. If it still doesn't work, you can try:

* pLL = (char) 11 ;
printf ( "%c", * pLL ) ;

Mayank.
0
 
bbtssAuthor Commented:
but than i have to copy the whole string into the buffer. and not printf the ob.my motive is to send this whole string across. so i have to make this whole message into only 1 pointer. unless there is another way of copying string.
strcpy ((char *)pTxBuffer->BitT.comm_buffer, pSS);


0
 
Mayank SAssociate Director - Product EngineeringCommented:
int len = strlen ( pLL ) ;
char * temp = new char[len+2] ;
* temp = (char) 11 ;

for ( i = 0 ; i < len ; i ++ )
  temp[i+1] = pLL[i] ; // end for

temp[i+1] = '\0' ;
pLL = realloc ( len + 2 ) ;
strcpy ( pLL, temp ) ;

Mayank.
0
 
bbtssAuthor Commented:
wow thanks it work. actually i could not really understand what u are writng. is it possible to write another hexadecimal number behind the first with a increment of 2?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Actually, I just allocated space for an extra character (only for one extra character, because pLL already has not len but len + 1 characters, including the NULL character). And then all I did was store the '\x0b' in the first character, copy the rest into a temporary string, and thn copy it back to pLL after reaalocating the extra memory for it.

Mayank.
0
 
bbtssAuthor Commented:
so how do i add a second hexidecimal behind the first hexidecimal??
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Sameway.... I suggest you write the code which I provided in a function and pass pLL and the number as argument.

void func ( char * pLL, int val )
{
  int len = strlen ( pLL ), i ;
  char * temp = new char[len+2] ;
  * temp = (char) val ;

  for ( i = 0 ; i < len ; i ++ )
    temp[i+1] = pLL[i] ; // end for

  temp[i+1] = '\0' ;
  pLL = realloc ( len + 2 ) ;
  strcpy ( pLL, temp ) ;

} // end of func ()

..
..

func ( pLL, 11 ) ; // stores '\x0b' at the front.

Mayank.
0
 
bbtssAuthor Commented:
but than although i can call the function twice to add in another hex number . pLL still remains in the function    void func ( char * pLL, int val ). i need to return the value back to that function so i can call it again with the ob in front of the message.
example:
short transmit(char *pMss, int leng)
{


 char pLL[100];

 if( leng >= 100 )
 {
    fprintf(stderr,"not enough space in string for %d chars\n",leng);
    exit(1);
 }
 strncpy(pLL,pMss,leng);
 pLL[leng]='\0';
 func(pLL,11);
 func(pLL,2);
......
.....
........
....
}

it seems that the value of pLL in the func function is not return to the transmit function. i do not know how to return vaule to the transmit function. can help me with this?

 
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Oh, God! Can't believe I ever did that mistake myself, after having corrected so many people on EE over it!


void func ( char * pLL, int val )
{
  for ( int i = strlen ( pLL ) + 1 ; i > 0 ; i -- )
    pLL[i] = pLL[i-1] ; // end for

  pLL[0] = ( char ) val ;

} // end of func ()


Mayank.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Did it work?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now