Пример #1
0
uint8_t check_checksum() {
	// Checksum for 'GP'
	uint8_t chksum = 'G' ^ 'P';

	uint8_t i = 0, num_len = 0;
	char num_buf[4];

	while (i < (GPS_CMD_BUF - 2)) {
		if (gps_data[i] != '*') {
			chksum ^= gps_data[i];
		} else {
			break;
		}

		i++;
	}

	if (i == (GPS_CMD_BUF - 2))
		return E_LEN_ERROR;

	stoh(chksum, num_buf, &num_len);

	if (num_len == 2) {
		if (gps_data[i + 1] == '0' && gps_data[i + 2] == num_buf[0])
			return E_OK;
	} else if (num_len == 3) {
		if (gps_data[i + 1] == num_buf[0] && gps_data[i + 2] == num_buf[1])
			return E_OK;
	} else {
		return E_LEN_ERROR;
	}

	return E_CHKSUM_ERROR;
}
Пример #2
0
uint8_t Gallery::begin(Serial_LCD * lcd0, String name) {
    uint8_t a;
    _pscreen = lcd0;
    String text;
    String s[5];
    _name = name;
    
    // check SD-card
    if ( _pscreen->checkSD()==false ) {
        a = _pscreen->initSD();
        if ( _pscreen->checkSD()==false ) return 0;        
    }
    
    // check .GCI and .DAT files
    a = _pscreen->findFile(_name + ".gci");
    if (a==0x15) return 0;
    
    a = _pscreen->findFile(_name + ".dat");
    if (a==0x15) return 0;
    
    a = _pscreen->openTextFileDelimiter(_name+".dat", '\n');
    if (a==0x15) return 0;
    
    while (_pscreen->nextTextFileDelimiter(&text)) {
        // clean and split
        text = text.trim();
        splitString(text, ' ', s, 5);
        
        // store
        image_t _image;
        _gallery.push_back(_image);
        
        _gallery[_gallery.size()-1].msb = stoh(s[2]);
        _gallery[_gallery.size()-1].lsb = stoh(s[1]);
        _gallery[_gallery.size()-1].x = stoh(s[3]);
        _gallery[_gallery.size()-1].y = stoh(s[4]);
    }    
    _index = 0;
    return _gallery.size();
}
Пример #3
0
void gps_write_cmd(uint8_t * cmd_buf, uint8_t len) {
	uint8_t chksum = 0, i, num_len = 0;
	char num_buf[4];

	for (i = 0; i < len; i++)
		chksum ^= cmd_buf[i];

	chIOPut(&GPS_SERIAL, '$');

	sdWrite(&GPS_SERIAL, cmd_buf, len);

	chIOPut(&GPS_SERIAL, '*');

	stoh(chksum, num_buf, &num_len);
	sdWrite(&GPS_SERIAL, num_buf, num_len - 1);

	chIOPut(&GPS_SERIAL, '\r');
	chIOPut(&GPS_SERIAL, '\n');
}