Esempio n. 1
0
void McuMessageHandler::SendPOSTime(time_t *timep)
{
    struct tm *t = localtime(timep);
    int year, month, day, hour, minute, second;
    vector<unsigned char> vyear, vmonth, vday, vhour, vminute, vsecond;
    
    year = 1900 + t->tm_year;
    month = t->tm_mon + 1;
    day = t->tm_mday;
    hour = t->tm_hour;
    minute = t->tm_min;
    second = t->tm_sec;
    
    GetCharSequenceFromInt(vyear, year, 4);
    GetCharSequenceFromInt(vmonth, month, 2);
    GetCharSequenceFromInt(vday, day, 2);
    GetCharSequenceFromInt(vhour, hour, 2);
    GetCharSequenceFromInt(vminute, minute, 2);
    GetCharSequenceFromInt(vsecond, second, 2);
    
    for(int i = 0; i < m_pos_num; i ++)
    {
        StruMcuPacket *thepacket = CreatePacket();
        McuPacket &packet = thepacket->packet;
        
        PushByte(packet, ((m_pos_addr[i] << 4) & MCU_POS_SRC_ADDR));
        PushByte(packet, 0x11);
        PushByte(packet, MCU_POS_FLAG);
        PushByte(packet, 0x30);
        PushByte(packet, 0x32);
        PushSequence(packet, vyear, 4);
        PushSequence(packet, vmonth, 2);
        PushSequence(packet, vday, 2);
        PushSequence(packet, m_pos_pass, 6);
        SendBody(thepacket, MCU_POS_DATE);
    }

    for(int i = 0; i < m_pos_num; i ++)
    {
        StruMcuPacket *thepacket = CreatePacket();
        McuPacket &packet = thepacket->packet;
        
        PushByte(packet, ((m_pos_addr[i] << 4) & MCU_POS_SRC_ADDR));
        PushByte(packet, 0x0F);
        PushByte(packet, MCU_POS_FLAG);
        PushByte(packet, 0x30);
        PushByte(packet, 0x33);
        PushSequence(packet, vhour, 2);
        PushSequence(packet, vmonth, 2);
        PushSequence(packet, vday, 2);
        PushSequence(packet, m_pos_pass, 6);
        SendBody(thepacket, MCU_POS_TIME);
    }
}
Esempio n. 2
0
void McuMessageHandler::SendLEDStateByDir(int dir)
{
    int send_dir;
    if(dir == 0)
    {
        send_dir = 0x01;
    }
    else
    {
        send_dir = 0x02;
    }

    for(int i = 0; i < (int)(sizeof(LEDID) / sizeof(short)); i ++)
    {
        if((LEDFLAG[i] & LED_FLAG_DIRECT) == 0)
        {
            continue;
        }
        
        StruMcuPacket *thepacket = CreatePacket();
        
        thepacket->data = MCU_PACKET_LED_SUBTYPE_STATE;
        
        McuPacket &packet = thepacket->packet;
        PushByte(packet, MCU_PACKET_LED_SUBTYPE_STATE);
        PushByte(packet, send_dir);
        PushByte(packet, 0x03);
        SendBody(thepacket, LEDID[i]);
    }
}
Esempio n. 3
0
void McuMessageHandler::SendLEDState(int flag)
{
    int dir = GpsLocationMessageHandler::Instance()->GetDirection();
    if(dir == 0)
    {
        dir = 0x01;
    }
    else
    {
        dir = 0x02;
    }

    m_driving_state = flag;
    
    for(int i = 0; i < (int)(sizeof(LEDID) / sizeof(short)); i ++)
    {
        if((LEDFLAG[i] & LED_FLAG_STATE) == 0)
        {
            continue;
        }
        
        StruMcuPacket *thepacket = CreatePacket();
        
        thepacket->data = MCU_PACKET_LED_SUBTYPE_STATE;
        
        McuPacket &packet = thepacket->packet;
        PushByte(packet, MCU_PACKET_LED_SUBTYPE_STATE);
        PushByte(packet, dir);
        PushByte(packet, flag);
        SendBody(thepacket, LEDID[i]);
    }
}
Esempio n. 4
0
void McuMessageHandler::SendGetPosPassengerRecord(int i, EnumRecordFlag clear)
{
    StruMcuPacket *thepacket = CreatePacket();
    McuPacket &packet = thepacket->packet;
    
    PushByte(packet, ((m_pos_addr[i] << 4) & MCU_POS_SRC_ADDR));
    if(clear == CLEAR_RECORD)
    {
        PushByte(packet, 0x03);
    }
    else
    {
        PushByte(packet, 0x05);
    }
    PushByte(packet, MCU_POS_FLAG);
    PushByte(packet, 0x38);
    PushByte(packet, 0x30);
    if(clear != CLEAR_RECORD)
    {
        PushByte(packet, 0x30);
        PushByte(packet, 0x31);
    }
    thepacket->data = (int)clear;
    thepacket->data2 = i;
    SendBody(thepacket, MCU_POS_GET_PASSENGER);
}
Esempio n. 5
0
void McuMessageHandler::SendPOSStation(unsigned char station, unsigned char call_station, unsigned char dir)
{
    vector<unsigned char> vstation;
    vector<unsigned char> vcall_station;
    vector<unsigned char> vdir;
    
    GetCharSequenceFromInt(vstation, station, 2);
    GetCharSequenceFromInt(vcall_station, call_station, 1);
    GetCharSequenceFromInt(vdir, dir, 1);
    
    for(int i = 0; i < m_pos_num; i ++)
    {
        StruMcuPacket *thepacket = CreatePacket();
        McuPacket &packet = thepacket->packet;
        
        PushByte(packet, ((m_pos_addr[i] << 4) & MCU_POS_SRC_ADDR));
        PushByte(packet, 0x07);
        PushByte(packet, MCU_POS_FLAG);
        PushByte(packet, 0x30);
        PushByte(packet, 0x31);
        PushSequence(packet, vstation, 2);
        PushSequence(packet, vcall_station, 1);
        PushSequence(packet, vdir, 1);
        SendBody(thepacket, MCU_POS_STATION);
    }
}
Esempio n. 6
0
  void HttpOutput::StateMachine::CloseBody()
  {
    switch (state_)
    {
      case State_WritingHeader:
        SetContentLength(0);
        SendBody(NULL, 0);
        break;

      case State_WritingBody:
        if (!hasContentLength_ ||
            contentPosition_ == contentLength_)
        {
          state_ = State_Done;
        }
        else
        {
          LOG(ERROR) << "The body size has not reached what was declared with SetContentSize()";
          throw OrthancException(ErrorCode_BadSequenceOfCalls);
        }

        break;

      case State_WritingMultipart:
        LOG(ERROR) << "Cannot invoke CloseBody() with multipart outputs";
        throw OrthancException(ErrorCode_BadSequenceOfCalls);

      case State_Done:
        return;  // Ignore

      default:
        throw OrthancException(ErrorCode_InternalError);
    }      
  }
Esempio n. 7
0
void McuMessageHandler::SendGetCanData()
{
    StruMcuPacket *thepacket = CreatePacket();
    McuPacket &packet = thepacket->packet;

    PushByte(packet, 0x01);
    SendBody(thepacket, MCU_CAN_GET_DATA);
}
Esempio n. 8
0
BOOL CHwSMTP::SendEmail()
{
	BOOL bRet = TRUE;
	char szLocalHostName[64] = {0};
	gethostname ( (char*)szLocalHostName, sizeof(szLocalHostName) );

	// hello,握手
	CString str;
	str.Format(_T("HELO %s\r\n"), GetCompatibleString(szLocalHostName,FALSE));
	if ( !Send (  str ))
	{
		return FALSE;
	}
	if ( !GetResponse ( _T("250") ) )
	{
		return FALSE;
	}
	// 身份验证
	if ( m_bMustAuth && !auth() )
	{
		return FALSE;
	}
	// 发送邮件头
	if ( !SendHead() )
	{
		return FALSE;
	}
	// 发送邮件主题
	if ( !SendSubject() )
	{
		return FALSE;
	}
	// 发送邮件正文
	if ( !SendBody() )
	{
		return FALSE;
	}
	// 发送附件
	if ( !SendAttach() )
	{
		return FALSE;
	}
	// 结束邮件正文
	if ( !Send ( CString(_T(".\r\n") ) ) ) return FALSE;
	if ( !GetResponse ( _T("250") ) )
		return FALSE;

	// 退出发送
	if ( HANDLE_IS_VALID(m_SendSock.m_hSocket) )
		Send ( CString(_T("QUIT\r\n")) );
	m_bConnected = FALSE;

	return bRet;
}
Esempio n. 9
0
void McuMessageHandler::SendGPSData(unsigned char *buf, int len)
{
    StruMcuPacket *thepacket = CreatePacket();
    McuPacket &packet = thepacket->packet;
    buf[1] = 'G';
    buf[2] = 'P';
    printf("GSPData: %s\n",buf);
    for(int i = 0; i < len; i++){
	    PushByte(packet, buf[i]);
    }

    SendBody(thepacket, MCU_PACKET_STATION_REPORT);
}
Esempio n. 10
0
  void HttpOutput::StateMachine::StartMultipart(const std::string& subType,
                                                const std::string& contentType)
  {
    if (subType != "mixed" &&
        subType != "related")
    {
      throw OrthancException(ErrorCode_ParameterOutOfRange);
    }

    if (keepAlive_)
    {
      LOG(ERROR) << "Multipart answers are not implemented together with keep-alive connections";
      throw OrthancException(ErrorCode_NotImplemented);
    }

    if (state_ != State_WritingHeader)
    {
      throw OrthancException(ErrorCode_BadSequenceOfCalls);
    }

    if (status_ != HttpStatus_200_Ok)
    {
      SendBody(NULL, 0);
      return;
    }

    stream_.OnHttpStatusReceived(status_);

    std::string header = "HTTP/1.1 200 OK\r\n";

    // Possibly add the cookies
    for (std::list<std::string>::const_iterator
           it = headers_.begin(); it != headers_.end(); ++it)
    {
      if (!Toolbox::StartsWith(*it, "Set-Cookie: "))
      {
        LOG(ERROR) << "The only headers that can be set in multipart answers are Set-Cookie (here: " << *it << " is set)";
        throw OrthancException(ErrorCode_BadSequenceOfCalls);
      }

      header += *it;
    }

    multipartBoundary_ = Toolbox::GenerateUuid();
    multipartContentType_ = contentType;
    header += "Content-Type: multipart/" + subType + "; type=" + contentType + "; boundary=" + multipartBoundary_ + "\r\n\r\n";

    stream_.Send(true, header.c_str(), header.size());
    state_ = State_WritingMultipart;
  }
Esempio n. 11
0
void McuMessageHandler::SendLEDTime(time_t *timep)
{
    struct tm *t = localtime(timep);
    int year, month, day, hour, minute, second, week;
    vector<unsigned char> vyear, vmonth, vday, vweek, vhour, vminute, vsecond;
    
    year = t->tm_year;
    month = t->tm_mon + 1;
    day = t->tm_mday;
    hour = t->tm_hour;
    minute = t->tm_min;
    second = t->tm_sec;
    week = t->tm_wday;
    
    IntToBcd(year % 100, vyear, 1);
    IntToBcd(month, vmonth, 1);
    IntToBcd(day, vday, 1);
    IntToBcd(hour, vhour, 1);
    IntToBcd(minute, vminute, 1);
    IntToBcd(second, vsecond, 1);
    IntToBcd(week, vweek, 1);

    for(int i = 0; i < (int)(sizeof(LEDID) / sizeof(short)); i ++)
    {
        if((LEDFLAG[i] & LED_FLAG_TIME) == 0)
        {
            continue;
        }
        
        StruMcuPacket *thepacket = CreatePacket();
        
        thepacket->data = MCU_PACKET_LED_SUBTYPE_TIME;
        
        McuPacket &packet = thepacket->packet;
        PushByte(packet, MCU_PACKET_LED_SUBTYPE_TIME);
        PushSequence(packet, vyear, 1);
        PushSequence(packet, vmonth, 1);
        PushSequence(packet, vday, 1);
        PushSequence(packet, vweek, 1);
        PushSequence(packet, vhour, 1);
        PushSequence(packet, vminute, 1);
        PushSequence(packet, vsecond, 1);
        SendBody(thepacket, LEDID[i]);
    }
}
Esempio n. 12
0
void TDCLInspectorCommand::SendCommand( TDCLStream* inStream, ProgressFuncPtr inProgressFuncPtr /* = nil */, void* inRefCon /* = nil */ )
{
	KUInt32 theLength = SendHeader( inStream );

	KDEBUG2( "<< Command %.8X, length %i", (unsigned int) GetCommand(), (int) GetLength() );
	if (inProgressFuncPtr)
	{
		(*inProgressFuncPtr)( inRefCon, ((double) 16) / ((double) (16 + theLength)) );
	}
	
	if (theLength)
	{
		SendBody( inStream, theLength, inProgressFuncPtr, inRefCon );
	}
	inStream->FlushOutput();

	if (inProgressFuncPtr)
	{
		(*inProgressFuncPtr)( inRefCon, 1.0 );
	}
}
Esempio n. 13
0
void McuMessageHandler::SendLEDStation(unsigned char mode, unsigned char speed, unsigned char times, unsigned char inout, unsigned char station)
{
    for(int i = 0; i < (int)(sizeof(LEDID) / sizeof(short)); i ++)
    {
        if((LEDFLAG[i] & LED_FLAG_STATION) == 0)
        {
            continue;
        }
        
        StruMcuPacket *thepacket = CreatePacket();
        
        thepacket->data = MCU_PACKET_LED_SUBTYPE_STATION;
        
        McuPacket &packet = thepacket->packet;
        PushByte(packet, MCU_PACKET_LED_SUBTYPE_STATION);
        PushByte(packet, mode);
        PushByte(packet, speed);
        PushByte(packet, times);
        PushByte(packet, inout);
        PushByte(packet, station);
        SendBody(thepacket, LEDID[i]);
    }
}
Esempio n. 14
0
void McuMessageHandler::SendGetDealRecord(int i, EnumRecordFlag clear, int index)
{
    StruMcuPacket *thepacket = CreatePacket();
    McuPacket &packet = thepacket->packet;
    
    PushByte(packet, ((m_pos_addr[i] << 4) & MCU_POS_SRC_ADDR));
    PushByte(packet, 0x06);
    PushByte(packet, MCU_POS_FLAG);
    PushByte(packet, 0x38);
    PushByte(packet, 0x31);
    if(clear == CLEAR_RECORD)
    {
        PushByte(packet, 0x02);
    }
    else
    {
        PushByte(packet, 0x01);
    }
    PushWord(packet, index);
    thepacket->data = (int)clear;
    thepacket->data2 = i;
    SendBody(thepacket, MCU_POS_GET_DEAL);
}
Esempio n. 15
0
void McuMessageHandler::SendHandshake()
{
    StruMcuPacket *thepacket = CreatePacket();

    SendBody(thepacket, MCU_PACKET_HANDSHAKE);
}