Example #1
0
int gsmSendMessage(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结束
	TRACE("%s", pdu);  //zhao
	gsmString2Bytes(pdu, &nSmscLength, 2);	// 取PDU串中的SMSC信息长度
	nSmscLength++;		// 加上长度字节本身

	// 命令中的长度,不包括SMSC信息长度,以数据字节计
	sprintf(cmd, "AT+CMGS=%d\r", nPduLength / 2 - nSmscLength);	// 生成命令

	TRACE("%s", cmd);  
	TRACE("%s\n", pdu);

	WriteComm(cmd, strlen(cmd));	// 先输出命令串
	
	nLength = ReadComm(ans, 128);	// 读应答数据

	// 根据能否找到"\r\n> "决定成功与否
	if(nLength == 4 && strncmp(ans, "\r\n> ", 4) == 0)
	{
		return WriteComm(pdu, strlen(pdu));		// 得到肯定回答,继续输出PDU串
	}

	return 0;
}
Example #2
0
int XTTY::WriteComm2(const char * buf, int n)
{
	if (m_fLocalEcho)
		WriteLog(buf, n);

	return WriteComm(m_idComDev, buf, n);
}
Example #3
0
void CSocketManager::OnDataReceived(const LPBYTE lpBuffer, DWORD dwCount)
{
	
	
	LPBYTE lpData = lpBuffer;
	SockAddrIn origAddr;
	stMessageProxy msgProxy;
	if (IsSmartAddressing())
	{
		dwCount = __min(sizeof(msgProxy), dwCount);
		memcpy(&msgProxy, lpBuffer, dwCount);
		origAddr = msgProxy.address;
		if (IsServer())
		{
			// broadcast message to all
			msgProxy.address.sin_addr.s_addr = htonl(INADDR_BROADCAST);
			WriteComm((const LPBYTE)&msgProxy, dwCount, 0L);
		}
		dwCount -= sizeof(msgProxy.address);
		lpData = msgProxy.byData;
	}
	
	
	// Display data to message list
	DisplayData( lpData, dwCount, origAddr );
}
Example #4
0
int far pascal zWriteComm( int pp1, void far* pp2, int pp3 )
{
    int r;

    SaveRegs();
    /*
    ** Log IN Parameters (No Create/Destroy Checking Yet!)
    */
    LogIn( (LPSTR)"APICALL:WriteComm int+FineString+",
        pp1, (LPSTR) pp2, (int) pp3 );

    /*
    ** Call the API!
    */
    RestoreRegs();
    GrovelDS();
    r = WriteComm(pp1,pp2,pp3);
    UnGrovelDS();
    SaveRegs();
    /*
    ** Log Return Code & OUT Parameters (No Create/Destroy Checking Yet!)
    */
    LogOut( (LPSTR)"APIRET:WriteComm int++++",
        r, (short)0, (short)0, (short)0 );

    RestoreRegs();
    return( r );
}
bool  CStrainDevice::RequestDataB(long &ad)
{
	if (m_hCom == INVALID_HANDLE_VALUE)
	{
		return false;
	}

	BYTE cmd = 'M';
	WriteComm(&cmd, 1);
	::Sleep(20);

	BYTE bytesRead[5];
	ZeroMemory(bytesRead, 2);
	DWORD nCount = ReadComm(bytesRead, 5);
	bool ok = (nCount == 5);

	if (ok)
	{
		BYTE *ptr = (BYTE*)&ad;
		ptr[0] = bytesRead[3];
		ptr[1] = bytesRead[2];
		ptr[2] = bytesRead[1];
		ptr[3] = bytesRead[0];
	}
	return ok;
}
Example #6
0
int	TSerialConnection :: SendData ( char *  buffer,
					 int	 buffer_size )
   {
	COMSTAT		ComStat ;
	register int	size	=  buffer_size ;


	if  ( DeviceId  <  0 )
		return ( 0 ) ;

	while  ( size )
		{
		SetCommEventMask ( DeviceId, EV_TXEMPTY ) ;

		while  ( GetCommEventMask ( DeviceId, EV_TXEMPTY ) )
			{
			SetCommEventMask ( DeviceId, EV_TXEMPTY ) ;
		    }

		GetCommError  ( DeviceId, & ComStat ) ;

		if  ( ComStat. cbOutQue )
			continue ;

		WriteComm ( DeviceId, buffer, 1 ) ;
		buffer ++, size -- ;
		  }

	return ( buffer_size ) ;
	 }
Example #7
0
void BlockWrite(unsigned int Xstart,unsigned int Xend,unsigned int Ystart,unsigned int Yend) 
{
	WriteComm(0x2a);   
	WriteData(Xstart>>8);
	WriteData(Xstart&0xff);
	WriteData(Xend>>8);
	WriteData(Xend&0xff);

	WriteComm(0x2b);   
	WriteData(Ystart>>8);
	WriteData(Ystart&0xff);
	WriteData(Yend>>8);
	WriteData(Yend&0xff);
	
	WriteComm(0x2c);
}
Example #8
0
/*
LCD块写(大量数据修改,相当于擦除)
*/
void BlockWrite(unsigned int Xstart, unsigned int Xend, unsigned int Ystart, unsigned int Yend)
{
    //ILI9163C
    WriteComm(0x2A);
    WriteData(Xstart >> 8);
    WriteData(Xstart);
    WriteData(Xend >> 8);
    WriteData(Xend);

    WriteComm(0x2B);
    WriteData(Ystart >> 8);
    WriteData(Ystart);
    WriteData(Yend >> 8);
    WriteData(Yend);

    WriteComm(0x2c);
}
Example #9
0
int gsmDeleteMessage(int index)
{
	char cmd[16];		// 命令串

	sprintf(cmd, "AT+CMGD=%d\r", index);	// 生成命令

	// 输出命令串
	return WriteComm(cmd, strlen(cmd));
}
Example #10
0
/*定位x0-127 y0-7*/
void set_xy(u8 x,u8 y) 
{
   if (x>=64)   
   	{
   		CS1H;
   		Delay(1);
   		CS2L;
   	} 
   else         
   	{
   		CS1L;
   		Delay(1);
   		CS2H;
   	}
	WriteComm(0x40|x);
    WriteComm(0xb8|y);
    OutPutData(0xff);  //判别是左半屏,还是右半屏
}
Example #11
0
// 初始化GSM状态
BOOL gsmInit(const char* pPort)
{
	char ans[128];		// 应答串
    ZeroMemory(ans,128);

	// 测试GSM-MODEM的存在性
	WriteComm(pPort,"AT\r\n", 4);
	ReadComm(pPort,ans, 128);
	if (strstr(ans, "OK") == NULL)  return FALSE;

	// ECHO OFF
	WriteComm(pPort,"ATE0\r", 5);
	ReadComm(pPort,ans, 128);

	// PDU模式
	WriteComm(pPort,"AT+CMGF=0\r", 10);
	ReadComm(pPort,ans, 128);

	return TRUE;
}
Example #12
0
// 初始化GSM状态
BOOL gsmInit()
{
	char ans[128];		// 应答串

	// 测试GSM-MODEM的存在性
	WriteComm("AT\r", 3);
	ReadComm(ans, 128);

	if (strstr(ans, "OK") == NULL)  return FALSE;

	// ECHO OFF
	WriteComm("ATE0\r", 5);
	ReadComm(ans, 128);

	// PDU模式
	WriteComm("AT+CMGF=0\r", 10);
	ReadComm(ans, 128);

	return TRUE;
}
void CCommThread::SendTxBuff(){
	BOOL bResult;
	for(int i=mIndex; i<mTotalcnt; i++ ){
		if(WriteComm(TxPktBuff[i].PKT, TxPktBuff[i].LENGTH)){
			mCommand = WRITEDATA_CMD;
			bResult = TRUE;
		}
		if(bResult)
			createtimeoutThread();
	}
	mIndex = mTotalcnt;
}
Example #14
0
 u16 GetPoint( u16 x, u16 y)
{
	WriteComm(0x2a);   
	WriteData(x>>8);
	WriteData(x);
	WriteData(x>>8);
	WriteData(x);

	WriteComm(0x2b);   
	WriteData(y>>8);
	WriteData(y);
	WriteData(y>>8);
	WriteData(y);

	WriteComm(0x2e);
	
	x = *(__IO u16 *) (Bank1_LCD_D);x=1;while(--x);
	x = *(__IO u16 *) (Bank1_LCD_D);
	y = *(__IO u16 *) (Bank1_LCD_D);
// 	printf("RIN=%04x\r\n",b);

	return (x&0xf800)|((x&0x00fc)<<3)|(y>>11);
}
bool  CStrainDevice::RequestAddr(BYTE addr /* = 0 */)
{
	if (m_hCom == INVALID_HANDLE_VALUE)
	{
		return false;
	}

	BYTE cmd[2];
	cmd[0] = 'K';
	cmd[1] = 0;
	WriteComm(cmd, 2);
	::Sleep(100);

	BYTE to_read[2];
	ZeroMemory(to_read, 2);
	ReadComm(to_read, 2);

	return memcmp(cmd, to_read, 2) == 0;
}
Example #16
0
//-------------------------------------------------------------------
// Write an array of bytes to the COM port, verify that it was
// sent out.  Assume that baud rate has been set and the buffers have
// been flushed.
//
//  portnum    - number 0 to MAX_PORTNUM-1.  This number is provided to
//                 indicate the symbolic port number.
//  outlen     - the length of the data to be written
//  outbuf     - the output data
//
// Returns TRUE for success and FALSE for failure
//
int WriteCOM(int portnum, int outlen, uchar *outbuf)
{
   short result;
   COMSTAT ComStat;
   ulong m;
   // declare and set the default timeout
   int timeout = 20 * outlen + 60;

   //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
   #ifdef DODEBUG
   short i;
      printf("W[");
      for (i = 0; i < outlen; i++)
         printf("%02X ",outbuf[i]);
   #endif
   //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//

   // Send data to write buffer
   result = WriteComm(ComID[portnum],outbuf,outlen);

   //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
   #ifdef DODEBUG
         printf("(%d)]",result);
   #endif
   //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
   // loop to wait for the write to complete
   if (result == outlen)
   {
      m = (ulong)msGettick() + (ulong)timeout;
      do
      {
         // yield this process
         //Yield();
         GetCommError(ComID[portnum],&ComStat);
         if ((short)ComStat.cbOutQue == 0)
            return result;
      }
      while ((ulong)msGettick() <= m);
   }
   else
      return FALSE;
}
Example #17
0
int gsmReadMessageList(const char* pPort)
{
	return WriteComm(pPort,"AT+CMGL=0\r", 10);  //zhao 
}
Example #18
0
int gsmReadMessageList()
{
	return WriteComm("AT+CMGL=4\r", 10);  //zhao 
}
Example #19
0
/*
LCD初始化函数
*/
void LCD_Init(void)
{
	DELAY_MS(100);
    RET_SET;
    DELAY_MS(100);
    RET_CLEAR;
    DELAY_MS(100);
    RET_SET;
    DELAY_MS(100);

    //-------------Start Initial Sequence--------//
    WriteComm(0x11); //Exit Sleep
    DELAY_MS(10);//20
    WriteComm(0x26); //Set Default Gamma
    WriteData(0x04);

    WriteComm(0xB1);//Set Frame Rate
    WriteData(0x0B);
    WriteData(0x14);

    WriteComm(0xC0); //Set VRH1[4:0] & VC[2:0] for VCI1 & GVDD
    WriteData(0x0C);
    WriteData(0x05);

    WriteComm(0xC1); //Set BT[2:0] for AVDD & VCL & VGH & VGL
    WriteData(0x02);

    WriteComm(0xC5); //Set VMH[6:0] & VML[6:0] for VOMH & VCOML
    WriteData(0x3F);//44
    WriteData(0x48);

    WriteComm(0xC7);// Set VMF
    WriteData(0xC2);

    WriteComm(0x2A); //Set Column Address
    WriteData(0x00);
    WriteData(0x00);
    WriteData(0x00);
    WriteData(0x7F);
    WriteComm(0x2B); //Set Page Address
    WriteData(0x00);
    WriteData(0x00);
    WriteData(0x00);
    WriteData(0x9F);

    WriteComm(0x3A); //Set Color Format
    WriteData(0x55);
    WriteComm(0x36);
    WriteData(0xC8);

    WriteComm(0xF2); //Enable Gamma bit
    WriteData(0x01);
    WriteComm(0xE0);
    WriteData(0x3F);//p1
    WriteData(0x25);//p2
    WriteData(0x21);//p3
    WriteData(0x24);//p4
    WriteData(0x1D);//p5
    WriteData(0x0D);//p6
    WriteData(0x4C);//p7
    WriteData(0xB8);//p8
    WriteData(0x38);//p9
    WriteData(0x17);//p10
    WriteData(0x0F);//p11
    WriteData(0x08);//p12
    WriteData(0x04);//p13
    WriteData(0x02);//p14
    WriteData(0x00);//p15
    WriteComm(0xE1);
    WriteData(0x00);//p1
    WriteData(0x1A);//p2
    WriteData(0x1E);//p3
    WriteData(0x0B);//p4
    WriteData(0x12);//p5
    WriteData(0x12);//p6
    WriteData(0x33);//p7
    WriteData(0x47);//p8
    WriteData(0x47);//p9
    WriteData(0x08);//p10
    WriteData(0x20);//p11
    WriteData(0x27);//p12
    WriteData(0x3C);//p13
    WriteData(0x3D);//p14
    WriteData(0x3F);//p15


    WriteComm(0x36); //MX, MY, RGB mode
    WriteData(0xC0);//c8竖屏  68横屏

    WriteComm(0x29); // Display On

    WriteComm(0x2C);
}
Example #20
0
/**********************************************
Lcd初始化函数
***********************************************/
void Lcd_Initialize(void)
{	
LCD_GPIO_Config();
LCD_FSMC_Config();
LCD_Rst();
	
//************* Start Initial Sequence **********//
WriteComm(0xFF); // EXTC Command Set enable register 
WriteData(0xFF); 
WriteData(0x98); 
WriteData(0x06); 

WriteComm(0xBA); // SPI Interface Setting 
WriteData(0xE0); 

WriteComm(0xBC); // GIP 1 
WriteData(0x03); 
WriteData(0x0F); 
WriteData(0x63); 
WriteData(0x69); 
WriteData(0x01); 
WriteData(0x01); 
WriteData(0x1B); 
WriteData(0x11); 
WriteData(0x70); 
WriteData(0x73); 
WriteData(0xFF); 
WriteData(0xFF); 
WriteData(0x08); 
WriteData(0x09); 
WriteData(0x05); 
WriteData(0x00);
WriteData(0xEE); 
WriteData(0xE2); 
WriteData(0x01); 
WriteData(0x00);
WriteData(0xC1); 

WriteComm(0xBD); // GIP 2 
WriteData(0x01); 
WriteData(0x23); 
WriteData(0x45); 
WriteData(0x67); 
WriteData(0x01); 
WriteData(0x23); 
WriteData(0x45); 
WriteData(0x67); 

WriteComm(0xBE); // GIP 3 
WriteData(0x00); 
WriteData(0x22); 
WriteData(0x27); 
WriteData(0x6A); 
WriteData(0xBC); 
WriteData(0xD8); 
WriteData(0x92); 
WriteData(0x22); 
WriteData(0x22); 

WriteComm(0xC7); // Vcom 
WriteData(0x1E);
 
WriteComm(0xED); // EN_volt_reg 
WriteData(0x7F); 
WriteData(0x0F); 
WriteData(0x00); 

WriteComm(0xC0); // Power Control 1
WriteData(0xE3); 
WriteData(0x0B); 
WriteData(0x00);
 
WriteComm(0xFC);
WriteData(0x08); 

WriteComm(0xDF); // Engineering Setting 
WriteData(0x00); 
WriteData(0x00); 
WriteData(0x00); 
WriteData(0x00); 
WriteData(0x00); 
WriteData(0x02); 

WriteComm(0xF3); // DVDD Voltage Setting 
WriteData(0x74); 

WriteComm(0xB4); // Display Inversion Control 
WriteData(0x00); 
WriteData(0x00); 
WriteData(0x00); 

WriteComm(0xF7); // 480x854
WriteData(0x81); 

WriteComm(0xB1); // Frame Rate 
WriteData(0x00); 
WriteData(0x10); 
WriteData(0x14); 

WriteComm(0xF1); // Panel Timing Control 
WriteData(0x29); 
WriteData(0x8A); 
WriteData(0x07); 

WriteComm(0xF2); //Panel Timing Control 
WriteData(0x40); 
WriteData(0xD2); 
WriteData(0x50); 
WriteData(0x28); 

WriteComm(0xC1); // Power Control 2 
WriteData(0x17);
WriteData(0X85); 
WriteData(0x85); 
WriteData(0x20); 

WriteComm(0xE0); 
WriteData(0x00); //P1 
WriteData(0x0C); //P2 
WriteData(0x15); //P3 
WriteData(0x0D); //P4 
WriteData(0x0F); //P5 
WriteData(0x0C); //P6 
WriteData(0x07); //P7 
WriteData(0x05); //P8 
WriteData(0x07); //P9 
WriteData(0x0B); //P10 
WriteData(0x10); //P11 
WriteData(0x10); //P12 
WriteData(0x0D); //P13 
WriteData(0x17); //P14 
WriteData(0x0F); //P15 
WriteData(0x00); //P16 

WriteComm(0xE1); 
WriteData(0x00); //P1 
WriteData(0x0D); //P2 
WriteData(0x15); //P3 
WriteData(0x0E); //P4 
WriteData(0x10); //P5 
WriteData(0x0D); //P6 
WriteData(0x08); //P7 
WriteData(0x06); //P8 
WriteData(0x07); //P9 
WriteData(0x0C); //P10 
WriteData(0x11); //P11 
WriteData(0x11); //P12 
WriteData(0x0E); //P13 
WriteData(0x17); //P14 
WriteData(0x0F); //P15 
WriteData(0x00); //P16

WriteComm(0x35); //Tearing Effect ON 
WriteData(0x00); 

WriteComm(0x36); 
WriteData(0x60); 

WriteComm(0x3A); 
WriteData(0x55); 

WriteComm(0x11); //Exit Sleep 
LCD_delay(120); 
WriteComm(0x29); // Display On 
LCD_delay(10);
	Lcd_Light_ON;
	
	WriteComm(0x3A); WriteData(0x55);
	WriteComm(0x36); WriteData(0xA8);
	Lcd_ColorBox(0,0,800,480,YELLOW);
	
// 	LCD_Fill_Pic(80,160,320,480, gImage_MM_T035);
// 	BlockWrite(0,0,799,479);
}
Example #21
0
/**********************************************
Lcd初始化函数
Initial condition  (DB0-15,RS,CSB,WRD,RDB,RESETB="L") 
***********************************************/
void Lcd_Initialize(void)
{	
int i;
SPI_CS(1);

WriteComm(0x0001);
Delay(100);
SPI_CS(0);
WriteComm(0x0011);
Delay(20);
WriteComm(0x00D0);    
WriteData(0x0007); 
WriteData(0x0041); 
WriteData(0x001C); 
 
WriteComm(0x00D1);    
WriteData(0x0000); 
WriteData(0x0036); //30 vcm
WriteData(0x001B); //15 vdv

                                                                 
WriteComm(0x00D2);
WriteData(0x0001);   // AP0[2:0]
WriteData(0x0011);   // DC10[2:0],DC00[2:0]
  
WriteComm(0x00C0);     //****** *******
WriteData(0x0010);   // REV & SM & GS
WriteData(0x003B);   // NL[5:0]
WriteData(0x0000);   // SCN[6:0]
WriteData(0x0012);   //02  NDL , PTS[2:0]
WriteData(0x0001);   //11 PTG , ISC[3:0]  
  
WriteComm(0x00C5);    
WriteData(0x0003);


WriteComm(0x00C8);
WriteData(0x0000);
WriteData(0x0057);
WriteData(0x0033);
WriteData(0x0000);
WriteData(0x0000);
WriteData(0x0000);
WriteData(0x0044);
WriteData(0x0002);
WriteData(0x0077);
WriteData(0x0000);
WriteData(0x0000);
WriteData(0x0000);
 
  
WriteComm(0x00F8);
WriteData(0x0001);
  
WriteComm(0x00FE);
WriteData(0x0000);
WriteData(0x0002);
  
WriteComm(0x0036);   // Set_address_mode
WriteData(0x000A);  // Bit3: RGB/BGR
Delay(20);
WriteComm(0x003a);   // Set_address_mode
WriteData(0x0055);  //05---16BIT,06---18BIT  
Delay(20);  

WriteComm(0x0029); 

Delay(10);
	WriteComm(0x36); //Set_address_mode
 	WriteData(0x68); //横屏,从左下角开始,从左到右,从下到上

Lcd_Light_ON;

// while(1)
{
WriteComm(0x36);//竖屏
WriteData(0x48);//
// 	while(!(SPI1->SR&0x0002));
for(i=0;i<320*480;i++)
{
	LCD_RS(1);
	SPI_I2S_SendData(SPI1, COLOR_BLUE>>8);
	LCD_RS(1);
	SPI_I2S_SendData(SPI1, COLOR_BLUE);
}
for(i=0;i<320*480;i++)
{
	LCD_RS(1);
	SPI_I2S_SendData(SPI1, COLOR_YELLOW>>8);
	LCD_RS(1);
	SPI_I2S_SendData(SPI1, COLOR_YELLOW);
}

WriteComm(0x36);
WriteData(0x28);//
}

}