Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
int Cominit(int port)
{
    char tmp[20];
    USHORT rc;
    HFILE hf;

    if(hcModem == NULL)
    {
        if (port_is_device)
        {
            sprintf(tmp, "com%1u", port+1);

            /* Bink/Opus/Max use 8K zmodem blocks.  Make the Rx and Tx queues at
             * least that size.  This won't affect Tx much,  but we don't want
             * Rx to ever overflow.
             */
            rc = !ComOpen(tmp, &hcModem, 8200, 8200);
        }
        else
        {
#ifndef UNIX
          sprintf(tmp, "handle %d", port+1);

          hf = (HFILE)port+1;  /* maximus subtracts 1 from the value on the command line. Add it back here. */
          rc = !ComOpenHandle((COMMHANDLE)hf, &hcModem, 8200, 8200);
#else
//	  logit("!Not yet implemented; %s, %s:%i", __FUNCTION__, 
//__FILE__, __LINE__);
//	  _exit(1);
	  sprintf(tmp, "com%1u", port+1);
	  rc = !ComOpen(tmp, &hcModem, 8200, 8200);
	  mdm_nowonline();
#endif
        }

        if(rc)
        {
            logit("!SYS%04u:  ComOpen(%s)", rc, tmp);
            return(0);
        }
    }
    else
        ComResume(hcModem);

    return (0x1954);
}
Ejemplo n.º 4
0
	BlockwiseImpl(const char* path,uint32_t baud, uint8_t parity)
	:read_over(OP_READ),write_over(OP_WRITE),read_size(1) {
		uint32_t flags = FILE_FLAG_OVERLAPPED;
		hCom = ComOpen(path, baud, parity, flags);
		if(INVALID_HANDLE_VALUE == hCom) throw -1;
		
		hIOCP = CreateIoCompletionPort(hCom,0,0,0);
		if(!hIOCP) {
			HandleLastError("CreateIoCompletionPort");
			throw -2;
		};
	
		io_thread = thread(boost::bind(&BlockwiseImpl::iocp_thread,this));		
	}
Ejemplo n.º 5
0
int CComAdjust::Init()
{
#if USE_COMBUS == 0		// 若使用串口扩展盒,则不在此处打开串口
	if( !ComOpen() )
	{
		PRTMSG(MSG_ERR, "open com failed!\n");
		perror("");
		return ERR_COM;
	}

	// 创建读串口线程
	if( pthread_create(&m_pthreadRead, NULL, G_ThreadComAdjustRead, NULL) != 0 )
	{
		PRTMSG(MSG_ERR, "Create com read thread failed!\n");
		perror("");
		
		return ERR_THREAD;
	}
#endif

	pthread_mutex_init(&m_MutexWrite, NULL);

	return 0;
}
Ejemplo n.º 6
0
int hslink_input(user_data_rec *udta,           /* current user data record */
                 int argc,                      /* argument count */
                 char *argv[])                  /* argument values */
{
        /* allocate application workspace if needed */
        if (udta->substt == 0)
        {
                udta->appws = (workspace_rec*)mem_alloc(sizeof(workspace_rec));
                if (udta->appws == 0)
                {
                        cprintf("Cannot allocate workspace for user %d!\r\n",usrnum);
                        return 0;
                }
        }

        /* current workspace to application workspace for this user */
        current_hsws = udta->appws;

        /* process current substate */
        switch (udta->substt)
        {
        case 0:
                if (top_init())
                {
                        udta->substt = 0;
                        break;
                }

                set_defaults();

                if (argc == 1)
                {
                        usage("No command line given\r\n","");
                        udta->substt = 0;
                        break;
                }

                if (process_options(argc,argv))
                {
                        usage("No command line given\r\n","");
                        udta->substt = 0;
                        break;
                }

                ComOpen();

                WS.Option.ComSpeed = ComGetSpeed();
                if (!WS.Option.EffSpeed)
                        WS.Option.EffSpeed = WS.Option.ComSpeed;

                /* we're now ready for SlowHandshake to work */
                WS.IoLevel = 0;

                /* allocate up to 10k for file buffers, but no more */
                WS.buffer_sizes = mem_avail()-1000>10240: 10240:mem_avail()-1000;

                /* display opening screen */
                prepare_display();
                process_filespecs(argc,argv);

                /* verify hardware handshake status */
                if (!ComGetCts() && !WS.Option.ForceCts)
                {
                        cprintf("CTS signal missing!  Please use -HC or -FC option.\r\n");
                        WS.Option.CtsHandshake = 0;
                }

                udta->substt = 1;
                break;

        case 1:
                /* wait for ready handshake with remote */
                service_receive();
                udta->substt = wait_for_ready()? 1:2;
                break;

        case 2:
                /* select first file in batch and begin transmit */
                udta->curnode = WS.first_send;
                udta->substt = 3;
                break;

        case 3:
                /* end of batch? change to state 4 */
                if (udta->curnode == NULL)
                {
                        udta->substt = 4;
                        PSEND("%d file%s transmitted.\r\n",WS.files_sent,
                                                           WS.files_sent==1?"":"s");
                        break;
                }

                service_receive();
                if (transmit_file(udta->curnode->name))
                        break;          /* remain in state 3 */

                /* advance to next file in the batch */
                udta->curnode = udta->curnode->next;
                break;

        case 4:
                /* wait for remaining receive activity to terminate */
                service_receive();
                udta->substt = finish_receive()? 4:5;
                break;

        case 5:
                /* close down link */
                udta->substt = terminate_link()? 5:6;
                break;

        case 6:
                /* process exit codes */
                if (ComCarrierLost())
                        set_cancel_link(CANCEL_CARRIER_LOST);
                if ((WS.files_received+WS.files_sent) ==0)
                        set_cancel_link(CANCEL_NO_FILES);

                ComClose();
                close_display();
                cprintf("HS/Link finished! (t:%d r:%d)",WS.files_sent,WS.files_received);
                cprintf("  Exit code = %d\r\n",(int)WS.cancel_link);
                udta->substt = 0;
                break;
        }

        /* if substt is 0 we are done and need to free the workspace */
        if (udta->substt == 0)
        {
                current_hsws = 0;
                mem_free(udta->appws);
                udta->appws = 0;
        }

        /* otherwise we need more calls- return non 0 */
        return udta->substt;
}