gnokii-users
[Top][All Lists]
Advanced

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

fake phone driver


From: Pavel Machek
Subject: fake phone driver
Date: Wed, 17 Apr 2002 02:26:30 +0200
User-agent: Mutt/1.3.28i

Hi!

I'd like to commit fake phone driver. Its usage is simple: You set
model to fake, and it prints its actions. Currently only sendsms is
implemented.

fake.c looks like:

Does it look okay to commit? [I used AT_ prefix sometimes so it is
clear where I copied it from. I'm not religious with it and it is easy
to change.]

Output looks like:

address@hidden:/usr/src/gnokii$ echo "foo" | gnokii/gnokii --sendsms 123456
GNOKII Version 0.4.0pre17
Please enter SMS text. End your input with <cr><control-D>:Strlen: 3
Sending SMS to 123456 via message center
In PDU mode: (15 bytes)
00 11 00 06 81 21 43 65 00 00 00 03 e6 f7 1b
3
SMS Send failed (No error.)
address@hidden:/usr/src/gnokii$

And I guess it could be very usefull for testing stuff like ringtones,
EMS (when implemented), etc. 
                                                                Pavel

/*

  $Id: fake.c,v 1.64 2002/03/26 01:10:29 pkot Exp $

  G N O K I I

  A Linux/Unix toolset and driver for Nokia mobile phones.

  Copyright (C) 2000 Hugh Blemings & Pavel Janík ml.
  Copyright (C) 2000 Chris Kemp
  Copyright (C) 2001 Markus Plail, Paweł Kot
  Copyright (C) 2002 Pavel Machek

  Released under the terms of the GNU GPL, see file COPYING for more details.

*/

#include <string.h>
#include <stdlib.h>
#include <ctype.h>

#include "misc.h"
#include "gsm-common.h"
#include "phones/generic.h"
#include "gsm-encoding.h"
#include "gsm-api.h"

/* Some globals */

static SMSMessage_PhoneLayout fake_layout;

static GSM_Error Pfake_Functions(GSM_Operation op, GSM_Data *data, 
GSM_Statemachine *state);

static const SMSMessage_Layout at_deliver = {
        true,                                           /* Is the SMS type 
supported */
         1, true, false,                                /* SMSC */
         2,  2, -1,  2, -1, -1,  4, -1, 13,  5,  2,
         -1, -1, -1,                                    /* Validity */
         3, true, false,                                /* Remote Number */
         6, -1,                                         /* Time */
        -1, -1,                                         /* Nonstandard fields */
        14, true                                        /* User Data */
};

static const SMSMessage_Layout at_submit = {
        true,                                           /* Is the SMS type 
supported */
         0, true, false,                                /* SMSC */
        -1,  1,  1,  1, -1,  2,  4, -1,  7,  5,  1,
         6, -1, -1,                                     /* Validity */
         3, true, false,                                /* Remote Number */
        -1, -1,                                         /* Time */
        -1, -1,                                         /* Nonstandard fields */
         8, true                                        /* User Data */
};

GSM_Phone phone_fake = {
        NULL,
        PGEN_IncomingDefault,
        /* Mobile phone information */
        {
                "fake",      /* Supported models */
                7,                     /* Max RF Level */
                0,                     /* Min RF Level */
                GRF_Percentage,        /* RF level units */
                7,                     /* Max Battery Level */
                0,                     /* Min Battery Level */
                GBU_Percentage,        /* Battery level units */
                GDT_DateTime,          /* Have date/time support */
                GDT_TimeOnly,          /* Alarm supports time only */
                1,                     /* Alarms available - FIXME */
                60, 96,                /* Startup logo size - 7110 is fixed at 
init */
                21, 78,                /* Op logo size */
                14, 72                 /* Caller logo size */
        },
        Pfake_Functions
};


/* Initialise is the only function allowed to 'use' state */
static GSM_Error Pfake_Initialise(GSM_Statemachine *state)
{
        GSM_Data data;
        char model[10];
        GSM_Error err;
        int try = 0, connected = 0;

        dprintf("Initializing...\n");

        /* Copy in the phone info */
        memcpy(&(state->Phone), &phone_fake, sizeof(GSM_Phone));

        /* SMS Layout */
        fake_layout.Type = 8; /* Locate the Type of the mesage field. */
        fake_layout.SendHeader = 6;
        fake_layout.ReadHeader = 4;
        fake_layout.Deliver = at_deliver;
        fake_layout.Submit =  at_submit;
        fake_layout.DeliveryReport = at_deliver;
        fake_layout.Picture = at_deliver;
        layout = fake_layout;

        dprintf("Connecting\n");

        /* Now test the link and get the model */
        GSM_DataClear(&data);
        data.Model = model;

        return GE_NONE;
}

static GSM_Error AT_WriteSMS(GSM_Data *data, GSM_Statemachine *state, char* cmd)
{
        unsigned char req[256];
        GSM_Error error;
        int length, i;

        if (!data->RawData) return GE_INTERNALERROR;

        printf("In PDU mode: ");
        dprintf("AT mode set\n");
        /* 6 is the frame header as above */
        length = data->RawData->Length;
        printf("(%d bytes)\n", length);
        for (i = 0; i < length; i++) {
                printf("%02x ", data->RawData->Data[i]);
        }
        printf("\n");
        return GE_NONE;
}

static GSM_Error Pfake_Functions(GSM_Operation op, GSM_Data *data, 
GSM_Statemachine *state)
{
        switch (op) {
        case GOP_Init:
                return Pfake_Initialise(state);
        case GOP_SendSMS:
                return AT_WriteSMS(data, state, "Writing ");
        default:
                return GE_NOTIMPLEMENTED;
        }
        return GE_INTERNALERROR;
}

-- 
(about SSSCA) "I don't say this lightly.  However, I really think that the U.S.
no longer is classifiable as a democracy, but rather as a plutocracy." --hpa



reply via email to

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