static void hex(const char *s) { unsigned long long i = 0; switch (s[0]) { case 'b': case 'B': i = read_bin(s + 1); break; case 'x': case 'X': i = read_hex(s + 1); break; case '0': if (s[1] == '\0') i = read_dec(s); else if (s[1] == 'x' || s[1] == 'X') i = read_hex(s + 2); else i = read_oct(s + 1); break; default: if (isdigit(*s)) i = read_dec(s); else usage(); break; } print_bin(i); print_chr(i); print_dec(i); print_hex(i); print_oct(i); }
/* We rely on a table held in the firmware - Quick check. */ int ivtv_yuv_filter_check(struct ivtv *itv) { int i, offset_y, offset_uv; for (i=0, offset_y = 16, offset_uv = 4; i<16; i++, offset_y += 24, offset_uv += 12) { if ((read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + offset_y) != i << 16) || (read_dec(IVTV_YUV_VERTICAL_FILTER_OFFSET + offset_uv) != i << 16)) { IVTV_WARN ("YUV filter table not found in firmware.\n"); return -1; } } return 0; }
/* parse_ppm(mmap pointer): * * Parse given mmapped file assuming it is a PPM P6 formatted * image. If expected headers cannot be read, program will * terminate with an error. * * Conforming to: http://netpbm.sourceforge.net/doc/ppm.html * * Returns the index after PPM header. */ unsigned int parse_ppm(char *addr, unsigned int *pix) { unsigned int i = 0; int width, height, scale, depth; /* Specification step 1 */ if (memcmp(addr+i, "P6", 2) != 0) errx(EXIT_FAILURE, EPPM); else i += 2; /* 2 */ i = req_skip_ws(addr, i); /* 3 */ i = read_dec(addr, i, &width); /* 4 */ i = req_skip_ws(addr, i); /* 5 */ i = read_dec(addr, i, &height); /* 6 */ i = req_skip_ws(addr, i); /* 7 */ i = read_dec(addr, i, &scale); if (scale <= 0) errx(EXIT_FAILURE, ESYNTAX); else if (scale < 256) depth = 1; else if (scale < 65536) depth = 2; else errx(EXIT_FAILURE, ESYNTAX); /* 8 */ if (addr[i] != '\n' && addr[i] != '\r' && addr[i] != '\t' && addr[i] != ' ') errx(EXIT_FAILURE, EWHITESPACE); else i++; /* 9 */ *pix = 3 * width * height * depth; return i; }
/* Check firmware running state. The checks fall through allowing multiple failures to be logged. */ int ivtv_firmware_check(struct ivtv *itv, char *where) { int res = 0; /* Check encoder is still running */ if (ivtv_vapi(itv, CX2341X_ENC_PING_FW, 0) < 0) { IVTV_WARN("Encoder has died : %s\n", where); res = -1; } /* Also check audio. Only check if not in use & encoder is okay */ if (!res && !atomic_read(&itv->capturing) && (!atomic_read(&itv->decoding) || (atomic_read(&itv->decoding) < 2 && test_bit(IVTV_F_I_DEC_YUV, &itv->i_flags)))) { if (ivtv_vapi(itv, CX2341X_ENC_MISC, 1, 12) < 0) { IVTV_WARN("Audio has died (Encoder OK) : %s\n", where); res = -2; } } if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) { /* Second audio check. Skip if audio already failed */ if (res != -2 && read_dec(0x100) != read_dec(0x104)) { /* Wait & try again to be certain. */ ivtv_msleep_timeout(14, 0); if (read_dec(0x100) != read_dec(0x104)) { IVTV_WARN("Audio has died (Decoder) : %s\n", where); res = -1; } } /* Check decoder is still running */ if (ivtv_vapi(itv, CX2341X_DEC_PING_FW, 0) < 0) { IVTV_WARN("Decoder has died : %s\n", where); res = -1; } } /* If something failed & currently idle, try to reload */ if (res && !atomic_read(&itv->capturing) && !atomic_read(&itv->decoding)) { IVTV_INFO("Detected in %s that firmware had failed - " "Reloading\n", where); res = ivtv_firmware_restart(itv); /* * Even if restarted ok, still signal a problem had occurred. * The caller can come through this function again to check * if things are really ok after the restart. */ if (!res) { IVTV_INFO("Firmware restart okay\n"); res = -EAGAIN; } else { IVTV_INFO("Firmware restart failed\n"); } } else if (res) { res = -EIO; } return res; }
bool CatalogDB::AddCatalogContents(const QString& fname) { QDir::setCurrent(QDir::homePath()); // for files with relative path QString filename = fname; // If the filename begins with "~", replace the "~" with the user's home // directory (otherwise, the file will not successfully open) if (filename.at(0) == '~') filename = QDir::homePath() + filename.mid(1, filename.length()); QFile ccFile(filename); if (ccFile.open(QIODevice::ReadOnly)) { QStringList columns; // list of data column descriptors in the header QString catalog_name; char delimiter; QTextStream stream(&ccFile); // TODO(spacetime) : Decide appropriate number of lines to be read QStringList lines; for (int times = 10; times >= 0 && !stream.atEnd(); --times) lines.append(stream.readLine()); /*WAS * = stream.readAll().split('\n', QString::SkipEmptyParts); * Memory Hog! */ if (lines.size() < 1 || !ParseCatalogInfoToDB(lines, columns, catalog_name, delimiter)) { kWarning() << "Issue in catalog file header: " << filename; ccFile.close(); return false; } ccFile.close(); // The entry in the Catalog table is now ready! /* * Now 'Columns' should be a StringList of the Header contents * Hence, we 1) Convert the Columns to a KSParser compatible format * 2) Use KSParser to read stuff and store in DB */ // Part 1) Conversion to KSParser compatible format QList< QPair<QString, KSParser::DataTypes> > sequence = buildParserSequence(columns); // Part 2) Read file and store into DB KSParser catalog_text_parser(filename, '#', sequence, delimiter); QHash<QString, QVariant> row_content; while (catalog_text_parser.HasNextRow()) { row_content = catalog_text_parser.ReadNextRow(); CatalogEntryData catalog_entry; dms read_ra(row_content["RA"].toString(), false); dms read_dec(row_content["Dc"].toString(), true); kDebug()<<row_content["Nm"].toString(); catalog_entry.catalog_name = catalog_name; catalog_entry.ID = row_content["ID"].toInt(); catalog_entry.long_name = row_content["Nm"].toString(); catalog_entry.ra = read_ra.Degrees(); catalog_entry.dec = read_dec.Degrees(); catalog_entry.type = row_content["Tp"].toInt(); catalog_entry.magnitude = row_content["Mg"].toFloat(); catalog_entry.position_angle = row_content["PA"].toFloat(); catalog_entry.major_axis = row_content["Mj"].toFloat(); catalog_entry.minor_axis = row_content["Mn"].toFloat(); catalog_entry.flux = row_content["Flux"].toFloat(); AddEntry(catalog_entry); } } return true; }
static void ivtv_yuv_filter(struct ivtv *itv, int h_filter, int v_filter_1, int v_filter_2) { int filter_index, filter_line; /* If any filter is -1, then don't update it */ if (h_filter > -1) { if (h_filter > 4) h_filter = 4; filter_index = h_filter * 384; filter_line = 0; while (filter_line < 16) { write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x02804); write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x0281c); filter_index += 4; write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x02808); write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x02820); filter_index += 4; write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x0280c); write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x02824); filter_index += 4; write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x02810); write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x02828); filter_index += 4; write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x02814); write_reg(read_dec(IVTV_YUV_HORIZONTAL_FILTER_OFFSET + filter_index), 0x0282c); filter_index += 8; write_reg(0, 0x02818); write_reg(0, 0x02830); filter_line ++; } IVTV_DEBUG_YUV("h_filter -> %d\n",h_filter); } if (v_filter_1 > -1) { if (v_filter_1 > 4) v_filter_1 = 4; filter_index = v_filter_1 * 192; filter_line = 0; while (filter_line < 16) { write_reg(read_dec(IVTV_YUV_VERTICAL_FILTER_OFFSET + filter_index), 0x02900); filter_index += 4; write_reg(read_dec(IVTV_YUV_VERTICAL_FILTER_OFFSET + filter_index), 0x02904); filter_index += 8; write_reg(0, 0x02908); filter_line ++; } IVTV_DEBUG_YUV("v_filter_1 -> %d\n",v_filter_1); } if (v_filter_2 > -1) { if (v_filter_2 > 4) v_filter_2 = 4; filter_index = v_filter_2 * 192; filter_line = 0; while (filter_line < 16) { write_reg(read_dec(IVTV_YUV_VERTICAL_FILTER_OFFSET + filter_index), 0x0290c); filter_index += 4; write_reg(read_dec(IVTV_YUV_VERTICAL_FILTER_OFFSET + filter_index), 0x02910); filter_index += 8; write_reg(0, 0x02914); filter_line ++; } IVTV_DEBUG_YUV("v_filter_2 -> %d\n",v_filter_2); } }
static void ivtv_yuv_filter(struct ivtv *itv, int h_filter, int v_filter_1, int v_filter_2) { u32 i, line; /* If any filter is -1, then don't update it */ if (h_filter > -1) { if (h_filter > 4) h_filter = 4; i = IVTV_YUV_HORIZONTAL_FILTER_OFFSET + (h_filter * 384); for (line = 0; line < 16; line++) { write_reg(read_dec(i), 0x02804); write_reg(read_dec(i), 0x0281c); i += 4; write_reg(read_dec(i), 0x02808); write_reg(read_dec(i), 0x02820); i += 4; write_reg(read_dec(i), 0x0280c); write_reg(read_dec(i), 0x02824); i += 4; write_reg(read_dec(i), 0x02810); write_reg(read_dec(i), 0x02828); i += 4; write_reg(read_dec(i), 0x02814); write_reg(read_dec(i), 0x0282c); i += 8; write_reg(0, 0x02818); write_reg(0, 0x02830); } IVTV_DEBUG_YUV("h_filter -> %d\n", h_filter); } if (v_filter_1 > -1) { if (v_filter_1 > 4) v_filter_1 = 4; i = IVTV_YUV_VERTICAL_FILTER_OFFSET + (v_filter_1 * 192); for (line = 0; line < 16; line++) { write_reg(read_dec(i), 0x02900); i += 4; write_reg(read_dec(i), 0x02904); i += 8; write_reg(0, 0x02908); } IVTV_DEBUG_YUV("v_filter_1 -> %d\n", v_filter_1); } if (v_filter_2 > -1) { if (v_filter_2 > 4) v_filter_2 = 4; i = IVTV_YUV_VERTICAL_FILTER_OFFSET + (v_filter_2 * 192); for (line = 0; line < 16; line++) { write_reg(read_dec(i), 0x0290c); i += 4; write_reg(read_dec(i), 0x02910); i += 8; write_reg(0, 0x02914); } IVTV_DEBUG_YUV("v_filter_2 -> %d\n", v_filter_2); } }
int ivtv_firmware_check(struct ivtv *itv, char *where) { int res = 0; /* */ if (ivtv_vapi(itv, CX2341X_ENC_PING_FW, 0) < 0) { IVTV_WARN("Encoder has died : %s\n", where); res = -1; } /* */ if (!res && !atomic_read(&itv->capturing) && (!atomic_read(&itv->decoding) || (atomic_read(&itv->decoding) < 2 && test_bit(IVTV_F_I_DEC_YUV, &itv->i_flags)))) { if (ivtv_vapi(itv, CX2341X_ENC_MISC, 1, 12) < 0) { IVTV_WARN("Audio has died (Encoder OK) : %s\n", where); res = -2; } } if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) { /* */ if (res != -2 && read_dec(0x100) != read_dec(0x104)) { /* */ ivtv_msleep_timeout(14, 0); if (read_dec(0x100) != read_dec(0x104)) { IVTV_WARN("Audio has died (Decoder) : %s\n", where); res = -1; } } /* */ if (ivtv_vapi(itv, CX2341X_DEC_PING_FW, 0) < 0) { IVTV_WARN("Decoder has died : %s\n", where); res = -1; } } /* */ if (res && !atomic_read(&itv->capturing) && !atomic_read(&itv->decoding)) { IVTV_INFO("Detected in %s that firmware had failed - " "Reloading\n", where); res = ivtv_firmware_restart(itv); /* */ if (!res) { IVTV_INFO("Firmware restart okay\n"); res = -EAGAIN; } else { IVTV_INFO("Firmware restart failed\n"); } } else if (res) { res = -EIO; } return res; }