Initial commit
commit
b42b30c251
|
@ -0,0 +1,4 @@
|
|||
*.beam
|
||||
*.ez
|
||||
/build
|
||||
erl_crash.dump
|
|
@ -0,0 +1,20 @@
|
|||
# ccsds_space_packet
|
||||
Basic CCSDS Space Packet Parsing in Gleam!
|
||||
|
||||
```sh
|
||||
gleam add ccsds_space_packet@1
|
||||
```
|
||||
```gleam
|
||||
import ccsds_space_packet
|
||||
|
||||
pub fn main() {
|
||||
// TODO: An example of the project in use
|
||||
}
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
```sh
|
||||
gleam run # Run the project
|
||||
gleam test # Run the tests
|
||||
```
|
|
@ -0,0 +1,19 @@
|
|||
name = "ccsds_space_packet"
|
||||
version = "1.0.0"
|
||||
|
||||
# Fill out these fields if you intend to generate HTML documentation or publish
|
||||
# your project to the Hex package manager.
|
||||
#
|
||||
# description = ""
|
||||
# licences = ["Apache-2.0"]
|
||||
# repository = { type = "github", user = "", repo = "" }
|
||||
# links = [{ title = "Website", href = "" }]
|
||||
#
|
||||
# For a full reference of all the available options, you can have a look at
|
||||
# https://gleam.run/writing-gleam/gleam-toml/.
|
||||
|
||||
[dependencies]
|
||||
gleam_stdlib = ">= 0.34.0 and < 2.0.0"
|
||||
|
||||
[dev-dependencies]
|
||||
gleeunit = ">= 1.0.0 and < 2.0.0"
|
|
@ -0,0 +1,11 @@
|
|||
# This file was generated by Gleam
|
||||
# You typically do not need to edit this file
|
||||
|
||||
packages = [
|
||||
{ name = "gleam_stdlib", version = "0.46.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "53940A91251A6BE9AEBB959D46E1CB45B510551D81342A52213850947732D4AB" },
|
||||
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" },
|
||||
]
|
||||
|
||||
[requirements]
|
||||
gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" }
|
||||
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
|
|
@ -0,0 +1,95 @@
|
|||
import gleam/bool
|
||||
import gleam/int
|
||||
import gleam/io
|
||||
import gleam/string_tree
|
||||
|
||||
pub type SpacePacketVersion {
|
||||
VersionZero
|
||||
}
|
||||
|
||||
pub type SpacePacketType {
|
||||
Telemetry
|
||||
Command
|
||||
}
|
||||
|
||||
pub type SpacePacketSequenceFlags {
|
||||
Continuation
|
||||
FirstSegment
|
||||
LastSegment
|
||||
Unsegmented
|
||||
}
|
||||
|
||||
pub type SpacePacketHeader {
|
||||
SpacePacketHeader(
|
||||
version: SpacePacketVersion,
|
||||
sp_type: SpacePacketType,
|
||||
sec_hdr_flag: Bool,
|
||||
apid: Int,
|
||||
seq_flag: SpacePacketSequenceFlags,
|
||||
seq_count: Int,
|
||||
packet_len: Int,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn version_to_string(sp_version: SpacePacketVersion) -> String {
|
||||
case sp_version {
|
||||
VersionZero -> "v0"
|
||||
}
|
||||
}
|
||||
|
||||
pub fn packet_type_to_string(sp_type: SpacePacketType) -> String {
|
||||
case sp_type {
|
||||
Telemetry -> "Telemetry"
|
||||
Command -> "Command"
|
||||
}
|
||||
}
|
||||
|
||||
pub fn seq_flag_to_string(sp_seq_flags: SpacePacketSequenceFlags) -> String {
|
||||
case sp_seq_flags {
|
||||
Continuation -> "Continuation"
|
||||
FirstSegment -> "First Segment"
|
||||
LastSegment -> "Last Segment"
|
||||
Unsegmented -> "Unsegmented"
|
||||
}
|
||||
}
|
||||
|
||||
pub fn space_packet_header_to_string(sp: SpacePacketHeader) -> String {
|
||||
string_tree.new()
|
||||
|> string_tree.append("Version: ")
|
||||
|> string_tree.append(version_to_string(sp.version))
|
||||
|> string_tree.append("\n")
|
||||
|> string_tree.append("Type: ")
|
||||
|> string_tree.append(packet_type_to_string(sp.sp_type))
|
||||
|> string_tree.append("\n")
|
||||
|> string_tree.append("Secondary Header Flag: ")
|
||||
|> string_tree.append(bool.to_string(sp.sec_hdr_flag))
|
||||
|> string_tree.append("\n")
|
||||
|> string_tree.append("APID: 0x")
|
||||
|> string_tree.append(int.to_base16(sp.apid))
|
||||
|> string_tree.append("\n")
|
||||
|> string_tree.append("Sequence Flags: ")
|
||||
|> string_tree.append(seq_flag_to_string(sp.seq_flag))
|
||||
|> string_tree.append("\n")
|
||||
|> string_tree.append("Sequence Count: ")
|
||||
|> string_tree.append(int.to_string(sp.seq_count))
|
||||
|> string_tree.append("\n")
|
||||
|> string_tree.append("Packet Length: ")
|
||||
|> string_tree.append(int.to_string(sp.packet_len))
|
||||
|> string_tree.append("\n")
|
||||
|> string_tree.to_string()
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let space_packet =
|
||||
SpacePacketHeader(
|
||||
VersionZero,
|
||||
Telemetry,
|
||||
False,
|
||||
0x55,
|
||||
Unsegmented,
|
||||
0x00,
|
||||
0x00,
|
||||
)
|
||||
|
||||
io.println(space_packet_header_to_string(space_packet))
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
import gleeunit
|
||||
import gleeunit/should
|
||||
|
||||
pub fn main() {
|
||||
gleeunit.main()
|
||||
}
|
||||
|
||||
// gleeunit test functions end in `_test`
|
||||
pub fn hello_world_test() {
|
||||
1
|
||||
|> should.equal(1)
|
||||
}
|
Loading…
Reference in New Issue