bool ActionStd::LoadFromXml(TiXmlElement *node)
{
    node = node->FirstChildElement();

    for (; node; node = node->NextSiblingElement())
    {
        if (node->ValueStr() == "calaos:output")
        {
            std::string id = "", val = "", val_var = "";

            if (node->Attribute("id")) id = node->Attribute("id");
            if (node->Attribute("val")) val = node->Attribute("val");
            if (node->Attribute("val_var")) val_var = node->Attribute("val_var");

            if (id == "OutTouchscreen" && ListeRule::Instance().size() > 0)
            {
                cInfoDom("rule.action.standard") <<  "Converting old OutTouchscreen to new ActionTouchscreen";
                Rule *rule = ListeRule::Instance().get_rule(ListeRule::Instance().size() - 1);
                ActionTouchscreen *action = new ActionTouchscreen(val);
                rule->AddAction(dynamic_cast<Action *>(action));
            }

            IOBase *out = ListeRoom::Instance().get_io(id);

            if (!out)
            {
                //for compatibility with old AudioPlayer and Camera, update ids if needed
                std::list<IOBase *> l = ListeRoom::Instance().getAudioList();
                for (IOBase *io: l)
                {
                    if (io->get_param("iid") == id ||
                        io->get_param("oid") == id)
                        out = io;
                }

                l = ListeRoom::Instance().getCameraList();
                for (IOBase *io: l)
                {
                    if (io->get_param("iid") == id ||
                        io->get_param("oid") == id)
                        out = io;
                }
            }

            if (out && out->isOutput())
            {
                Add(out);
                params.Add(id, val);
                if (val_var != "")
                    params_var.Add(id, val_var);
            }
            else
            {
                return false;
            }
        }
    }

    return true;
}
Beispiel #2
0
Room *Camera::getRoom()
{
    if (room) return room;

    map<string, IOBase *>::const_iterator it = CalaosModel::Instance().getHome()->getCacheOutputs().find(params["oid"]);
    if (it == CalaosModel::Instance().getHome()->getCacheOutputs().end())
        return NULL;

    IOBase *output = (*it).second;
    return output->getRoom();
}
Beispiel #3
0
void testDebug()
{
  IOBase *io;
  io=new IODebug();
  unsigned char tdi[]={0x3a,0xa3};
  unsigned char tdo[10];
  io->setTapState(IOBase::SHIFT_DR);
  io->shiftTDITDO(tdi,tdo,16,false);
  for(int i=0; i<2; i++)printf("TDO %02x\n",tdo[i]);
  delete io;
}
Beispiel #4
0
void testPP()
{
  IOBase *io;
  io=new IOParport("/dev/parport0");
  unsigned char tdi[]={0,0,0,0,0,0,0,0};
  unsigned char tdo[100];
  io->setTapState(IOBase::SHIFT_DR);
  io->shiftTDITDO(tdi,tdo,64);
  for(int i=0; i<8; i++)printf("TDO %02x\n",tdo[i]);
  printf("\n");
  getSwitches(io);
  getID(io);
  delete io;
}
Beispiel #5
0
bool Room::SaveToXml(TiXmlElement *node)
{
    TiXmlElement *room_node = new TiXmlElement("calaos:room");
    room_node->SetAttribute("name", name);
    room_node->SetAttribute("type", type);
    room_node->SetAttribute("hits", Utils::to_string(hits));
    node->LinkEndChild(room_node);

    for (int i = 0;i < get_size();i++)
    {
        IOBase *io = get_io(i);

        io->SaveToXml(room_node);
    }

    return true;
}
Beispiel #6
0
void Application::homeLoaded(const QVariantMap &homeData)
{
    homeModel->load(homeData);
    audioModel->load(homeData);
    favHomeModel->load(homeData);
    cameraModel->load(homeData);
    update_applicationStatus(Common::LoggedIn);

    favModel->load(favoritesList);

    saveSettings();

    if (!startedWithOptHandled)
    {
        qDebug() << "handling start options if any";
        startedWithOptHandled = true;
        if (HardwareUtils::Instance()->hasStartedWithOption())
        {
            //If app has been started with option, it should be a scenario (only supported action for now)
            QString io = HardwareUtils::Instance()->getStartOption("scenario");
            qDebug() << "Start option: activate scenario: " << io;
            IOBase *iosc = IOCache::Instance().searchInput(io);
            if (!iosc)
                qDebug() << "Unable to start scenario " << io << " reason: not found";
            else
                iosc->sendTrue(); //Start scenario
        }
    }

    //Export 4 first scenarios to hardware (for QuickLinks on iOS)
    //This allows iOS with 3D touch to quick start a scenario on home screen
    QVariantList scenariosLinks;
    for (int i = 0;i < scenarioSortModel->rowCount() && i < 4;i++)
    {
        IOBase *io = dynamic_cast<IOBase *>(scenarioSortModel->getItemModel(i));
        QVariantMap sc = {{ "id", io->get_ioId() },
                          { "name", io->get_ioName() }};
        scenariosLinks.append(sc);
    }
    HardwareUtils::Instance()->setQuickLinks(scenariosLinks);
}
Beispiel #7
0
IOBase *ListeRoom::get_chauffage_var(std::string &chauff_id, ChauffType type)
{
    for (uint j = 0;j < rooms.size();j++)
    {
        for (int m = 0;m < rooms[j]->get_size();m++)
        {
            IOBase *io = rooms[j]->get_io(m);
            if (io->get_param("chauffage_id") == chauff_id)
            {
                switch (type)
                {
                case PLAGE_HORAIRE: if (io->get_param("gui_type") == "time_range") return io; break;
                case CONSIGNE: if (io->get_param("gui_type") == "var_int") return io; break;
                case ACTIVE: if (io->get_param("gui_type") == "var_bool") return io; break;
                }
            }
        }
    }

    return nullptr;
}
bool ActionStd::SaveToXml(TiXmlElement *node)
{
    TiXmlElement *action_node = new TiXmlElement("calaos:action");
    action_node->SetAttribute("type", "standard");
    node->LinkEndChild(action_node);

    for (uint i = 0;i < outputs.size();i++)
    {
        IOBase *out = outputs[i];

        TiXmlElement *cnode = new TiXmlElement("calaos:output");

        cnode->SetAttribute("id", out->get_param("id"));
        cnode->SetAttribute("val", params[out->get_param("id")]);
        if (params_var[out->get_param("id")] != "")
            cnode->SetAttribute("val_var", params_var[out->get_param("id")]);

        action_node->LinkEndChild(cnode);
    }

    return true;
}
void AudioPlayer::audio_get_cb(bool success, vector<string> result, void *data)
{
    for (uint b = 2;b < result.size();b++)
    {
        vector<string> tmp;
        Utils::split(result[b], tmp, ":", 2);

        if (tmp.size() < 2) continue;

        params.Add(tmp[0], tmp[1]);
    }

    string cmd;

    //Query some more infos
    cmd = "audio " + params["num"] + " volume?";
    connection->SendCommand(cmd, sigc::mem_fun(*this, &AudioPlayer::audio_volume_get_cb));

    cmd = "audio " + params["num"] + " status?";
    connection->SendCommand(cmd, sigc::mem_fun(*this, &AudioPlayer::audio_status_get_cb));

    cmd = "audio " + params["num"] + " songinfo?";
    connection->SendCommand(cmd, sigc::mem_fun(*this, &AudioPlayer::audio_songinfo_get_cb));

    cmd = "audio " + params["num"] + " playlist size?";
    connection->SendCommand(cmd, sigc::mem_fun(*this, &AudioPlayer::audio_playlist_size_get_cb));

    cmd = "audio " + params["num"] + " database stats?";
    connection->SendCommand(cmd, sigc::mem_fun(*this, &AudioPlayer::audio_db_stats_get_cb));

    IOBase *amp = getAmplifier();
    if (amp)
    {
        amp->sendUserCommand("states?", sigc::mem_fun(*this, &AudioPlayer::getAmpStates_cb));
        amp->sendUserCommand("query input_sources ?", sigc::mem_fun(*this, &AudioPlayer::getInputSource_cb));
    }

    load_done.emit(this);
}
Beispiel #10
0
bool ConditionScript::SaveToXml(TiXmlElement *node)
{
    TiXmlElement *cond_node = new TiXmlElement("calaos:condition");
    cond_node->SetAttribute("type", "script");
    node->LinkEndChild(cond_node);

    for (auto it: in_event)
    {
        IOBase *io = it.first;
        TiXmlElement *in_node = new TiXmlElement("calaos:input");
        in_node->SetAttribute("id", io->get_param("id"));
        cond_node->LinkEndChild(in_node);
    }

    TiXmlElement *sc_node = new TiXmlElement("calaos:script");
    sc_node->SetAttribute("type", "lua");
    cond_node->LinkEndChild(sc_node);

    TiXmlText *txt_node = new TiXmlText(script);
    txt_node->SetCDATA(true);
    sc_node->LinkEndChild(txt_node);

    return true;
}
Beispiel #11
0
void process(IOBase &io, BitFile &file, int chainpos)
{
  const byte IDCODE=0x09;
  const byte XCF_IDCODE=0xfe;

  Jtag jtag(&io);
  int num=jtag.getChain();
  DeviceDB db(DEVICEDB);
  for(int i=0; i<num; i++){
    int length=db.loadDevice(jtag.getDeviceID(i));
    if(length>0)jtag.setDeviceIRLength(i,length);
    else{
      byte *id=jtag.getDeviceID(i);
      fprintf(stderr,"Cannot find device having IDCODE=%02x%02x%02x%02x\n",id[0],id[1],id[2],id[3]);
      return;
    }
  }
  

  byte tdo[4];

  if(jtag.selectDevice(chainpos)<0){
    fprintf(stderr,"Invalid chain position %d, position must be less than <%d.\n",chainpos,num);
    return;
  }

  jtag.shiftIR(&IDCODE);
  jtag.shiftDR(0,tdo,32);
  printf("IDCODE: 0x%02x%02x%02x%02x\tDesc: %s\n",tdo[0],tdo[1],tdo[2],tdo[3],db.getDeviceDescription(chainpos)); 

  const byte JPROGRAM=0x0b;
  const byte CFG_IN=0x05;
  const byte JSHUTDOWN=0x0d;
  const byte JSTART=0x0c;
  const byte BYPASS=0x3f;

  jtag.shiftIR(&JPROGRAM);
  jtag.shiftIR(&CFG_IN);
  byte init[]={0x00, 0x00, 0x00, 0x00, // Flush
	       0x00, 0x00, 0x00, 0x00, // Flush
	       0xe0, 0x00, 0x00, 0x00, // Clear CRC
	       0x80, 0x01, 0x00, 0x0c, // CMD
	       0x66, 0xAA, 0x99, 0x55, // Sync
	       0xff, 0xff, 0xff, 0xff  // Sync
  };
  jtag.shiftDR(init,0,192,32); // Align to 32 bits.
  jtag.shiftIR(&JSHUTDOWN);
  io.cycleTCK(12);
  jtag.shiftIR(&CFG_IN);
  byte hdr[]={0x00, 0x00, 0x00, 0x00, // Flush
	      0x10, 0x00, 0x00, 0x00, // Assert GHIGH
	      0x80, 0x01, 0x00, 0x0c  // CMD
  };
  jtag.shiftDR(hdr,0,96,32,false); // Align to 32 bits and do not goto EXIT1-DR
  jtag.shiftDR(file.getData(),0,file.getLength()); 
  io.tapTestLogicReset();
  io.setTapState(IOBase::RUN_TEST_IDLE);
  jtag.shiftIR(&JSTART);
  io.cycleTCK(12);
  jtag.shiftIR(&BYPASS); // Don't know why, but without this the FPGA will not reconfigure from Flash when PROG is asserted.
}
bool ActionStd::Execute()
{
    std::string tmp;
    bool ret = true;
    std::string sval;
    bool bval = false;
    double dval = 0;

    for (uint i = 0;i < outputs.size();i++)
    {
        bool ovar = false;
        switch (outputs[i]->get_type())
        {
        case TBOOL:
        {
            if (params_var[outputs[i]->get_param("id")] != "")
            {
                std::string var_id = params_var[outputs[i]->get_param("id")];
                IOBase *out = ListeRoom::Instance().get_io(var_id);
                if (out && out->get_type() == TBOOL)
                {
                    bval = out->get_value_bool();
                    ovar = true;
                }
            }

            if (ovar)
            {
                if (!outputs[i]->set_value(bval)) ret = false;
            }
            else if (params[outputs[i]->get_param("id")] == "true")
            {
                if (!outputs[i]->set_value(true)) ret = false;
            }
            else if (params[outputs[i]->get_param("id")] == "false")
            {
                if (!outputs[i]->set_value(false)) ret = false;
            }
            else
            {
                if (!outputs[i]->set_value(params[outputs[i]->get_param("id")])) ret = false;
            }
            break;
        }
        case TINT:
        {
            if (params_var[outputs[i]->get_param("id")] != "")
            {
                std::string var_id = params_var[outputs[i]->get_param("id")];
                IOBase *out = ListeRoom::Instance().get_io(var_id);
                if (out && out->get_type() == TINT)
                {
                    dval = out->get_value_double();
                    ovar = true;
                }
            }
            tmp = params[outputs[i]->get_param("id")];

            if (ovar)
            {
                if (!outputs[i]->set_value(dval)) ret = false;
            }
            else if (is_of_type<double>(tmp))
            {
                if (!outputs[i]->set_value(atof(tmp.c_str()))) ret = false;
            }
            else
            {
                if (!outputs[i]->set_value(tmp)) ret = false;
            }
            break;
        }
        case TSTRING:
        {
            if (params_var[outputs[i]->get_param("id")] != "")
            {
                std::string var_id = params_var[outputs[i]->get_param("id")];
                IOBase *out = ListeRoom::Instance().get_io(var_id);
                if (out && out->get_type() == TSTRING)
                {
                    sval = out->get_command_string();
                    ovar = true;
                }
            }
            tmp = params[outputs[i]->get_param("id")];

            if (ovar)
            {
                if (!outputs[i]->set_value(sval)) ret = false;
            }
            else if (tmp != "")
            {
                if (!outputs[i]->set_value(tmp)) ret = false;
            }

            break;
        }
        default: break;
        }
    }

    if (ret)
        cDebugDom("rule.action.standard") <<  "Ok";
    else
        cErrorDom("rule.action.standard") <<  "Failed !";

    return ret;
}
Beispiel #13
0
//===========================================================================
void ScriptBool::serialize(IOBase& output) const
{
  output.write(get_string());
}
Beispiel #14
0
bool ConditionOutput::Evaluate()
{
    string sval, oper;
    bool bval;
    double dval;
    bool ret = false;

    bool ovar = false;
    bool changed = false;
    switch (output->get_type())
    {
    case TBOOL:
        if (params_var != "")
        {
            IOBase *out = ListeRoom::Instance().get_io(params_var);
            if (out && out->get_type() == TBOOL)
            {
                bval = out->get_value_bool();
                ovar = true;
            }
        }

        if (!ovar)
        {
            if (params == "true")
                bval = true;
            else if (params == "false")
                bval = false;
            else if (params == "changed")
                changed = true;
            else
            {
                cWarningDom("rule.condition.output") <<  "get_value(bool) not bool !";
                ret = false;
                break;
            }
        }

        if (!changed)
        {
            ret = eval(output->get_value_bool(), ops, bval);
        }
        else
        {
            ret = true;
        }
        break;
    case TINT:
        if (params_var != "")
        {
            IOBase *out = ListeRoom::Instance().get_io(params_var);
            if (out && out->get_type() == TINT)
            {
                dval = out->get_value_double();
                sval = "ovar";
                ovar = true;
            }
        }

        if (!ovar)
            sval = params;

        if (sval != "")
        {
            if (!ovar)
            {
                if (sval == "changed")
                    changed = true;
                else
                    from_string(sval, dval);
            }

            if (!changed)
            {
                ret = eval(output->get_value_double(), ops, dval);
            }
            else
            {
                ret = true;
            }
        }
        else
            cWarningDom("rule.condition.output") <<  "get_value(int) not int !";
        break;
    case TSTRING:
        if (params_var != "")
        {
            IOBase *out = ListeRoom::Instance().get_io(params_var);
            if (out && out->get_type() == TSTRING)
            {
                sval = out->get_value_string();
                ovar = true;
            }
        }
        if (!ovar)
        {
            sval = url_decode2(params);
            if (sval == "changed")
                changed = true;
        }

        if (!changed)
        {
            ret = eval(output, ops, sval);
        }
        else
        {
            ret = true;
        }
        break;
    default: break;
    }

    if (ret)
        cDebugDom("rule.condition.output") <<  "Ok";
    else
        cDebugDom("rule.condition.output") <<  "Failed !";

    return ret;
}
Beispiel #15
0
int main(int argc, char **args)
{
  bool verbose = false;
  char *device = NULL;
  int ch, ll_driver = DRIVER_PARPORT;
  IOBase *io;
  IOParport io_pp;
  IOFtdi io_ftdi;

  // Produce release info from CVS tags
  char release[]={"$Name: Release-0-5 $"};
  char *loc0=strchr(release,'-');
  if(loc0>0){
    loc0++;
    char *loc=loc0;
    do{
      loc=strchr(loc,'-');
      if(loc)*loc='.';
    }while(loc);
    release[strlen(release)-1]='\0'; // Strip off $
  }
  printf("Release %s\n",loc0);

  // Start from parsing command line arguments
  while ((ch = getopt(argc, args, "c:d:v")) != -1)
    switch ((char)ch)
    {
      case 'c':
        if (strcmp(optarg, "pp") == 0)
          ll_driver = DRIVER_PARPORT;
        else if (strcmp(optarg, "ftdi") == 0)
          ll_driver = DRIVER_FTDI;
        else
          usage();
        break;
      case 'd':
        device = strdup(optarg);
        break;
      case 'v':
        verbose = true;
        break;
      default:
        usage();
    }
  
  if ((device == NULL) && (ll_driver == DRIVER_PARPORT))
    if(getenv("XCPORT"))
      device = strdup(getenv("XCPORT"));
    else
      device = strdup(PPDEV);

  switch (ll_driver)
  {
    case DRIVER_PARPORT:
      io = &io_pp;
      break;
    case DRIVER_FTDI:
      io = &io_ftdi;
      break;
    default:
      usage();
  }
  
  io->setVerbose(verbose);

  printf("argc: %d\n", argc);

  // Get rid of options
  argc -=  optind;
  args +=  optind;

  printf("argc: %d\n", argc);
  
  if(argc<1) usage();

  io->dev_open(device);
  
  if(io->checkError()){
    if (ll_driver == DRIVER_FTDI)
      fprintf(stderr, "Could not access USB device (%s).\n", 
              (device == NULL) ? "*" : device);
    else
    {
      fprintf(stderr,"Could not access parallel device '%s'.\n", device);
      fprintf(stderr,"You may need to set permissions of '%s' \n", device);
      fprintf(stderr,
              "by issuing the following command as root:\n\n# chmod 666 %s\n\n",
              device);
    }
    return 1;
  }

  free(device);
  
  
  int chainpos=0;

  if(argc>1)chainpos=atoi(args[1]);
  if(verbose)
    printf("JTAG chainpos: %d\n", chainpos);

  int length;
  BitFile file;
  if((length = file.load(args[0])))
  {
    if (verbose)
    {
      printf("Created from NCD file: %s\n",file.getNCDFilename());
      printf("Target device: %s\n",file.getPartName());
      printf("Created: %s %s\n",file.getDate(),file.getTime());
      printf("Bitstream length: %d bits\n",length);
    }      
    process(*io, file, chainpos, verbose);
  }
  else
    return 1;
  return 0;
}