Esempio n. 1
0
void BattleToJson::onStatBoost(int spot, int stat, int boost, bool silent)
{
    makeCommand("boost");
    map.insert("stat", stat);
    map.insert("boost", boost);
    map.insert("silent", silent);
}
Esempio n. 2
0
void BattleToJson::onMoveChange(int spot, int slot, int move, bool definite)
{
    makeCommand("movechange");
    map.insert("slot", slot);
    map.insert("move", move);
    map.insert("temporary", !definite);
}
Esempio n. 3
0
void BattleToJson::onUseAttack(int spot, int attack, bool silent, bool special)
{
    makeCommand("move");
    map.insert("move", attack);
    map.insert("silent", silent);
    map.insert("special", special);
}
Esempio n. 4
0
void BattleToJson::onSendOut(int spot, int player, ShallowBattlePoke *pokemon, bool silent)
{
    makeCommand("send");
    map.insert("slot", player);
    map.insert("silent", silent);
    map.insert("pokemon", toJson(*pokemon));
}
Esempio n. 5
0
void BattleToJson::onMajorStatusChange(int spot, int status, bool multipleTurns, bool silent)
{
    makeCommand("status");
    map.insert("status", status);
    map.insert("multiple", multipleTurns);
    map.insert("silent", silent);
}
Esempio n. 6
0
void BattleToJson::onAbilityMessage(int spot, int ab, int part, int type, int foe, int other)
{
    makeCommand("abilitymessage");
    map.insert("ability", ab);
    map.insert("part", part);
    map.insert("type", type);
    map.insert("foe", foe);
    map.insert("other", other);
}
Esempio n. 7
0
void BattleToJson::onItemMessage(int spot, int item, int part, int foe, int berry, int other)
{
    makeCommand("itemmessage");
    map.insert("item", item);
    map.insert("part", part);
    map.insert("foe", foe);
    map.insert("berry", berry);
    map.insert("other", other);
}
Esempio n. 8
0
void BattleToJson::onDynamicStats(int spot, const BattleStats& stats)
{
    makeCommand("stats");
    QVariantList vstats;
    for (int i = 0; i < 6; i++) {
        vstats.push_back(int(stats.stats[i]));
    }
    map.insert("stats", vstats);
}
Esempio n. 9
0
void BattleToJson::onMoveMessage(int spot, int move, int part, int type, int foe, int other, const QString &data)
{
    makeCommand("movemessage");
    map.insert("move", move);
    map.insert("part", part);
    map.insert("type", type);
    map.insert("foe", foe);
    map.insert("other", other);
    map.insert("data", data);
}
Esempio n. 10
0
void *doTest(void *arg) {
    int i = 0, nread = 0;
    int connfd = 0;
    int loopcnt = 0;
    int flags = 0;

    char *errmsg = NULL;
    char command_set[50] = "";
    char command_set_key[20] = "";
    char command_set_val[20] = "";
    char readBuf[20];
    char *ptr = NULL;
    struct hostent *host;
    struct sockaddr_in serv_addr;
    host = gethostbyname(SERVIP);
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port = htons(SERVPORT);
    serv_addr.sin_addr = *((struct in_addr *)host->h_addr);
    bzero(&(serv_addr.sin_zero), 8);
    if((connfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { 
        printf("socket创建出错!\n");
    }
    struct timeval tv_out;
    tv_out.tv_sec = 1;
    tv_out.tv_usec = 0;
    int ret = -2;
    if((ret = setsockopt(connfd, SOL_SOCKET, SO_RCVTIMEO, &tv_out, sizeof(tv_out)))==-1) {
        printf("set timeout failed.\n");
    }
    if (connect(connfd, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr)) != 0) { 
        printf("connect出错!\n");
        errmsg = strerror(errno);
        printf("Mesg:%s\n",errmsg); //可以看到返回的错误码
    } 
//printf("in thread %lu, arg1 is:%d, arg2 is:%d\n", pthread_self(), ((args *)arg)->arg1, ((args *)arg)->arg2);
    for(loopcnt = ((args *)arg)->arg1; loopcnt < ((args *)arg)->arg2; loopcnt++) {
        strcpy(command_set,"set\ta");
        sprintf(command_set_key,"%d",loopcnt);   //fill key with loopcnt
        strcat(command_set,command_set_key);     //combine commend_get and command_get_key
        strcat(command_set,"\t");
        sprintf(command_set_val,"%d",loopcnt);
        strcat(command_set,command_set_val);
        ptr = makeCommand(command_set);
//        printf("%s\n", ptr);
        write(connfd, ptr, strlen(ptr));
        memset(readBuf,'\0',20);
        read(connfd,readBuf,20);
    }
/*
    strcpy(command_set,"shutdown");
    ptr = makeCommand(command_set);
    write(connfd, ptr, strlen(ptr));
    close(connfd);
*/
}
Esempio n. 11
0
void BattleToJson::onDynamicInfo(int spot, const BattleDynamicInfo &info)
{
    makeCommand("dynamicinfo");
    map.insert("fieldflags", int(info.flags));

    QVariantList vstats;
    for (int i = 0; i < 8; i++) {
        vstats.push_back(int(info.boosts[i]));
    }
    map.insert("boosts", vstats);
}
Esempio n. 12
0
int main(int argc,char* argv[])
{
   int loop = 1;
   while(loop) {
      Command* com  = makeCommand();
      printCommand(com);
      loop = executeCommand(com);
      freeCommand(com);
   }
   return 0;
}
Esempio n. 13
0
TResult CKKMApi::exec_command(const QByteArray& baCmd, QByteArray& baAnswer, int nTimeOut)
{
	TResult nRet = kResult_Success;
	LOG_DBG("exec_command ==>");

	do
	{
		sendENQ();
		readACK();
		//sendENQ_readACK();

		QByteArray baRawCommand = makeCommand(baCmd);
		LOG_DBG("command : '"<<ba2hex(baRawCommand)<<"'");
		m_pSerial->write(baRawCommand);

		readACK();
		sendEOT();

		readENQ(nTimeOut);
		sendACK();

		nRet = loadKKMData(baAnswer);
		if (nRet == kResult_Success)
		{
			if (baAnswer.size() > 2)
			{
				baAnswer = baAnswer.mid(1, baAnswer.size()-2);
			}
			else
			{
				nRet = kResult_ReadError;
				LOG_ERR("incorrect answer size");
				break;
			}
		}

		sendACK();
		readEOT();
	}
	while (false);
	LOG_DBG("exec_command <==");
	return nRet;
}
Esempio n. 14
0
	static void send(TBS::Serial::SerialWrapper & w1, std::string command) {
		std::cout << "mancmd: " << command << std::endl;
		TBS::Serial::SerialWrapper::VectorBuffer buff = makeCommand(command);
		w1.send(buff);
		for (int i = 0; i < 10; i++) {
			Poco::Thread::sleep(10);
			TBS::Serial::SerialWrapper::VectorBuffer buff2 = w1.receive();
			if (!buff2.empty()) {

				//std::cout << "size: " << buff2.size() << std::endl;
				std::cout << "manrecv:" << std::endl;
				for (auto b = buff2.begin(); b != buff2.end(); b++) {
					std::cout << *b << " ";
				}
				std::cout << std::endl;
				break;
			}
		}
	}
Esempio n. 15
0
void myshutDown() {
    int i = 0, nread = 0;
    int connfd = 0;
    int loopcnt = 0;
    int flags = 0;

    char *errmsg = NULL;
    char command_set[50] = "";
    char command_set_key[20] = "";
    char command_set_val[20] = "";
    char readBuf[20];
    char *ptr = NULL;
    struct hostent *host;
    struct sockaddr_in serv_addr;
    host = gethostbyname(SERVIP);
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port = htons(SERVPORT);
    serv_addr.sin_addr = *((struct in_addr *)host->h_addr);
    bzero(&(serv_addr.sin_zero), 8);
    if((connfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
        printf("socket创建出错!\n");
    }
    struct timeval tv_out;
    tv_out.tv_sec = 1;
    tv_out.tv_usec = 0;
    int ret = -2;
    if((ret = setsockopt(connfd, SOL_SOCKET, SO_RCVTIMEO, &tv_out, sizeof(tv_out)))==-1) {
        printf("set timeout failed.\n");
    }
    if (connect(connfd, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr)) != 0) {
        printf("connect出错!\n");
        errmsg = strerror(errno);
        printf("Mesg:%s\n",errmsg); //可以看到返回的错误码
    }
    strcpy(command_set,"shutdown");
    ptr = makeCommand(command_set);
    write(connfd, ptr, strlen(ptr));
    close(connfd);
}
Esempio n. 16
0
/**
 * operator()
 *
 *   Called when a partial barrier has been processed.  This method 
 *   constructs the command and executes it.
 *
 * @param barrierTypes - a vector of pairs. Each pair is a source id and the
 *                       type of barrier emitted by that source.
 * @param missingSources - A vector of the sources that did not contribute barriers
 *                       prior to the timeout.
 *
 */
void
CPartialBarrierCallback::operator()(const std::vector<std::pair<uint32_t, uint32_t> >& barrierTypes, 
				     const std::vector<uint32_t>& missingSources)
{

  try {
    std::string command = makeCommand(barrierTypes, missingSources);
    m_Interp.GlobalEval(command);
  }
  catch (std::string msg) {
    std::cerr << "Partial barrier observer script error: " << msg << std::endl;
  }
  catch (const char* msg) {
    std::cerr << "Partial barrier observer script error: " << msg << std::endl;
  }
  catch (CException& e) {
    std::cerr << "Partial barrier observer script error: " << e.ReasonText() << std::endl;
  }
  catch (...) {
    std::cerr << "Partial barrier obserbver; unexopected exception type\n";
  }
}
Esempio n. 17
0
void MockCompositor::sendMousePress(const QSharedPointer<MockSurface> &surface, const QPoint &pos)
{
    Command command = makeCommand(Impl::Compositor::sendMousePress, m_compositor);
    command.parameters << QVariant::fromValue(surface) << pos;
    processCommand(command);
}
Esempio n. 18
0
void MockCompositor::setKeyboardFocus(const QSharedPointer<MockSurface> &surface)
{
    Command command = makeCommand(Impl::Compositor::setKeyboardFocus, m_compositor);
    command.parameters << QVariant::fromValue(surface);
    processCommand(command);
}
Esempio n. 19
0
void MockCompositor::setOutputGeometry(const QRect &rect)
{
    Command command = makeCommand(Impl::Compositor::setOutputGeometry, m_compositor);
    command.parameters << rect;
    processCommand(command);
}
Esempio n. 20
0
void MockCompositor::sendKeyRelease(const QSharedPointer<MockSurface> &surface, uint code)
{
    Command command = makeCommand(Impl::Compositor::sendKeyRelease, m_compositor);
    command.parameters << QVariant::fromValue(surface) << code;
    processCommand(command);
}
Esempio n. 21
0
int main(int argc, char *argv[])
{

// Pid Code,erlaubt nur eine Instanz
int pid_file = open("/var/run/ctlmissile.pid", O_CREAT | O_RDWR, 0666);
int rc = flock(pid_file, LOCK_EX | LOCK_NB);
if(rc) {
    if(EWOULDBLOCK == errno)
		fprintf(stderr, "Another Instance is running!");
        exit(0);
}

		libusb_device **devlist;
		libusb_device *dev;
		ssize_t numdev, i;
		int ret = 0;
		do_init();
		 
		numdev = libusb_get_device_list(ctx, &devlist);
		
		 
		for(ret = 1, i = 0; i < numdev; i++) {
			dev = devlist[i];
			struct libusb_device_descriptor d;
			libusb_get_device_descriptor(dev, &d);			
			int ret=0;
			if (d.idVendor == 0x0a81  &&
				d.idProduct == 0x0701) {
				//fprintf(stderr, "Found Device:\n");
				// Try to detach:
				ret = detach_device(dev);
				//fprintf(stderr, "%d:\n",ret);
				
				libusb_device_handle *handle;
				// get Handle:
				ret = libusb_open(dev, &handle);
				if(ret!=0){
					fprintf(stderr, "Couldnt get Handle: %s\n",libusb_error_name(ret));	
				}				
				// Claim Device:
				ret = libusb_claim_interface(handle,0);
				if(ret!=0){
					fprintf(stderr, "Error with Claiming: %s\n",libusb_error_name(ret));	
				}
				int delay;
				sscanf (argv[2],"%d",&delay);
				// Try Command
				makeCommand(handle,argv[1],delay);				
				// Try to reset
				//libusb_reset_device(handle);
				break;
			}
			
		}
	

	if (!dev) {
		fprintf(stderr, "Unable to find device.\n");
		exit(EXIT_FAILURE);
	}

	return 0;
}
Esempio n. 22
0
std::string InputForm::Run()
{
  for (int i = 0;i < choices;i++)
  {
    fillField();
    form_driver(form, REQ_NEXT_FIELD);
    form_driver(form, REQ_NEXT_FIELD);
    index++;
    index %= choices;
  }
  fillField();
  wrefresh(win);
  show_panel(panel);
  int ch;  
  bool exit = false;
  while (!exit && (ch = wgetch(stdscr)) != KEY_ESC)
  {	
    switch(ch)
    {
      case KEY_LEFT:
      case KEY_RIGHT:
        switchOkCancle();
        form_driver(form, (int)'0');
        form_driver(form, REQ_DEL_PREV);  
        break;
      case KEY_UP:
      case KEY_BTAB:
        index--;
        index = (index+choices)%choices;
        form_driver(form, REQ_PREV_FIELD);
        form_driver(form, REQ_PREV_FIELD);
        fillField();
        break;
      case KEY_DOWN:
      case KEY_TAB:  
        index++;
        index %= choices;
        form_driver(form, REQ_NEXT_FIELD);
        form_driver(form, REQ_NEXT_FIELD);
        fillField();
        break;
      case KEY_BACKSPACE:
        delAchar(); 	
        break;
      case KEY_NL:
        if (index == choices-1 || !okCancle)
        {
          exit = true;
        }
        else
        {
          index++;
          index %= choices;
          form_driver(form, REQ_NEXT_FIELD);
          form_driver(form, REQ_NEXT_FIELD);
          fillField();
        }
        break;
      default:
        if (itemTypes[index].compare("password") == 0) 
        {
          itemInputs[index].push_back(ch);
          form_driver(form, '*');
        }
        else if (itemTypes[index].compare("checklist") == 0)
        {
          if (ch == ' ')
          {
            if (itemInputs[index].compare("y") == 0)
            {
              itemInputs[index] = "n"; 
              fillCheckList(false);
            }
            else
            {
              itemInputs[index] = "y";
              fillCheckList(true);
            }
          }
        }
        else
        {
          itemInputs[index].push_back(ch);
          form_driver(form, ch);
        }
        break;
    }
    update_panels();
    doupdate();
  }
  hide_panel(panel);
  if (ch == KEY_ESC || !okCancle)
    return "cancle";
  else
    return makeCommand();
}
Esempio n. 23
0
void BattleToJson::onKo(int spot)
{
    makeCommand("ko");
}
Esempio n. 24
0
void BattleToJson::onPPChange(int spot, int move, int PP)
{
    makeCommand("ppchange");
    map.insert("move", move);
    map.insert("pp", PP);
}
Esempio n. 25
0
void BattleToJson::onAvoid(int spot)
{
    makeCommand("miss");
}
Esempio n. 26
0
void BattleToJson::onCriticalHit(int spot)
{
    makeCommand("critical");
}
Esempio n. 27
0
void BattleToJson::onEffectiveness(int spot, int effectiveness)
{
    makeCommand("effectiveness");
    map.insert("effectiveness", effectiveness);
}
Esempio n. 28
0
void BattleToJson::onChoiceSelection(int spot)
{
    makeCommand("choiceselection");
}
Esempio n. 29
0
void BattleToJson::onHitCount(int spot, int count)
{
    makeCommand("hitcount");
    map.insert("count", count);
}
Esempio n. 30
0
void BattleToJson::onHpChange(int spot, int newHp)
{
    makeCommand("hpchange");
    map.insert("newHP", newHp);
}