static inline void get_timestamp_setting() { const char *target = empty_timestamp_str(getenv(AM_TIMESTAMP_ENV_VAR)); if (is_str_equal(target, "Yes") || is_str_equal(target, "True") || is_str_equal(target, "1") || is_str_equal(target, "On")) { logTimeStamp = true; } else { logTimeStamp = false; } }
int main(int argc, char *argv[]) { if (argc != 2) { ERROR("Usage: %s module[vin | vout | vdevice | stream | photo]", argv[0]); exit (0); } else { AmConfig *config = new AmConfig(); if (is_str_equal(argv[1], "vin")) { if (config->load_vdev_config()) { config->print_vin_config(); } } else if (is_str_equal(argv[1], "vout")) { if (config->load_vdev_config()) { config->print_vout_config(); } } else if (is_str_equal(argv[1], "vdevice")) { if (config->load_vdev_config()) { VDeviceParameters *vdev = config->vdevice_config(); if (vdev) { config->print_vdev_config(); } delete config; config = NULL; } } else if (is_str_equal(argv[1], "stream")) { if (config->load_vdev_config() && config->load_record_config()) { RecordParameters *record = config->record_config(); if (record) { config->print_record_config(); } delete config; config = NULL; } } else if (is_str_equal(argv[1], "photo")) { if (config->load_photo_config()) { PhotoParameters *photo = config->photo_config(); if (photo) { config->print_photo_config(); } } } else { ERROR("Unknown module type %s", argv[1]); } delete config; DEBUG("Exit!"); } return 0; }
static inline void get_log_level() { logLevel = AM_LOG_LEVEL_WARN; const char *levelstr = empty_level_str(getenv(AM_LEVEL_ENV_VAR)); int level = atoi(levelstr); switch(level) { case 1: case 2: case 3: case 4: case 5: case 6: logLevel = (AmLogLevel)level; break; case 0: { if (is_str_equal(levelstr, "print") || is_str_equal(levelstr, "0")) { logLevel = AM_LOG_LEVEL_PRINT; } else if (is_str_equal(levelstr, "error")) { logLevel = AM_LOG_LEVEL_ERROR; } else if (is_str_equal(levelstr, "warn")) { logLevel = AM_LOG_LEVEL_WARN; } else if (is_str_equal(levelstr, "stat")) { logLevel = AM_LOG_LEVEL_STAT; } else if (is_str_equal(levelstr, "notice")) { logLevel = AM_LOG_LEVEL_NOTICE; } else if (is_str_equal(levelstr, "info")) { logLevel = AM_LOG_LEVEL_INFO; } else if (is_str_equal(levelstr, "debug")) { logLevel = AM_LOG_LEVEL_DEBUG; } }break; default: break; } }
static inline void get_log_target() { logTarget = AM_LOG_TARGET_NULL; const char *target = empty_target_str(getenv(AM_TARGET_ENV_VAR)); if (is_str_equal(target, "stderr")) { logTarget = AM_LOG_TARGET_STDERR; } else if (is_str_equal(target, "syslog")) { logTarget = AM_LOG_TARGET_SYSLOG; } else if (is_str_start_with(target, "file:")) { int fd = -1; char logname[512] = {0}; time_t current = time(NULL); struct tm* tmstruct = gmtime(¤t); const char *filename = strstr(target, ":"); const char* ext = strrchr(&filename[1], '.'); if (ext) { snprintf(logname, (ext - &filename[1]) + 1, "%s", &filename[1]); sprintf(logname + strlen(logname), "-%04d%02d%02d%02d%02d%02d", tmstruct->tm_year + 1900, tmstruct->tm_mon + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); sprintf(logname + strlen(logname), "%s", ext); } else { sprintf(logname, "%s-%04d%02d%02d%02d%02d%02d.log", &filename[1], tmstruct->tm_year + 1900, tmstruct->tm_mon + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); } if ((fd = open(logname, O_WRONLY|O_TRUNC|O_CREAT, S_IRUSR|S_IWUSR)) >= 0) { logfile.set_log_fd(fd); logTarget = AM_LOG_TARGET_FILE; } else { fprintf(stderr, "Failed to open file %s: %s(Reset log target to stderr)", &filename[1], strerror(errno)); logTarget = AM_LOG_TARGET_STDERR; } } else if (is_str_equal(target, "null")) { logTarget = AM_LOG_TARGET_NULL; } }
bool NetDeviceInfo::check_mac(const char *mac) { if (mac) { for (NetDeviceInfo *devInfo = this; devInfo; devInfo = devInfo->next()) { if (AM_LIKELY(is_str_equal(devInfo->get_netdev_mac (), mac))) { return true; } } } return false; }
LcdPanelType AmConfigVout::str_to_lcd_type(const char *name) { LcdPanelType type = AM_LCD_PANEL_NONE; if (AM_LIKELY(name)) { for (uint32_t i = 0; i < sizeof(GlcdTypeList)/sizeof(CameraLcdType); ++ i) { if (is_str_equal(name, GlcdTypeList[i].lcdName)) { type = GlcdTypeList[i].lcdType; break; } } } return type; }
amba_video_mode AmConfigBase::str_to_video_mode(const char* mode) { amba_video_mode videoMode = AMBA_VIDEO_MODE_AUTO; if (mode) { for (uint32_t i = 0; i < (sizeof(gVideoModeList) / sizeof(CamVideoMode)); ++ i) { if (is_str_equal(mode, gVideoModeList[i].videoMode)) { videoMode = gVideoModeList[i].ambaMode; break; } } } return videoMode; }
/* * Main search algorithm function * Search algorithm taken from CLRS book */ void rabin_karp_search(char pat[], char txt[], int q) { int n = strlen(txt); int m = strlen(pat); int p = 0; /* hash value for pattern */ int t = 0; /* hash value for text */ int h = 1; int i,s; /* Precompute constant h = d^(m-1)(mod q) * do not use ^ for power as without modulo, * number can get really large. Use loop * h is going to be used multiple times, so precompute it. */ for (i = 0; i < m-1; i++) h = (h*d) % q; /* * Preprocessing: * Calculate hash(p) of complete search pattern(pat[0...m-1]) * Calculate hash(t) of substring text[0...m-1] */ for (i = 0; i < m; i++) { p = (d*p + pat[i]) % q; t = (d*t + txt[i]) % q; } /* Matching */ for (s = 0; s < n-m; s++) { if ((p == t) && (is_str_equal(pat, txt, s, m))) printf("String found at location: %d\n", s+1); if (s < n-m) { t = (d*(t-txt[s]*h) + txt[s+m]) % q; /* Take care of -ve mod values (add q) */ if (t < 0) t += q; } } }
static void log_check_env(void) { _log_level = LOG_LEVEL_DEFAULT; const char *levelstr = level_str(getenv(LOG_LEVEL_ENV)); const char *outputstr = output_str(getenv(LOG_OUTPUT_ENV)); const char *timestr = time_str(getenv(LOG_TIMESTAMP_ENV)); int level = atoi(levelstr); int output = atoi(outputstr); int timestamp = atoi(timestr); switch (level) { case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: _log_level = level; break; case 0: if (is_str_equal(levelstr, "error")) { _log_level = LOG_ERR; } else if (is_str_equal(levelstr, "warn")) { _log_level = LOG_WARNING; } else if (is_str_equal(levelstr, "notice")) { _log_level = LOG_NOTICE; } else if (is_str_equal(levelstr, "info")) { _log_level = LOG_INFO; } else if (is_str_equal(levelstr, "debug")) { _log_level = LOG_DEBUG; } else if (is_str_equal(levelstr, "verbose")) { _log_level = LOG_VERB; } break; default: break; } switch (output) { case 1: case 2: case 3: case 4: _log_output = output; break; case 0: if (is_str_equal(outputstr, "stderr")) { _log_output = LOG_STDERR; } else if (is_str_equal(outputstr, "file")) { _log_output = LOG_FILE; } else if (is_str_equal(outputstr, "rsyslog")) { _log_output = LOG_RSYSLOG; } break; default: break; } switch (timestamp) { case 1: UPDATE_LOG_PREFIX(_log_prefix, LOG_TIMESTAMP_BIT); break; case 0: if (is_str_equal(timestr, "y") || is_str_equal(timestr, "yes") || is_str_equal(timestr, "true")) { UPDATE_LOG_PREFIX(_log_prefix, LOG_TIMESTAMP_BIT); } break; default: break; } if (_log_level == LOG_DEBUG) { UPDATE_LOG_PREFIX(_log_prefix, LOG_FUNCLINE_BIT); } if (_log_level == LOG_VERB) { UPDATE_LOG_PREFIX(_log_prefix, LOG_VERBOSE_BIT); } }
int main(int argc, char *argv[]) { if ((argc != 2) || (!is_str_equal("idle", argv[1]) && !is_str_equal("prev", argv[1]) && !is_str_equal("encode", argv[1]) && !is_str_equal("decode", argv[1]) && !is_str_equal("stop", argv[1]) && !is_str_equal("ready", argv[1]) && !is_str_equal("reset", argv[1]))) { ERROR("Usage: test_simplecam operation " "[idle | prev | encode | stop | ready | reset]"); exit (0); } else { AmConfig *config = new AmConfig(); //If you have different config, please set it here config->set_vin_config_path(SIMPLE_CAM_VIN_CONFIG); //config->set_vout_config_path (vout_config_path); //config->set_vdevice_config_path (vdevice_config_path); //config->set_record_config_path (record_config_path); if (config && config->load_vdev_config()) { VDeviceParameters *vdevConfig = config->vdevice_config(); if (vdevConfig) { AmSimpleCam simplecam(vdevConfig); for (uint32_t i = 0; i < vdevConfig->vin_number; ++ i) { simplecam.set_vin_config(config->vin_config(i), i); } for (uint32_t i = 0; i < vdevConfig->vout_number; ++ i) { simplecam.set_vout_config(config->vout_config(i), i); } simplecam.set_encoder_config(config->encoder_config()); for (uint32_t i = 0; i < vdevConfig->stream_number; ++ i) { simplecam.set_stream_config(config->stream_config(i), i); } if (is_str_equal("idle", argv[1]) || is_str_equal("stop", argv[1])) { simplecam.goto_idle() ? INFO("Goto Idle successfully!") : ERROR("Goto Idle failed!"); } else if (is_str_equal("prev", argv[1])) { simplecam.enter_preview() ? INFO("Enter preview successfully!") : ERROR("Enter preview failed!"); } else if (is_str_equal("encode", argv[1])) { simplecam.start_encode() ? INFO("Start encoding successfully!") : ERROR("Start encoding failed!"); } else if (is_str_equal("decode", argv[1])) { simplecam.enter_decode_mode() ? INFO("Enter decoding mode successfully!") : ERROR("Start decoding mode failed!"); } else if (is_str_equal("ready", argv[1])) { simplecam.ready_for_encode() ? INFO("Camera is ready for encoding!") : ERROR("Failed preparing camera for encoding!"); } else if (is_str_equal("reset", argv[1])) { simplecam.reset_device() ? INFO("Reset camera successfully!") : ERROR("Reset camera failed!"); } else { ERROR("Unrecognized parameter: %s", argv[1]); } } else { ERROR("Faild to get VideoDevice's configurations!"); } delete config; } else { ERROR("Failed to load configurations!"); } } return 0; }