<commit_before>var express = require('express');
var router = express.Router();
var xmlParser = require('express-xml-bodyparser');
var fs = require('fs');
var inspect = require('util').inspect;

var xml2js = require('xml2js');
var parser = new xml2js.Parser();

var mavlink = require('mavlink');

var myMAV = new mavlink(1,1);


//model
var RockblockPacket = require('../models/rockblock_packet');

var decodedData;
var newRockblockPacket_frame;
/* POST */
myMAV.on("ready", function() {
  //parse incoming serial data
  console.log("ready");
});
myMAV.on("message", function(message) {
   //console.log(message);
});

myMAV.on("SYS_STATUS", function(message, fields) {
    console.log(fields);
    newRockblockPacket_frame = {  
      decodeData: message,
      decodePayload: fields
    };
    
    var newRockblockPacket = RockblockPacket(newRockblockPacket_frame);

    newRockblockPacket.save(function(err){
      if(err) throw err;
    });
});

myMAV.on("GPS_RAW_INT", function(message, fields) {
    console.log(fields);
    newRockblockPacket_frame = {  
      decodeData: message,
      decodePayload: fields
    };
    
    var newRockblockPacket = RockblockPacket(newRockblockPacket_frame);

    newRockblockPacket.save(function(err){
      if(err) throw err;
    });
});

function gps_raw_int_generator(longitude,latitude,altitude)
{
    myMAV.createMessage('GPS_RAW_INT', 
  {
    'fix_type' : 4,
    'lat' : latitude,
    'lon' : longitude,
    'alt': altitude,
    'time_usec': 0,
    'eph': 0,
    'epv': 0,
    'vel': 0,
    'hdg': 0,
    'cog': 0,
    'satellites_visible': []
  },
  function(msg) {
   console.log(msg.buffer);
 });
}

function sys_status_generator(volt,amp,bat)
{
    myMAV.createMessage('SYS_STATUS', 
  {
    'mode' : 0,
    'load': 1,
    'voltage_battery' : volt,
    'current_battery' : amp,
    'battery_remaining': bat,
    'onboard_control_sensors_present': 1,
    'onboard_control_sensors_enabled': 1,
    'onboard_control_sensors_health': 1,
    'drop_rate_comm': 0,
    'errors_comm': 0,
    'errors_count1': 0,
    'errors_count2': 0,
    'errors_count3': 0,
    'errors_count4': 0
  },
  function(msg) {
   console.log(msg.buffer);
 });
}

router.post('/'+ process.env.GATEWAY_KEY, xmlParser({trim: false, explicitArray: false}), function(req, res) {
  //console.log(req.body.packet);
  var transit_time = req.body.packet.transit_time;
  var year='20'.concat(transit_time[0],transit_time[1]);
  var month=transit_time[3].concat(transit_time[4]);
  var day=transit_time[6].concat(transit_time[7]);
  var hour=transit_time[8].concat(transit_time[9]);
  var minute=transit_time[11].concat(transit_time[12]);
  var second=transit_time[14].concat(transit_time[15]);
  var dt = new Date(year,month-1,day,hour,minute,second);
    //listen for messages
  
  newRockblockPacket_frame = {  
    imei: parseFloat(req.body.packet.imei),
    momsn: parseFloat(req.body.packet.momsn),
    transit_time: dt, //transit_time,
    iridium_latitude: parseFloat(req.body.packet.iridium_latitude),
    iridium_longitude: parseFloat(req.body.packet.iridium_longitude),
    iridium_cep: parseFloat(req.body.packet.iridium_cep),
    data: req.body.packet.data
  }
  
  myMAV.parse(new Buffer(req.body.packet.data,'hex'));
  
  res.status(200).send('OK');
});

/* GET */
router.get('/data/'+ process.env.GATEWAY_KEY, function(req, res, next) {
  var final="";
  RockblockPacket.find({}, function(err, docs) {
    if (!err){
        docs.forEach(function(item,index){
          final=final.concat(String(item.data),"\n");
        });
        final=final.concat("")
        res.send(final);
    } else {throw err;}
  });

});

router.get('/generator/gps_raw_int/'+ process.env.GATEWAY_KEY, function(req, res, next) {
  var a = gps_raw_int_generator(10,10,100);
  res.send(a);
});

router.get('/generator/sys_status/'+ process.env.GATEWAY_KEY, function(req, res, next) {
  var a = sys_status_generator(9000,200,100);
  res.send(a);
});

router.get('/'+ process.env.GATEWAY_KEY, function(req, res, next) {
  RockblockPacket.find({}, function(err, docs) {
    if (!err){
        res.send(docs);
    } else {throw err;}
  });

});

module.exports = router;<commit_msg>add the generator of raw_pressure mavlink msg<commit_after>var express = require('express');
var router = express.Router();
var xmlParser = require('express-xml-bodyparser');
var fs = require('fs');
var inspect = require('util').inspect;

var xml2js = require('xml2js');
var parser = new xml2js.Parser();

var mavlink = require('mavlink');

var myMAV = new mavlink(1,1);


//model
var RockblockPacket = require('../models/rockblock_packet');

var decodedData;
var newRockblockPacket_frame;
/* POST */
myMAV.on("ready", function() {
  //parse incoming serial data
  console.log("ready");
});
myMAV.on("message", function(message) {
   //console.log(message);
});

myMAV.on("RAW_PRESSURE", function(message, fields) {
    console.log(fields);
    newRockblockPacket_frame = {  
      decodeData: message,
      decodePayload: fields
    };
    
    var newRockblockPacket = RockblockPacket(newRockblockPacket_frame);

    newRockblockPacket.save(function(err){
      if(err) throw err;
    });
});

myMAV.on("SYS_STATUS", function(message, fields) {
    console.log(fields);
    newRockblockPacket_frame = {  
      decodeData: message,
      decodePayload: fields
    };
    
    var newRockblockPacket = RockblockPacket(newRockblockPacket_frame);

    newRockblockPacket.save(function(err){
      if(err) throw err;
    });
});

myMAV.on("GPS_RAW_INT", function(message, fields) {
    console.log(fields);
    newRockblockPacket_frame = {  
      decodeData: message,
      decodePayload: fields
    };
    
    var newRockblockPacket = RockblockPacket(newRockblockPacket_frame);

    newRockblockPacket.save(function(err){
      if(err) throw err;
    });
});

function gps_raw_int_generator(longitude,latitude,altitude)
{
    myMAV.createMessage('GPS_RAW_INT', 
  {
    'fix_type' : 4,
    'lat' : latitude,
    'lon' : longitude,
    'alt': altitude,
    'time_usec': 0,
    'eph': 0,
    'epv': 0,
    'vel': 0,
    'hdg': 0,
    'cog': 0,
    'satellites_visible': []
  },
  function(msg) {
   console.log(msg.buffer);
 });
}

function sys_status_generator(volt,amp,bat)
{
    myMAV.createMessage('SYS_STATUS', 
  {
    'mode' : 0,
    'load': 1,
    'voltage_battery' : volt,
    'current_battery' : amp,
    'battery_remaining': bat,
    'onboard_control_sensors_present': 1,
    'onboard_control_sensors_enabled': 1,
    'onboard_control_sensors_health': 1,
    'drop_rate_comm': 0,
    'errors_comm': 0,
    'errors_count1': 0,
    'errors_count2': 0,
    'errors_count3': 0,
    'errors_count4': 0
  },
  function(msg) {
   console.log(msg.buffer);
 });
}

function raw_pressure_generator(press_abs,temperature)
{
    myMAV.createMessage('RAW_PRESSURE', 
  {
    'time_usec' : 0,
    'press_abs': press_abs,
    'press_diff1' : 0,
    'press_diff2' : 0,
    'temperature': temperature
  },
  function(msg) {
   console.log(msg.buffer);
 });
}

router.post('/'+ process.env.GATEWAY_KEY, xmlParser({trim: false, explicitArray: false}), function(req, res) {
  //console.log(req.body.packet);
  var transit_time = req.body.packet.transit_time;
  var year='20'.concat(transit_time[0],transit_time[1]);
  var month=transit_time[3].concat(transit_time[4]);
  var day=transit_time[6].concat(transit_time[7]);
  var hour=transit_time[8].concat(transit_time[9]);
  var minute=transit_time[11].concat(transit_time[12]);
  var second=transit_time[14].concat(transit_time[15]);
  var dt = new Date(year,month-1,day,hour,minute,second);
    //listen for messages
  
  newRockblockPacket_frame = {  
    imei: parseFloat(req.body.packet.imei),
    momsn: parseFloat(req.body.packet.momsn),
    transit_time: dt, //transit_time,
    iridium_latitude: parseFloat(req.body.packet.iridium_latitude),
    iridium_longitude: parseFloat(req.body.packet.iridium_longitude),
    iridium_cep: parseFloat(req.body.packet.iridium_cep),
    data: req.body.packet.data
  }
  
  myMAV.parse(new Buffer(req.body.packet.data,'hex'));
  
  res.status(200).send('OK');
});

/* GET */
router.get('/data/'+ process.env.GATEWAY_KEY, function(req, res, next) {
  var final="";
  RockblockPacket.find({}, function(err, docs) {
    if (!err){
        docs.forEach(function(item,index){
          final=final.concat(String(item.data),"\n");
        });
        final=final.concat("")
        res.send(final);
    } else {throw err;}
  });

});

router.get('/generator/gps_raw_int/'+ process.env.GATEWAY_KEY, function(req, res, next) {
  var a = gps_raw_int_generator(10,10,100);
  res.send(a);
});

router.get('/generator/sys_status/'+ process.env.GATEWAY_KEY, function(req, res, next) {
  var a = sys_status_generator(9000,200,100);
  res.send(a);
});

router.get('/generator/raw_pressure/'+ process.env.GATEWAY_KEY, function(req, res, next) {
  var a = raw_pressure_generator(100,-20);
  res.send(a);
});



router.get('/'+ process.env.GATEWAY_KEY, function(req, res, next) {
  RockblockPacket.find({}, function(err, docs) {
    if (!err){
        res.send(docs);
    } else {throw err;}
  });

});

module.exports = router;
{'fraction_non_alphanumeric': 0.1622916893584577, 'fraction_numerical': 0.015466724757651672, 'mean_word_length': 3.947198275862069, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '2732419', 'n_tokens_mistral': 3449, 'n_tokens_neox': 3301, 'n_words': 531}