Exemplo n.º 1
0
void run_task(uint8_t *Task)
{
	switch(Task[2])
	{
		case '0':
		send_string("boot");
		break;
		case '1':
		page_address = Task[9] << 8;
		page_address |= Task[8];
		readFlashPage(page_address, 128);
		send_buff(gBuffer, 128);
		Task[2] = 0;
		break;
		case '2':
		Task[2] = 0;
		break;
		case '3':
		page_address = Task[9] << 8;
		page_address |= Task[8];
		for (uint16_t i = 0; i < SPM_PAGESIZE; i++)
		gBuffer[i] = data_buffer[i + 16];
		writeFlashPage(page_address,SPM_PAGESIZE);
		send_string("page done");
		Task[2] = 0;
		break;
		case '4':
		eraseFlash();
		send_string("erase ok");
		Task[2] = 0;
		break;
		case '5':
		Task[2] = 0;
		break;
		case '6':
		fill_page();
		send_buff(gBuffer, 256);
		Task[2] = 0;
		break;
		case '7':
		blink_led();
		Task[2] = 0;
		break;
		case '8':
		MCUCR |= 1<<IVCE;
		MCUCR = 0<<IVSEL;
		send_string("jump ok");
		jump_to_app();		// Jump to application sector
		Task[2] = 0;
		break;
		default:
		Task[2] = 0;
	}
}
Exemplo n.º 2
0
// 发送数据子程序		 
extern void write_prf(unsigned char *buffer,unsigned int num)
{
	unsigned char temp;	
	write_reg(SCON_60,0x5);	 //PTRCLR =1,CARRYON =1
	write_reg(SCON_60,0x01);    //PTRCLR=0;
	temp = 0x80;			 //写数据寄存器命令 
	SS_N = 0;
	send_buff(&temp,1);
	send_buff(buffer,num);	 //写入数据
	SS_N = 1;

	write_reg(SCON_60,0x03);    // STARTSEND =1 ,开始发送	
}
Exemplo n.º 3
0
extern unsigned int read_prf(unsigned char *buffer)
{
	unsigned char temp;
	unsigned int num =0;
	
	temp = read_reg(RSTAT);
	    
	while( (temp &0x80) != 0x80 )
	{  	  	
	temp = read_reg(RSTAT);
	}
	
	if(temp&0x01)
	{
		    
			 	//计算长度	
        	num = (unsigned int)read_reg(RSCL)+ ((unsigned int)(read_reg(RSCH))<<8);
			if(num==0)return (num); 
			temp = 0x00;              //读取 DAT_REG寄存器命令
			SS_N = 0;	
			send_buff(&temp,1);       //发送读取命令
			receive_buff(buffer,num); //读取数据
			SS_N = 1;
		
	}
	else
	{
		num =0;	
			
	}
	return num;

}
Exemplo n.º 4
0
// 通过 SPI 总线写 address 寄存器的值
extern void write_reg(unsigned char address,unsigned char content)
{
	unsigned char temp_buff[2];
	temp_buff[0] = address | 0x80;
	temp_buff[1] = content;
	SS_N = 0;
	send_buff(temp_buff,2);
	SS_N = 1;
}
Exemplo n.º 5
0
void 
Connection::send_msg(const char *msg) {
	memcpy(sendbuff, msg, strlen(msg));
	buffsize = strlen(msg);
	save_state();
	translate(RECV_ACK);
	send_buff();
	manager.addWaiting(*this);
}
Exemplo n.º 6
0
// 通过 SPI 总线读 address 寄存器的值
extern unsigned char read_reg(unsigned char address)
{
	unsigned char temp_buff[1];
	SS_N = 0;
	temp_buff[0] = address & 0x7F;	
	send_buff(temp_buff,1);
	receive_buff(temp_buff,1);
	SS_N = 1;
	return(temp_buff[0]);
}
Exemplo n.º 7
0
// SPI 模式等待接收结束,并读出接收数据,数据存在缓冲区 buffer 中,长度为 len
// 返回值为接收状态
//Waiting for receiving end, write the received data to the "buffer" ,its length is "len"
//Return of function is the receiving status
extern unsigned char THM_WaitReadFrame(unsigned short *len, unsigned char *buffer)
{
	unsigned char temp,temp1;	
	*len = 0;
	// 等待接收结束	
	//waiting for the end of receive
	while (1)	
	{  	    
	   temp = read_reg(RSTAT);   
	   if (temp & 0x80)
	        break;
    }	           
    // 处理返回状态状态值
	// handling the  receiving status
    if (temp & CERR )   
        temp = CERR;                //碰撞错误
		                            //BitPos  
    else if (temp & PERR)       
        temp = PERR;                //奇偶校验位错误
		                            //Frame Error
    else if (temp & FERR)       
        temp = FERR;
    else if (temp & DATOVER)       
        temp = DATOVER;            //数据溢出
		                           //Data Overflow
    else if (temp & TMROVER)
        temp = TMROVER;             //超时错误
		                            //Timeout
    else if (temp & CRCERR)   
        temp = CRCERR;              //CRC 计算错误
		                            //CRC Error
    else 
        temp = FEND;                //帧正常结束
		                            //Frame correct 
    //取得接收长度值
	//read the data length
    *len =((unsigned short)(read_reg(RSCH)) <<8 ) + read_reg(RSCL);  		    
    //读取接收数据 
	//read the data
    if (*len != 0x00 )
    {
        SS_N = 0;
        
        temp1 = DATA;
        send_buff( &temp1,1);
        receive_buff( buffer,*len);
        
        SS_N = 1;
    }      
    //清除状态标志
	//clear the status
    write_reg(RSTAT,0x00);        
    return (temp);
}
Exemplo n.º 8
0
void bill_find_all(char *buff)
{
   int id;   
  // printf("bb=%s\n",buff+8);
   char buf[4096]="\0";
   id=buff[8]-'0';
   buff=bill_select_all();
   strcat(buf,buff);
  buff=buf;
  printf("before  send_buff    buff====%s\n",buff);
  char flag[6]="1+ba+\0";
  send_buff(id,buff,strlen(buff),flag);
   
}
Exemplo n.º 9
0
void manage_money(char*buff)
{
    int id;
  char buf[4096]="\0";
  id=buff[8]-'0';
  struct struct_dished * dished;
  dished = stringTOstruct_dished(buff);
  buff=money_getBill(dished->dish_number,dished->bill_number);
  strcat(buf,buff);
  buff=buf;
  
  // printf("bb=%s\n",bill->bill_number);
  //send_buff(id,buff,strlen(buff));
  char flag[6]="1+Tm+\0";
  send_buff(id,buff,strlen(buff),flag);
}
Exemplo n.º 10
0
void staff_find_pth(char *buff)
{
    int id;
   char buf[4096]="\0";
   id=buff[8]-'0';
  struct struct_staff *staff;
  staff = stringTOstruct_staff(buff);
  buff=staff_select(staff);
  strcat(buf,buff);
  buff=buf;
  printf("staff_find_pth staff.number=%s\n",staff->number);
  //send_buff(id,buff,strlen(buff));
  char flag[6]="1+sl+\0";
  send_buff(id,buff,strlen(buff),flag);
  //return ;
}
Exemplo n.º 11
0
/********************************************************************
* FUNCTION send_ncxconnect
*
* Send the <ncx-connect> message to the ncxserver
* 
* RETURNS:
*   status
*********************************************************************/
static status_t
    send_ncxconnect (void)
{
    status_t  res;
    char connectmsg[] = 
    "%s\n<ncx-connect xmlns=\"%s\" version=\"1\" user=\"%s\" "
    "address=\"%s\" magic=\"%s\" transport=\"ssh\" port=\"%s\" />\n%s";

    memset(msgbuff, 0x0, BUFFLEN);
    snprintf(msgbuff, BUFFLEN, connectmsg, (const char *)XML_START_MSG, 
             NCX_URN, user, client_addr, NCX_SERVER_MAGIC, port, NC_SSH_END);

    res = send_buff(ncxsock, msgbuff, strlen(msgbuff));
    return res;

} /* send_ncxconnect */
Exemplo n.º 12
0
/* Send name to socket */
int send_name (SOCKET sock) {
  /* First send byte indicating length. */
  char len = (char)strlen (my_name);
  
  if (send (sock, &len, 1, 0) != 1) {
    fprintf (stderr, "Failed to send name length\n");
    return 1;
  }

  /* Now send the name */
  if (send_buff (sock, my_name, len) != 0) {
    fprintf (stderr, "Failed to send name\n");
    return 2;
  }

  return 0;
}
Exemplo n.º 13
0
void bill_find_pth(char *buff)
{

   //char flag[5]="1+bq+";
   struct struct_bill *bill;
   int id;   
   printf("bb=%s\n",buff+8);
   char buf[4096]="\0";
   id=buff[8]-'0';
   
   bill = stringTOstruct_bill(buff);
   
  buff=bill_select(bill);
  strcat(buf,buff);
  buff=buf;
  printf("before  send_buff    buff====%s\n",buff);
  char flag[6]="1+bq+\0";
  send_buff(id,buff,strlen(buff),flag);
	//return ;
}
Exemplo n.º 14
0
void table_check_pth(char *buff)
{
  int id;
  char buf[4096]="\0";
  id=buff[8]-'0';

   division_buff(buff);

  struct struct_tableinfo * table;
  struct struct_bill* bill;
  // printf("table2=%s\n",table_buff+12);
  table = stringTOstruct_tableinfo(table_buff);
  bill =  stringTOstruct_bill(bill_buff);
 // printf("table_number=%s\n",table->table_number);
 // printf("bill_number=%s\n",bill->bill_number);
   //tableinfo_insert
  buff=bill_select(bill);
  strcat(buf,buff);
  buff=buf;
  //printf("bb=%s\n",bill->bill_number);
 // send_buff(id,buff,strlen(buff));
  char flag[6]="1+tc+\0";
  send_buff(id,buff,strlen(buff),flag);
}
Exemplo n.º 15
0
/********************************************************************
* FUNCTION io_loop
*
* Handle the IO for the program
* 
* INPUTS:
*              
* RETURNS:
*   status
*********************************************************************/
static status_t
    io_loop (void)
{
    status_t  res;
    boolean   done;
    fd_set    fds;
    int       ret;
    ssize_t   retcnt;

    res = NO_ERR;
    done = FALSE;
    FD_ZERO(&fds);

    while (!done) {
        FD_SET(STDIN_FILENO, &fds);
        FD_SET(ncxsock, &fds);

        ret = select(FD_SETSIZE, &fds, NULL, NULL, NULL);
        if (ret < 0) {
            if ( errno != EINTR ) {
                SUBSYS_TRACE1( "ERROR: io_loop(): select() "
                               "failed with error: %s\n", strerror( errno ) );
                res = ERR_NCX_OPERATION_FAILED;
                done = TRUE;
            }
            else
            {
                SUBSYS_TRACE2( "INFO: io_loop(): select() "
                               "failed with error: %s\n", strerror( errno  ) );
            }
            continue;
        } else if (ret == 0) {
            SUBSYS_TRACE1( "ERROR: io_loop(): select() "
                           "returned 0, exiting...\n" );
            res = NO_ERR;
            done = TRUE;
            continue;
        } /* else some IO to process */

        /* check any input from client */
        if (FD_ISSET(STDIN_FILENO, &fds)) {
            /* get buff from openssh */
            retcnt = do_read(STDIN_FILENO, 
                             msgbuff, 
                             (size_t)BUFFLEN,
                             &res);

            if (res == ERR_NCX_EOF) {
                res = NO_ERR;
                done = TRUE;
                continue;
            } else if (res == ERR_NCX_SKIPPED) {
                res = NO_ERR;
            } else if (res == NO_ERR && retcnt > 0) {
                /* send this buffer to the ncxserver */
                res = send_buff(ncxsock, msgbuff, (size_t)retcnt);
                if (res != NO_ERR) {
                    SUBSYS_TRACE1( "ERROR: io_loop(): send_buff() to ncxserver "
                                   "failed with %s\n", strerror( errno ) );
                    done = TRUE;
                    continue;
                }
            }
        }  /* if STDIN set */

        /* check any input from the ncxserver */
        if (FD_ISSET(ncxsock, &fds)) {
            res = NO_ERR;
            retcnt = do_read(ncxsock, 
                             msgbuff, 
                             (size_t)BUFFLEN,
                             &res);

            if (res == ERR_NCX_EOF) {
                res = NO_ERR;
                done = TRUE;
                continue;
            } else if (res == ERR_NCX_SKIPPED) {
                res = NO_ERR;
            } else if (res == NO_ERR && retcnt > 0) {
                /* send this buffer to STDOUT */
                res = send_buff(STDOUT_FILENO, msgbuff, (size_t)retcnt);
                if (res != NO_ERR) {
                    SUBSYS_TRACE1( "ERROR: io_loop(): send_buff() to client "
                                   "failed with %s\n", strerror( errno ) );
                    done = TRUE;
                    continue;
                }
            }
        }
    }

    return res;

} /* io_loop */
Exemplo n.º 16
0
void 
Connection::retransmit() {
	send_buff();
}