Skip to content

Commit

Permalink
iridium-extractor: add generate-sigmf-meta feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Sec42 committed Nov 20, 2024
1 parent 81fa0a1 commit daad087
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions apps/iridium-extractor
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ if __name__ == "__main__":
help='Sample rate of the source or the file in Hz. Must be divisible by 100000.')
parser.add_argument('--raw-capture', dest='raw_capture_filename', action="store",
help='Write a copy of the samples to a SigMF recording.')
parser.add_argument('--generate-sigmf-meta', dest='sigmf_meta_filename', action="store",
help='Create a sigm-meta file based on the input format.')
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true',
help='Enable verbose output.')

Expand Down Expand Up @@ -337,6 +339,39 @@ if __name__ == "__main__":
print("/tmp/signals directory missing!", file=sys.stderr)
exit(1)

if args.sigmf_meta_filename is not None:
import json
import datetime
dt = None
if args.file_info is not None and (g := re.search(r"i-(\d+(\.\d+)?)-", args.file_info)):
try:
dt = datetime.datetime.fromtimestamp(float(g.group(1)), datetime.timezone.utc)
except ValueError:
pass
if dt is None:
dt = datetime.datetime.fromtimestamp(os.path.getctime(filename), datetime.timezone.utc)

data = {
'global': {
'core:datatype': fmt,
'core:description': 'autogenerated for ' + os.path.basename(filename),
'core:recorder': 'iridium-extractor',
"core:num_channels": 1,
'core:sample_rate': sample_rate,
'core:version': '1.0.0'
},
'captures': [
{
'core:datetime': datetime.datetime.utcnow().replace(microsecond=0).isoformat() + 'Z',
'core:frequency': center,
'core:sample_start': 0
}
]
}

with open(args.sigmf_meta_filename, 'w') as outfile:
json.dump(data, outfile, indent=4)

if args.raw_capture_filename is not None:
import json
import datetime
Expand Down

0 comments on commit daad087

Please sign in to comment.