Ejemplo n.º 1
0
void ShowFileVer(const char * cp)
{
PutRawByte(LOG_REC_START); 
PutRawByte(MSG_TYPE );
while(*cp) PutEscapedByte(*cp++);
PutRawByte(LOG_REC_END); 
}
Ejemplo n.º 2
0
    /* Ciruclar buffer layout **************************************
     ***********ack**********get********put*************** Mode 0
     ***put********ack**********get*********************** Mode 1
     *********get*******put********ack******************** Mode 2
     */

    WORD space()
    {
        WORD cpy_ack;
        WORD cpy_put;

        cpy_ack = ack_pos;
        cpy_put = put_pos;

        if ( cpy_ack > cpy_put ) /* mode 1,2 above */
        {
            return ( cpy_ack - cpy_put );
        }

        return ( ( cpy_ack + TCPBLEN ) - cpy_put );
    }


    void WriteBufferData(int tcp)
    {

        WORD cpy_get;
        WORD cpy_put;
        int force_send;

        USER_ENTER_CRITICAL();
        cpy_get = get_pos;
        cpy_put = put_pos;
        USER_EXIT_CRITICAL();

        if ( cpy_put == cpy_get )
            return;
		force_send=1;


        if ( cpy_get > cpy_put ) /* mode 1 above */
        {
            if ( write_for_callback( tcp, (const char *) ( CircBuffer + cpy_get ), ( TCPBLEN
                    - cpy_get ), force_send ) )
            {
                cpy_get = 0;
            }
        }

        if ( cpy_get < cpy_put ) /* Mode 0 or 2  above */
        {
            if ( write_for_callback( tcp, (const char *) ( CircBuffer + cpy_get ), ( cpy_put - cpy_get ), force_send ) )
            {
                cpy_get = cpy_put;
            }

        }
        USER_ENTER_CRITICAL();
        get_pos = cpy_get;
        USER_EXIT_CRITICAL();
    }
};


int lfd;
int cfd;
bool bSentBlob;

						  
log_to_TCP_Buffer  ltb;

void PutRawByte(BYTE b)
{

//IRQ_writechar(LOG_UART,hexnib(b>>4));
//IRQ_writechar(LOG_UART,hexnib(b &0x0f));

//	iprintf("%c",b);
//   iprintf("%02X",b);
if(cfd)
{
while(((bBlock)  && (ltb.space()==0 ))) OSTimeDly(2);
	
	ltb.PutBufChar(b); 
	if((LogCount & 127)==127)ltb.WriteBufferData(cfd);

}
	//IRQ_writechar(LOG_UART,b); 	
//else
	//IRQ_WriteCharNoBlock(LOG_UART,b);

	LogCount++;
}



TCPCallbacks mycallback;

WORD WinSiz(int socket) {return 1;};
void ReadDataCB(int socket, PBYTE data, int len) {};
void WriteFreeCB(int socket, const char * data_sent, int len){ ltb.FreeBuf(len);};
void CloseErrCB(int socket) {close(cfd); cfd=0; iprintf("Closed \n");};


TCPCallbacks *  MyAccept(int listen_socket, int new_socket)
{
 if(cfd) close(cfd);
 bSentBlob=false;
 cfd=new_socket;
 ltb.Flush();
 iprintf("Accept");
 return &mycallback;
}




void PutEscapedByte(BYTE b)
{
if(b==LOG_REC_START) {PutRawByte(LOG_REC_ESC); PutRawByte(0); }
else
if(b==LOG_REC_ESC) {PutRawByte(LOG_REC_ESC); PutRawByte(1); }
else
if(b==LOG_REC_END) {PutRawByte(LOG_REC_ESC); PutRawByte(2); }
else
if(b==LOG_REC_TICK) {PutRawByte(LOG_REC_ESC); PutRawByte(3); }
else
if(b==0x11) {PutRawByte(LOG_REC_ESC); PutRawByte(4); }
else
if(b==0x13) {PutRawByte(LOG_REC_ESC); PutRawByte(5); }
else
PutRawByte(b);
}




inline void StartLogRecord() { PutRawByte(LOG_REC_START); }
inline void EndLogRecord()   { PutRawByte(LOG_REC_END); }

void LogRawRecord(BYTE msg, const unsigned char * data, int len)
{
BYTE bs=(msg);
StartLogRecord();
PutRawByte(msg);
for(int i=0; i<len; i++)
{
 bs+=data[i];
 PutEscapedByte(((PBYTE)data)[i]);
}
EndLogRecord();
PutEscapedByte(bs);
}






void StartItemIntro(BYTE id, int siz, const char * name)
{
PutRawByte(LOG_REC_START);
PutRawByte(LOG_TYPE_STRUCT);
BYTE bs=LOG_TYPE_STRUCT;
PutRawByte(id);
bs+=id;

PutEscapedByte((BYTE)(siz>>8)&0xFF);
bs+=(BYTE)(siz>>8)&0xFF;

PutEscapedByte((BYTE)(siz&0xFF));
bs+=(BYTE)(siz&0xFF);

	while(*name) 
		{bs+=*name;
		 PutEscapedByte(*name++);
		}
PutRawByte(LOG_REC_END); 
PutEscapedByte(bs);
}


//Log the base element of a structure */
void ShowBaseElement(BYTE id,PBYTE p1, PBYTE p2,int siz, enum  tNames tn, const char * el_name)
{
//iprintf("Offset : %d  size :%d  type %d  name %s\r\n",(p2-p1),siz,tn ,el_name);
int offset=(p2-p1);
PutRawByte(LOG_REC_START); 
PutRawByte(LOG_TYPE_ITEM );
BYTE bs=LOG_TYPE_ITEM;


PutEscapedByte((BYTE)id);
bs+=id;

PutEscapedByte((BYTE)tn);
bs+=tn;

PutEscapedByte((BYTE)(siz>>8)&0xFF);
bs+=(BYTE)(siz>>8)&0xFF;
PutEscapedByte((BYTE)(siz&0xFF));
bs+=(BYTE)(siz&0xFF);
PutEscapedByte((BYTE)(offset>>8)&0xFF);
bs+=(BYTE)(offset>>8)&0xFF;
PutEscapedByte((BYTE)(offset&0xFF));
bs+=(BYTE)(offset&0xFF);

 	while(*el_name) 
		{
		bs+=*el_name;
		PutEscapedByte(*el_name++);
		}
PutRawByte(LOG_REC_END); 
PutEscapedByte(bs);
}
Ejemplo n.º 3
0
void PutLL(int target, long long value) {
  CheckNodeId(target);
  if (DEBUG) PutRawByte(&outgoing_buffers[target], kLL);
  int i;
  for (i = 0; i < 8; i++)
    PutRawByte(&outgoing_buffers[target], (0xff & (value >> (8 * i))));
}
Ejemplo n.º 4
0
void PutInt(int target, int value) {
  CheckNodeId(target);
  if (DEBUG) PutRawByte(&outgoing_buffers[target], kInt);
  int i;
  for (i = 0; i < 4; i++)
    PutRawByte(&outgoing_buffers[target], (0xff & (value >> (8 * i))));
}
Ejemplo n.º 5
0
void StartItemIntro(BYTE id, int siz, const char * name)
{
PutRawByte(LOG_REC_START);
PutRawByte(LOG_TYPE_STRUCT);
BYTE bs=LOG_TYPE_STRUCT;
PutRawByte(id);
bs+=id;

PutEscapedByte((BYTE)(siz>>8)&0xFF);
bs+=(BYTE)(siz>>8)&0xFF;

PutEscapedByte((BYTE)(siz&0xFF));
bs+=(BYTE)(siz&0xFF);

	while(*name) 
		{bs+=*name;
		 PutEscapedByte(*name++);
		}
PutRawByte(LOG_REC_END); 
PutEscapedByte(bs);
}
Ejemplo n.º 6
0
void LogRawRecord(BYTE msg, const unsigned char * data, int len)
{
BYTE bs=(msg);
StartLogRecord();
PutRawByte(msg);
for(int i=0; i<len; i++)
{
 bs+=data[i];
 PutEscapedByte(((PBYTE)data)[i]);
}
EndLogRecord();
PutEscapedByte(bs);
}
Ejemplo n.º 7
0
void PutChar(int target, char value) {
  CheckNodeId(target);
  if (DEBUG) PutRawByte(&outgoing_buffers[target], kChar);
  PutRawByte(&outgoing_buffers[target], value);
}
Ejemplo n.º 8
0
inline void EndLogRecord()   { PutRawByte(LOG_REC_END); }
Ejemplo n.º 9
0
inline void StartLogRecord() { PutRawByte(LOG_REC_START); }
Ejemplo n.º 10
0
void PutEscapedByte(BYTE b)
{
if(b==LOG_REC_START) {PutRawByte(LOG_REC_ESC); PutRawByte(0); }
else
if(b==LOG_REC_ESC) {PutRawByte(LOG_REC_ESC); PutRawByte(1); }
else
if(b==LOG_REC_END) {PutRawByte(LOG_REC_ESC); PutRawByte(2); }
else
if(b==LOG_REC_TICK) {PutRawByte(LOG_REC_ESC); PutRawByte(3); }
else
if(b==0x11) {PutRawByte(LOG_REC_ESC); PutRawByte(4); }
else
if(b==0x13) {PutRawByte(LOG_REC_ESC); PutRawByte(5); }
else
PutRawByte(b);
}