gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help understanding gnokii / Nokia FBUS please


From: root
Subject: Re: Help understanding gnokii / Nokia FBUS please
Date: Wed, 30 Oct 2002 23:32:38 +0000
User-agent: KMail/1.4.1

> I'm also try to understand protocol. I'm not sure but I had
> read somewhere that FBUS will only work with 115200 or
> something like that.

Thank's Krishna, most appreciated. The program below succesfully pings my 
Nokia 3310 maybe it will be helpfull ?

Regard's

Rob Beattie


/***************************************************************************
                          main.cpp  -  description
                             -------------------
    begin                : Tue Oct 29 22:31:56 GMT 2002
    copyright            : (C) 2002 by root
    email                : address@hidden
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/


#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <termios.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <sys/select.h>


// this program was writen to ping my nokia 3310 phone over an fbus
// serial cable. it sends the packet which gets the hw / sw version and
// prints out the responce. have a look at the gnokii documentation for
// more information.
int main(int argc, char *argv[])
{
  int fd;
  int rt;
  termios tp;

  // open the serial port
  fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY);
  if (fd == -1)
  {
    perror("nping : ");
    return -1;
  }

  // flush it
  rt = tcflush(fd, TCIFLUSH);
  if (rt == -1)
  {
    perror("nping : ");
    close(fd);
    return -1;
  }

  // attributes
  tp.c_cflag = B0 | CS8 | CLOCAL | CREAD | HUPCL;
  tp.c_iflag = IGNPAR;
  tp.c_cflag &= ~CRTSCTS;
  tp.c_oflag = 0;
  tp.c_lflag = 0;
  tp.c_cc[VMIN] = 1;
  tp.c_cc[VTIME] = 0;

  // set speed
  rt = cfsetspeed(&tp, 115200);
  if (rt == -1)
  {
    perror("nping : ");
    close(fd);
    return -1;
  }

  // set port attributes
  rt = tcsetattr(fd, TCSANOW, &tp);
  if (rt == -1)
  {
    perror("nping : ");
    close(fd);
    return -1;
  }

  // set dtr = 1 / rcs = 0
  unsigned int flags = TIOCM_DTR;
  ioctl(fd, TIOCMBIS, &flags);
  flags = TIOCM_RTS;
  ioctl(fd, TIOCMBIC, &flags);

  // init the link (sync recieve uart)
  unsigned char initc = 0x55;
  for (int c = 0; c < 255; c++)
  {
    usleep(100);
    rt = write(fd, &initc, 1);
    if (rt != 1)
    {
      perror("nping : ");
      close(fd);
      return -1;
    }
  }

  fd_set fs;
  struct timeval to;
  unsigned char rxm[255];
  unsigned char txm[255] = 
{0x1e,0x00,0x0c,0xd1,0x00,0x07,0x00,0x01,0x00,0x03,0x00,0x01,0x00,0x00,0x00,0x00};
  unsigned char seq, sub = 0x00;
  unsigned char chs;
  for (int j = 0; j < 5; j++)
  {
    // sequence number
    seq = 0x40 + sub;
    sub = (sub + 1) & 0x07;
    txm[12] = seq;

    // checksum
    chs = 0x00;
    for (int i = 0; i < 14; i += 2)
    {
      chs ^= txm[i];
    }
    txm[14] = chs;

    chs = 0x00;
    for (int i = 1; i < 15; i += 2)
    {
      chs ^= txm[i];
    }
    txm[15] = chs;

    // send the message
    rt = write(fd, txm, 16);
    if (rt != 16)
    {
      perror("nping : ");
      close(fd);
      return -1;
    }

    printf("sent ");
    for (int i = 0; i < 16; i++)
    {
      printf("%.2X ",txm[i]);
    }
    printf("\n\n");

    // read the responce
    printf("got back ");
    for (int k = 0; k < 30; k++)
    {
      FD_ZERO(&fs);
      FD_SET(fd, &fs);
      to.tv_sec = 0;
      to.tv_usec = 100000;
      rt = select(fd + 1, &fs, NULL, NULL, &to);
      if (rt > 0)
      {
        rt = read(fd, rxm, 255);
        for (int i = 0; i < rt; i++)
        {
          printf("%.2X ",rxm[i]);
        }
      }
    }
    printf("\n\n");
  }

  close(fd);
  return 0;
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]