#!/usr/bin/perl -w
#
# Submit OASIS download info to SSDS
# Typically called from getM1 and getM2.  "devices" must be set up in SSDS first.
# <deviceID> is the "device" for getM1 (1698) or getM2 (1699)
# <parentID is the device for the torroid that is either M1 or M2 (e.g. 1306)
#
# Mike McCann  12 Jan 2009

BEGIN {
	unshift(@INC, '/oasis/bin');
}

use SSDSSubmit;
use strict;

#
# Must have 3 arguments
#
die "\nUsage: \n\t$0 <deviceID> <parentID> <payload>\n\nPut <payload> in double quotes if it contains whitespace.\n\n" unless $#ARGV == 2;

my $deviceId = $ARGV[0];
my $parentId = $ARGV[1];
my $packetType = 1;
my $packetSubType = 1;
my $dataDescriptionId = 1;
my $dataDescriptionVersion = 1;
my $timestampSeconds = time();	 # For test purposes, make the timestamp 'now' on every packet
my $timestampNanoseconds = 123000000;
my $sequenceNumber = 1;
my $bufferBytes = $ARGV[2];
my $bufferLen = length($bufferBytes);
my $bufferTwoBytes = "Second Buffer";
my $bufferTwoLen = length($bufferTwoBytes);

my $bytesSubmitted = SSDSSubmit::submitSsdsRecord($deviceId,$parentId,$packetType,$packetSubType,
	$dataDescriptionId,$dataDescriptionVersion,$timestampSeconds,$timestampNanoseconds,
	$sequenceNumber,$bufferLen,$bufferBytes);

if ($bytesSubmitted >= 0) {
       print "Device $deviceId data record of $bytesSubmitted bytes submitted to SSDS.\n";
}
else {
   print "Data record from device $deviceId not successfully submitted.\n" ;
}
