コード例 #1
0
ファイル: pstn.c プロジェクト: krishnaneeraja/PDS_Demo
int
pulse_test ()
{
  int res;
  unsigned char response[256] = "";
  static char phnum[32], dialnum[64];
  char *expect[] =
    { "CONNECT", "NO CARRIER", "NO DIALTONE", "LINE BUSY", "ERROR",
"DIALING OK", NULL };

  res = ModemOpen ("/dev/ttyS0");
  if (res < 0)
    {
      fprintf (stderr, "Modem Open failed\n");
      return ERROR;
    }

  setmodemparams (2400);
  memset (response, 0, 256);
  //   memset(phnum,0,32);
  //   memset(dialnum,0,64);
  lk_disptext (2, 3, "Enter Phone no. ", 0);
  res = lk_getnumeric (4, 0, phnum, 14, phnum, 4);

  if (res <= 0)
    {
      lk_dispclr ();
      lk_disptext (3, 0, "Phone Number Not Entered", 0);
      Modemclose ();
      return -1;
    }

  lk_dispclr ();
  lk_disptext (3, 4, "DIALING ....", 1);
  sprintf (dialnum, "ATDP%s;\r\n", phnum);
  res = Test_modem_response_without_signal (dialnum, response, expect, 60);
  fprintf (stderr, "The value of res=%d\n", res);

  lk_dispclr ();
  if (res != -2)
    lk_disptext (3, 3, expect[res], 1);
  else
    lk_disptext (3, 4, "DIALING OK", 1);
  lk_getkey ();
  Modemclose ();
  return 0;



}
コード例 #2
0
ファイル: pstn.c プロジェクト: krishnaneeraja/PDS_Demo
int
async_connect_test (PSTN_SET * settings)
{
  int res;
  char response[256];
  char *expect[] =
    { "CONNECT", "NO CARRIER", "NO DIALTONE", "BUSY", "ERROR", "OK", NULL };
  static char phnum[32], dialnum[64] = "ATDT";

  res = ModemOpen ("/dev/ttyS0");
  if (res < 0)
    {
      fprintf (stderr, "Modem Open failed\n");
      return ERROR;
    }
  setmodemparams (2400);
  //sprintf(settings->phnum,"%s%s;\r\n",settings->command,settings->phnum);
  res = Test_modem_response_without_signal ("AT\r\n", response, expect, 10);
  fprintf (stderr, "The value of res=%d\n", res);
  printf ("Response = %s \n", response);

  strcat (dialnum, settings->phnum);
  strcat (dialnum, "\r\n");
  lk_dispclr ();
  lk_disptext (3, 4, "DIALING ....", 1);
  res = Test_modem_response_without_signal (dialnum, response, expect, 60);
  fprintf (stderr, "The value of res=%d\n", res);
  printf ("Response = %s \n", response);

  if (res == 0)
    {
      lk_dispclr ();
      lk_disptext (2, 3, "Modem Connected", 0);
      lk_getkey ();
    }
  else
    {
      lk_dispclr ();
      lk_disptext (2, 3, "ERROR", 0);
      lk_getkey ();
    }
  Modemclose ();
  return 0;
}
コード例 #3
0
ファイル: sms_funcs.c プロジェクト: GreenfieldTech/kamailio
void modem_process(struct modem *mdm)
{
	struct sms_msg    *sms_messg;
	struct incame_sms sms;
	struct network *net;
	int i,k,len;
	int counter;
	int dont_wait;
	int empty_pipe;
	int cpms_unsupported;
	int max_mem=0, used_mem=0;

	sms_messg = 0;
	cpms_unsupported = 0;

	/* let's open/init the modem */
	LM_DBG("opening modem\n");
	if (openmodem(mdm)==-1) {
		LM_ERR("failed to open modem %s! %s \n",
			mdm->name,strerror(errno));
		return;
	}

	setmodemparams(mdm);
	initmodem(mdm,check_cds_report);

	if ( (max_mem=check_memory(mdm,MAX_MEM))==-1 ) {
		LM_WARN("CPMS command unsupported! using default values (10,10)\n");
		used_mem = max_mem = 10;
		cpms_unsupported = 1;
	}
	LM_DBG("modem maximum memory is %d\n",max_mem);

	set_gettime_function();

	while(1)
	{
		/* update the local config */
		cfg_update();

		dont_wait = 0;
		for (i=0;i<nr_of_networks && mdm->net_list[i]!=-1;i++)
		{
			counter = 0;
			empty_pipe = 0;
			net = &(networks[mdm->net_list[i]]);
			/*getting msgs from pipe*/
			while( counter<net->max_sms_per_call && !empty_pipe )
			{
				/* let's read a sms from pipe */
				len = read(net->pipe_out, &sms_messg,
					sizeof(sms_messg));
				if (len!=sizeof(sms_messg)) {
					if (len>=0)
						LM_ERR("truncated message read from pipe!"
								" -> discarded\n");
					else if (errno==EAGAIN)
						empty_pipe = 1;
					else
						LM_ERR("pipe reading failed: %s\n",strerror(errno));
					sleep(1);
					counter++;
					continue;
				}
				(*queued_msgs)--;

				/* compute and send the sms */
				LM_DBG("%s processing sms for net %s:"
					" \n\tTo:[%.*s]\n\tBody=<%d>[%.*s]\n",
					mdm->device, net->name,
					sms_messg->to.len,sms_messg->to.s,
					sms_messg->text.len,sms_messg->text.len,sms_messg->text.s);
				send_as_sms( sms_messg , mdm);

				counter++;
				/* if I reached the limit -> set not to wait */
				if (counter==net->max_sms_per_call)
					dont_wait = 1;
			}/*while*/
		}/*for*/

		/* let's see if we have incoming sms */
		if ( !cpms_unsupported )
			if ((used_mem = check_memory(mdm,USED_MEM))==-1) {
				LM_ERR("CPMS command failed! cannot get used mem -> using 10\n");
				used_mem = 10;
			}

		/* if any, let's get them */
		if (used_mem)
			LM_DBG("%d new SMS on modem\n",used_mem);
			for(i=1,k=1;k<=used_mem && i<=max_mem;i++) {
				if (getsms(&sms,mdm,i)!=-1) {
					k++;
					LM_DBG("SMS Get from location %d\n",i);
					/*for test ;-) ->  to be remove*/
					LM_DBG("SMS RECEIVED:\n\rFrom: %s %s\n\r%.*s %.*s"
						"\n\r\"%.*s\"\n\r",sms.sender,sms.name,
						DATE_LEN,sms.date,TIME_LEN,sms.time,
						sms.userdatalength,sms.ascii);
					if (!sms.is_statusreport)
						_send_sms_as_sip(&sms, mdm);
					else 
						check_sms_report(&sms);
				}
			}

		/* if reports are used, checks for expired records in report queue */
		if (sms_report_type!=NO_REPORT)
			check_timeout_in_report_queue();

		/* sleep -> if it's needed */
		if (!dont_wait) {
				sleep(mdm->looping_interval);
		}
	}/*while*/
}