示例#1
0
文件: GpsSrc.cpp 项目: awzhang/MyWork
bool CGpsSrc::_ReleaseGpsSrc()
{
	m_bGpsInit = false;
	if( false == _KillSirfReq() )
	{
		PRTMSG(MSG_NOR, "关闭SifvNav进程失败\n");
		g_bProgExit = true;
		return false;
	}
	else
	{
		PRTMSG(MSG_NOR, "关闭SifvNav进程成功\n");
	}

	sleep(1);

	if(-1 != m_iSemid)
	{
		semctl(m_iSemid,0,IPC_RMID);
		m_iSemid = -1;
	}

	if(-1 != m_iShmid)
	{
		//que 是否需要做失败的判断?
		shmctl(m_iShmid, IPC_RMID, NULL);
		m_iShmid = -1;
	}
	m_pShm = NULL;

	return true;
}
示例#2
0
void CLN_Login::LoginAnswer(char *v_szBuf, DWORD v_dwLen)
{
	if( v_dwLen != 1 )
	{
		PRTMSG(MSG_ERR, "LoginAnswer len err, v_dwLen = %d\n", v_dwLen);
		return;
	}
	
	switch( v_szBuf[0] )
	{
	case 0x01:		// 登陆成功
		{
			PRTMSG(MSG_NOR, "Login succ!\n");
			g_objLNDownLoad.m_bNetFined = true;
			m_dwLoginTimers = 0;
			m_dwLoginSucc = 1;
			
			_KillTimer(&g_objTimerMng, LOGIN_TIMER);
			
			// 发送心跳维护帧
			HeartKeep();
		}
		break;
		
	case 0x00:		// 登陆失败,继续登陆
		{
			PRTMSG(MSG_NOR, "Login failed, continue Login!\n");
		}
		break;
		
	default:
		break;
	}
}
示例#3
0
文件: IO.cpp 项目: awzhang/MyWork
int CIO::IOCfgGet( unsigned char v_ucIOSymb, void *v_pIOCfg, DWORD v_dwCfgSize )
{
/*	_Init();*/

	if( v_ucIOSymb >= sizeof(SYSIO_CFG) / sizeof(SYSIO_CFG[0]) )
	{
		PRTMSG( MSG_ERR, "IOCfgGet %d: IOSymb Over Max Number\n", int(v_ucIOSymb) );
		return ERR_PAR;
	}

	if( v_pIOCfg && v_dwCfgSize >= sizeof(tagIOCfg) )
	{
		memcpy( v_pIOCfg, &SYSIO_CFG[v_ucIOSymb], sizeof(tagIOCfg) );
		PRTMSG( MSG_DBG, "IOCfgGet OK, No.%3d,Pin-%3d,prd-%4d,io-%d,brken-%d,brktyp-%d,brklvl-%d,low-%3d,hig-%3d\n", v_ucIOSymb,
			SYSIO_CFG[v_ucIOSymb].m_uiPinNo, SYSIO_CFG[v_ucIOSymb].m_uiContPrid, SYSIO_CFG[v_ucIOSymb].m_ucInOut,
			SYSIO_CFG[v_ucIOSymb].m_bBreak, SYSIO_CFG[v_ucIOSymb].m_cBreakType, SYSIO_CFG[v_ucIOSymb].m_cBreakPow,
			SYSIO_CFG[v_ucIOSymb].m_ucPinLowApp, SYSIO_CFG[v_ucIOSymb].m_ucPinHigApp );
		return 0;
	}
	else
	{
		PRTMSG( MSG_ERR, "IOCfgGet %d: output size(%d) lack!\n", int(v_ucIOSymb), int(v_dwCfgSize) );
		return ERR_PTR;
	}
}
示例#4
0
文件: GpsSrc.cpp 项目: awzhang/MyWork
//设置RTC时间,使用GPS时间校对RTC(格林威治时间格式)
bool CGpsSrc::_SetTimeToRtc(struct tm* v_SetTime)
{
	struct rtc_time objRtcTime;

	memset(&objRtcTime, 0, sizeof(objRtcTime));

	int iDevRtc = open("/dev/misc/rtc", O_NONBLOCK);

	if(-1 == iDevRtc)
	{
		PRTMSG(MSG_ERR,"open rtc dev err\n");
		return false;
	}
		
	objRtcTime.tm_sec = v_SetTime->tm_sec;
	objRtcTime.tm_min = v_SetTime->tm_min;
	objRtcTime.tm_hour = v_SetTime->tm_hour;
	objRtcTime.tm_mday = v_SetTime->tm_mday;
	objRtcTime.tm_mon =	v_SetTime->tm_mon;
	objRtcTime.tm_year = v_SetTime->tm_year+1900;

	if(0 != ioctl(iDevRtc, RTC_SET_TIME, &objRtcTime))
	{
		close(iDevRtc);
		iDevRtc = -1;
		return false;
	}

	PRTMSG(MSG_DBG,"set gps time to rtc\n");

	close(iDevRtc);
	iDevRtc = -1;

	return true;
}
示例#5
0
文件: GpsSrc.cpp 项目: awzhang/MyWork
//共享内存
int CGpsSrc::_ShmInit()
{
	int iShmid = -1;
	int i;
	key_t shmKey;
	int flag1, flag2;

	shmKey = ftok(KEYPATH,0);

	if (shmKey == -1)
	{
		PRTMSG(MSG_ERR,"failed to get a key from ftok(name, 0)\n");
		perror(" ");
		return -1;
	}
	for(i = 0; i<5; i++)
	{
		iShmid = shmget(shmKey,SHM_SIZE,0666 );
		if(-1 == iShmid)
		{
			PRTMSG(MSG_ERR,"shmget failed times: %d\n",i+1);
			sleep(1);
			continue;
		}
		else
		{
			return iShmid;
		}
	}

	PRTMSG(MSG_ERR,"gps shmget error\n");
	perror(" ");

	return -1;
}
示例#6
0
文件: GpsSrc.cpp 项目: awzhang/MyWork
//信号量
int CGpsSrc::_SemInit()
{	
	int iFlag1,iFlag2,iSemKey;
	int i;
	int iSemid;
	int tmperrno;

	iSemKey=ftok(KEYPATH,'a');

	if (iSemKey == -1)
	{
		PRTMSG(MSG_ERR,"failed to get a key for IPC\n");
		return -1;
	}
	for(i=0; i<10; i++ )
	{
		iSemid=semget(iSemKey,1,0666);//create a semaphore set that only includes one semphore.

		if(-1 == iSemid)
		{
			PRTMSG(MSG_ERR,"semget failed times: %d\n",i+1);
			sleep(1);
			continue;
		}
		else
		{
			return iSemid;
		}
	}

	PRTMSG(MSG_ERR,"gps semget error\n");
	perror(" ");

	return -1;
}
示例#7
0
int main()
{
	//unsigned char ucIOSta = 0;
	int iVal = 0;
	tag2QServCodeCfg cfg;
	//tag1LComuCfg cfg2;
	int iCode = 1111111111;
	int iRet = 0;
	char buf[100] = { 0 };
	while(1)
	{
		memset( buf, 0, sizeof(buf) );
		sprintf( buf, "%d", iCode ++ );
		
		memcpy( cfg.m_szTaxHandtel, buf, sizeof(cfg.m_szTaxHandtel) );
		iRet = SetSecCfg( &cfg, offsetof(tagSecondCfg, m_uni2QServCodeCfg.m_obj2QServCodeCfg), sizeof(cfg) );
		PRTMSG( MSG_NOR, "Set seccfg: %s, result: %d\n", buf, iRet );

// 		memcpy( cfg2.m_szVeIDKey, buf, sizeof(cfg2.m_szVeIDKey) );
// 		iRet = SetImpCfg( &cfg2, offsetof(tagImportantCfg, m_uni1LComuCfg.m_obj1LComuCfg), sizeof(cfg2) );
// 		//iRet = SetImpCfg( buf, 200, sizeof(buf) );
// 		PRTMSG( MSG_NOR, "Set impcfg: %s, result: %d\n", buf, iRet );
		

		iVal ++;
		if( 20 == iVal ) break;

		usleep( 1000000 );
	}

	PRTMSG( MSG_NOR, "exit!\n" );
	exit( 0 );
}
示例#8
0
文件: GpsSrc.cpp 项目: awzhang/MyWork
bool CGpsSrc::_InitGps()
{
	m_iGpsSta = stInit;

#if VEHICLE_TYPE == VEHICLE_M
	if(system("insmod /dvs/extdrv/yx3510_gps.ko") != 0)
	{
		PRTMSG(MSG_ERR,"GPS模块加载失败!\n");
		return false;
	}
#endif

	if(0 != pthread_mutex_init( &m_hMutexGsv, NULL))
	{
		PRTMSG(MSG_ERR,"初始化互斥量失败!\n");
		return false;
	}

	if(0 != pthread_create(&m_pthreadGpsRead, NULL, (void *(*)(void*))G_GpsReadThread, (void *)&g_objGpsSrc) )
	{
		PRTMSG(MSG_ERR,"创建GPS读线程失败!\n");
		return false;
	}

	return true;
}
示例#9
0
文件: yx_Oil.cpp 项目: awzhang/MyWork
int COil::Init()
{
	// 打开串口
	if( !ComOpen() )
	{
		PRTMSG(MSG_ERR, "Open Com failed!\n");
		return ERR_COM;
	}

	pthread_mutex_init(&m_MutexAD, NULL);

	// 创建线程
	pthread_t pThreadRecv, pThreadSend;
	if( pthread_create(&pThreadRecv, NULL, G_ThreadOilRecv, NULL) != 0
		||
		pthread_create(&pThreadSend, NULL, G_ThreadOilSend, NULL) != 0
		)
	{
		PRTMSG(MSG_ERR, "Create thread failed!\n");
		perror("");
		return ERR_THREAD;
	}

	return 0;
}
示例#10
0
int JBDemo_StartAudio( void )
{
	int result;

	/* Initialize audio hardware and open an output stream. */
	Pa_Initialize();
	result = Pa_OpenDefaultStream( &audioStream,
	                               0, SAMPLES_PER_FRAME,
	                               paInt16,
	                               (double) SAMPLE_RATE,
	                               JukeBox_GetFramesPerTick(),
	                               0,
	                               JBDemo_Callback,
	                               NULL );
	if( result < 0 )
	{
		PRTMSG( "Pa_OpenDefaultStream returns " );
		PRTMSG( Pa_GetErrorText( result ) );
		PRTMSG( "\n" );

		goto error;
	}

	Pa_StartStream( audioStream );

error:
	return result;
}
示例#11
0
int main()
{
	unsigned char ucIOSta = 0;
	int iVal = 0;
	int iResult = 0;
	tag2QServCodeCfg cfg;
	tag1LComuCfg cfg2;
	char buf[100] = { 0 };
	//PRTMSG( MSG_NOR, "Run!\n" );
	while(1)
	{
		//PRTMSG( MSG_DBG, "Loop!\n" );

		memset( buf, 0, sizeof(buf) );

		//iResult = GetSecCfg( &cfg, sizeof(cfg), offsetof(tagSecondCfg, m_uni2QServCodeCfg.m_obj2QServCodeCfg), sizeof(cfg) );
		//memcpy( buf, cfg.m_szTaxHandtel, sizeof(cfg.m_szTaxHandtel) );
		
		iResult = GetImpCfg( &cfg2, sizeof(cfg2), offsetof(tagImportantCfg, m_uni1LComuCfg.m_obj1LComuCfg), sizeof(cfg2) );
		memcpy( buf, cfg2.m_szVeIDKey, sizeof(cfg2.m_szVeIDKey) );

		//iResult = GetImpCfg( buf, sizeof(buf), 200, sizeof(buf) );

		PRTMSG( MSG_NOR, "Get seccfg: %s, result: %d\n", buf, iResult );

		iVal ++;
		if( 50 == iVal ) break;

		usleep( 1000000 );
	}

	PRTMSG( MSG_NOR, "exit!\n" );
	exit( 0 );
}
示例#12
0
int CKTIrdMod::Init()
{
	// 打开红外口
	if( !ComOpen() )
	{
		PRTMSG(MSG_ERR, "Open Ird failed\n");
		return ERR_COM;
	}
	
	// 创建接收线程
	if( pthread_create(&m_pthreadRecv, NULL, G_ThreadIrdModKaiTianRecv, NULL) != 0 )
	{
		Release();
		PRTMSG(MSG_ERR, "Create Recv Thread failed\n");
		return ERR_THREAD;
	}

#if USE_IRD_KAITIAN == 1
	if( pthread_create(&m_pthreadWork, NULL, G_ThreadIrdModKaiTianWork, NULL) != 0 )
	{
		Release();
		PRTMSG(MSG_ERR, "Create Work Thread failed\n");
		return ERR_THREAD;
	}
#endif

	return 0;
}
示例#13
0
bool ExeUpdate()
{
	if( WaitForEvent(MOUNT, &g_objUsbSta.UDisk[0], 15000)==0 )
	{
		char const szUpdateFile[32] = "exe.bin";
		char diskPathUpfile[128] = {0};	//升级路径+升级文件
		
		sprintf(diskPathUpfile, "/mnt/%s/%s", UDISK_UP_PATH, szUpdateFile);
	
		// 将升级文件exe.bin复制到part3的下载目录下,以作为升级备份
		if( AppIntact(diskPathUpfile) == false || 0 != system("cp -f /mnt/UDisk/part1/exe.bin /mnt/Flash/part3/Down/exe.bin") )
		{
			PRTMSG(MSG_DBG, "cp exe.bin to part3 fail!\n");
			return false;
		}
		
#if VEHICLE_TYPE == VEHICLE_M
		if( G_ExeUpdate(diskPathUpfile, 1) == true )
#endif
#if VEHICLE_TYPE == VEHICLE_V8 || VEHICLE_TYPE == VEHICLE_M2
		if( G_ExeUpdate(diskPathUpfile, 0) == true )
#endif
		{
			PRTMSG(MSG_DBG, "soft update succ\n");
			
			DelErrLog();	// 升级成功后程序从分区5启动
		
			return true;
		}
	}
	
	return false;
}
示例#14
0
void CLN_Login::HeartKeep()
{
	m_dwSendHeartKeepTimers++;

	// 心跳数据重传了9次未收到心跳应答,请求ComuExe重新拨号
	if( m_dwSendHeartKeepTimers >= 9 )
	{
		PRTMSG(MSG_NOR, "Send HeartKeep to max timers, Ask ComuExe to queck net!\n");
		char buf[] = {0x34, 0x01};
		DataPush((void*)&buf, 2, DEV_SOCK, DEV_PHONE, LV3);
		g_objLNDownLoad.m_bNetFined = false;
		m_dwSendHeartKeepTimers = 0;
		m_dwLoginSucc = 0;
		_KillTimer(&g_objTimerMng, HEART_KEEP_TIMER);

		return;
	}

	char  szBuf[100] = {0};
	DWORD dwLen = 0;
	
	szBuf[dwLen++] = 0x41;	// 命令类型
	
	szBuf[dwLen++] = 0x00;	// 动作:心跳
	szBuf[dwLen++] = 0x03;
	
	// 发送
	g_objApplication.SendAppFrame(MODE_A, 0x80, true, 0, szBuf, dwLen);
	PRTMSG(MSG_NOR, "Send HeartKeep Frame!\n");
	
	// 重启定时器
	tag1PComuCfg obj1PComuCfg;
	GetImpCfg( (void*)&obj1PComuCfg, sizeof(obj1PComuCfg), offsetof(tagImportantCfg, m_uni1PComuCfg.m_obj1PComuCfg), sizeof(obj1PComuCfg) );
	_SetTimer(&g_objTimerMng, HEART_KEEP_TIMER, obj1PComuCfg.m_iHeartKeepInterval*1000, G_TmHeartKeep );
}
示例#15
0
文件: yx_Sock.cpp 项目: zyh329/MyWork
int CSock::DealSmsFrame( char* v_szBuf, int v_iBufLen, char* v_szVeTel, size_t v_sizTel)
{
    // 检查数据长度
    if( v_iBufLen < QIANDOWNFRAME_BASELEN )
    {
        XUN_ASSERT_VALID( false, "" );
        return ERR_PAR;
    }

    char* szDesTelInFrm = v_szBuf;
    char* szSrcTelInFrm = v_szBuf;
#if 0 == USE_PROTOCOL || 1 == USE_PROTOCOL || 30 == USE_PROTOCOL
    szDesTelInFrm = v_szBuf + 5;
    szSrcTelInFrm = v_szBuf + 20;
#endif
#if 2 == USE_PROTOCOL
    szDesTelInFrm = v_szBuf + 6;
    szSrcTelInFrm = v_szBuf + 21;
#endif

    BYTE bytTranType, bytDataType;
#if 0 == USE_PROTOCOL || 30 == USE_PROTOCOL
    bytTranType = BYTE( v_szBuf[3] );
    bytDataType = BYTE( v_szBuf[4] );
#endif
#if 1 == USE_PROTOCOL
    bytTranType = BYTE( v_szBuf[0] );
    bytDataType = BYTE( v_szBuf[1] );
#endif
#if 2 == USE_PROTOCOL
    bytTranType = BYTE( v_szBuf[4] );
    bytDataType = BYTE( v_szBuf[5] );
#endif

    // 检查请求帧的目的手机号
    if( 0x10 != bytTranType || 0x01 != bytDataType ) // 若不是设置短信中心号
    {
        if( v_szVeTel && v_szVeTel[0] && strncmp(szDesTelInFrm, v_szVeTel, v_sizTel) )
        {
            PRTMSG(MSG_DBG, "DesTel is uncorrect!\n");
            PRTMSG(MSG_DBG, "szDesTelInFrm is:%s\n", szDesTelInFrm);
            PRTMSG(MSG_DBG, "v_szVeTel is:%s\n", v_szVeTel);
            return ERR_PAR;
        }
    }

    // 检查校验和
    byte bytSum = get_crc_sms((byte*)v_szBuf, v_iBufLen - 1);
    if( bytSum != BYTE( v_szBuf[v_iBufLen - 1] ) )
    {
        PRTMSG(MSG_DBG, "get_crc_sms err!\n");
        return ERR_PAR;
    }

    // 转入具体事务处理
    AnalyzeSmsFrame( szSrcTelInFrm, szDesTelInFrm, bytTranType, bytDataType, v_szBuf + QIANDOWNFRAME_BASELEN - 1, v_iBufLen - QIANDOWNFRAME_BASELEN);

    return 0;
}
示例#16
0
文件: yx_Sock.cpp 项目: zyh329/MyWork
void CSock::TcpLog()
{
    char buf[ 200 ] = { 0 };
    int iLen = 0;

    // TCP连续登陆失败次数达到上限
    if(m_iTcpLogTimers > TCP_MAX_LOG_TIMERS)
    {
        m_iTcpLogTimers = 0;
        _KillTimer(&g_objTimerMng, DVRTCP_LOG_TIMER);

        buf[0] = 0x01;	// 请求SockServExe重新连接套接字
        DataPush(buf, 1, DEV_DVR, DEV_SOCK, LV3);
        PRTMSG(MSG_NOR, "Tcp Log failed to max timers, request Tcp Reconnect!\n");

        // 调度屏进行提示
        G_TmShowMsg(NULL, 0);

        return;
    }

    m_bTcpLogged = false;

#if USE_LIAONING_SANQI == 1
    buf[0] = 0x07;
    buf[1] = m_bTcpLogged ? 0x01 : 0x00;
    DataPush(buf, 2, DEV_DVR, DEV_QIAN, LV3);
#endif
    _SetTimer(&g_objTimerMng, DVRTCP_LOG_TIMER, 15000, G_TmTcpLog );

#if 2 == USE_PROTOCOL
    tag1PComuCfg obj1PComuCfg;
    obj1PComuCfg.Init(CDMA_NAME,CDMA_PASS);
    GetImpCfg( &obj1PComuCfg, sizeof(obj1PComuCfg),	offsetof(tagImportantCfg, m_uni1PComuCfg.m_obj1PComuCfg), sizeof(obj1PComuCfg) );
    memcpy( m_objGPRS01.m_szUserIdenCode, USERIDENCODE, sizeof(m_objGPRS01.m_szUserIdenCode) );
#endif

    GetSelfTel( m_objGPRS01.m_szParData, sizeof(m_objGPRS01.m_szParData) );

#if 0 == USE_PROTOCOL || 1 == USE_PROTOCOL || 30 == USE_PROTOCOL
    const BYTE GPRSLOGFRM_TYPE = 0x11;
    const BYTE GPRSLOGFRM_GRADE = 0x10;
#endif
#if 2 == USE_PROTOCOL
    const BYTE GPRSLOGFRM_TYPE = 0x01;
    const BYTE GPRSLOGFRM_GRADE = 0x04;
#endif
    if( !_MakeTcpFrame( (char*)&m_objGPRS01, sizeof(m_objGPRS01), GPRSLOGFRM_TYPE, GPRSLOGFRM_GRADE, buf, sizeof(buf), iLen ) )
    {
        PRTMSG(MSG_NOR, "Send Tcp Log Frame\n" );

        G_RecordDebugInfo("Dvr Send Tcp Log Frame" );

        DataPush(buf, iLen, DEV_DVR, DEV_SOCK, LV3);
        m_iTcpLogTimers++;
    }
}
示例#17
0
void Deal_ReUpload(void *arg, int len)
{
	if( g_szReUploadBuf[0] == 0xC1 )
		PRTMSG(MSG_DBG, "ReUpload C1 frame\n");
	if( g_szReUploadBuf[0] == 0xC3 )
		PRTMSG(MSG_DBG, "ReUpload C3 frame\n");

	//PrintString((char*)g_szReUploadBuf, g_iReUploadLen);

	DataPush(g_szReUploadBuf, (DWORD)g_iReUploadLen, DEV_DVR, DEV_SOCK, LV2);
}
示例#18
0
int CLightCtrl::Init()
{
	// ´´½¨¿ØÖƵÆÏß³Ì
	if( pthread_create(&m_pthreadLightCtrl, NULL, G_ThreadLightCtrl, NULL) != 0 )
	{
		PRTMSG(MSG_ERR, "create light thread failed!\n");
		return ERR_THREAD;
	}

	PRTMSG(MSG_ERR, "create light thread succ!\n");
	return 0;
}
示例#19
0
bool CTcpSock::_JudgeConFailMaxTime(int &v_iFailTimes)
{
	if( DEV_QIAN == m_dwSymb || DEV_DVR == m_dwSymb)
	{
		if( v_iFailTimes >= 3 )	// 连续三次连接失败,则请求ComuExe重新拨号
		{
			v_iFailTimes = 0;
			
			if(m_dwSymb == DEV_DVR)
			{
				PRTMSG(MSG_ERR, "Dvr Tcp connect failed to max timers! Ask ComuExe to queck net!\n");
				G_RecordDebugInfo("Dvr Tcp connect failed to max timers! Ask ComuExe to queck net!");
			}
			if(m_dwSymb == DEV_QIAN)
			{
				PRTMSG(MSG_ERR, "Qian Tcp connect failed to max timers! Ask ComuExe to queck net!\n");
				G_RecordDebugInfo("Qian Tcp connect failed to max timers! Ask ComuExe to queck net!");
			}
			
			// 请求ComuExe重新拨号
			char buf[] = {0x34, 0x01};
			DataPush((void*)&buf, 2, DEV_SOCK, DEV_PHONE, LV3);
			
			buf[0] = 0x01;
			buf[1] = 0x03;
			if(DEV_QIAN == m_dwSymb)
			{
				// 同时请求QianExe向调度屏发送提示
				DataPush((void*)&buf, 2, DEV_SOCK, DEV_QIAN, LV3);
			}
			if(DEV_DVR == m_dwSymb)
			{
				// 同时请求DvrExe向调度屏发送提示
				DataPush((void*)&buf, 2, DEV_SOCK, DEV_DVR, LV3);
			}

			return true;
		}
		else
		{
			return false;
		}
	}
	else if( DEV_UPDATE == m_dwSymb )	// 升级服务器的TCP不去判断失败次数,一直重连
	{
		return false; // 暂不填充
	}
	
	return false;
}
示例#20
0
bool CKTIrdMod::ComOpen()
{
	m_iComPort = open("/dev/misc/irdadrv", O_RDWR);
	if(m_iComPort == -1)
	{
		PRTMSG(MSG_ERR, "Ird Open failed\n");
		perror("");
		return false;
	}
	
	PRTMSG(MSG_DBG,"Ird Open Succ!\n"); 
	
	return true;
}
示例#21
0
文件: Dog.cpp 项目: awzhang/MyWork
int CDog::_ShmCreate()
{
	int iRet = 0;
	void* pShare = NULL;
	bool bFirstCreate = false;
	
	m_iShmID = shmget( (key_t)KEY_SHM_DOG, sizeof(DWORD), 0666 | IPC_CREAT | IPC_EXCL );
	if( -1 == m_iShmID )
	{
		m_iShmID = shmget( (key_t)KEY_SHM_DOG, sizeof(DWORD), 0666 | IPC_CREAT );
		if( -1 == m_iShmID )
		{
			iRet = ERR_SHMGET;
			PRTMSG( MSG_ERR, "shmget fail\n" ); 
			goto _SHM_CREATE_END;
		}
		else
		{
			PRTMSG( MSG_DBG, "shmget succ\n" ); 
		}
	}
	else
	{
		bFirstCreate = true;
	}
	
	pShare = shmat( m_iShmID, 0, 0 );
	if( (void*)-1 == pShare )
	{
		iRet = ERR_SHMAT;
		PRTMSG( MSG_ERR, "shmat fail\n" );
		goto _SHM_CREATE_END;
	}
	else
	{
		PRTMSG( MSG_DBG, "shmat succ\n" );
		m_pShareMem = (char*)pShare;
	}
	
	if( bFirstCreate )
	{
		_SemP();
		memset( m_pShareMem, 0xff, sizeof(DWORD) );
		_SemV();
	}
	
_SHM_CREATE_END:
	return iRet;
}
示例#22
0
int StopBlack()
{
	if( g_objWorkStart.Black )
	{
		PRTMSG(MSG_NOR, "Stop Black\n");
		
		g_objWorkStop.Black = TRUE;
		/*pthread_join(g_pthreadBlack, NULL);*/
		
		PRTMSG(MSG_NOR, "stop black succ\n");
		return 0;
	}
	
	return -1;
}
示例#23
0
bool CComAdjust::ComOpen()
{
	int iResult;
	int i;
	struct termios options;
	const int COMOPEN_TRYMAXTIMES = 5;
	
	for( i = 0; i < COMOPEN_TRYMAXTIMES; i ++ )
	{
		m_iComPort = open("/dev/ttySIM0", O_RDWR );
		//m_iComPort = open("/dev/ttyAMA0", O_RDWR );

		if( -1 != m_iComPort )
		{
			PRTMSG(MSG_ERR,"Open com succ!\n");
			break;
		}
		
		sleep(1);
	}

	if( -1 == m_iComPort )
	{
		PRTMSG(MSG_ERR,"Open com fail!\n");
		return false;
	}
	
	if(tcgetattr(m_iComPort, &options) != 0)
	{
		perror("GetSerialAttr");
		return false;
	}
	
	options.c_iflag &= ~(IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IUCLC|IXON|IXOFF|IXANY); 
	options.c_lflag &= ~(ECHO|ECHONL|ISIG|IEXTEN|ICANON);
	options.c_oflag &= ~OPOST;
	
	cfsetispeed(&options,B9600);	//设置波特率,调度屏设置波特率为9600
	cfsetospeed(&options,B9600);
	
	if (tcsetattr(m_iComPort,TCSANOW,&options) != 0)   
	{ 
		perror("Set com Attr"); 
		return false;
	}
	
	return true;
}
示例#24
0
文件: IO.cpp 项目: awzhang/MyWork
int CIO::_ShmCreate()
{
	bool bFstCreate = false;

	if( -1 == m_iShmID )
	{
		m_iShmID = shmget( (key_t)KEY_SHM_IO, IO_MEMSHARE_SIZE, 0666 | IPC_CREAT | IPC_EXCL );
		if( -1 == m_iShmID )
		{
			m_iShmID = shmget( (key_t)KEY_SHM_IO, IO_MEMSHARE_SIZE, 0666 | IPC_CREAT );
			if( -1 == m_iShmID )
			{
				PRTMSG( MSG_ERR, "shm get fail\n" );
				return ERR_SHMGET;
			}
			else
			{
				PRTMSG( MSG_DBG, "shm get succ\n" );
			}
		}
		else
		{
			bFstCreate = true;
			PRTMSG( MSG_DBG, "shm get succ(first)\n" );
		}
	}

	if( !m_pMemShare )
	{
		void *pShare = shmat( m_iShmID, 0, 0 );
		if( (void*)-1 != pShare )
		{
			PRTMSG( MSG_DBG, "shmat succ\n" );
			m_pMemShare = (char*)pShare;
			if( bFstCreate )
			{
				memset( pShare, 0, IO_MEMSHARE_SIZE );
			}
		}
		else
		{
			PRTMSG( MSG_ERR, "shmat fail\n" );
			return ERR_SHMAT;
		}
	}

	return 0;
}
示例#25
0
文件: yx_Oil.cpp 项目: awzhang/MyWork
int COil::_DealComuC1(char *v_szData, DWORD v_dwDataLen)
{
	PRTMSG(MSG_DBG, "DealComuC1!\n");

	char buf[200] = {0};
	int  len = 0;

	buf[0] = 0x01;		// 0x01表示要发往调度屏或者手柄的数据
	buf[1] = 0xF0;
	
	byte bytOilStatus = 0;
	unsigned short usOilAD = 0;
	unsigned short usPowAD = 0;
	
	if( !QueryOilData(bytOilStatus, usOilAD, usPowAD) )
	{ 		
		buf[2] = 0x01;
		memcpy(buf+3,&usOilAD,2);
		memcpy(buf+5,&usPowAD,2);
		len = 7;    
	}
	else
	{
		buf[2] = 0x02;
		len = 3;    
	}

	DataPush(buf, len, DEV_QIAN, DEV_DIAODU, LV2);
	return 0;
}
示例#26
0
文件: yx_Sock.cpp 项目: zyh329/MyWork
void CSock::_TcpKeep( BYTE v_bytNextInterval )
{
    if( !m_bTcpLogged ) return;

    PRTMSG(MSG_NOR, "Rcv Cent Tcp Link Keep Req: %d m\n", v_bytNextInterval );

    G_RecordDebugInfo("Dvr Tcp Rcv Cent Link Keep Req: %d m", v_bytNextInterval );

    char buf[ 100 ] = { 0 };
    int iLen = 0;

#if 0 == USE_PROTOCOL || 1 == USE_PROTOCOL || 30 == USE_PROTOCOL
    char* pData = NULL;
    int iDataLen = 0;
    const BYTE FRM04_GRADE = 0x10;
#endif

#if 2 == USE_PROTOCOL
    char cAnsType = 1;
    char* pData = &cAnsType;
    int iDataLen = sizeof(cAnsType);
    const BYTE FRM04_GRADE = 0x04;
#endif

    if( !_MakeTcpFrame( pData, iDataLen, 0x04, FRM04_GRADE, buf, sizeof(buf), iLen ) )
    {
        // 将数据推到业务支撑子层进行发送
        DataPush(buf, iLen, DEV_DVR, DEV_SOCK, LV2);
    }

    _SetTimer(&g_objTimerMng, DVRTCP_RECONN_TIMER, 4*v_bytNextInterval*60000 + 50000, G_TmTcpReConn);
}
示例#27
0
文件: GpsSrc.cpp 项目: awzhang/MyWork
//获取gps原始数据
bool CGpsSrc::_GetGpsOrigData(gps_data_share* v_p_objGpsData)
{
	int i;
	int iRet;

	for(i = 0; i<5; i++)
	{
		iRet = _SemaphoreP();
		if(true != iRet)
		{
			PRTMSG(MSG_ERR,"have not got the sem\n");
			_SemaphoreV();
			sleep(1);
			continue;
		}	
		memcpy(v_p_objGpsData, m_pShm, sizeof(gps_data_share));

		_SemaphoreV();

		//判断数据的有效性,'$'
		if(0 == m_objGpsDataShm.combine_data[0].gga_data[0]) 
		{
			sleep(2);
		}
		else break;
	}

	if(i >= 5)
	{
		return false;
	}
	else return true;
}
示例#28
0
void CComAdjust::P_ThreadComAdjustRead()
{
	char szReadBuf[1024] = {0};
	int  iBufLen = sizeof(szReadBuf);
	int  iReadLen = 0;
	int  i = 0;
	byte bytLvl = 0;
	DWORD dwPushTm;
	
	while(!g_bProgExit) 
	{
		iReadLen = read(m_iComPort, szReadBuf, iBufLen);
		
//   		PRTMSG(MSG_DBG, "com recv:");
//  		PrintString(szReadBuf, iReadLen);
		
		if(iReadLen > iBufLen)
		{
			PRTMSG(MSG_ERR,"Com Read Over Buf!\n");
			memset(szReadBuf, 0, sizeof(szReadBuf));
			iReadLen = 0;
			
			continue;
		}		
		
		if( iReadLen > 0 )
		{
			AnalyseComFrame(szReadBuf, iReadLen);
		}
	}
}
示例#29
0
文件: IO.cpp 项目: awzhang/MyWork
int CIO::IOGet( unsigned char v_ucIOSymb, unsigned char *v_p_ucIOSta )
{	// 返回值: 0,低电平; 1,高电平

/*	_Init();*/

	if( v_ucIOSymb >= sizeof(SYSIO_CFG) / sizeof(SYSIO_CFG[0]) )
	{
		PRTMSG( MSG_ERR, "IOGet %d: IOSymb Over Max Number\n", int(v_ucIOSymb) );
		return ERR_PAR;
	}

	if( 65535 == SYSIO_CFG[v_ucIOSymb].m_uiPinNo ) return ERR_IO;

	if( v_p_ucIOSta )
	{
		//_SemP();

		char cVal = YX_GPIO_GetValue( SYSIO_CFG[v_ucIOSymb].m_uiPinNo );

		//_SemV();

		*v_p_ucIOSta = (cVal == 0 ? SYSIO_CFG[v_ucIOSymb].m_ucPinLowApp : SYSIO_CFG[v_ucIOSymb].m_ucPinHigApp);

		//PRTMSG( MSG_DBG, "IOGet: pin-%3d, val-%d\n", SYSIO_CFG[v_ucIOSymb].m_uiPinNo, cVal );

		return 0;
	}
	else
	{
		return ERR_PTR;
	}
}
示例#30
0
bool ImageUpdate()
{
	if( WaitForEvent(MOUNT, &g_objUsbSta.UDisk[0], 15000)==0 )
	{
		char const szUpdateFile[32] = "image.bin";
		char diskPathUpfile[128] = {0};	//升级路径+升级文件
		
		sprintf(diskPathUpfile, "/mnt/%s/%s", UDISK_UP_PATH, szUpdateFile);
		
#if VEHICLE_TYPE == VEHICLE_M
		if( G_ImageUpdate(diskPathUpfile, 1)==true )
#endif
#if VEHICLE_TYPE == VEHICLE_V8 || VEHICLE_TYPE == VEHICLE_M2
		if( G_ImageUpdate(diskPathUpfile, 0)==true )
#endif
		{
			PRTMSG(MSG_DBG, "%s update succ\n", szUpdateFile);
			
			DelErrLog();	// 升级成功后程序从分区5启动
			DelVerFile();	// 升级成功后修改系统版本号
		
			return true;
		}
	}
	
	return false;
}