Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ienorand/829be91d10aba7829482fcbc3f0dfa7f to your computer and use it in GitHub Desktop.
Save ienorand/829be91d10aba7829482fcbc3f0dfa7f to your computer and use it in GitHub Desktop.
# encoding: ascii-8bit
# Copyright 2018 Fredrik Persson <u.fredrik.persson@gmail.com>
# Martin Erik Werner <martinerikwerner@gmail.com>
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt
require 'cosmos/config/config_parser'
require 'cosmos/interfaces/protocols/protocol'
require 'thread'
module Cosmos
# Make ccsds transfer frames from from stream of ccsds channel access data units ("cadu").
class CcsdsCaduToTransferFramesProtocol < Protocol
CCSDS_SYNC_MARKER_LEN = 4
# @param transfer_frame_size [Integer] Size of transfer frame in bytes
# @param reed_solomon_size [Integer] Size of Reed-Solomon coding field in bytes
# @param allow_empty_data [true/false/nil] See Protocol#initialize
def initialize(
transfer_frame_size,
reed_solomon_size,
allow_empty_data = nil)
super(allow_empty_data)
@reed_solomon_size = Integer(reed_solomon_size)
@cadu_size = CCSDS_SYNC_MARKER_LEN + Integer(transfer_frame_size) + @reed_solomon_size
end
def reset
super()
@data = ''
end
def read_data(data)
@data << data
packet_data = reduce_to_single_transfer_frame()
# Potentially allow blank string to be sent to other protocols if no packet is ready in this one
if Symbol === packet_data
if (data.length <= 0) and packet_data == :STOP
return super(data)
else
return packet_data
end
end
return packet_data
end
def write_data(data)
return data
end
def reduce_to_single_transfer_frame
return :STOP if (@data.length < @cadu_size)
cadu = @data.slice!(0...@cadu_size)
transfer_frame = cadu[CCSDS_SYNC_MARKER_LEN..-(@reed_solomon_size + 1)]
return transfer_frame
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment