void CallBack_socket_accept(u8 contexid, s8 sock, bool result, s32 error){
    //OUTD("accept context:%d socket:%d result:%d error:%d",contexid, sock,result,error);
    u16 pp;
    u8 i;
    u8 cli_address[4];
    s8 accept_socket=Ql_SocketAccept(__http_socketID,cli_address,&pp);
    if(accept_socket >= 0)
        {
            OUTD("accept_socket=%d, ip=%d.%d.%d.%d, port=%d", accept_socket,cli_address[0],cli_address[1],cli_address[2],cli_address[3], pp);
            for(i = 0; i < MAXCLIENT_NUM; i++)
                {
                    if(__client[i].socketId == 0x7F)
                        {
                            OUTD("Socket accept success %d", accept_socket);
                            client_init(i,accept_socket);
                            __client[i].send_handle_callback = func_send_handle_callback;
                            __client[i].send_handle = func_send_handle;
                            __client[i].read_handle_callback=func_read_handle_callback;    
                            __client[i].protocol=NONE;
                              break;
                         }
                  }
            //accept_count = 0; //use to send connection success tips
            //OUTD("nSTATE_TCPLONG = STATE_TRANSFERS_TCPDATA \r\n");						
            //nSTATE_TCPLONG = STATE_TRANSFERS_TCPDATA;
         }

}
void CallBack_socket_connect(u8 contexid, s8 sock, bool result, s32 error){
	if (!result) {
            Ql_SocketClose(sock);
        
		if (__tmr_index>3) {
            __tmr_index=0;//__tmr_index;
            Ql_Reset(0);
		}
        else
          __tmr_index++;
        Ql_StartGPTimer(__tmr_array[__tmr_index],hwTimer_handler,NULL);    
        OUTD("!Error connect. Try over %d second.",__tmr_array[__tmr_index]/100);
        LOG("!Error connect. Try over %d second.",__tmr_array[__tmr_index]/100);
	}
    else{
        __tmr_index=0;
         Ql_StopGPTimer();
        __est_connection=TRUE;
        OUTD(">Connected OK",NULL); 
        LOG(">Est connect OK",NULL); 
        __toSend=BuildInputStateMessage();
        Ql_SocketSend(__est_connector_socket, &__SendBuffer[0], __toSend);
        TrigerEvent(None,0,&__currentEvData);  
        __toSend=BuildEventMessage(0,&__currentEvData,1);
        Ql_SocketSend(__est_connector_socket, &__SendBuffer[0], __toSend);
        //OUTD("<Send input message",NULL);
          LOG("<Send input message",NULL);
		 Ql_StartGPTimer(TIME_WAIT_CONFIRM_MSG,CheckAnyMessage,NULL);  

    }	
}
void CheckAnyMessage(void* param){
     if (__countRepeat>2) {
         __countRepeat=0;
         OUTD("!Timeout system recive", NULL);
         LOG("!Timeout system recive", NULL);
		 nSTATE=STATE_EST_SOCKET_CLOSE;
         
      }
      else{
          __countRepeat++;     
          OUTD("!Timeout recive.Repeate:%d", __countRepeat); 
          LOG("!Timeout recive.Repeate:%d", __countRepeat); 
          nSTATE = STATE_SOCKET_SEND; 
      }
}
Beispiel #4
0
/*----------------------------------------------------------------------------*/
YT_BOOL 
next_step () 
{ 
  char move[128] = {0};
  int  x, y;

  printf ("Command: ");
  get_line (move, sizeof (move));

  if      (!strncmp (move, "undo", 4)) { OUTD (11);
  }
  else if (!strncmp (move, "help", 4)) { OUTD (22);
  }
  else if (!strncmp (move, "game", 4)) { baby_menu_newgame (TRUE);
  }
  /*     else if (!strncmp (move, "pass", 4)) { */
  /*       rating_minus ();  */
  /*       baby_menu_newgame (); */
  /*     } */
  else if (!strncmp (move, "null", 4)) {
    baby_menu_ratingset (0); 
    baby_menu_newgame (TRUE);
  }
  else if (!strncmp (move, "exit", 4) || !strncmp(move, "quit", 4)) {
    baby_menu_exit (); 
    //break;
    return (FALSE);
  }

  // ------------ введены координаты хода с клавы --------------
  else if ( isalpha(move[0]) && isdigit(move[1]) ) { 

    //board_name_to_index ((pa->game)->aboard, move, &y, &x); 
    //name_to_index (move, &y, &x);
    board_name_to_index (baby_ptr_goban (), move, &y, &x); 

    baby_onestep_moves (y, x); 
  }
  // нажали Enter - просьба сделать ход компом
  else if (strlen (move) == 0) { 
    if (baby_is_game_end ())  baby_menu_newgame (TRUE); // menu_game_NEW
    else                      baby_onestep_moves (-1, -1); 
  }

  return (TRUE);
} 
bool vilidation(HttpHeader *http_header){
    OUTD("cookie value is:%s",http_header->cookie);
    if (Ql_strstr(http_header->cookie,"NONE")) 
    {
        return FALSE;
    }
    else return TRUE;
}
/*---------------------------------------------------------------------------
 * OsPciReadDWord
 *
 * This routine reads one double word from the PCI configuration header
 * defined by 'bus', 'dev', 'func' and 'address' to the double word
 * pointed to by 'data'.
 *
 * Returns : None.
 *---------------------------------------------------------------------------
 */
void
OsPciReadDWord(int bus, int dev, int func, int address, unsigned long *data)
{
    /*
     * The address of a double word in the Configuration Header is built in
     * the following way :
     * {10000000,bus[23:16],device[15:11],function[10:8],address[7:2],00}
     */
    long addr = (0x80000000 |
                 ((bus & 0xff) << 16) |
                 ((dev & 0x1f) << 11) | ((func & 0x7) << 8) | (address & 0xff));
    OUTD(PCI_INDEX, addr);
    *data = IND(PCI_DATA);
}
Beispiel #7
0
// write to the pci config space
static void pci_write(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg_offset, uint8_t len, uint32_t value)
{
	uint32_t val = 0x80000000 |
		(bus << 16) |
		(dev << 11) |
		(func << 8) |
		(reg_offset & 0xFC);

	OUTD(PCI_ADDR_IO_PORT, val);

	// get current value
	val = IND(PCI_DATA_IO_PORT + (reg_offset & 0x3));

	// mask out new section
	if (len != 4)
		val &= (0xFFFFFFFF << (len * 8));
	else
		val = 0;         // vc++/processor does not allow shift counts of 32

	val |= value;

	OUTD(PCI_DATA_IO_PORT + (reg_offset & 0x3), val);
}
void WriteSettings(void){
    s32 handle;
    u32 writed;
    s32 result;
    handle=Ql_FileOpenEx(SETTINGS_FILE,QL_FS_CREATE_ALWAYS);
    //handle=Ql_FileOpen(SETTINGS_FILE,TRUE,FALSE);
    if (handle<0) {
        OUTD("!Open file settings error:%d",handle);
        return;
    }
    else
    {
        result=Ql_FileWrite(handle,(u8*)&__settings,sizeof(settings),&writed);
        if (result!=0) {
            OUTD("!Write file settings error:%d",result);
        }
        else{
            Ql_FileFlush(handle);
            //OUTD("Write file settings is OK",NULL);
            Ql_FileClose(handle);
        }
    }
}
void CallBack_socket_close(u8 contexid, s8 sock, bool result, s32 error){
    s32 index;
    if (sock==__est_connector_socket) {
        nSTATE = STATE_EST_SOCKET_CREATE;
        __est_connection=FALSE;   
	}
    else{
        
        index = findClientBySockid(sock);
        if(index >= 0)
         {
            __client[index].socketId = 0x7F;
            __client[index].protocol=HTTP;
         }
        Ql_SocketClose(sock);
    }
    OUTD("!Soccket closed:%d",sock);
    //LOG("!Soccket closed:%d",sock);
}
Beispiel #10
0
// -------------------------------------------------------------------------
// Privates
// -------------------------------------------------------------------------
static uint32_t pci_read(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg_offset, uint8_t len)
{
	uint32_t ret;

	const uint32_t val = 0x80000000 |
		(bus << 16) |
		(dev << 11) |
		(func << 8) |
		(reg_offset & 0xFC);


	OUTD(PCI_ADDR_IO_PORT, val);

	ret = IND(PCI_DATA_IO_PORT + (reg_offset & 0x3));

	ret &= (0xFFFFFFFF >> ((4-len) * 8));

	return ret;
}
Beispiel #11
0
/*----------------------------------------------------------------------------*/
void  
baby_onestep_moves (int i, int j) 
{

  if (i == -1 && j == -1) {
    // комп играет сам с собой, т.е. делает ход за человека
    if (! computer_move (STONE_BLACK)) return; 
  }
  else {
    if (! human_move (i, j)) {return; OUTD (555);}
  }

  if (update_check_end ()) return;

  //draw_status ("Я думаю.."); 
  if (! computer_move (STONE_WHITE)) return; 

  if (update_check_end ()) return;
  //draw_status ("Ваш ход.."); 

  return;
}
Beispiel #12
0
void CheckStateGpio(){
    QlPinLevel pinlevel;
    unsigned char pin_state;
    unsigned char val;
    EventData locData;
   __debong+=DEVICE_CYCLE;
   if (__debong>=__settings.Deboung) {
       for (u8 i = 0; i < sizeof(__pinLow); i++) {
            pin_state=0;
            Ql_pinRead(__pinLow[i], &pinlevel);
            //OUTD("pin:%d val:%d\r\n",__pinLow[i],pinlevel);
            val=((1 << i) & __pins)>>i;
            if (val!=pinlevel) {
                OUTD(">Change pin nubmer:%d val:%d",__pinLow[i]-2,pinlevel,val); 
                 if (pinlevel==QL_PINLEVEL_HIGH){
                     __pins =(1<<i)|__pins;    
                 }
                  else
                    __pins =((1<<i)^0xFF)&__pins;
                GetInputDescripon(i,pinlevel,&pin_state);            
                TrigerEvent((TypeEvent)pin_state,0,&locData);
                WriteEvents(&locData);
                
                //__toSend=BuildEventMessage(__numPacket,0,&__currentEvData,1);     
            }
        }
       __debong=0;
   }
    //OUTD("pin value %d set.deb:%d loc.deb:%d\r\n",__pins,__settings.Deboung,__debong);
    if (__pins==31) {
        Ql_pinWrite(QL_PINNAME_GPIO4, QL_PINLEVEL_LOW);
        //OUTD("result set gpio-4 mode:%d light to low:%d\r\n",iret,light);
    }
    else{
        Ql_pinWrite(QL_PINNAME_GPIO4, QL_PINLEVEL_HIGH);
        //OUTD("result set gpio-4 mode:%d light to high:%d\r\n",iret,light);
    }

}
void CallBack_socket_write(u8 contexid, s8 sock, bool result, s32 error){
    
   s32 index;
   s32 ret;
	//OUTD("CallBack_socket_write(contexid=%d,sock=%d,result=%d,error=%d)\r\n",contexid,sock,result,error);
   
	index = findClientBySockid(sock);
	if(index >= 0)
	{
        
        //for (int i=0;i<10;i++) {
            ret=__client[index].send_handle_callback(contexid, sock, result, error, index); 
           OUTD("socket nuber:%d send:%d send-rem:%d pos:%d",sock,ret,__client[index].sendRemain_len,__client[index].pSendCurrentPos);
            //if((ret < 0) && (ret == QL_SOC_WOULDBLOCK)){
              //  continue;
           // }
            //else{
              //   break;
            //}
           // }
        }
      
}
Beispiel #14
0
void ReadSettings(void){
    s32 result;
    u32 readed;
    s32 handle;
    result=Ql_FileCheck(SETTINGS_FILE);
    if (result!=0) {
        //OUTD("!File settings not found:%d",result);
        //handle=Ql_FileOpenEx(SETTINGS_FILE,QL_FS_CREATE);
        //if (handle<0) {
          //  OUTD("Error create file settings.Error:%d",handle);
            //return;
        WriteSettings();
        }
        else{
           handle=Ql_FileOpenEx(SETTINGS_FILE,QL_FS_READ_ONLY);
           result=Ql_FileRead(handle,(u8*)&__settings,sizeof(settings),&readed);
            if (result!=0) {
                OUTD("!Error read file settings.Error:%d",result);
            }
            
            Ql_FileClose(handle);
            //PrintSettings();
        }
}
void CallBack_socket_read(u8 contexid, s8 sock, bool result, s32 error){
    u8 len=0;
    s32 index=0;
    s32 ret=0;
    //OUTLOG("resive from socket:%d",sock);
    //Ql_memset(__socketBuffer,0,LEN_SOCKET_BUFFER);
    //len=Ql_SocketRecv(sock,(u8*)&__socketBuffer[0],LEN_SOCKET_BUFFER);
	//if (len>0) {
		if (sock==__est_connector_socket) {
            Ql_memset(__socketBuffer,0,LEN_SOCKET_BUFFER);
            len=Ql_SocketRecv(sock,(u8*)&__socketBuffer[0],LEN_SOCKET_BUFFER);
            if (len>0) {
                unreplace(&__socketBuffer[0],len);
                if (!__waitConfirm){
                    nSTATE = STATE_SOCKET_SEND; 
                    __toSend=0;
                  Ql_StopGPTimer();
                }
                 __countRepeat=0;
                 __start_empty_tmr=Ql_GetRelativeTime();
            }
         }
        else{
           // __socketBuffer[len] = '\0'; 
           //read_request((char*)__socketBuffer, sock); 
            index=findClientBySockid(sock);

            ret=__client[index].read_handle_callback(contexid,sock,result,error,index);
            //OUTD("size recive:%d",ret);
            if (ret>0) {
                  if (__client[index].protocol==HTTP) {
                    if (parse_header((char*)__client[index].recvBuffer,(u32)__client[index].pRecvCurrentPos)) {
                        //OUTD("header:%s",__client[index].recvBuffer);
                        if (__header.method==GET) {
                           if (!__header.authorization) {
                                    Ql_strcpy(__header.action,"autorize");
                           }
                           page_response(); 
                            __client[index].send_handle(sock,__s_buf);
                        }
                        else if (__header.method==POST) {
                                OUTD("len:%d",__header.length);
                          }
                      }
                   }
                   else if (__client[index].protocol==STREAM) {
                       OUTD("stream",NULL);
                        Ql_SendToUart(ql_uart_port3,__client[index].recvBuffer,ret);
                    }
                   else if ( __client[index].protocol==UPGRADE) {
                        s32 init=0;
                        int pp=(u16)(__client[index].pRecvCurrentPos);
                        if (Ql_strstr((char*)&__client[index].recvBuffer[pp-3],"END")) {
                            OUTD("end file is:%s",&__client[index].recvBuffer[pp]);
                            init = Ql_Fota_App_Write_Data(ret-3, (s8 *)__client[index].recvBuffer);
                            OUTD("write fota:%d", init); 
                            init=Ql_Fota_App_Finish();
                            __client[index].send_handle(sock,init==0 ? "0":"1");
                            OUTD("finish write:%d", init); 
                            if (init==0) {
                                init=Ql_Fota_Update();
                            }
                        }
                        else{
                            init = Ql_Fota_App_Write_Data(ret, (s8 *)__client[index].recvBuffer);
                            __client[index].send_handle(sock,init==0 ? "0":"1");
                            OUTD("fota write:%d", init); 
                        }
                }
            }
        }
}
bool parse_header(void *clients,HttpHeader *http_header){
	char *param;
	char *value;
	char *last;
	char *ph;
	char* bon_val = NULL;
	char header[1024 * 2];
    char*lens=NULL;
    QlClient *client=(QlClient*)clients;
	char* head = Ql_strstr((char*)client->recvBuffer, "\r\n\r\n");
	if (head) {
       
        http_header->set_cookie=FALSE;
        http_header->authorization=FALSE;
        Ql_memset(http_header->action,0,100);
        Ql_memset(http_header->boundary,0,200);
        Ql_memset(http_header->cookie,0,200);
        Ql_memset(http_header->data,0,10 * 1024);
        http_header->length=0;
         Ql_strcpy(http_header->cookie, "NONE"); 
		int head_len = (char*)head - ((char*)client->recvBuffer);
		int body_len = (int)(client->pRecvCurrentPos) - head_len - 4;
		Ql_memcpy(header, client->recvBuffer, head_len);
		ph = strtok_r(header, "\r\n", &last);
		char* lst;
		if (Ql_strstr(ph, "GET")!=NULL)
		{
			char* act = strtok_r(ph+4, " ", &lst);
			if (Ql_strlen(act)>1) 
                Ql_strcpy(http_header->action, act+1); 
            else
                Ql_strcpy(http_header->action, act); 
			http_header->method = GET;
            OUTD("action:%s",http_header->action);
		}
		if (Ql_strstr(ph, "POST")!=NULL) {
			http_header->method = POST;
			char* act = strtok_r(ph+5, " ", &lst);
            if (Ql_strlen(act)>1) 
                Ql_strcpy(http_header->action, act+1); 
            else
                Ql_strcpy(http_header->action, act); 
		}
		while (1)
		{
			ph = strtok_r(NULL, "\r", &last);
			if (ph == NULL) {
				return TRUE;
			}
			param = strtok_r(ph + 1, ":", &value);
			if (Ql_strstr(param, "Content-Type")) {
				char* bon = Ql_strstr(value, "boundary");
				bon_val = bon + 9;
				Ql_strcpy(http_header->boundary, bon_val);
			}
			else if ((lens = Ql_strstr(param, "Cookie"))!=NULL)
			{
                char* cookie;
                if ((cookie=Ql_strstr(value,"__ztp"))!=NULL) {
                    Ql_strcpy(http_header->cookie, cookie+6); 
                    http_header->authorization=TRUE;
                    http_header->set_cookie=FALSE;
                }
			}
			else if ((lens = Ql_strstr(param, "Content-Length"))!=NULL) {
				char* slen = lens + 16;
				int len_head = Ql_atoi(slen);
				http_header->length = len_head;
				if (len_head == body_len){
					OUTD("data full",NULL);
                }
                else
                {
                    OUTD("not full data.wait:%d have:%d", len_head, body_len);
                    return FALSE;
                }
              }
            else if ((lens = Ql_strstr(param, "Authorization"))!=NULL) {
                /*char* slen = lens + 21;
                unsigned char dbuf[50];
                Ql_memset(dbuf,0,50);
                decode_b64((unsigned char*)slen,dbuf);
                OUTD("decode buf:%s",dbuf);
                param = strtok_r((char*)dbuf, ":", &value);
                if (Ql_strstr(param,"admin") && Ql_strstr(value,"admin")) {
                    OUTD("Autorization user:%s pswd:%s",param,value);
                    http_header->authorization=TRUE;
                    http_header->set_cookie=TRUE;
                }*/
            }
        }
		}
	else
	{
        return FALSE;
	}
}
Beispiel #17
0
/*------------------------------page3_proc----------------------------------*/
long
page3_proc (PFUNC_VAR)       
{        
  char *top_menu[] = {
    "Main",   
    "  This is", 
    "  very good",
    "    item1",
    "    item2",
    "      item0",
    "      item1",
    "      item2",
    "    item3",
    "  program!!",
    "  ---",  
    "  Exit",     
    "Control",     
    "  PUSH",     
    "  LIST",     
    "  SCROLL",    
    "  COMBO",     
    "  TEXT",
    "  CHECK",
    "  and etc.",
    "Colors",
    "  Red",
    "  Green",
    "  Blue",
    "  Yellow",
    "Animals",
    "  Cat",
    "  ----",
    "  Dog",
    "  Wolf",
    "  Elephant",
    "Menu",
    "  Check flag| true",
    "  Make Me Grayed",
    "  Make Prev. Norm.",
    "  (ON/OFF): OFF",
    "  ----",
    "  Short menu",
    "Items",
    "  Item_1",
    "  Item_2",
    "  Item_3",
    "  Item_4",
    "  ----",
    "  Item_5",
    "  Item_6",
    "" 
  };
  
  char *top_menu_short[] = {
    "Main",   
    "  This is", 
    "  very good",
    "  ---",  
    "  Exit",     
    "Menu",
    "  Long menu",
    "Items",
    "  Item_1",
    "  Item_2",
    "  Item_3",
    "" 
  };

  static int hTest = ID_NULL;
  static int hMenu1=ID_NULL, hMenu2=ID_NULL, hMenu;
  char * str;

  static float fvalue=10.9;   
  static int hScroll, hScroll1;
  static int hFloat1, hFloat2;

  static char  **ptr_menu;

  switch (message) {       
  case YOPEN:  
    hTest = *((int*)YGet("wlong1"));
   case YDRAW:       
    YDrawRectF (0,0,WND->w,WND->h, YColor("fuchsia"));        

    YBeginGroup ("FLOATS", 110,170, 140,70, YColor("aqua"));  
    YWnd (&hFloat1, FLOATS, "Float1 ",  65,10, 60,20, LP(fvalue),YFLOAT,0,0, YColor("white"));   
    YWnd (&hFloat2, FLOATS, "Float2 ",  65,40, 60,20, LP(fvalue),YFLOAT,0,0, YColor("white"));   
    YEndGroup (); 

    YBeginGroup ("SCROLL", 280,150, 100,130, YColor("aqua"));  
    YWnd (&hScroll,  SCROLL,   "", 30, 10, 20,90, 100,40,10, YVERT, CLR_DEF);
    YWnd (&hScroll1, SCROLL_H, "", 05,105, 90,20, 100,30,20, YHORZ, CLR_DEF);
    YEndGroup (); 
 
    ptr_menu = top_menu;
  case YREDRAW:  
    YBeginGroup ("TOPMENU", 30,30, 430,100, YColor(""));
    YWnd (&hMenu1, TOPMENU, "", 10, 15, 410, 25, (long)ptr_menu, 0, 0, 0, YColor("aqua")); 
    YWnd (&hMenu2, TOPMENU, "", 10, 60, 410, 25, (long)ptr_menu, 0, 0, 0, YColor("yellow")); 
    YEndGroup();
    break;        
  case YMREGIONOUT:
    OUTD(33);
    break;
  case YMENU:
    str = (char *)mes3;
    hMenu = mes1;
    YSWITCH (str) {
    YCASE ("Main/very good/item2/item1")
      YSend (hMenu, YSET, TRUE, 0, 0, (long)str);
    YCASE ("Main/very good/item2/item2")
      YSend (hMenu, YSET, FALSE, 0, 0, (long)"Main/very good/item2/item1");
    YCASE ("Menu/Make Me Grayed")
      YSend (hMenu, YSET, TRUE, 0, 0, (long)"Menu/Make Me Grayed");
    YCASE ("Menu/Make Prev. Norm.")
      YSend (hMenu, YSET, FALSE, 0, 0, (long)"Menu/Make Me Grayed");
    YCASE ("Menu/Short menu")
      YUnWnd (hMenu);
      ptr_menu = top_menu_short;
      YGoto (YREDRAW, hMenu, 0, 0, 0);
    YCASE ("Menu/Long menu")
      YUnWnd (hMenu);
      /* YWndClose (hMenu); */
      ptr_menu = top_menu;
      YGoto (YREDRAW, 0, 0, 0, 0);
    YDEFAULT
    }
   /* fprintf(YSTDERR,"Choice menuitem = %s \n", mes3); */
    YSend (hTest,message,mes1,mes2,mes3,mes4);
    break;
  case YCLOSE:
    hMenu1=ID_NULL;
/*     hMenu2=ID_NULL; */
   /*  YWndClose (id);   */      
    YWndClean (id);        
    break;   
  default:
    YSend (hTest,message,mes1,mes2,mes3,mes4);
  }       
  
  RETURN_TRUE;
}
Beispiel #18
0
// main routine
int main(int argc, char **argv)
{
  // Define force-deformation relationship for spring

  // dummy specimen
  UniaxialMaterial *theMaterial1 = new ElasticMaterial(1, 5.0);
  UniaxialMaterial *theMaterial2 = new Steel01(2, 5.0, 5.0, 0.1);

    
  // set ctrlData, daqData
  int numMat = 2;
  /*
  ExperimentalCP **cCP = new ExperimentalCP* [2];
  ArrayOfTaggedObjects *ctrlData = new ArrayOfTaggedObjects(1);
  cCP[0] = new ExperimentalCP(1, 1, OF_Dir_X, OF_Resp_Disp);
  cCP[1] = new ExperimentalCP(2, 1, OF_Dir_X, OF_Resp_Vel);
  for(int i=0; i<2; i++) 
    ctrlData->addComponent(cCP[i]);

  ExperimentalCP **dCP = new ExperimentalCP* [3];
  ArrayOfTaggedObjects *daqData = new ArrayOfTaggedObjects(1);
  dCP[0] = new ExperimentalCP(1, 1, OF_Dir_X, OF_Resp_Disp);
  dCP[1] = new ExperimentalCP(2, 1, OF_Dir_X, OF_Resp_Force);
  dCP[2] = new ExperimentalCP(3, 1, OF_Dir_X, OF_Resp_Vel);
  for(int i=0; i<3; i++) 
    daqData->addComponent(dCP[i]);
  */
  ID sizeTrial(OF_Resp_All), sizeOut(OF_Resp_All);
//  ID sizeTrial(5), sizeOut(5);
  sizeTrial[0] = numMat;
  sizeTrial[1] = numMat;
  sizeOut[0] = numMat;
  sizeOut[1] = numMat;
  sizeOut[3] = numMat;
  
  // Define ExperimentalControl
  ECSimUniaxialMaterials *theController 
    = new ECSimUniaxialMaterials(1, sizeTrial, sizeOut);
  //    = new ECSimUniaxialMaterials(1, *ctrlData, *daqData);
  theController->addDummySpecimen(theMaterial1);
  theController->addDummySpecimen(theMaterial2);

  theController->setup();

  Vector *disp, *vel, *force;
  Vector *Tdisp, *Tvel;
  disp = new Vector(numMat);
  vel = new Vector(numMat);
  force = new Vector(numMat);
  Tdisp = new Vector(numMat);
  Tvel = new Vector(numMat);

  ofstream OUTD("outD.dat");
  ofstream OUTF("outF.dat");
  int i,j;
  for(i=0; i<100; i++) {
    for(j=0; j<numMat; j++) {
      (*Tdisp)[j] = 3.0*sin(2.*3.141592*i/100);
    }

    theController->setTrialResponse(Tdisp, Tvel, (Vector*)0, (Vector*)0, (Vector*)0);
    theController->getDaqResponse(disp, vel, (Vector*)0, force, (Vector*)0);

    opserr << "Tdisp = " << *Tdisp;
    opserr << "Tvel = " << *Tvel << endln;
    opserr << "disp = " << *disp;
    opserr << "vel = " << *vel;
    opserr << "force = " << *force << endln;

    for(j=0; j<numMat; j++) {
      OUTD << ' ' << (*disp)[j];
      OUTF << ' ' << (*force)[j];
    }
    OUTD << endln; OUTF << endln;

    theController->commitState();
  }

  return 0;
}	
Beispiel #19
0
/*OUTD*/
static void op_ED_0xab(Z80EX_CONTEXT *cpu)
{
	OUTD(/*rd*/5, /*wr*/9);
	T_WAIT_UNTIL(12);
	return;
}
Beispiel #20
0
void setCommand(char* command){
    char* cmd = NULL;
    char idx=0;
    char* pch=NULL;
	cmd = Ql_strstr(command, "DEBUG=");
	if (cmd){
		cmd += 6;
		if (Ql_strstr(cmd, "TRUE")){
            __debug=TRUE;
        }
        else{
            __debug=FALSE;
        }
        Ql_strcpy(&__settings.Debug[0],cmd);
	}
    cmd = Ql_strstr(command, "LOG=");
	if (cmd){
		cmd += 4;
		if (Ql_strstr(cmd, "TRUE")){
            __log=TRUE;
        }
        else{
            __log=FALSE;
        }
        Ql_strcpy(&__settings.Log[0],cmd);
	}
	cmd = Ql_strstr(command, "TCP=");
	if (cmd){
		cmd += 4;
        __settings.TCP=Ql_atoi(cmd);
	}
	cmd = Ql_strstr(command, "IP=");
	if (cmd){
		cmd += 3;
       
        pch = strtok(cmd, ".");
		while (pch != NULL)
		{
			__settings.IP[idx] = Ql_atoi(pch);   
			pch = strtok(NULL, ".");
			idx++;
		}
        //OUTD("Set IP:%d.%d.%d.%d\r\n",__settings.IP[0],__settings.IP[1],__settings.IP[2],__settings.IP[3]);
		
	}
	cmd = Ql_strstr(command, "APN=");
	if (cmd){
		cmd += 4;
		Ql_strcpy(&__settings.APN[0],cmd);
        
	}
	cmd = Ql_strstr(command, "PASS="******"NUM=");
	if (cmd){
		cmd += 4;
		__settings.Num=Ql_atoi(cmd);
	}
    /*cmd = Ql_strstr(command, "PWD=");
	if (cmd){
		cmd += 4;
		Ql_strcpy(&__settings.Pwd[0],cmd);
        
	}*/
     cmd = Ql_strstr(command, "USER="******"TIME=");
	if (cmd){
        char* last;
        QlSysTimer tm;
        Ql_GetLocalTime(&tm);
        cmd+=5;
        if (Ql_strlen(cmd)==8) {
        tm.hour = Ql_atoi(strtok_r(cmd, ":",&last));
		tm.minute = Ql_atoi(strtok_r(last, ":",&last));
        tm.second = Ql_atoi(strtok_r(last, ":",&last));
        Ql_SetLocalTime(&tm);
     }
	}
    cmd = Ql_strstr(command, "DATE=");
	if (cmd){
		char* last;
        QlSysTimer tm;
        Ql_GetLocalTime(&tm);
        cmd+=5;
        if (Ql_strlen(cmd)==8) {
        tm.day = Ql_atoi(strtok_r(cmd, ".",&last));
		tm.month = Ql_atoi(strtok_r(last, ".",&last));
        tm.year = Ql_atoi(strtok_r(last, ".",&last));
        Ql_SetLocalTime(&tm);
        }
	}
    cmd = Ql_strstr(command, "REBOOT");
	if (cmd){
        OUTD("!-----Get command to reboot..-----",NULL);
        Ql_Sleep(100);
		Ql_Reset(0);
	}

     cmd = Ql_strstr(command, "TSEND=");
	if (cmd){
        s32 tsend;
        cmd+=6;
        tsend=Ql_atoi(cmd);
        if (tsend>10 && tsend<60) {
            __settings.TSend = tsend;
        }
        
    }

    cmd = Ql_strstr(command, "DEBOUNCE=");
	if (cmd){
        s32 deboung;
        cmd+=9;
        deboung=Ql_atoi(cmd);
        //OUTD("set debounce ok:%d",deboung);
        if (deboung>=100 && deboung<=1000) {
            //OUTD("set debounce ok:%d",deboung);
            __settings.Deboung = deboung;
        }
        
    }
    cmd = Ql_strstr(command, "WUser="******"WPass="******"?");
	if (cmd){
        PrintSettings();
	}
}
void page_response(HttpHeader *header){
	bool reset=FALSE;
	bool prepare=TRUE;
    char* action=header->action;
    OUTD("action=%s",action);
	Ql_memset(__data_buf,0,4096);
	Ql_memset(__s_buf,0,10240);
    
    if (Ql_strstr(header->action, "/")) {
		get_main_page( __est_connection ? "System state is start":"System state stop");
        OUTD("main page",NULL);
	}
	else if (Ql_strstr(action,"reboot")) {
		get_rebot_page();
		reset=TRUE;
	}
	else if (Ql_strstr(action,"settings?")) {
		char* pch=NULL;
		char* last=NULL;
		//OUTD("parse setting action:%s",pch);
		pch=strtok_r(action+9,"&",&last);
	  //OUTD("parse command:%s",pch);
     while (pch!=NULL) {
        setCommand(pch);
        pch=strtok_r(NULL,"&",&last);
		//OUTD("parse command:%s",pch);
    }
	
     WriteSettings();
	 ReadSettings();
	 get_main_page("Save settings controller is OK");
	}
	else if (Ql_strstr(action,"date?")) {
		bool sdt=SetLocDate(action+5);
		get_main_page(sdt ? "Set date and time is OK":"Error set date and time");
	}
	else if (Ql_strstr(action,"stop")) {
		StopEstConnection();
		get_main_page("Recive command Stop");
	}
	else if (Ql_strstr(action,"run")) {
		nSTATE=STATE_EST_SOCKET_CREATE;
		get_main_page("Recive command Start");
	}
	else if (Ql_strstr(action,"log")) {
		u16 size=0;
		ReadLogFile(&size);
		Ql_sprintf(__s_buf,__download_page,size);
		//Ql_strcpy(&__s_buf[Ql_strlen(__s_buf)],__buf_log);
		
		Ql_memcpy(&__s_buf[Ql_strlen(__s_buf)],__buf_log,size);
		OUTD("__download_page:%d file size:%d buffer-len:%d",Ql_strlen(__download_page),size,Ql_strlen(__s_buf));
		
		prepare=FALSE;
	}
    else if (Ql_strstr(action, "autorize")) {
        Ql_sprintf(__s_buf,__autorize,0);
        prepare=FALSE;
        OUTD("set autorize",NULL);
    }
    else {
		get_error_page();
		Ql_sprintf(__s_buf,__error_page,0);
		prepare=FALSE;
	}
	if (prepare) {
        //if (header->set_cookie) {
          //   Ql_sprintf(__s_buf, __ok_page, Ql_strlen(__data_buf),"\r\nSet-Cookie: __ztp=987654321\r\n"); 
        //}
        Ql_sprintf(__s_buf, __ok_page, Ql_strlen(__data_buf)); 
		Ql_strcpy(&__s_buf[Ql_strlen(__s_buf)],__data_buf);
        OUTD("sbuf:%d dbuf:%d",Ql_strlen(__s_buf),Ql_strlen(__data_buf));
        
	}
	if (reset) {
		Ql_Sleep(10000);
		Ql_Reset(0);
	}
}
Beispiel #22
0
/*OUTD*/
static void op_ED_0xab(void)
{
	OUTD(/*rd*/5, /*wr*/9);
	T_WAIT_UNTIL(12);
	return;
}
void GprsState(){

   //OUTD("nState:%d\r\n",nSTATE);
    switch (nSTATE) {
    case STATE_WAIT_CALLBACK:{
        OUTNET("Waiting callback function...",NULL);
        break;
    }
    case STATE_WAIT_GPRS:{
        nSTATE = STATE_SET_APN; 
        OUTNET("GPRS network waiting for attach",NULL);
        break;
    }
    case STATE_QUERY_NETWORKSTATUS:{
        u8 ps_status;
        s32 simcard;
        s32 creg;
        s32 cgreg;
        u8 rssi;
        u8 ber;
       
        Ql_GetDeviceCurrentRunState(&simcard, &creg, &cgreg, &rssi, &ber);
        if(simcard != 1 || creg != 1 || cgreg != 1){
           //LOG("!SIMCARD:%d.CREG:%d.CGREG:%d.",simcard,creg,cgreg); 
           OUTNET("!SIMCARD:%d.CREG:%d.CGREG:%d.",simcard,creg,cgreg);
           if (__simcard!=simcard) {
               OUTD("Change SIM card state:%d",simcard);
               LOG("Change SIM card state:%d",simcard);
               __simcard=simcard;
           }
           if (__creg!=creg) {
               OUTD("Change network registion:%d",creg);
               LOG("Change network registion:%d",creg);
               __creg=creg;
           }
            if (__cgreg!=cgreg) {
               OUTD("Change GPRS Network registion:%d",cgreg);
               LOG("Change GPRS registion:%d",cgreg);
               __cgreg=cgreg;
           }
            if (__rssi!=rssi) {
               OUTD("Change signal strength, unit in dBm:%d",rssi);
               LOG("Change signal unit dBm:%d",rssi);
               __rssi=rssi;
           }
            if (__ber!=ber) {
               OUTD("Change bit error rate:%d",ber);
               LOG("Change bit error:%d",ber);
               __ber=ber;
           }
        }else{
            _error = Ql_GprsNetworkGetState(0, NULL, &ps_status);
              if(ps_status == 1) 
               {
                nSTATE = STATE_SET_APN; 
                OUTNET(">GPRS network OK.Code:%d",ps_status);
                //LOG(">GPRS network OK.Code:%d",ps_status);
               }
              else{
                   OUTNET("!GPRS network error code:%d",ps_status);
                   //LOG("!GPRS network error code:%d",ps_status);
               }
        }
       break;
    }
    case STATE_TIME_SYNC:{

        break;
    }
    case STATE_SET_APN:{
        OUTD(">Try set APN:%s Login:%s Pass:%s",__settings.APN,__settings.User,__settings.Pass);
        LOG(">Try set APN:",NULL);
        _error=Ql_GprsAPNSet(0,(u8*)__settings.APN,(u8*)__settings.User,(u8*)__settings.Pass,CallBack_GprsAPNSet);
        if (_error) {
            nSTATE=STATE_WAIT_GPRS;
            //OUTNET("!Error network set APN:%d",_error);
            nSTATE=STATE_WAIT_CALLBACK;
        }
        else 
        {
            nSTATE=STATE_WAIT_CALLBACK;
        }
        break; 
    }
    case STATE_ACTIVE_PDP:{
        nSTATE=STATE_WAIT_CALLBACK;
        _error = Ql_GprsNetworkActive(0);
         break;
    }
    case STATE_EST_SOCKET_CREATE:{
        if (!__est_connection) {
        __est_connector_socket = Ql_SocketCreate(0, SOC_TYPE_TCP); 
        if (__est_connector_socket>=0) {
                nSTATE=STATE_SOCKET_CONNECT;
                OUTD(">EST socket:OK",NULL);
                //LOG(">EST socket:OK",NULL);
            }
            else{
                nSTATE=STATE_EST_SOCKET_CREATE;
                OUTD("!EST socket error:%d",__est_connector_socket);
                LOG("!EST socket error:%d",__est_connector_socket);
            }
        }
        break; 
    }
    case STATE_SOCKET_CREATE:{
        
        __http_socketID = Ql_SocketCreate(0, SOC_TYPE_TCP); 
            if (__http_socketID>=0) {
                nSTATE=STATE_LISTEN; 
                OUTNET(">EST socket:OK",NULL);
                   //LOG(">EST socket:OK",NULL);
            }
            else{
                nSTATE=STATE_QUERY_NETWORKSTATUS;
                OUTNET("!EST socket error:%d",__http_socketID);
                //LOG("!EST socket error:%d",__http_socketID);
            }
            break;
        }
    case STATE_LISTEN:{
        s32 ret;
        
        ret=Ql_SocketListen(__http_socketID,__local_ip_addr,80,5);
		if (ret<0) {
            OUTD("Error listen port:%d",ret);
            LOG("Http port error:%d",ret);
            nSTATE=STATE_LISTEN;
		}
        else{
            OUTD("Listen port OK:",NULL);
           LOG("Http port OK:",NULL);
              //nSTATE=STATE_ING;  
            nSTATE=STATE_EST_SOCKET_CREATE;
            client_socketId_init();
            //OUTD("client_socketId_init OK:",NULL);
        }
		break; 
    }
    case STATE_SOCKET_CONNECT:{
        //QlSysTimer tmr;
       /* u16 a_port=0;
        s8 loc_socket=-1;*/
        s32 err;
        nSTATE=STATE_ING;
            err=Ql_SocketConnect(__est_connector_socket,__settings.IP,__settings.TCP);
			//if (err!=0) {
                //OUTD("Error EST connect:%d",err);
                //LOG("Error EST connect:%d",err);
			//}
			break; 
    }
    case STATE_SOCKET_SEND:{
        if (__toSend>0) {

            OUTD("<Send message:num:%d",__numPacket);
            LOG("<Send message:num:%d",__numPacket);
            //__empty_msg=0;
            Ql_SocketSend(__est_connector_socket, &__SendBuffer[0], __toSend);
            //nSTATE=STATE_SOCKET_RECIVE;
            nSTATE=STATE_ING;
           Ql_StartGPTimer(TIME_WAIT_CONFIRM_MSG,CheckAnyMessage,NULL);
            return;
          }
        
        else{
            //__empty_msg += DEVICE_CYCLE; 
           if (CheckSendEmptyMessage())//(__empty_msg>__settings.TSend*TIME_SECOND) 
           {
              // __empty_msg=0;
               TrigerEvent(None,0,&__currentEvData);  
               __toSend=BuildEventMessage(0,&__currentEvData,1);
               OUTD("<Time send empty message",NULL);
               //LOG("<Time send empty msg",NULL);
            Ql_SocketSend(__est_connector_socket, &__SendBuffer[0], __toSend);
            Ql_StartGPTimer(TIME_WAIT_CONFIRM_MSG,CheckAnyMessage,NULL);
            //nSTATE=STATE_SOCKET_RECIVE;
            nSTATE=STATE_ING;
            return;
           }
        }
        ReadEvents(); 
        break;
    }
    case STATE_EST_SOCKET_PAUSE:{
        
        break;
    }
    case STATE_EST_SOCKET_CLOSE:{
        OUTD("Close Est Tools connection",NULL);
        LOG("Close Est connect",NULL);
         nSTATE=STATE_EST_SOCKET_CREATE;
        Ql_SocketClose(__est_connector_socket);
        __est_connection=FALSE;
        break;
    }
    case STATE_SOCKET_RECIVE:{
        
        break;
    }
    }
}
Beispiel #24
0
/*----------------------------------board_test--------------------------------*/
void
board_test ()
{ 

  OUTD (1);
  int a3x3[9] = { STONE_BLACK, STONE_NONE,   STONE_NONE, 
                  STONE_NONE,  STONE_WHITE,  STONE_BLACK, 
                  STONE_NONE,  STONE_WHITE,  STONE_NONE  };
  GO_BOARD b3x3 = {3, 3, &a3x3[0]};

  int a2x3[6] = { STONE_BLACK, STONE_NONE,   STONE_NONE, 
                  STONE_NONE,  STONE_WHITE,  STONE_NONE  };
  GO_BOARD b2x3 = {2, 3, &a2x3[0]};

  int a1x3[3] = { STONE_BLACK, STONE_NONE,   STONE_NONE };
  GO_BOARD b1x3 = {1, 3, &a1x3[0]};

  GO_BOARD *bs[NUM_SYM];
  int i;

  OUTD (2);
  UNUSED (b3x3);
  UNUSED (b1x3);
  UNUSED (b2x3);

  if (0) {
  //---------------------------------
  printf ("short  = %d \n", (int) sizeof (short));
  printf ("int    = %d \n", (int) sizeof (int));
  printf ("long   = %d \n", (int) sizeof (long));
  printf ("double = %d \n", (int) sizeof (double));
  printf ("\n");
  printf ("MAXSHORT = %d \n", G_MAXSHORT);
  //#ifdef _UNIX
  printf ("MAXLONG  = %ld \n", G_MAXLONG);
  //#endif

  char *p;
  YMALLOC (p, char, /* MAXLONG */G_MAXSHORT);
  if (!p)  printf ("Not memory! \n");
  else     printf ("Yes memory! \n");
  //---------------------------------
  }

  OUTD (3);
  //((long)(&b3x3))++;
  int num_sym = board_symm_calc (bs, &b1x3);
  //int num_sym = board_symm_calc (bs, &b2x3);
  //int num_sym = board_symm_calc (bs, &b3x3);

  OUTD (4);

  for (i=0; i<num_sym; i++) {
    aboard_show (bs[i], FALSE,  TRUE); 

    short index = board_calc_index (bs[i]);
    printf ("Index = %d \n", index);

    printf ("\n");
  }
  OUTD (5);

  printf ("\n");
  return;
}