Example #1
0
int intrSerESC (selfStruct *self) {
int got_OK=0;

	// Attention/interrupt
	writeSer (self,"+++AT\r");
// # Guard time (seconds)
// AT*E2ESC=1
	usleep (1100000);
	got_OK = readSer (self, "OK",100);
	if (!got_OK) {
		writeSer (self,"AT\r");
		got_OK = readSer (self, "OK",100);
	}
	return (got_OK);
}
Example #2
0
int rstrSerESC (selfStruct *self) {
int got_connect=0;

	writeSer (self,"ATO\r");
	got_connect = readSer (self, "CONNECT",100);
	return (got_connect);
}
Example #3
0
int intrSerDTR (selfStruct *self) {
int ser_bits;
int got_OK=0;
struct termios tio;

	tcgetattr(self->ser_fd, &tio);           /* get the termio information */
	tio.c_cflag &= ~HUPCL;             /* clear the HUPCL bit */
	tcsetattr(self->ser_fd, TCSANOW, &tio);  /* set the termio information */

	ioctl(self->ser_fd, TIOCMGET, &ser_bits); /* get the serial port status */
	ser_bits |= TIOCM_DTR;              /* de-assert DTR (assert is ser_bits &= ~TIOCM_DTR;) */
	ioctl(self->ser_fd, TIOCMSET, &ser_bits); /* set the serial port status */

	usleep (100000); // 100ms sleep
	writeSer (self,"AT\r");
	got_OK = readSer (self, "OK",100);
	if (!got_OK) {
		writeSer (self,"+++AT\r");
		got_OK = readSer (self, "OK",100);
	}
	return (got_OK);
}
Example #4
0
int rstrSerDTR (selfStruct *self) {
int ser_bits;
int got_connect=0;

	writeSer (self,"ATO\r");
	got_connect = readSer (self, "CONNECT",100);

	// Reassert DRT
	ioctl(self->ser_fd, TIOCMGET, &ser_bits); /* get the serial port status */
	ser_bits &= ~TIOCM_DTR;             /* assert DTR (deassert is ser_bits |= TIOCM_DTR;) */
	ioctl(self->ser_fd, TIOCMSET, &ser_bits); /* set the serial port status */

	return (got_connect);
}
Example #5
0
int do_modem_status (selfStruct *self) {
int got_expect;
int retries;

	// Signal quality
	// This does not start right away when the modem reboots
	// reports +CSQ: 99,99 until ready.
	// Don't know what it would report if there's really no signal
	retries=30;
	while (!self->signal_valid && retries--) {
		writeSer (self,"AT+CSQ\r");
		got_expect = readSer (self, "OK",100);
		if (!self->signal_valid) sleep(2);
	}
	
	if (!got_expect && self->do_verbose) {
		sprintf (self->error,"Could not read cellular signal");
		return (0);
	}

	// SIM ID (ICCID) AT*E2SSN  N.B.: This number is usually printed on the SIM card
	writeSer (self,"AT*E2SSN\r");
	readSer (self, "OK",100);
	// SIM IMSI AT+CIMI N.B.: This number is considered "secret"
	writeSer (self,"AT+CIMI\r");
	readSer (self, "OK",100);
	
	// Text mode SMS
	writeSer (self,"AT+CMGF=1\r");
	readSer (self, "OK",100);
	writeSer (self,"AT+CSMP=17,167\r");
	readSer (self, "OK",100);
	// List text messages (this also reads them)
	writeSer (self,"AT+CMGL\r");
	readSer (self, NULL,100);
	// Delete text messages
	writeSer (self,"AT+CMGD=0,4\r");
	readSer (self, NULL,100);
	
	return (1);
}
///////////////////////////////////////////////////////////////////////////////
// TestFCOSetImpl -- FCOSetImpl component test harness
///////////////////////////////////////////////////////////////////////////////
void TestFCOSetImpl()
{
    cDebug d("TestFCOSetImpl()");
    d.TraceDebug("Entering...\n");


    iFCO* pFCO1 = new cFSObject(cFCOName(_T("fco1")));
    iFCO* pFCO2 = new cFSObject(cFCOName(_T("fco2")));
    iFCO* pFCO3 = new cFSObject(cFCOName(_T("fco3")));

    cFCOSetImpl set;
    set.Insert(pFCO1);
    set.Insert(pFCO2);
    set.Insert(pFCO3);

    // the set should have AddRef()ed, so I can release these now.
    pFCO1->Release();
    pFCO2->Release();
    pFCO3->Release();

    // let's iterate over the fcos
    cIterProxy<iFCOIter> pit(set.GetIter());
    pit->SeekBegin();
    PrintIter(pit, d);

    // lookup a specific fco
    cIterProxy<iFCOIter> pit2(set.Lookup(cFCOName(_T("fco2"))));
    if(! (iFCOIter*)pit2)
    {
        d.TraceError("Lookup failed for fco2!\n");
        TEST(false);
    }
    
    d.TraceDebug("Iterating from fco2 to end...\n");
    PrintIter(pit2, d);

    // Insert something
    d.TraceDebug("Inserting dog...\n");
    pFCO1 = new cFSObject(cFCOName(_T("dog")));
    set.Insert(pFCO1);
    pFCO1->Release();
    pit->SeekBegin();
    PrintIter(pit, d);

    // ...and then remove it
    d.TraceDebug("Removing fco3\n");
    cIterProxy<iFCOIter> pit3(set.Lookup(cFCOName(_T("fco3"))));
    if(! (iFCOIter*)pit3)
    {
        d.TraceError("Lookup failed for fco3!\n");
        TEST(false);
    }
    pit3->Remove();
    pit3->SeekBegin();
    PrintIter(pit3, d);

    // test operator=
    cFCOSetImpl set2;
    set2 = set;
    pit = set2.GetIter();
    d.TraceDebug("Made a new set and set it equal to the first with operator=; printing out...\n");
    PrintIter(pit, d);

    // test IsEmpty
    set.Clear();
    TEST(set.IsEmpty());

    // test refrence counting...
    d.TraceDebug("Set 1 was cleared out; printing set 2 to ensure ref counting worked\n");
    pit->SeekBegin();
    PrintIter(pit, d);

    // test serialization
    cFCOSetImpl set3;
    cMemoryArchive a;
    cSerializerImpl writeSer(a, cSerializerImpl::S_WRITE);
    writeSer.Init();
    set2.Write(&writeSer);
    writeSer.Finit();
    a.Seek(0, cBidirArchive::BEGINNING);
    cSerializerImpl readSer(a, cSerializerImpl::S_READ);
    readSer.Init();
    set3.Read(&readSer);
    readSer.Finit();
    d.TraceDebug("Serialized the set out and read it back in; this should be the same as above...\n");
    pit = set3.GetIter();
    PrintIter(pit, d);


    d.TraceDebug("Leaving...\n");
    return;

}
Example #7
0
int main (int argc, char **argv) {
int got_OK, got_connect, retries, got_expect, i;
char useDTR=0;
int exit_stat=EXIT_SUCCESS;
char data_mode=1;
selfStruct *self;
char do_shutdown=0, do_status=0;




	/* vvvv Init */
	self = &self_glob;
	memset (self,0,sizeof(selfStruct));

	/* chdir to the root of the filesystem to not block dismounting */
	chdir("/");

	if (argc < 3) usage();
	for (i=3; i < argc; i++) {
		if (!strcmp (argv[i],"-v")) self->do_verbose = 1;
	}
	
	strcpy (self->port_dev,argv[1]);

	if (! strcmp (argv[2],"status")) do_status = 1;
	if (! strcmp (argv[2],"shutdown")) do_shutdown = 1;
	if (! strcmp (argv[2],"reboot")) do_shutdown = do_status = 1;

	

	self->ser_fd = initSer (self->port_dev, baud_const[getBaudID(115200)], &(self_glob.oldtio));
	if (self->ser_fd < 0) {
		sprintf (self->error,"Couldn't open serial line %s: %s",self->port_dev,strerror(errno));
		clean_exit (self,EXIT_FAILURE);
	}

	// Register our signal handler to restore serial line
	signal (SIGTERM, sigTermHandler);
	signal (SIGINT, sigTermHandler);
	signal (SIGQUIT, sigTermHandler);


	/* ^^^^ Init */
	writeSer (self,"AT\r");
	got_OK = readSer (self, "OK",100);
	if (got_OK) data_mode=0;

	if (!got_OK) {
		if (self->do_verbose) fprintf (stderr,"Interrupting modem with escape sequence\n");
		for (retries = 0; !(got_OK = intrSerESC (self)) && retries < MAX_RETRIES; retries++);
	}

	if (!got_OK) {
		if (self->do_verbose) fprintf (stderr,"Interrupting modem with DTR\n");
		for (retries = 0; !(got_OK = intrSerDTR (self)) && retries < MAX_RETRIES; retries++);
		if (got_OK) useDTR = 1;
	}
	if (got_OK) {

		if (do_shutdown) {
			// Power down.
			// We do this instead of a watchdog reboot to make sure the SIM boots as well
			writeSer (self,"AT+CFUN=0\r");
			if (! readSer (self, "SHUTDOWN",10000)) {
				sprintf (self->error,"Could not shutdown modem");
				clean_exit (self,EXIT_FAILURE);
			}
		}

		if (do_shutdown && do_status) {
		// wait for the modem to reset itself
			// The power-up takes ~ 7 seconds.
			// Getting the modem to register a signal takes ~ 20 seconds
			sleep (30);
			retries = 30;
			got_expect = 0;
			while (retries-- && !got_expect) {
				writeSer (self,"AT\r");
				got_expect = readSer (self, "OK",100);
				if (!got_expect) sleep (1);
			}
			if (!got_expect) {
				sprintf (self->error,"Could not reach modem after reboot");
				clean_exit (self,EXIT_FAILURE);
			}
		}
		
		if (do_status) {
			if (! do_modem_status (self) ) clean_exit (self,EXIT_FAILURE);
		}

		if (data_mode && ! do_shutdown) {
			if (useDTR) {
				for (retries = 0; !(got_connect = rstrSerDTR (self)) && retries < MAX_RETRIES; retries++);
			} else {
				for (retries = 0; !(got_connect = rstrSerESC (self)) && retries < MAX_RETRIES; retries++);
			}
			if (retries >= MAX_RETRIES) exit_stat = EXIT_FAILURE;
		}
	} else {
		if (self->do_verbose) fprintf (stderr,"Could not interrupt modem\n");
		sprintf (self->error,"Could not interrupt modem");
		clean_exit (self,EXIT_FAILURE);
	}

	if (self->do_verbose) fprintf (stderr,"-+-+-+-+-+-+-+-+-+-+-+\n");
	if (self->signal_valid) {
		fprintf (stdout,"%d dBm (%d/5)",self->sig_dBm,self->sig_bars);
	} else {
		fprintf (stdout,"No dBm (-/5)");
	}
	if ( *(self->ICCID) && *(self->IMSI) ) {
		fprintf (stdout," SIM: OK");
	} else if ( !*(self->ICCID) && !*(self->IMSI) ) {
		fprintf (stdout," SIM: None");
	} else {
		fprintf (stdout," SIM: Error");
	}
	if (self->checkin_SMS) {
		fprintf (stdout," SMS: Checkin\n");
	} else {
		fprintf (stdout," SMS: None\n");
	}

	return (exit_stat);
}