|
From: | strajan |
Subject: | [gnokii-users] urgent -- sms from dos / win mode |
Date: | Mon, 1 Apr 2002 13:57:27 +0530 |
hi all,
i want to send sms using PC, 5110 and the following
C program .
if anyone found the bug means, pls inform me. Or send me the
corrected code immed.
i want to send sms from my PC thro command line program ( win32
console program or DOS appl ).
Thanks and regards
Thiagu
----------------------------pls check this code
-------------------
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <getopt.h> #include <netinet/in.h> #include "gsm-common.h"
#include "gsm-api.h" #include "gsm-networks.h" #include "gsm-filetypes.h" /* global variables */
int opt_8bit = 0; int opt_long = 0; int opt_class = -1; /* this is what gnokii uses by default */ int opt_validity = 4320; /* 4320 minutes = 72 hours */ /* function prototypes */
void err_usage(void); GSM_Error gsm_init(GSM_ConnectionType connection, char *port, char *model); GSM_Error sendsms(char *destination); /* structure defining concatenated SMS header */
struct long_header { char len; char iei; char iei_len; char ref; char total; char nr; } __attribute__ ((packed)); /* print some blurb for the clueless */
void err_usage(void) { fprintf(stderr, "usage: sendsms [ -8l -c connection -p port -m model -v validity -C class ] destination[:port]\n"); exit(1); } GSM_Error gsm_init(GSM_ConnectionType connection, char *port, char *model)
{ int count=0; GSM_Error error; error = GSM_Initialise(model, port, "1", connection,
NULL);
if (error != GE_NONE) { return (error); } while (count++ < 200 && *GSM_LinkOK == false)
{
usleep(50000); } if (*GSM_LinkOK == false) { return (GE_NOLINK); } return (0);
} int main(int argc, char *argv[])
{ int rc; char opt; GSM_ConnectionType connection = GCT_Serial; char port [32] = "/dev/ttyS0"; char model [32] = "5110"; while (1) {
opt = getopt(argc, argv, "8lc:p:m:v:C:"); if (opt == -1) { break; } switch (opt) {
case '8': opt_8bit = 1; break; case 'l': opt_long = 1; break; case 'c': if (strcmp(optarg, "infrared") == 0) { connection = GCT_Infrared; } else if (strcmp(optarg, "serial") == 0) { connection = GCT_Serial; } else { err_usage(); } break; case 'p': strncpy(port, optarg, sizeof port - 1); break; case 'm': strncpy(model, optarg, sizeof model - 1); break; case 'v': opt_validity = atoi(optarg); if (!opt_validity) { fprintf(stderr, "error: validity must be numeric\n"); exit(1); } break; case 'C': opt_class = atoi(optarg); if ((opt_class < 0) || (opt_class > 3)) { fprintf(stderr, "error: class must be between 0 and 3\n"); exit(1); } break; default: err_usage(); break; } } argc -= optind;
if (!argc) { err_usage(); } if ((rc = gsm_init(connection, port, model)))
{
fprintf(stderr, "GSM_Initialise: error %d\n", rc); exit(1); } if ((rc = sendsms(argv[optind])))
{
fprintf(stderr, "SendSMSMessage: error %d\n", rc); GSM->Terminate(); exit(1); } GSM->Terminate();
exit(0); } GSM_Error sendsms(char *destination)
{ GSM_SMSMessage SMS; GSM_Error error; char buffer[GSM_MAX_CONCATENATED_SMS_LENGTH], *p; struct long_header udh; int nr, total, nbs_port; size_t n, offset, remains, size, max_size; memset(&SMS, 0, sizeof SMS);
SMS.Type = GST_MO; SMS.Class = opt_class; SMS.Compression = false; SMS.EightBit = opt_8bit; SMS.MessageCenter.No = 1; SMS.Validity = opt_validity; if (opt_long) { SMS.UDHType = GSM_ConcatenatedMessages; } else { SMS.UDHType = GSM_NoUDH; } if ((p = strchr(destination, ':')) != NULL)
{
nbs_port = atoi(++p); *p = 0; /* ignore for now */ } strcpy(SMS.Destination,destination);
n = fread(buffer, 1, GSM_MAX_CONCATENATED_SMS_LENGTH,
stdin);
if (!n || ferror(stdin)) { fprintf(stderr, "error: couldn't read from stdin\n"); return (-1); } if (opt_long) { if (opt_8bit) { /* 134 octets per 8bit message fragment */ max_size = 134; } else { /* 153 septets per 7bit message fragment */ max_size = 153; } nr = 1; offset = 0; remains = n; total = n/max_size; if (total * max_size < n) { total++; } udh.len = 0x05; udh.iei = 0x00; udh.iei_len = 0x03; udh.ref = 0x01; udh.total = total; while (nr <= total) { udh.nr = nr; size = (remains < max_size) ? remains : max_size; memcpy(SMS.UDH, &udh, sizeof SMS.UDH); memset(SMS.MessageText, 0, sizeof SMS.MessageText); memcpy(SMS.MessageText, buffer + offset, size); error =
GSM->SendSMSMessage(&SMS, size);
if (error == GE_SMSSENDOK) { remains -= size; offset += size; nr++; sleep(1); continue; } else { return (error); } } return (0); } else { if (opt_8bit) { /* 140 octets per 8bit message */ max_size = 140; } else { /* 160 septets per 7bit message */ max_size = 160; } if (n > max_size) { fprintf(stderr, "warning: input too long, extra input ignored\n"); } size = (n < max_size) ? n : max_size; memcpy(SMS.MessageText, buffer, size); error = GSM->SendSMSMessage(&SMS, size); if (error == GE_SMSSENDOK) {
return (0); } else { return (error); } } } int identify( void )
{ /* Hopefully is 64 larger as FB38_MAX* / FB61_MAX* */ char imei[64], model[64], rev[64]; while (GSM->GetIMEI(imei) !=
GE_NONE)
sleep(1); while (GSM->GetRevision(rev) != GE_NONE)
sleep(1); while (GSM->GetModel(model) !=
GE_NONE)
sleep(1); fprintf(stdout, _("IMEI: %s\n"),
imei);
fprintf(stdout, _("Model: %s\n"), model); fprintf(stdout, _("Revision: %s\n"), rev); GSM->Terminate();
return 0;
} -------------
|
[Prev in Thread] | Current Thread | [Next in Thread] |