public int getSiteDeviceNo(ref sconnSite site) { SconnClient client = new SconnClient(site.serverIP, site.serverPort, "testpass", true); int sites = 0; byte[] cmd = new byte[ipcDefines.NET_CMD_PACKET_LEN]; cmd[0] = ipcCMD.GET; cmd[1] = ipcCMD.getDevNo; byte[] resp = client.berkeleySendMsg(cmd); //ethernet.berkeleySendMsg(site.serverIP, cmd, site.serverPort); if (resp[0] == ipcCMD.SVAL) { sites = (int)resp[1]; // second byte is data, <SVAL> <DATA> <EVAL> } client.CloseConnection(); return(sites); }
public bool ReadSiteRunningConfig(sconnSite site) { site.siteStat.StartConnectionTimer(); bool globalUploadStat = false; bool deviceUploadStat = false; int devices = 0; byte[] cmd = new byte[32]; SconnClient client = new SconnClient(site.serverIP, site.serverPort, "testpass", true); if (site.siteCfg != null) { devices = site.siteCfg.deviceNo; } else { devices = getSiteDeviceNo(ref site); site.siteCfg = new ipcSiteConfig(devices); //init device configs } /********** Read global config ***********/ short siteMemAddr = (short)(ipcDefines.mAdrGlobalConfig); byte[] rxBF = new byte[ipcDefines.ipcGlobalConfigSize + 2]; cmd[0] = ipcCMD.GET; cmd[1] = ipcCMD.getRunGlobCfg; rxBF = client.berkeleySendMsg(cmd); // ethernet.berkeleySendMsg(site.serverIP, cmd, site.serverPort); if (rxBF[0] == ipcCMD.SVAL) { for (int j = 0; j < ipcDefines.ipcGlobalConfigSize; j++) { site.siteCfg.globalConfig.memCFG[j] = rxBF[j + 1]; } globalUploadStat = true; } /********** Get device configs **********/ cmd = new byte[32]; rxBF = new byte[ipcDefines.deviceConfigSize + 2]; byte[] NamesBF = new byte[ipcDefines.RAM_DEVICE_NAMES_SIZE]; byte[] SchedBF = new byte[ipcDefines.RAM_DEV_SCHED_SIZE]; siteMemAddr = (short)(ipcDefines.mAdrDevStart); int MsgByteOffset = 1; try { for (int i = 0; i < devices; i++) { /******* Get Device Config ****/ cmd[0] = ipcCMD.GET; cmd[1] = ipcCMD.getRunDevCfg; cmd[2] = (byte)i; //device number rxBF = client.berkeleySendMsg(cmd); /******* Get Device Names ****/ cmd[1] = ipcCMD.getNamesDevCfg; NamesBF = client.berkeleySendMsg(cmd); /***** Get Device Schedules ******/ cmd[1] = ipcCMD.getSchedulesDevCfg; SchedBF = client.berkeleySendMsg(cmd); if (rxBF[0] == ipcCMD.SVAL) { //read device config for (int j = 0; j < ipcDefines.deviceConfigSize; j++) { site.siteCfg.deviceConfigs[i].memCFG[j] = rxBF[j + MsgByteOffset]; } //read names config if (NamesBF[0] == ipcCMD.SVAL) { for (int name = 0; name < ipcDefines.RAM_DEV_NAMES_NO; name++) { for (int txtbyte = 0; txtbyte < ipcDefines.RAM_NAME_SIZE; txtbyte++) { if (NamesBF[(name * ipcDefines.RAM_NAME_SIZE) + txtbyte] == (byte)32) //decode space sign { NamesBF[(name * ipcDefines.RAM_NAME_SIZE) + txtbyte] = 0; } site.siteCfg.deviceConfigs[i].NamesCFG[name][txtbyte] = NamesBF[(name * ipcDefines.RAM_NAME_SIZE) + txtbyte + MsgByteOffset]; //1 byte buffer offset } } } //read schedule config if (SchedBF[0] == ipcCMD.SVAL) { for (int schedule = 0; schedule < ipcDefines.RAM_DEV_SCHED_NO; schedule++) { for (int schedbyte = 0; schedbyte < ipcDefines.RAM_DEV_SCHED_MEM_SIZE; schedbyte++) { site.siteCfg.deviceConfigs[i].ScheduleCFG[schedule][schedbyte] = NamesBF[(schedule * ipcDefines.RAM_DEV_SCHED_MEM_SIZE) + schedbyte + MsgByteOffset]; //1 byte buffer offset } } } } else { deviceUploadStat = false; } } //get events cmd[0] = ipcCMD.GET; cmd[1] = ipcCMD.getEventNo; rxBF = client.berkeleySendMsg(cmd); cmd[1] = ipcCMD.getEvent; cmd[2] = (byte)1; //test event id 1 rxBF = client.berkeleySendMsg(cmd); site.siteStat.StopConnectionTimer(); } catch (Exception) { site.siteStat.StopConnectionTimer(); site.siteStat.FailedConnections++; client.CloseConnection(); return((bool)(deviceUploadStat & globalUploadStat)); throw; } client.CloseConnection(); return((bool)(deviceUploadStat & globalUploadStat)); }