Example #1
0
void DataFlash_Class::validate_structures(const struct LogStructure *logstructures, const uint8_t num_types)
{
    Debug("Validating structures");
    bool passed = true;

    bool seen_ids[256] = { };
    for (uint16_t i=0; i<num_types; i++) {
        const struct LogStructure *logstructure = &logstructures[i];

#if DEBUG_LOG_STRUCTURES
        Debug("offset=%d ID=%d NAME=%s\n", i, logstructure->msg_type, logstructure->name);
#endif

        // names must be null-terminated
        if (logstructure->name[4] != '\0') {
            Debug("Message name not NULL-terminated");
            passed = false;
        }

        // ensure each message ID is only used once
        if (seen_ids[logstructure->msg_type]) {
            Debug("ID %d used twice (LogStructure offset=%d)", logstructure->msg_type, i);
            passed = false;
        }
        seen_ids[logstructure->msg_type] = true;

        // ensure we have enough labels to cover columns
        uint8_t fieldcount = strlen(logstructure->format);
        uint8_t labelcount = count_commas(logstructure->labels)+1;
        if (fieldcount != labelcount) {
            Debug("fieldcount=%u does not match labelcount=%u",
                  fieldcount, labelcount);
            passed = false;
        }

        // check that the structure is of an appropriate length to take fields
        const int16_t msg_len = Log_Write_calc_msg_len(logstructure->format);
        if (msg_len != logstructure->msg_len) {
            Debug("Calculated message length for (%s) based on format field (%s) does not match structure size (%d != %u)", logstructure->name, logstructure->format, msg_len, logstructure->msg_len);
            passed = false;
        }
    }
    if (!passed) {
        Debug("Log structures are invalid");
        abort();
    }
}
Example #2
0
void
xps_parse_color(xps_document *doc, char *base_uri, char *string,
		fz_colorspace **csp, float *samples)
{
	char *p;
	int i, n;
	char buf[1024];
	char *profile;

	*csp = fz_device_rgb;

	samples[0] = 1;
	samples[1] = 0;
	samples[2] = 0;
	samples[3] = 0;

	if (string[0] == '#')
	{
		if (strlen(string) == 9)
		{
			samples[0] = unhex(string[1]) * 16 + unhex(string[2]);
			samples[1] = unhex(string[3]) * 16 + unhex(string[4]);
			samples[2] = unhex(string[5]) * 16 + unhex(string[6]);
			samples[3] = unhex(string[7]) * 16 + unhex(string[8]);
		}
		else
		{
			samples[0] = 255;
			samples[1] = unhex(string[1]) * 16 + unhex(string[2]);
			samples[2] = unhex(string[3]) * 16 + unhex(string[4]);
			samples[3] = unhex(string[5]) * 16 + unhex(string[6]);
		}

		samples[0] /= 255;
		samples[1] /= 255;
		samples[2] /= 255;
		samples[3] /= 255;
	}

	else if (string[0] == 's' && string[1] == 'c' && string[2] == '#')
	{
		if (count_commas(string) == 2)
			sscanf(string, "sc#%g,%g,%g", samples + 1, samples + 2, samples + 3);
		if (count_commas(string) == 3)
			sscanf(string, "sc#%g,%g,%g,%g", samples, samples + 1, samples + 2, samples + 3);
	}

	else if (strstr(string, "ContextColor ") == string)
	{
		/* Crack the string for profile name and sample values */
		fz_strlcpy(buf, string, sizeof buf);

		profile = strchr(buf, ' ');
		if (!profile)
		{
			fz_warn(doc->ctx, "cannot find icc profile uri in '%s'", string);
			return;
		}

		*profile++ = 0;
		p = strchr(profile, ' ');
		if (!p)
		{
			fz_warn(doc->ctx, "cannot find component values in '%s'", profile);
			return;
		}

		*p++ = 0;
		n = count_commas(p) + 1;
		i = 0;
		while (i < n)
		{
			samples[i++] = fz_atof(p);
			p = strchr(p, ',');
			if (!p)
				break;
			p ++;
			if (*p == ' ')
				p ++;
		}
		while (i < n)
		{
			samples[i++] = 0;
		}

		/* TODO: load ICC profile */
		switch (n)
		{
		case 2: *csp = fz_device_gray; break;
		case 4: *csp = fz_device_rgb; break;
		case 5: *csp = fz_device_cmyk; break;
		default: *csp = fz_device_gray; break;
		}
	}
}
int main(int argc, char **argv) {
    FILE * fr;
    char* fileInput = "test.csv";
    char * line = NULL;
    ssize_t read;
    size_t len = 0;
    int maxLines = -1;
    char* neurons = "100";
    char* netFile = "nets/digit_float_100.net";

    fann_type *calc_out;

    if(argc == 4) {
        fileInput = argv[1];
        maxLines = atoi(argv[2]);
        neurons = argv[3];
        netFile = (char*)malloc(strlen(netFile)+strlen(neurons)-2);
        strcpy(netFile,"nets/digit_float_");
        int i;
        for(i = 17; i < 17 + strlen(neurons); i++)
            netFile[i] = neurons[i - 17];
        netFile[i] = '.';
        netFile[i+1] = 'n';
        netFile[i+2] = 'e';
        netFile[i+3] = 't';
        netFile[i+4] = '\0';
    }

    //printf("File: %s\n",netFile);
    printf("ImageId,label\n");

    fr = fopen(fileInput, "r");
    int count = 0, ni = 0;
    while ((read = getline(&line, &len, fr)) != -1) {
        ni = count_commas(line) + 1;
        break;
    }
    fann_type *input = (fann_type*)malloc(sizeof(fann_type)*ni);
    count = 0;
    rewind(fr);

    struct fann *ann = fann_create_from_file(netFile);

    while ((read = getline(&line, &len, fr)) != -1) {
        if(count > 0) {
            setInput(input, line, ni);
            /*int i;
            for(i = 0;i < ni; i++)
            	printf("%0.0f ", input[i]);
            printf("\n");*/
            calc_out = fann_run(ann, input);
            //int n = sizeof(calc_out) / sizeof(calc_out[0]);
            int output = getMaxOutput(calc_out, 10);
            /*if((count -1) % 10 == 0)
            	printf("\n");
            printf("%d ", output);*/
            printf("%d,%d\n", count,output);
        }
        if(maxLines > 0 && count == maxLines)
            break;
        count++;
    }
    //printf("\n");
    fann_destroy(ann);
    return 0;
}
Example #4
0
bool AP_Logger::validate_structure(const struct LogStructure *logstructure, const int16_t offset)
{
    bool passed = true;

#if DEBUG_LOG_STRUCTURES
    Debug("offset=%d ID=%d NAME=%s", offset, logstructure->msg_type, logstructure->name);
#endif

    // fields must be null-terminated
#define CHECK_ENTRY(fieldname,fieldname_s,fieldlen)                     \
    do {                                                                \
        if (strnlen(logstructure->fieldname, fieldlen) > fieldlen-1) {  \
            Debug("  Message " fieldname_s " not NULL-terminated or too long"); \
            passed = false;                                             \
        }                                                               \
    } while (false)
    CHECK_ENTRY(name, "name", LS_NAME_SIZE);
    CHECK_ENTRY(format, "format", LS_FORMAT_SIZE);
    CHECK_ENTRY(labels, "labels", LS_LABELS_SIZE);
    CHECK_ENTRY(units, "units", LS_UNITS_SIZE);
    CHECK_ENTRY(multipliers, "multipliers", LS_MULTIPLIERS_SIZE);
#undef CHECK_ENTRY

    // ensure each message ID is only used once
    if (seen_ids[logstructure->msg_type]) {
        Debug("  ID %d used twice (LogStructure offset=%d)", logstructure->msg_type, offset);
        passed = false;
    }
    seen_ids[logstructure->msg_type] = true;

    // ensure we have enough labels to cover columns
    uint8_t fieldcount = strlen(logstructure->format);
    uint8_t labelcount = count_commas(logstructure->labels)+1;
    if (fieldcount != labelcount) {
        Debug("  fieldcount=%u does not match labelcount=%u",
              fieldcount, labelcount);
        passed = false;
    }

    // check that the structure is of an appropriate length to take fields
    const int16_t msg_len = Write_calc_msg_len(logstructure->format);
    if (msg_len != logstructure->msg_len) {
        Debug("  Calculated message length for (%s) based on format field (%s) does not match structure size (%d != %u)", logstructure->name, logstructure->format, msg_len, logstructure->msg_len);
        passed = false;
    }

    // ensure we have units for each field:
    if (strlen(logstructure->units) != fieldcount) {
        Debug("  fieldcount=%u does not match unitcount=%u",
              (unsigned)fieldcount, (unsigned)strlen(logstructure->units));
        passed = false;
    }

    // ensure we have multipliers for each field
    if (strlen(logstructure->multipliers) != fieldcount) {
        Debug("  fieldcount=%u does not match multipliercount=%u",
              (unsigned)fieldcount, (unsigned)strlen(logstructure->multipliers));
        passed = false;
    }

    // ensure the FMTU messages reference valid units
    for (uint8_t j=0; j<strlen(logstructure->units); j++) {
        char logunit = logstructure->units[j];
        uint8_t k;
        for (k=0; k<_num_units; k++) {
            if (logunit == _units[k].ID) {
                // found this one
                break;
            }
        }
        if (k == _num_units) {
            Debug("  invalid unit=%c", logunit);
            passed = false;
        }
    }

    // ensure the FMTU messages reference valid multipliers
    for (uint8_t j=0; j<strlen(logstructure->multipliers); j++) {
        char logmultiplier = logstructure->multipliers[j];
        uint8_t k;
        for (k=0; k<_num_multipliers; k++) {
            if (logmultiplier == _multipliers[k].ID) {
                // found this one
                break;
            }
        }
        if (k == _num_multipliers) {
            Debug("  invalid multiplier=%c", logmultiplier);
            passed = false;
        }
    }

    // ensure any float has a multiplier of zero
    if (passed) {
        for (uint8_t j=0; j<strlen(logstructure->multipliers); j++) {
            const char fmt = logstructure->format[j];
            if (fmt != 'f') {
                continue;
            }
            const char logmultiplier = logstructure->multipliers[j];
            if (logmultiplier == '0' ||
                logmultiplier == '?' ||
                logmultiplier == '-') {
                continue;
            }
            Debug("  %s[%u] float with non-zero multiplier=%c",
                  logstructure->name,
                  j,
                  logmultiplier);
            passed = false;
        }
    }

    return passed;
}