uint_t ADVBPatterns::ParsePatterns(ADataList& patternlist, const AString& patterns, AString& errors, const AString& sep, const AString& user) { uint_t i, n = patterns.CountLines(sep); for (i = 0; i < n; i++) { ParsePattern(patternlist, patterns.Line(i, sep), errors, user); } return patternlist.Count(); }
/*--------------------------------------------------------------------------------*/ AString PostgresDatabase::GetErrorMessage(PGconn *conn, bool full) { AString msg; if (conn) { msg = AString(PQerrorMessage(conn)).SearchAndReplace("\r", "").SearchAndReplace("\n\n", ", "); if (msg.EndsWith(", ")) msg = msg.Left(msg.len() - 2); if (!full) msg = msg.Line(0); } else msg = "No connection!"; return msg; }
void ADVBConfig::vlogit(const char *fmt, va_list ap, bool show) const { ADateTime dt; AString filename = GetLogFile(dt.GetDays()); AString str; AStdFile fp; str.vprintf(fmt, ap); if (fp.open(filename, "a")) { uint_t i, n = str.CountLines("\n", 0); for (i = 0; i < n; i++) { fp.printf("%s [%05u]: %s\n", dt.DateFormat("%Y-%M-%D %h:%m:%s.%S").str(), (uint_t)getpid(), str.Line(i, "\n", 0).str()); } fp.close(); } if (show && !webresponse) { Stdout->printf("%s\n", str.str()); } }
void MotionDetector::Configure() { AString nstr = AString("%").Arg(index); log.printf("%s[%u]: Reading new settings...\n", ADateTime().DateFormat("%Y-%M-%D %h:%m:%s.%S").str(), index); stream.Close(); stream.SetUsernameAndPassword(GetSetting("username", "admin"), GetSetting("password", "arsebark")); AString camera = GetSetting("camera", ""); log.printf("%s[%u]: Connecting to %s...\n", ADateTime().DateFormat("%Y-%M-%D %h:%m:%s.%S").str(), index, camera.str()); if (!stream.OpenHost(camera)) { log.printf("%s[%u]: Failed to connect to %s...\n", ADateTime().DateFormat("%Y-%M-%D %h:%m:%s.%S").str(), index, camera.str()); } imagedir = GetSetting("imagedir", "/media/cctv"); imagefmt = GetSetting("filename", "%Y-%M-%D/%h/Image-{camera}-%Y-%M-%D-%h-%m-%s-%S"); detimgdir = GetSetting("detimagedir"); detimgfmt = GetSetting("detfilename", "%Y-%M-%D/%h/detection/Image-{camera}-%Y-%M-%D-%h-%m-%s-%S"); detcmd = GetSetting("detcommand", ""); nodetcmd = GetSetting("nodetcommand", ""); coeff = (double)GetSetting("coeff", "1.0e-3"); avgfactor = (double)GetSetting("avgfactor", "1.0"); sdfactor = (double)GetSetting("sdfactor", "2.0"); redscale = (double)GetSetting("rscale", "1.0"); grnscale = (double)GetSetting("gscale", "1.0"); bluscale = (double)GetSetting("bscale", "1.0"); threshold = (double)GetSetting("threshold", "3000.0"); verbose = (uint_t)GetSetting("verbose", "0"); matmul = 1.f; matwid = mathgt = 0; AString _matrix = GetSetting("matrix", ""); if (_matrix.Valid()) { uint_t row, nrows = _matrix.CountLines(";"); uint_t col, ncols = 1; int p; if ((p = _matrix.Pos("*")) >= 0) { AString mul = _matrix.Mid(p + 1); _matrix = _matrix.Left(p); if ((p = mul.Pos("/")) >= 0) { matmul = (float)mul.Left(p) / (float)mul.Mid(p + 1); } else matmul = (float)mul; } else if ((p = _matrix.Pos("/")) >= 0) { AString mul = _matrix.Mid(p + 1); _matrix = _matrix.Left(p); matmul = 1.f / (float)mul; } for (row = 0; row < nrows; row++) { uint_t n = _matrix.Line(row, ";").CountLines(","); ncols = MAX(ncols, n); } nrows |= 1; ncols |= 1; matrix.resize(nrows * ncols); for (row = 0; row < nrows; row++) { AString line = _matrix.Line(row,";"); for (col = 0; col < ncols; col++) matrix[col + row * ncols] = (float)line.Line(col, ","); } matwid = ncols; mathgt = nrows; #if 0 printf("Matrix is %u x %u:\n", matwid, mathgt); for (row = 0; row < nrows; row++) { for (col = 0; col < ncols; col++) printf("%8.3f", matrix[col + row * ncols]); printf("\n"); } printf("Multiplier %0.6f\n", matmul); #endif } else matrix.resize(0); }