Esempio n. 1
0
void PSMoveManager::Process ()
{
  std::vector<struct pollfd> fdvec;

  for (auto w : m_wands) {
    struct pollfd p;
    p.fd = w.second.controller->FileHandle();
    p.events = POLLIN;
    p.revents = 0;
    fdvec.push_back (p);
  }

  auto fdptr = &(*fdvec.begin());

  int ret = poll (fdptr, fdvec.size(), 10);
  
  if (ret < 0) {
    throw (ret);
  }

  if (ret != 0) {
    for (auto w : m_wands) {
      w.second.controller->Process ();
    }
  }

  Heartbeat ();
}
Esempio n. 2
0
void Heartbeat_Timer(uv_timer_t* handle){
	std::cout << "Send Heartbeat..." << std::endl;
	int rc = Heartbeat();
	if (rc == -10000) {
		std::cerr << "Timeout!!! need login again" << std::endl;
		exit(EXIT_FAILURE);
	}
}
Esempio n. 3
0
BOOL Detour_ProcessGameEvents(VOID) 
{ 
    Heartbeat();
#ifdef ISXEQ
    if (!pISInterface->ScriptEngineActive()) 
        pISInterface->LavishScriptPulse();
#endif
    return Trampoline_ProcessGameEvents();
}
Esempio n. 4
0
/*********************************************************************
*
*                            Main Function 
*
*********************************************************************/
void main(void)
{    
    InitDevice();
    
    while(1)
    {
         // Transmit message
         ECAN_Transmit();
         // Toggle LED
         Heartbeat();
         // Delay for one millisecond 
         Delay(ONE_MS);
    }
}
Esempio n. 5
0
BOOL Detour_ProcessGameEvents(VOID)
{
	CAutoLock Lock(&gPulseCS);
	int ret = Heartbeat();
#ifdef ISXEQ
	if (!pISInterface->ScriptEngineActive())
		pISInterface->LavishScriptPulse();
#endif
	int ret2 =  Trampoline_ProcessGameEvents();
#ifndef ISXEQ
	if(ret==2 && bPluginCS==0) {
		OutputDebugString("I am loading in ProcessGameEvents");
		//we are loading stuff
		DWORD oldscreenmode = ScreenMode;
		ScreenMode = 3;
		InitializeMQ2Commands();
		InitializeMQ2Windows();
		MQ2MouseHooks(1);
		Sleep(100);
		InitializeMQ2KeyBinds();
		#ifndef ISXEQ
		InitializeMQ2Plugins();
		#endif
		ScreenMode = oldscreenmode;
		SetEvent(hLoadComplete);
	} else if(ret==1) {
		OutputDebugString("I am unloading in ProcessGameEvents");
		//we are unloading stuff
		DWORD oldscreenmode = ScreenMode;
		ScreenMode = 3;
		WriteChatColor(UnloadedString,USERCOLOR_DEFAULT);
		DebugSpewAlways("%s", UnloadedString);
		UnloadMQ2Plugins();
		MQ2Shutdown();
		DebugSpew("Shutdown completed");
		g_Loaded = FALSE;
		ScreenMode = oldscreenmode;
		SetEvent(hUnloadComplete);

	}
#endif
	return ret2;
}
Esempio n. 6
0
/*********************************************
 DeleteLicense(): Given an upload ID, delete all
 licenses associated with it.
 The DoBegin flag determines whether BEGIN/COMMIT
 should be called.
 Do this if you want to reschedule license analysis.
 *********************************************/
void	DeleteLicense	(long UploadId)
{
  void *VDB;
  char TempTable[256];

  if (Verbose) { printf("Deleting licenses for upload %ld\n",UploadId); }
  DBaccess(DB,"SET statement_timeout = 0;"); /* no timeout */
  MyDBaccess(DB,"BEGIN;");
  memset(TempTable,'\0',sizeof(TempTable));
  snprintf(TempTable,sizeof(TempTable),"DelLic_%ld",UploadId);

  /* Create the temp table */
  if (Verbose) { printf("# Creating temp table: %s\n",TempTable); }
  memset(SQL,'\0',sizeof(SQL));

  /* Get the list of pfiles to process */
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"SELECT DISTINCT(pfile_fk) FROM uploadtree WHERE upload_fk = '%ld' ;",UploadId);
  MyDBaccess(DB,SQL);
  VDB = DBmove(DB);

  /***********************************************/
  /* delete pfile licenses */
  if (Verbose) { printf("# Deleting licenses\n"); }
      memset(SQL,'\0',sizeof(SQL));
      snprintf(SQL,sizeof(SQL),"DELETE FROM licterm_name WHERE pfile_fk IN (SELECT pfile_fk FROM uploadtree WHERE upload_fk = '%ld');",UploadId);
      MyDBaccess(DB,SQL);

      memset(SQL,'\0',sizeof(SQL));
      snprintf(SQL,sizeof(SQL),"DELETE FROM agent_lic_status WHERE pfile_fk IN (SELECT pfile_fk FROM uploadtree WHERE upload_fk = '%ld');",UploadId);
      MyDBaccess(DB,SQL);

      memset(SQL,'\0',sizeof(SQL));
      snprintf(SQL,sizeof(SQL),"DELETE FROM agent_lic_meta WHERE pfile_fk IN (SELECT pfile_fk FROM uploadtree WHERE upload_fk = '%ld');",UploadId);
      MyDBaccess(DB,SQL);
  ItemsProcessed+=DBdatasize(VDB);
  Heartbeat(ItemsProcessed);

  /***********************************************/
  /* Commit the change! */
  if (Verbose) { printf("# Delete completed\n"); }
  if (Test) MyDBaccess(DB,"ROLLBACK;");
  else
	{
	MyDBaccess(DB,"COMMIT;");
#if 0
	/** Disabled: DB will take care of this **/
	if (Verbose) { printf("# Running vacuum and analyze\n"); }
	MyDBaccess(DB,"VACUUM ANALYZE agent_lic_status;");
	MyDBaccess(DB,"VACUUM ANALYZE agent_lic_meta;");
#endif
	}
  DBaccess(DB,"SET statement_timeout = 120000;");

  DBclose(VDB);
  if (ItemsProcessed > 0)
	{
	/* use heartbeat to say how many are completed */
	raise(SIGALRM);
	}
  if (Verbose) { printf("Deleted licenses for upload %ld\n",UploadId); }
} /* DeleteLicense() */
Esempio n. 7
0
/*********************************************
 DeleteUpload(): Given an upload ID, delete it.
 *********************************************/
void	DeleteUpload	(long UploadId)
{
  void *VDB;
  char *S;
  int Row,MaxRow;
  char TempTable[256];

  if (Verbose) { printf("Deleting upload %ld\n",UploadId); }
  DBaccess(DB,"SET statement_timeout = 0;"); /* no timeout */
  MyDBaccess(DB,"BEGIN;");
  memset(TempTable,'\0',sizeof(TempTable));
  snprintf(TempTable,sizeof(TempTable),"DelUp_%ld",UploadId);

  /***********************************************/
  /*** Delete everything that impacts the UI ***/
  /***********************************************/

  /***********************************************/
  /* Delete the upload from the folder-contents table */
  memset(SQL,'\0',sizeof(SQL));
  if (Verbose) { printf("# Deleting foldercontents\n"); }
  snprintf(SQL,sizeof(SQL),"DELETE FROM foldercontents WHERE (foldercontents_mode & 2) != 0 AND child_id = %ld;",UploadId);
  MyDBaccess(DB,SQL);

  if (!Test)
	{
	/* The UI depends on uploadtree and folders for navigation.
	   Delete them now to block timeouts from the UI. */
	if (Verbose) { printf("# COMMIT;\n"); }
	MyDBaccess(DB,"COMMIT;");
	if (Verbose) { printf("# BEGIN;\n"); }
	MyDBaccess(DB,"BEGIN;");
	}


  /***********************************************/
  /*** Begin complicated stuff ***/
  /***********************************************/

  /* Get the list of pfiles to delete */
  /** These are all pfiles in the upload_fk that only appear once. **/
  memset(SQL,'\0',sizeof(SQL));
  if (Verbose) { printf("# Getting list of pfiles to delete\n"); }
  snprintf(SQL,sizeof(SQL),"SELECT DISTINCT pfile_pk,pfile_sha1 || '.' || pfile_md5 || '.' || pfile_size AS pfile INTO %s_pfile FROM uploadtree INNER JOIN pfile ON upload_fk = %ld AND pfile_fk = pfile_pk;",TempTable,UploadId);
  MyDBaccess(DB,SQL);

  /* Remove pfiles with reuse */
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DELETE FROM %s_pfile USING uploadtree WHERE pfile_pk = uploadtree.pfile_fk AND uploadtree.upload_fk != %ld;",TempTable,UploadId);
  MyDBaccess(DB,SQL);

  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"SELECT COUNT(*) FROM %s_pfile;",TempTable);
  MyDBaccess(DB,SQL);
  if (Verbose) { printf("# Created pfile table: %ld entries\n",atol(DBgetvalue(DB,0,0))); }

  /* Get the file listing -- needed for deleting pfiles from the repository. */
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"SELECT * FROM %s_pfile ORDER BY pfile_pk;",TempTable);
  MyDBaccess(DB,SQL);
  VDB = DBmove(DB);
  MaxRow = DBdatasize(VDB);

  /***********************************************
   This begins the slow part that locks the DB.
   The problem is, we don't want to lock a critical row,
   otherwise the scheduler will lock and/or fail.
   ***********************************************/

  /***********************************************/
  /* delete pfile references from all the pfile dependent tables */
  if (Verbose) { printf("# Deleting from licterm_name\n"); }
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DELETE FROM licterm_name USING %s_pfile WHERE pfile_fk = pfile_pk;",TempTable);
  MyDBaccess(DB,SQL);

  if (Verbose) { printf("# Deleting from agent_lic_status\n"); }
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DELETE FROM agent_lic_status USING %s_pfile WHERE pfile_fk = pfile_pk;",TempTable);
  MyDBaccess(DB,SQL);

  if (Verbose) { printf("# Deleting from agent_lic_meta\n"); }
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DELETE FROM agent_lic_meta USING %s_pfile WHERE pfile_fk = pfile_pk;",TempTable);
  MyDBaccess(DB,SQL);

  if (Verbose) { printf("# Deleting from attrib\n"); }
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DELETE FROM attrib USING %s_pfile WHERE pfile_fk = pfile_pk;",TempTable);
  MyDBaccess(DB,SQL);

  /* delete package info table */
  if (Verbose) { printf("# Deleting pkg_deb_req\n"); }
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DELETE FROM pkg_deb_req USING pkg_deb,%s_pfile WHERE pkg_fk = pkg_pk AND pfile_fk = pfile_pk;",TempTable);
  MyDBaccess(DB,SQL);

  if (Verbose) { printf("# Deleting pkg_deb\n"); }
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DELETE FROM pkg_deb USING %s_pfile WHERE pfile_fk = pfile_pk;",TempTable);
  MyDBaccess(DB,SQL);

  if (Verbose) { printf("# Deleting pkg_rpm_req\n"); }
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DELETE FROM pkg_rpm_req USING pkg_rpm,%s_pfile WHERE pkg_fk = pkg_pk AND pfile_fk = pfile_pk;",TempTable);
  MyDBaccess(DB,SQL);

  if (Verbose) { printf("# Deleting pkg_rpm\n"); }
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DELETE FROM pkg_rpm USING %s_pfile WHERE pfile_fk = pfile_pk;",TempTable);
  MyDBaccess(DB,SQL);

  /* delete pfiles in the license_file table */
  if (Verbose) { printf("# Deleting from licese_file\n"); }
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DELETE FROM license_file USING %s_pfile "
	   "WHERE pfile_fk = pfile_pk;",TempTable);
  MyDBaccess(DB,SQL);

  /* Delete pfile reference from tag and tag_file table */
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"SELECT DISTINCT tag_fk, pfile_fk INTO temp_tag_file FROM tag_file INNER JOIN %s_pfile ON pfile_fk = pfile_pk;",TempTable);
  MyDBaccess(DB,SQL);

  if (Verbose) { printf("# Deleting tag_file\n"); }
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DELETE FROM tag_file USING %s_pfile WHERE pfile_fk = pfile_pk;",TempTable);
  MyDBaccess(DB,SQL);
  if (Verbose) { printf("# Deleting tag\n"); }
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DELETE FROM tag USING temp_tag_file,%s_pfile WHERE tag_fk = tag_pk AND pfile_fk = pfile_pk;",TempTable);
  MyDBaccess(DB,SQL);
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DROP TABLE temp_tag_file;");
  MyDBaccess(DB,SQL);

  /***********************************************/
  /*** Everything above is slow, everything below is fast ***/
  /***********************************************/

  /* Delete upload from nomos_ars */
  memset(SQL,'\0',sizeof(SQL));
  if (Verbose) { printf("# Deleting nomos_ars\n"); }
  snprintf(SQL,sizeof(SQL),"DELETE FROM nomos_ars WHERE upload_fk = %ld;",UploadId);
  MyDBaccess(DB,SQL);

  /* Delete upload reference from bucket_ars */
  memset(SQL,'\0',sizeof(SQL));
  if (Verbose) { printf("# Deleting bucket_ars\n"); }
  snprintf(SQL,sizeof(SQL),"DELETE FROM bucket_ars WHERE upload_fk = %ld;",UploadId);
  MyDBaccess(DB,SQL);
  /* Delete uploadtree reference from bucket_container  */
  memset(SQL,'\0',sizeof(SQL));
  if (Verbose) { printf("# Deleting bucket_container\n"); }
  snprintf(SQL,sizeof(SQL),"DELETE FROM bucket_container USING uploadtree WHERE uploadtree_fk = uploadtree_pk AND upload_fk = %ld;",UploadId);
  MyDBaccess(DB,SQL);
  /* Delete pfile reference from bucket_file */
  if (Verbose) { printf("# Deleting bucket_file\n"); }
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DELETE FROM bucket_file USING %s_pfile WHERE pfile_fk = pfile_pk;",TempTable);
  MyDBaccess(DB,SQL);

  /* Delete pfile reference from copyright table */
  if (Verbose) { printf("# Deleting copyright\n"); }
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DELETE FROM copyright USING %s_pfile WHERE pfile_fk = pfile_pk;",TempTable);
  MyDBaccess(DB,SQL);

  /***********************************************/
  /* Blow away jobs */
  /*****
   There is an ordering issue.
   The delete from attrib and pfile can take a long time (hours for
   a source code DVD).
   If we delete from the jobqueue first, then it will hang the scheduler
   as the scheduler tries to update the jobqueue record.  (Row is locked
   by the delete process.)
   The solution is to delete the jobqueue LAST, so the scheduler won't hang.
   *****/
  memset(SQL,'\0',sizeof(SQL));
  if (Verbose) { printf("# Deleting jobdepends\n"); }
  snprintf(SQL,sizeof(SQL),"DELETE FROM jobdepends USING jobqueue,job WHERE jdep_jq_fk = jq_pk AND jq_job_fk = job_pk AND job_upload_fk = %ld;",UploadId);
  MyDBaccess(DB,SQL);

  memset(SQL,'\0',sizeof(SQL));
  if (Verbose) { printf("# Deleting jobqueue\n"); }
  snprintf(SQL,sizeof(SQL),"DELETE FROM jobqueue USING job WHERE jq_job_fk = job_pk AND job_upload_fk = %ld;",UploadId);
  MyDBaccess(DB,SQL);

  memset(SQL,'\0',sizeof(SQL));
  if (Verbose) { printf("# Deleting job\n"); }
  snprintf(SQL,sizeof(SQL),"DELETE FROM job WHERE job_upload_fk = %ld;",UploadId);
  MyDBaccess(DB,SQL);

  /***********************************************/
  /* Delete the actual upload */
  memset(SQL,'\0',sizeof(SQL));
  if (Verbose) { printf("# Deleting uploadtree\n"); }
  snprintf(SQL,sizeof(SQL),"DELETE FROM uploadtree WHERE upload_fk = %ld;",UploadId);
  MyDBaccess(DB,SQL);

  memset(SQL,'\0',sizeof(SQL));
  if (Verbose) { printf("# Deleting upload\n"); }
  snprintf(SQL,sizeof(SQL),"DELETE FROM upload WHERE upload_pk = %ld;",UploadId);
  MyDBaccess(DB,SQL);

  /***********************************************/
  /* Commit the change! */
  if (Test)
	{
	if (Verbose) { printf("# ROLLBACK\n"); }
	MyDBaccess(DB,"ROLLBACK;");
	}
  else
	{
	if (Verbose) { printf("# COMMIT\n"); }
	MyDBaccess(DB,"COMMIT;");
#if 0
	/** Disabled: Database will take care of this **/
	if (Verbose) { printf("# VACUUM and ANALYZE\n"); }
	MyDBaccess(DB,"VACUUM ANALYZE agent_lic_status;");
	MyDBaccess(DB,"VACUUM ANALYZE agent_lic_meta;");
	MyDBaccess(DB,"VACUUM ANALYZE attrib;");
	MyDBaccess(DB,"VACUUM ANALYZE pfile;");
	MyDBaccess(DB,"VACUUM ANALYZE foldercontents;");
	MyDBaccess(DB,"VACUUM ANALYZE upload;");
	MyDBaccess(DB,"VACUUM ANALYZE uploadtree;");
	MyDBaccess(DB,"VACUUM ANALYZE jobdepends;");
	MyDBaccess(DB,"VACUUM ANALYZE jobqueue;");
	MyDBaccess(DB,"VACUUM ANALYZE job;");
#endif
	}


  /***********************************************/
  /* delete from pfile is SLOW due to constraint checking.
     Do it separately. */
  if (Verbose) { printf("# Deleting from pfile\n"); }
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DELETE FROM pfile USING %s_pfile WHERE pfile.pfile_pk = %s_pfile.pfile_pk;",TempTable,TempTable);
  MyDBaccess(DB,SQL);
  memset(SQL,'\0',sizeof(SQL));
  snprintf(SQL,sizeof(SQL),"DROP TABLE %s_pfile;",TempTable);
  MyDBaccess(DB,SQL);

  DBaccess(DB,"SET statement_timeout = 120000;");

  if (Verbose) { printf("Deleted upload %ld from DB, now doing repository.\n",UploadId); }

  /***********************************************/
  /* Whew!  Now to delete the actual pfiles from the repository. */
  /** If someone presses ^C now, then at least the DB is accurate. **/
  if (Test <= 1)
    {
    for(Row=0; Row<MaxRow; Row++)
      {
      memset(SQL,'\0',sizeof(SQL));
      S = DBgetvalue(VDB,Row,1); /* sha1.md5.len */
      if (RepExist("license",S))
	{
	if (Test) printf("TEST: Delete %s %s\n","license",S);
	else RepRemove("license",S);
	}
      if (RepExist("files",S))
	{
	if (Test) printf("TEST: Delete %s %s\n","files",S);
	else RepRemove("files",S);
	}
      if (RepExist("gold",S))
	{
	if (Test) printf("TEST: Delete %s %s\n","gold",S);
	else RepRemove("gold",S);
	}
      ItemsProcessed++;
      Heartbeat(ItemsProcessed);
      }
    } /* if Test <= 1 */
  DBclose(VDB);
  if (ItemsProcessed > 0)
	{
	/* use heartbeat to say how many are completed */
	raise(SIGALRM);
	}
  if (Verbose) { printf("Deleted upload %ld\n",UploadId); }
} /* DeleteUpload() */
Esempio n. 8
0
void GPRS_main ( void )
{
    uint8_t i, len;
    uint8_t sum_check;
    uint16_t data_len;
    uint8_t tmp;
 /*     
    uint16_t *data;
    uint8_t crcl, crch;
    uint16_t addr = 0;
    uint16_t temp_;
 */  
    
    if(( SysTickCnt - HeartbeatCnt ) > HeartBeatTime)
    {
    	if(Get_UpdateStates() == 0)
        	Heartbeat();
        HeartbeatCnt = SysTickCnt;
    } 
    
    if (Dev_Status == 1)
    {
        ChargingTime = (SysTickCnt - ChargingBeginTime)/1000 ;
        if(( SysTickCnt - InfoCnt ) > 17000)
        {
            AC_Info();
            InfoCnt = SysTickCnt;
        } 
        Cur_0_Time = (SysTickCnt - Cur_0_BeginTime)/1000;     
        if ((Cur_0_Time > 180)||                //180s检测不到有效电流则认为充电已经停止
            (linkv != 6)||   //充电过程中如果检测枪断开则停止充电
            (MeterCommErr == 1)||               //电表通信故障
            (output_cur > 3500)||               //电流软保护,当输出电流大于35A时停止充电
            (output_vol > 25300)||(output_vol < 18700))           //电压软保护,当输入电压超出253V或者低于187V时充电机停止输出
        {
            end_CurKwh = CurKwh;
 //           ClrOutput(1);           //停止输出
            OUTPUTCLOSE;
            ClrOutput(2);           //关闭运行指示灯
            Dev_Status = 0;
            Stop();
        }
        
    }
  	UpdateInit(&RS232Tx.Len,&RS232Tx.Flag,RS232Tx.Buff,RS232Rx.Buff,&Dev_Status);
	SendUpdateCommand(SysTickCnt);  
    if ( GetRs232Sta() == 1 ) //帧接收结束标记
    {
        //接收状态指示灯
    /*    RelaySta232 = ~ RelaySta232 ;
        tmp = RelaySta232;
        if ( tmp & 0x1 )
        {
            SetOutput ( LED1 );
        }
        else
        {
            ClrOutput ( LED1 );
        }*/
        //
        len = RS232Rx.Len ;
        RS232Rx.Flag = 0 ;
        RS232Rx.Len = 0;
        RS232Rx.Idx = 0 ;
        if( RS232Rx.Buff[0] == 0x68 )
		{

			if(RS232Rx.Buff[ADDR_FUNCODE] != 0x01)
				{
					//if(!Dev_Status)   //不在充电状态进行相应
					DealUpdate_Flash(len,SysTickCnt);
				}
			if(Get_UpdateStates())
				return;
			//else
        {
            data_len = ( RS232Rx.Buff[9] << 8 ) + RS232Rx.Buff[10];
            if( len == ( data_len + 12 ) )
            {
                sum_check = 0;
                for ( i = 0; i < data_len; i++ )
                {
                    sum_check += RS232Rx.Buff[11+i]; 
                }
                if( sum_check == RS232Rx.Buff[11+data_len])
                {
                    switch ( RS232Rx.Buff[2] )
                    {
                    case 0x01:
                        {
                            communication_state = 1;
                            communication_delay = 0;
                            break;
                        }
                     case 0x02:
                        {
                            communication_state = 1;
                            return_sign = 1;
                            back_type = RS232Rx.Buff[7];
                            memcpy(r_user_info.tel_number,&RS232Rx.Buff[11],12);
                            r_user_info.Balance = 0;
                            r_user_info.Balance = RS232Rx.Buff[23];
                            r_user_info.Balance <<= 8;
                            r_user_info.Balance |= RS232Rx.Buff[24];
                            r_user_info.Balance <<= 8;
                            r_user_info.Balance |= RS232Rx.Buff[25];
                            r_user_info.Balance <<= 8;
                            r_user_info.Balance |= RS232Rx.Buff[26];
                            break;
                        }
                     case 0x03:
                        {
                          SetOutput ( LED1 );//03 light
                            LoginPermission = 1;
                            memcpy(r_user_info.tel_number,&RS232Rx.Buff[11],12);
                            r_user_info.Balance = 0;
                            r_user_info.Balance = RS232Rx.Buff[23];
                            r_user_info.Balance <<= 8;
                            r_user_info.Balance |= RS232Rx.Buff[24];
                            r_user_info.Balance <<= 8;
                            r_user_info.Balance |= RS232Rx.Buff[25];
                            r_user_info.Balance <<= 8;
                            r_user_info.Balance |= RS232Rx.Buff[26];
                            break;
                        }
                     case 0x04:
                        {
                            if (RS232Rx.Buff[7] == 0)
                            {
                                Order_number[0] = RS232Rx.Buff[11];
                                Order_number[1] = RS232Rx.Buff[12];
                                Order_number[2] = RS232Rx.Buff[13];
                                Order_number[3] = RS232Rx.Buff[14];
                                
                                ChargingPermission = 1;
                                
                                r_user_info.Balance = 0;
                                r_user_info.Balance = RS232Rx.Buff[15];
                                r_user_info.Balance <<= 8;
                                r_user_info.Balance |= RS232Rx.Buff[16];
                                r_user_info.Balance <<= 8;
                                r_user_info.Balance |= RS232Rx.Buff[17];
                                r_user_info.Balance <<= 8;
                                r_user_info.Balance |= RS232Rx.Buff[18];
                            }
                            break;
                        }
                     case 0x05:
                        {
                            StopPermission = 1;
                            r_user_info.Balance = 0;
                            r_user_info.Balance = RS232Rx.Buff[11];
                            r_user_info.Balance <<= 8;
                            r_user_info.Balance |= RS232Rx.Buff[12];
                            r_user_info.Balance <<= 8;
                            r_user_info.Balance |= RS232Rx.Buff[13];
                            r_user_info.Balance <<= 8;
                            r_user_info.Balance |= RS232Rx.Buff[14];
                            r_user_info.pay = 0;
                            r_user_info.pay = RS232Rx.Buff[15];
                            r_user_info.pay <<= 8;
                            r_user_info.pay |= RS232Rx.Buff[16];
                            r_user_info.pay <<= 8;
                            r_user_info.pay |= RS232Rx.Buff[17];
                            r_user_info.pay <<= 8;
                            r_user_info.pay |= RS232Rx.Buff[18];
                            break;
                        }
                     case 0x06:
                        {
                            r_user_info.pay = 0;
                            r_user_info.pay = RS232Rx.Buff[11];
                            r_user_info.pay <<= 8;
                            r_user_info.pay |= RS232Rx.Buff[12];
                            r_user_info.pay <<= 8;
                            r_user_info.pay |= RS232Rx.Buff[13];
                            r_user_info.pay <<= 8;
                            r_user_info.pay |= RS232Rx.Buff[14];
                            communication_state = 1;
                            if(RS232Rx.Buff[7] == 0x03 )
                            {
  //                              ClrOutput(1);           //停止输出
                                OUTPUTCLOSE;
                                ClrOutput(2);           //关闭运行指示灯
                                Stop();
                            }
                            break;
                        }
                     case 0x07:
                        {
                            r_user_info.pay = 0;
                            r_user_info.pay = RS232Rx.Buff[11];
                            r_user_info.pay <<= 8;
                            r_user_info.pay |= RS232Rx.Buff[12];
                            r_user_info.pay <<= 8;
                            r_user_info.pay |= RS232Rx.Buff[13];
                            r_user_info.pay <<= 8;
                            r_user_info.pay |= RS232Rx.Buff[14];
                            communication_state = 1;
                            if(RS232Rx.Buff[7] == 0x03 )
                            {
    //                            ClrOutput(1);           //停止输出
                                OUTPUTCLOSE;
                                ClrOutput(2);           //关闭运行指示灯
                                Stop();
                            }
                            break;
                        }
                     case 0x08:
                        {
                            StopRequest = 1;
                    /*      end_CurKwh = CurKwh;
                            Dev_Status = 0;
                            return_sign = 0;
                            communication_state = 1;
                            ClrOutput(1);           //停止输出
                            OUTPUTCLOSE;
                            ClrOutput(2);           //关闭运行指示灯
                            server_stop = 1;
                            Stop();*/
                            break;
                        }
                     case 0x09:
                        {
                            communication_state = 1;
                            memcpy(t_user_info.card_number,&RS232Rx.Buff[11],16);
                            r_user_info.Balance = 0;
                            r_user_info.Balance = RS232Rx.Buff[27];
                            r_user_info.Balance <<= 8;
                            r_user_info.Balance |= RS232Rx.Buff[28];
                            r_user_info.Balance <<= 8;
                            r_user_info.Balance |= RS232Rx.Buff[29];
                            r_user_info.Balance <<= 8;
                            r_user_info.Balance |= RS232Rx.Buff[30];
                            r_user_info.card_status = RS232Rx.Buff[31];
                            break;
                        }
                     case 0x0a:
                        {
                            communication_state = 1;
                            sys_year = RS232Rx.Buff[11];
                            sys_month = RS232Rx.Buff[12];
                            sys_day = RS232Rx.Buff[13];
                            sys_hour = RS232Rx.Buff[14];
                            sys_minute = RS232Rx.Buff[15];
                            sys_cecond = RS232Rx.Buff[16];
                            break;
                        } 
                    }
                }
                else
                {
                  RS232Rx.Flag = 0 ;
                  RS232Rx.Len = 0;
                  RS232Rx.Idx = 0 ;
                  return;
                }
            }
            else
            {
              RS232Rx.Flag = 0 ;
              RS232Rx.Len = 0;
              RS232Rx.Idx = 0 ;
              return;
            }
}
        }
        else
        {
          RS232Rx.Flag = 0 ;
          RS232Rx.Len = 0;
          RS232Rx.Idx = 0 ;
          return;
        }
    }
}
Esempio n. 9
0
int	main	(int argc, char *argv[])
{
  int arg;
  char Parm[MAXCMD];
  char *TempFileDir=NULL;
  int c;
  int InitFlag=0;
  char *agent_desc = "Network downloader.  Uses wget(1).";

  memset(GlobalTempFile,'\0',MAXCMD);
  memset(GlobalURL,'\0',MAXCMD);
  memset(GlobalParam,'\0',MAXCMD);
  memset(Parm,'\0',MAXCMD);
  GlobalUploadKey = -1;
  /* Process command-line */
  while((c = getopt(argc,argv,"d:Gg:ik:A:R:l:")) != -1)
    {
    switch(c)
	{
	case 'd':
		TempFileDir = optarg;
		break;
	case 'g':
		{
		struct group *SG;
		SG = getgrnam(optarg);
		if (SG) ForceGroup = SG->gr_gid;
		}
		break;
	case 'G':
		GlobalImportGold=0;
		break;
	case 'i':
		InitFlag=1;
		break;
	case 'k':
		GlobalUploadKey = atol(optarg);
		if (!GlobalTempFile[0])
			strcpy(GlobalTempFile,"wget.default_download");
		break;
        case 'A':
                sprintf(GlobalParam, "%s -A %s ",GlobalParam, optarg);
                break;
        case 'R':
                sprintf(GlobalParam, "%s -R %s ",GlobalParam, optarg);
                break;
        case 'l':
                sprintf(GlobalParam, "%s -l %s ",GlobalParam, optarg);
                break;
	default:
		Usage(argv[0]);
		exit(-1);
	}
    }
  if (argc - optind > 1)
	{
	Usage(argv[0]);
	exit(-1);
	}

  /* Init */
  DB = DBopen();
  if (!DB)
	{
	printf("FATAL: Unable to connect to database\n");
	fflush(stdout);
	exit(20);
	}

  /* When initializing the DB, don't do anything else */
  if (InitFlag)
	{
	DBclose(DB);
	return(0);
	}

  /* Get the Agent Key from the DB */
  GetAgentKey(DB, basename(argv[0]), GlobalUploadKey, SVN_REV, agent_desc);

  /* Run from the command-line (for testing) */
  InitHeartbeat();
  signal(SIGALRM,ShowHeartbeat);
  for(arg=optind; arg < argc; arg++)
    {
    memset(GlobalURL,'\0',sizeof(GlobalURL));
    strncpy(GlobalURL,argv[arg],sizeof(GlobalURL));
    /* If the file contains "://" then assume it is a URL.
       Else, assume it is a file. */
    if (Debug) printf("Command-line: %s\n",GlobalURL);
    if (strstr(GlobalURL,"://"))
      {
      alarm(60);
      Heartbeat(0);
      if (Debug) printf("It's a URL\n");
      if (GetURL(GlobalTempFile,GlobalURL,TempFileDir) != 0)
	{
	printf("ERROR: Download of %s failed.\n",GlobalURL);
	fflush(stdout);
	DBclose(DB);
	exit(21);
	}
      InitHeartbeat();
      if (GlobalUploadKey != -1) { DBLoadGold(); }
      unlink(GlobalTempFile);
      alarm(0);
      }
    else /* must be a file */
      {
      if (Debug) printf("It's a file -- GlobalUploadKey = %ld\n",GlobalUploadKey);
      if (GlobalUploadKey != -1)
	{
	memcpy(GlobalTempFile,GlobalURL,MAXCMD);
	DBLoadGold();
	}
      }
    }

  /* Run from scheduler! */
  if (optind == argc)
    {
    printf("OK\n"); /* inform scheduler that we are ready */
    fflush(stdout);
    InitHeartbeat();
    alarm(60);
    while(ReadLine(stdin,Parm,MAXCMD) >= 0)
      {
      if (Parm[0] != '\0')
	{
    Heartbeat(0);
	/* 3 parameters: uploadpk downloadfile url */
	SetEnv(Parm,TempFileDir); /* set globals */
        char TempDir[MAXCMD];
        memset(TempDir,'\0',MAXCMD);
        snprintf(TempDir, MAXCMD-1, "%s/wget", TempFileDir); // /var/local/lib/fossology/agents/wget
	if (GetURL(GlobalTempFile,GlobalURL,TempDir) == 0)
		{
	  	  DBLoadGold();
		  unlink(GlobalTempFile);
                  struct stat sb;
                  /* Run from scheduler! delete the temp directory, /var/local/lib/fossology/agents/wget */
                  if (!stat(TempDir, &sb))
                  {
                    char CMD[MAXCMD];
                    memset(CMD,'\0',MAXCMD);
                    snprintf(CMD,MAXCMD-1, "rm -rf '%s' 2>&1", TempDir);
                    int rc_system = system(CMD); 
                    if (rc_system != 0) exit(25); // failed to delete the temperary directory
                  }
		}
	else
		{
		printf("FATAL upload %ld File retrieval failed.\n",GlobalUploadKey);
		printf("LOG upload %ld File retrieval failed: uploadpk=%ld tempfile=%s URL=%s\n",GlobalUploadKey,GlobalUploadKey,GlobalTempFile,GlobalURL);
		fflush(stdout);
		DBclose(DB);
		exit(22);
		}
	printf("OK\n"); /* inform scheduler that we are ready */
	fflush(stdout);
	alarm(60);
	}
      }
    } /* if run from scheduler */

  /* Clean up */
  DBclose(DB);
  return(0);
} /* main() */