<commit_before>var _ = require('underscore');
var log = require('../../log')(module);

// --- GlobalSat GPS ------------------------------------------------------------
var parser = {};
module.exports = parser;

labels = {
    NO_VALUE: '<no value>',
    NO_PARAM: 'unknown'
};

/**
 * Are passed data in supported format and can be parsed ?
 *
 * @param data
 * @returns {boolean}   true if data format recognized and can be parsed,
 *                      false otherwise.
 */
parser.canParse = function(buffer)
{
    log.debug('globalsat.canParse():');
    var strData;
    try {
        //  TODO:   wrap as ensureString() method.
        if (_.isString(buffer)) {
            strData = buffer;
        } else {
            //  trying convert data
            if (buffer instanceof Buffer) {
                strData = buffer.toString('ascii'); // convert binary data to string so it can be processed.
            } else {
                throw new Exception("can't convert binary data to String.");
            }
        }

        //  The general format of GlobalSat TR-600 message is:    GSx,IMEI,[T,S,]Field1,Field2,……,FieldN*Checksum!
        //  NOTE:   Checksum - is the hexadecimal value, converted to two ASCII characters (0-9, A-F)
        var pattern = /GS[SsGgCrhe]{1},\d{15},.+\*[0-9A-F]{2}!/; //  use RegExp for data format verification
        var passed = pattern.test(strData);
        log.debug('passed RegExp ? ' + passed);
        return passed;

    } catch(ex) {
        log.error('Data packet analysis failed: ' + ex);
    }
    return false;
}

//parser.parse = function (data)
parser.parse = function(socket, data)
{
    if (!_.isString(data)) {
        var strData;
        //  trying convert data
        if (data instanceof Buffer) {
            strData = data.toString('utf8'); // convert binary data to string so it can be processed.
        }
        data = strData;
    }

    //  for 'GlobalSat' only
    var arrParsedMaps = [];<commit_msg>fixed RexExp for GlobalSat packets (a-f range added for checksum verification)<commit_after>var _ = require('underscore');
var log = require('../../log')(module);

// --- GlobalSat GPS ------------------------------------------------------------
var parser = {};
module.exports = parser;

labels = {
    NO_VALUE: '<no value>',
    NO_PARAM: 'unknown'
};

/**
 * Are passed data in supported format and can be parsed ?
 *
 * @param data
 * @returns {boolean}   true if data format recognized and can be parsed,
 *                      false otherwise.
 */
parser.canParse = function(buffer)
{
    log.debug('globalsat.canParse():');
    var strData;
    try {
        //  TODO:   wrap as ensureString() method.
        if (_.isString(buffer)) {
            strData = buffer;
        } else {
            //  trying convert data
            if (buffer instanceof Buffer) {
                strData = buffer.toString('ascii'); // convert binary data to string so it can be processed.
            } else {
                throw new Exception("can't convert binary data to String.");
            }
        }

        //  The general format of GlobalSat TR-600 message is:    GSx,IMEI,[T,S,]Field1,Field2,……,FieldN*Checksum!
        //  NOTE:   Checksum - is the hexadecimal value, converted to two ASCII characters (0-9, A-F)
        var pattern = /GS[SsGgCrhe]{1},\d{15},.+\*[0-9A-Fa-f]{2}!/; //  use RegExp for data format verification
        var passed = pattern.test(strData);
        log.debug('passed RegExp ? ' + passed);
        return passed;

    } catch(ex) {
        log.error('Data packet analysis failed: ' + ex);
    }
    return false;
}

//parser.parse = function (data)
parser.parse = function(socket, data)
{
    if (!_.isString(data)) {
        var strData;
        //  trying convert data
        if (data instanceof Buffer) {
            strData = data.toString('utf8'); // convert binary data to string so it can be processed.
        }
        data = strData;
    }

    //  for 'GlobalSat' only
    var arrParsedMaps = [];
{'fraction_non_alphanumeric': 0.156794425087108, 'fraction_numerical': 0.006968641114982578, 'mean_word_length': 1.906001446131598, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '807539', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1144, 'n_words': 348}