Ejemplo n.º 1
0
	void L298MotorShield::Motor2Backward(int speed)
	{
		DCMotorParameters parameters = motor2.GetParameters();

		WritePort(parameters.PortA, 0);
	    WritePort(parameters.PortB, speed);
	};
Ejemplo n.º 2
0
	void L298MotorShield::Motor2Break()
	{
		DCMotorParameters parameters = motor2.GetParameters();

		WritePort(parameters.PortA, 0);
	    WritePort(parameters.PortB, 0);
	};
Ejemplo n.º 3
0
bool CPeripherals::FloodLight(unsigned int FloodLightNumber, bool State)
{
	DWORD numBytesWritten = 0;

	if(State)
	{
		switch(FloodLightNumber)
		{
			case 0:
				TRACE("Flood Light 1 Activated\n");
				m_pOwner->SystemInfo.SetWindowText("");
				m_pOwner->SystemInfo.SetWindowText("Flood Light 1 Activated.");
				m_pOwner->UpdateData(true);
				WritePort(&m_activateFloodlights, 1, numBytesWritten);
			break;

			case 1: 
				TRACE("Flood Light 2 Activated\n");
				m_pOwner->SystemInfo.SetWindowText("");
				m_pOwner->SystemInfo.SetWindowText("Flood Light 2 Activated.");
				m_pOwner->UpdateData(true);
				WritePort(&m_activateFloodlights, 1, numBytesWritten);
			break;
		}
	}
	else
	{	
		switch(FloodLightNumber)
		{
			case 0:
				TRACE("Flood Light 1 Deactivated\n");
				m_pOwner->SystemInfo.SetWindowText("");
				m_pOwner->SystemInfo.SetWindowText("Flood Light 1 Deactivated.");
				m_pOwner->UpdateData(true);
				WritePort(&m_deactivateFloodlights, 1, numBytesWritten);
			break;

			case 1: 
				TRACE("Flood Light 2 Deactivated\n");
				m_pOwner->SystemInfo.SetWindowText("");
				m_pOwner->SystemInfo.SetWindowText("Flood Light 2 Deactivated.");
				m_pOwner->UpdateData(true);
				WritePort(&m_deactivateFloodlights, 1, numBytesWritten);
			break;
		}
	}

	return true;
}
Ejemplo n.º 4
0
bool CPeripherals::Siren(unsigned int SirenNumber, bool State)
{
	DWORD numBytesWritten = 0;

	if(State)
	{
		switch(SirenNumber)
		{
			case 0: 
				TRACE("Siren 1 Activated\n");
				m_pOwner->SystemInfo.SetWindowText("");
				m_pOwner->SystemInfo.SetWindowText("Siren 1 Activated.");
				m_pOwner->UpdateData(true);
				WritePort(&m_activateSirens, 1, numBytesWritten);
			break;

			case 1: 
				TRACE("Siren 2 Activated\n");
				m_pOwner->SystemInfo.SetWindowText("");
				m_pOwner->SystemInfo.SetWindowText("Siren 2 Activated.");
				m_pOwner->UpdateData(true);
				WritePort(&m_activateSirens, 1, numBytesWritten);
			break;
		}
	}
	else
	{	
		switch(SirenNumber)
		{
			case 0: 
				TRACE("Siren 1 Deactivated\n");
				m_pOwner->SystemInfo.SetWindowText("");
				m_pOwner->SystemInfo.SetWindowText("Siren 1 Deactivated.");
				m_pOwner->UpdateData(true);
				WritePort(&m_deactivateSirens, 1, numBytesWritten);
			break;

			case 1: 
				TRACE("Siren 2 Deactivated\n");
				m_pOwner->SystemInfo.SetWindowText("");
				m_pOwner->SystemInfo.SetWindowText("Siren 2 Deactivated.");
				m_pOwner->UpdateData(true);
				WritePort(&m_deactivateSirens, 1, numBytesWritten);
			break;
		}
	}

	return true;
}
Ejemplo n.º 5
0
int CSerialPort::InitPort(CString strComName)
{
    hSerialPort = OpenPort(strComName, CBR_9600,NOPARITY,8, ONESTOPBIT);   
    if(hSerialPort==NULL)
    {
		//MessageBox(NULL, "打开指定串口失败,请重新选择串口。","失败", MB_OK|MB_ICONWARNING);
        return -1;
    }
	CString cmd = "AT+CSCA?\r";
	char ans[128] ;
	WritePort(cmd.GetBuffer(0),strlen(cmd));
	Sleep(ShortSleepTime);
	ReadPort(ans,128);
	CString ansStr = ans;
	int cou;
	if((cou=ansStr.Find("+86")) != -1)
	{
	    m_SmsCenterNum = ansStr.Mid(cou+1,13);	
	}
	else
	{
		return -2;
	}
    return 0;
}
Ejemplo n.º 6
0
//
// Процедура обрабатывает нажатие кнопки "Вкл.(1)".
//
void Window::bn_switch_on_Clicked()
{
        // Найти запись базы данных, соответствующую выбранному элементу
        // и поместить в sdb.
 int key = h_ListItem2index[m_SelectedItem];
 struct s_sdb_recode *sdb = hash_sdb_recode[key];
 int port =  sdb->O_PORT_ADAM;
 int addr =  sdb->O_ADR_ADAM;
 int nr  =  sdb->O_NR_ADAM;

 qDebug() << "Вкл.(1) " << m_SelectedItem->text()
          << "    ADAM PORT=" << port
          <<           "ADR="  << addr
          <<            "NR="   << nr;

 int state=WritePort( port, addr, nr, 1 );
 if ( state!=0) {
   qDebug() << "Bad";
   messbox("Ошибка записи");
   lwg->setFocus( Qt::TabFocusReason );   // Установить фокус на список.
   return;
}
else         qDebug() << "Ok";
lwg->setFocus( Qt::TabFocusReason );   // Установить фокус на список.
}
Ejemplo n.º 7
0
/*!
@brief put a char to driver, blocking mode.
*/
void PutChar_proc(struct _SerialPort *thisport, unsigned char* byte)
{
	int res, tmp;
	
	while ( (res = WritePort(thisport->m_fd, byte, 1, &tmp)) != SUCCESS) ; 

	return;
}
Ejemplo n.º 8
0
/////////////////////////////////////////////////////////////////////////////////
// 函数:gsmReadMessage                                                        //
// 说明:读取短消息,用+CMGL代替+CMGR,可一次性读出全部短消息                  //
// 参数:                                                                      //
//      pMsg: 短消息缓冲区,必须足够大                                         //
// 返回: 短消息条数                                                            //
/////////////////////////////////////////////////////////////////////////////////
int CSerialPort::gsmReadMessage(SM_PARAM* pMsg)
{
	int nLength;        // 串口收到的数据长度
    int nMsg;           // 短消息计数值
    char* ptr;          // 内部用的数据指针
	char *ptr1;
    char cmd[16];       // 命令串
    char ans[1024];     // 应答串
   
    nMsg = 0;
    ptr = ans;

	sprintf(cmd, "AT+CMGR=1\r");    // 生成命令
    
    WritePort(cmd, strlen(cmd));    // 输出命令串
	Sleep(ShortSleepTime);
    nLength = ReadPort(ans, 1024);    // 读应答数据
    // 根据能否找到"+CMS ERROR"决定成功与否
	ans[nLength]='\0';

	if(nLength > 0 && strncmp(ans, "+CMGR:", 6) != 0)
    {
        // 循环读取每一条短消息, 以"+CMGL:"开头
        pMsg->index=1;
        ptr = strstr(ans, "\r\n089168");
        ptr += 2;        // 跳过"\r\n"
        ptr1=ptr;
        for(int ii=0;;ii++)
        {
            ptr1=ptr1+1;
            if(*ptr1=='\r'&&*(ptr1+1)=='\n'&&*(ptr1+2)=='\r'&&*(ptr1+3)=='\n')
            {
                *ptr1=0x0;
                break;
            }
        }     
        gsmDecodePdu(ptr, pMsg);    // PDU串解码
        nMsg++;        // 短消息计数加1        
    }

    sprintf(cmd, "AT+CMGD=1,4\r");    // 生成命令
    
    WritePort(cmd, strlen(cmd));    // 输出命令串
	Sleep(ShortSleepTime);
    return nMsg;
}
Ejemplo n.º 9
0
int main()
{
	OpenTVicPort();

        WritePort(0x2050,0x00);

	CloseTVicPort();
        return(0);
}
Ejemplo n.º 10
0
void BinaryCount(int num)
{
 for (int i=0; i<=num; i++)
	{
	WritePort(++valueOutput[0]);
       //	DisplayPort(i);
	wait(gSpeed);
	}
}
Ejemplo n.º 11
0
/////////////////////////////////////////////////////////////////////////////////
// 函数:gsmSendMessage                                                        //
// 说明:发送短消息                                                            //
// 参数:                                                                      //
//      pSrc: 源PDU参数指针                                                    //
/////////////////////////////////////////////////////////////////////////////////
bool CSerialPort::gsmSendMessage(const SM_PARAM* pSrc)
{
    int nPduLength;        // PDU串长度
    unsigned char nSmscLength;    // SMSC串长度
    int nLength;           // 串口收到的数据长度
    char cmd[16];          // 命令串
    char pdu[512];         // PDU串
    char ans[128];         // 应答串
    
    nPduLength = gsmEncodePdu(pSrc, pdu);    // 根据PDU参数,编码PDU串
    strcat(pdu, "\x01a");        // 以Ctrl-Z结束
    
    gsmString2Bytes(pdu, &nSmscLength, 2);    // 取PDU串中的SMSC信息长度
    nSmscLength++;        // 加上长度字节本身
    // 命令中的长度,不包括SMSC信息长度,以数据字节计
    sprintf(cmd, "AT+CMGS=%d\r", nPduLength / 2 - nSmscLength);    // 生成命令
    printf(cmd);
    WritePort(cmd, strlen(cmd));    // 先输出命令串

    Sleep(ShortSleepTime);
	WritePort(pdu, strlen(pdu));
    WritePort("\x1A", 1);
    nLength = ReadPort(ans, 128);   // 读应答数据
	Sleep(ShortSleepTime);
    
    // 根据能否找到"\r\n> "决定成功与否
/*    if(nLength == 4 && strncmp(ans, "\r\n> ", 4) == 0)
    {
        WritePort(pdu, strlen(pdu)); 
		Sleep(ShortSleepTime);// 得到肯定回答,继续输出PDU串    
        nLength = ReadPort(ans, 128);       // 读应答数据    
        // 根据能否找到"+CMS ERROR"决定成功与否
        if(nLength > 0 && strncmp(ans, "+CMS ERROR", 10) != 0)
        {
            nLength = ReadPort(ans, 128);       // 读应答数据 
            return FALSE;
        }
    }*/

    return TRUE;
}
Ejemplo n.º 12
0
int getResult(struct sserial_props *pProps, const char *pCmd, char *pResponse, int nRespLength) {
	WritePort(pProps, (void*)pCmd, strlen(pCmd));
	int nLength = readLine(pProps, pResponse, nRespLength);
	if (nLength > 4) {
		// Cut out CRLF at the end of buffer
		pResponse[nLength - 2] = '\0';
		size_t nOffset = strchr(pResponse,':') - pResponse + 1;
		LOGV("Response: \"%s\", Payload: \"%s\", Offset: %ld", pResponse, pResponse + nOffset, nOffset);
		strcpy(pResponse, pResponse + nOffset);
		return strlen(pResponse);
	}

	return 0;
}
Ejemplo n.º 13
0
bool CPeripherals::Buzzer_LED(bool State)
{
	DWORD numBytesWritten = 0;

	if(State)
	{
		TRACE("Buzzer & LED Activated\n");
		m_pOwner->SystemInfo.SetWindowText("");
		m_pOwner->SystemInfo.SetWindowText("Buzzer & LED Activated.");
		m_pOwner->UpdateData(true);	
		WritePort(&m_activateBuzzerLed, 1, numBytesWritten);
	}
	else
	{
		TRACE("Buzzer & LED Deactivated\n");
		m_pOwner->SystemInfo.SetWindowText("");
		m_pOwner->SystemInfo.SetWindowText("Buzzer & LED Deactivated.");
		m_pOwner->UpdateData(true);	
		WritePort(&m_deactivateBuzzerLed, 1, numBytesWritten);
	}

	return true;
}
Ejemplo n.º 14
0
int WriteJob(PORTHANDLE hPort,LPCVOID lpvBuf,int cbBufLen,LPINT lpcbWrite)
{
  PSPCB pSPCB;
  int   rv;

  TRACE0(TEXT("--WriteJob\r\n"));

  if (!ValidHandle(hPort))
  {
    return(QP_BAD_PARAMETER);
  }

  pSPCB = &SPCBTable[hPort];

  rv = (int) WritePort(lpvBuf,cbBufLen,lpcbWrite,pSPCB);

  TRACE3(TEXT("--Poll@%8u,Last = %8u,Curr = %8u\r\n"),PollRate,pSPCB->nTimeAtLastPoll,
         GetTickCount());

  // read device status ?
  if (pSPCB->bTwoWay)
  {
    if (PollRate != 0 && GetTickCount() - pSPCB->nTimeAtLastPoll > PollRate)
    {
      PJLGetMessage(pSPCB,NULL,NULL);
      pSPCB->nTimeAtLastPoll = GetTickCount();
    }
    else
      TRACE1(TEXT("--WriteJob: Skip Poll %s\r\n"),pSPCB->szPortName);
  }

#ifndef WIN32
  switch (rv)
  {
    case RC_SUCCESS:
      rv = QP_PORT_OK;
      break;
    case RC_CE_PTO:
      rv = QP_PORT_BUSY;
      break;
    default:
      rv = QP_PORT_ERROR;
      break;
  }
#endif

  return(rv);
}
void TxPacket1(int port_num)
{
    int _idx;

    UINT8_T _checksum = 0;
    UINT8_T _total_packet_length = packetData[port_num].txpacket_[PKT_LENGTH] + 4; // 4: HEADER0 HEADER1 ID LENGTH
    UINT8_T _written_packet_length = 0;

    if (is_using_[port_num])
    {
        packetData[port_num].communication_result_ = COMM_PORT_BUSY;
        return ;
    }
    is_using_[port_num] = true;

    // check max packet length
    if (_total_packet_length > TXPACKET_MAX_LEN)
    {
        is_using_[port_num] = false;
        packetData[port_num].communication_result_ = COMM_TX_ERROR;
        return;
    }

    // make packet header
    packetData[port_num].txpacket_[PKT_HEADER0] = 0xFF;
    packetData[port_num].txpacket_[PKT_HEADER1] = 0xFF;

    // add a checksum to the packet
    for (_idx = 2; _idx < _total_packet_length - 1; _idx++)   // except header, checksum
        _checksum += packetData[port_num].txpacket_[_idx];
    packetData[port_num].txpacket_[_total_packet_length - 1] = ~_checksum;

    // tx packet
    ClearPort(port_num);
    _written_packet_length = WritePort(port_num, packetData[port_num].txpacket_, _total_packet_length);
    if (_total_packet_length != _written_packet_length)
    {
        is_using_[port_num] = false;
        packetData[port_num].communication_result_ = COMM_TX_FAIL;
        return;
    }

    packetData[port_num].communication_result_ = COMM_SUCCESS;
}
Ejemplo n.º 16
0
/////////////////////////////////////////////////////////////////////////////////
// 函数:gsmDeleteMessage                                                      //
// 说明:删除短消息                                                            //
// 参数:                                                                      //
//      index: 短消息序号,从1开始                                             //
/////////////////////////////////////////////////////////////////////////////////
bool CSerialPort::gsmDeleteMessage(const int index)
{
    int nLength;          // 串口收到的数据长度
    char cmd[16];         // 命令串
    char ans[128];        // 应答串
    
    sprintf(cmd, "AT+CMGD=%d\r", index);    // 生成命令
    
    // 输出命令串
    WritePort(cmd, strlen(cmd));
    
    // 读应答数据
    nLength = ReadPort(ans, 128);
    
    // 根据能否找到"+CMS ERROR"决定成功与否
    if(nLength > 0 && strncmp(ans, "+CMS ERROR", 10) != 0)
    {
        return TRUE;
    }
    return FALSE;
}
Ejemplo n.º 17
0
void Chase(int speed, int startbit, int stopbit)
{
	int value = 0;
	if(startbit > stopbit) {     // CHASE DOWN
		//value = 2^(startbit); //128;
		switch(startbit) {
		  case 7:		value = 128; break;
		  case 3:		value =8;	break;
		  default:	value =1;
		}
		for (int i=startbit; i>=stopbit; i--)
		{
			//gotoxy(10, 10+i);
			//printf("start=%d  stop=%d, i=%d, value=%d",startbit,stopbit,i,value);
			WritePort(value);
			value >>= 1;
			wait(speed);
		}
	}
	else
	{      // Chase Up
		switch(startbit) {
Ejemplo n.º 18
0
void OutputBit(int bit,int val)
{
   // calculate mask return
   int mask = 0;
   for(int i=0; i<=bit; i++)
   {
	mask = mask * 2+1;    //almost works
   }
   mask++;
   mask=mask/2;

   locate(25,1);
   cprintf("bit=%d mask=%d val=%d",bit,mask,val);
   switch (val)
   {
	case 2:	// toggle output bit
	{
	   valueOutput[0] = valueOutput[0] ^ mask;
	}
	break;
	case 1:	// turn BIT ON
	{
	   valueOutput[0] = valueOutput[0] ^ mask;

	}
	break;

	case 0: // turn BIT OFF
	{
	   mask = ~mask;
	   valueOutput[0] = valueOutput[0] ^ mask;

	}
	break;
   }
   WritePort(valueOutput[0]);

}
Ejemplo n.º 19
0
    //
    // Процедура обрабатывает нажатие кнопки "Откл.(0)".
    //
void Window::bn_switch_off_Clicked()
{
 int key = h_ListItem2index[m_SelectedItem];
 struct s_sdb_recode *sdb = hash_sdb_recode[key];
 int port =  sdb->O_PORT_ADAM;
 int addr =  sdb->O_ADR_ADAM;
 int nr  =  sdb->O_NR_ADAM;

 qDebug() << "Откл.(0)  " << m_SelectedItem->text()
          << "    ADAM PORT=" << port
          <<           "ADR=" << addr
          <<            "NR="   << nr;
 int state=WritePort( port, addr, nr, 0 );
 if ( state!=0) {
   qDebug() << "Bad";
   messbox("Ошибка записи");
   lwg->setFocus( Qt::TabFocusReason );   // Установить фокус на список.
   return;
}
 else         qDebug() << "Ok";
 lwg->setFocus( Qt::TabFocusReason );   // Установить фокус на список.

}
Ejemplo n.º 20
0
int main(void)
{
    char *currenttime;	    /* current time/date string	*/
    int	old_sec = 0;
//    int cur_hour = 0;	    /* current hour			*/
//    int cur_day = 0;	    /* current current day		*/
    int result = 0;
    int key = 0;
    Initialise();		// turn outputs on and off for 1 second
    InitDisplay();
    int keepgoing = 1;	    /* tells program to keep running until ESC pressed */
    while ( keepgoing == 1 )
    {

	currenttime = thetime();    /* get the current time	*/
	cur_sec = extract_num(currenttime, 18, 2); /* extract minute	*/
	cur_min = extract_num(currenttime, 15, 2); /* extract minute	*/
	cur_hour = extract_num(currenttime, 12,2); /* extract hour	*/
	//cur_day = extract_num(currenttime, 9, 2);  /* extract day	*/

	if(old_sec != cur_sec) {	/* only update screen once per second	*/
	    ReadAnalogInputs(3);
	    DisplayAnalogValues(3);
	    ReadDigitalInputs(3);
	    DisplayDigitalInputs(3);
	    locate( 25, 56);
	    color(CF_SETTINGS,CB_SETTINGS);
	    cprintf(currenttime);	/* update current time on screen	*/
	    //locate(20,1);cprintf("cur_min=%d",cur_min);
	    old_sec = cur_sec;
	    //  EVENTS (new function)
	    //OutputBit(0,valueInput[0]);
	    //OutputBit(1,valueInput[1]);
	    //OutputBit(2,valueInput[2]);
	    //OutputBit(3,valueInput[3]);

	    if (valueInput[1] == 1) {
		WritePort(1);
		DisplayPort(1,XOUTPUT,YOUTPUT);
	    }
	    if (valueAnalog[0] < 50) {
		WritePort(16);
		DisplayPort(16,XOUTPUT,YOUTPUT);
	    }
	Log("e:\\user\\c\\a_pcio\\logfile.log", currenttime);
	}

	if( kbhit() ) {
	    result = getkeypressed();	/* get a single keypress    */

	    switch (result)  {		/* perform task user pressed	*/
		case 27: {		/* ESC	*/
		    Message( "Do you really want to quit? (Y/n) " , 0);
		    key = getch();
		    if( ( key  == 'Y') || (key =='y') || (key == 13) )
			keepgoing = 0;	/* stop program execution	*/
		    Message("", 0);
		}
		break;

		case 59: {		/* F1	*/
		    Message("Initialising",0);
		    Message("Fast Pulse", 0);
		    Pulse(255, gPulse_fast);
		}
		break;

		case 60: {		/* F2	*/
		    Message("Storage CRO - enter settings", 0);
		    //getch();
		    gotoHiResMode();
		    DrawOscilliscopeScreen(50,0,550,255,50,51);
		    StorageOscilliscope("waiting for trigger", 1, 0, 220, 40, 0, 499);
		    InitDisplay();

		}
		break;

		case 61: {		/* F3	*/
		    gotoHiResMode();
		    DrawOscilliscopeScreen(100,100,355,355,20,32);
		    Oscilliscope();

		    InitDisplay();
		    Message("Oscilliscope", 0);
		     Pulse(255, gPulse_slow);
		}
		break;

		case 62: {		/* F4	*/
		    Message("BinaryCount", 0);
		    BinaryCount(gCounter);
		}
		break;

		case 63: {		/* F5	*/
		    Message("Chase Multiple", 0);
		    ChaseMultiple(gIterations, gSpeed);

		}
		break;
		case 64: {		/* F6	*/
		    Message("Chase Up", 0);
		    Chase(gSpeed, 0, 7);

		}
		break;
		case 65: {		/* F7	*/
		    Message("Chase Down", 0);
		    Chase(gSpeed, 7,0);

		}
		break;
		case 66: {		/* F8	*/
		    Message("Reading Analog inputs", 0);
		    ReadAnalogInputs(3);
		    DisplayAnalogValues(3);
		    ReadDigitalInputs(3);
		    DisplayDigitalInputs(3);
		}
		break;
		case 67: {		/* F9	*/
		    Message("Logging - PRESS A KEY TO STOP", 0);
		    FastAcquisition("e:\\user\\c\\a_pcio\\fastlog.log", currenttime);
		    Message("Done Logging to e:\user\c\a_pcio\fastlog.log", 0);
		}
		break;
		case 68: {		/* F10	*/
		    Message("Setup", 0);
		    //locate(12,65); scanf("%d", &gPORT);   // port change
		    locate(11, 62);
		    color(CF_SETTINGS,CB_SETTINGS);
	//	    color(YELLOW,BLACK);
		    cprintf("Enter new settings");
		    locate(13,75); scanf("%d", &gCounter);   // port change
		    if(gCounter<0||gCounter>999) gCounter=10; else fflush(stdin);
		    locate(14,75); scanf("%d", &gSpeed);   // port change
		    if(gSpeed<0||gSpeed>999) gSpeed=10; else fflush(stdin);
		    locate(15,75); scanf("%d", &gPulse_fast);   // port change
		    if(gPulse_fast<0||gPulse_fast>999) gPulse_fast=10; else fflush(stdin);
		    locate(16,75); scanf("%d", &gPulse_slow);   // port change
		    if(gPulse_slow<0||gPulse_slow>999) gPulse_slow=10; else fflush(stdin);
		    locate(17,75); scanf("%d", &gIterations);   // port change
		    if(gIterations<0||gIterations>999) gIterations=10; else fflush(stdin);

		    DisplaySettings(XSETTINGS,YSETTINGS);
		}
		break;
		case 48: { OutputBit(0,2); DisplayPort(1,XOUTPUT,YOUTPUT); } break;
		case 49: { OutputBit(1,2); DisplayPort(2,XOUTPUT,YOUTPUT); } break;
		case 50: { OutputBit(2,2); DisplayPort(4,XOUTPUT,YOUTPUT); } break;
		case 51: { OutputBit(3,2); DisplayPort(16,XOUTPUT,YOUTPUT); } break;
		case 52: { OutputBit(4,2); DisplayPort(32,XOUTPUT,YOUTPUT); } break;
		case 53: { OutputBit(5,2); DisplayPort(64,XOUTPUT,YOUTPUT); } break;
		case 54: { OutputBit(6,2); DisplayPort(128,XOUTPUT,YOUTPUT); } break;
		case 55: { OutputBit(7,2); DisplayPort(255,XOUTPUT,YOUTPUT); } break;

		case 43: { WritePort(++valueOutput[0]); } break;
		case 45: { WritePort(--valueOutput[0]); } break;

	    }

	}
    }
   return 0;

}
Ejemplo n.º 21
0
 //enum errorType WritePort(char *buff ,unsigned int num_to_write);  gsSerialPort definition
 errorType Write(GSIChar chr) {return(WritePort( (char *)&chr,1));}
Ejemplo n.º 22
0
int initBluetooth(struct sserial_props *pProps, const char *btName, const char *btPin) {
	char pTxBuff[32];
	char pRxBuff[RX_BUFF_LENGTH] = {0};
	int bSame, nLength;

	LOGI("> Triger reset pin");
	resetBluetooth(pProps);

	LOGI("> Switch device to AT-mode");
	ClrDtr(pProps);
	SleepMs(1000);

#if 0
	LOGV("> Reset to default");
	WritePort(pProps, "AT+ORGL" CRLF, strlen("AT+ORGL" CRLF));
	SleepMs(1000);
#endif

	LOGV("> Switch to Slave mode");
	WritePort(pProps, "AT+ROLE=0" CRLF, strlen("AT+ROLE=0" CRLF));
	if (readLine(pProps, pRxBuff, OK_BUFF_LENGTH) <= 0 &&
			strncasecmp(pRxBuff, "ok", 2)) {
		LOGE("AT+ROLE failed to set (%s)", pRxBuff);
		return 0;
	}

	if (getResult(pProps, "AT+NAME?" CRLF, pRxBuff, RX_BUFF_LENGTH)) {
		bSame = strncmp(pRxBuff, btName, strlen(btName)) == 0;

		// Get "OK"
		readLine(pProps, pRxBuff, OK_BUFF_LENGTH);

		if (bSame) {
			LOGW("Bluetooth name is same and will not be changed");
			goto skip_name;
		}
	}

	LOGV("> Set name");
	nLength = sprintf(pTxBuff, "AT+NAME=%s" CRLF, btName);
	WritePort(pProps, pTxBuff, nLength);
	if (readLine(pProps, pRxBuff, OK_BUFF_LENGTH) <= 0 &&
			strncasecmp(pRxBuff, "ok", 2)) {
		LOGE("AT+NAME failed to set (%s)", pRxBuff);
		return 0;
	}

skip_name:
	if (getResult(pProps, "AT+PSWD?" CRLF, pRxBuff, RX_BUFF_LENGTH)) {
		bSame = strncmp(pRxBuff, btPin, strlen(btPin)) == 0;

		// Get "OK"
		readLine(pProps, pRxBuff, OK_BUFF_LENGTH);

		if (bSame) {
			LOGW("Bluetooth pin code is same and will not be changed");
			goto skip_password;
		}
	}

	LOGV("> Set password");
	nLength = sprintf(pTxBuff, "AT+PSWD=%s" CRLF, btPin);
	WritePort(pProps, pTxBuff, nLength);
	if (readLine(pProps, pRxBuff, OK_BUFF_LENGTH) <= 0 &&
			strncasecmp(pRxBuff, "ok", 2)) {
		LOGE("AT+PSWD failed to set (%s)", pRxBuff);
		return 0;
	}

skip_password:
	LOGI("> Switch device to Data-mode");
	SetDtr(pProps);
	SleepMs(10);

	resetBluetooth(pProps);

	return 1;
}
Ejemplo n.º 23
0
/////////////////////////////////////////////////////////////////////////////////
// 函数:SendMsg                                                               //
// 说明:通过指定端口,发送短信                                                //
// 参数:                                                                      //
//      strRecvPhone,接收手机号码                                             //
//      strMsgContent,短信内容                                                //
//      strPortName,串行端口的名称                                            //
/////////////////////////////////////////////////////////////////////////////////
int CSerialPort::SendMsg(CString strRecvPhone , CString strMsgContent)
{
    m_strRecvPhone = strRecvPhone;
    m_strMsgContent = strMsgContent;
    int i=0 , t=0;
    char ans[128];        // 应答串
    //char SCA[16];       // 短消息服务中心号码(SMSC地址)
    char TPA[16];       // 目标号码或回复号码(TP-DA或TP-RA)
    //char TP_PID;        // 用户信息协议标识(TP-PID)
    //char TP_DCS;        // 用户信息编码方式(TP-DCS)
//    char TP_UD[161];    // 原始用户信息(编码前或解码后的TP-UD)
    char  cmd[20];
    MsgList *msglist = new MsgList;
	int iPage = page(strMsgContent.GetBuffer(strMsgContent.GetLength()),msglist);
    
    t= m_strRecvPhone.GetLength()+2;
	for(i=2;i<t;i++)
    {
	   TPA[i]=m_strRecvPhone.GetAt(i-2);
    }
    TPA[0]='8';
    TPA[1]='6';
	TPA[t]='\0';

	for(int iIndex=0 ;iIndex < iPage;iIndex++)
	{
        sprintf(cmd , "AT\r");
        WritePort(cmd, strlen(cmd));
	    Sleep(ShortSleepTime);
        int nLength = ReadPort(ans, 128);
        ans[nLength] = '\0';

        sprintf(cmd, "ATE0\r"); 
        WritePort(cmd, strlen(cmd));
	    Sleep(ShortSleepTime);
        nLength = ReadPort(ans, 128);
        ans[nLength] = '\0';

	    sprintf(cmd, "AT+CSMS=0\r");      
        WritePort(cmd, strlen(cmd));  
 	    Sleep(ShortSleepTime);
        nLength = ReadPort(ans, 128);
        ans[nLength] = '\0';
 
	    sprintf(cmd, "AT+CMGF=0\r");      
        WritePort(cmd, strlen(cmd));  
	    Sleep(ShortSleepTime);
        nLength = ReadPort(ans, 128);
        ans[nLength] = '\0';
          sm_param_temp= new SM_PARAM;
        strcpy(sm_param_temp->SCA,m_SmsCenterNum);

        sm_param_temp->TP_DCS=0x8;
        sm_param_temp->TP_PID=0x0;
        strcpy(sm_param_temp->TPA,TPA);
        strcpy(sm_param_temp->TP_UD,msglist->chMsg);
        if(iPage > 1)
            sprintf(sm_param_temp->TP_UD,"%d/%d %s" ,iIndex+1,iPage,msglist->chMsg);
        //printf("Msg :%s\n" ,sm_param_temp->TP_UD);
        msglist = msglist->pNext;      
        if(!gsmSendMessage(sm_param_temp))//发送短信
        {
            printf("Send SMS Failed\n");
            return -1;
        }
        Sleep(5000);
    }
	return 0;
}
Ejemplo n.º 24
0
void mahaf_WritePort32(u16 port, u32 value)
{
	WritePort(port, value, 4);
}
Ejemplo n.º 25
0
void mahaf_WritePort8(u16 port, u8 value)
{
	WritePort(port, (u32)value, 1);
}
Ejemplo n.º 26
0
void mahaf_WritePort16(u16 port, u16 value)
{
	WritePort(port, (u32)value, 2);
}