Skip to content

Instantly share code, notes, and snippets.

View hovsep's full-sized avatar
🤓
Constant learner

Ovsep Avakian hovsep

🤓
Constant learner
  • SumUp
  • Sofia, Bulgaria
View GitHub Profile
@hovsep
hovsep / custom_commands.go
Created January 13, 2026 08:36
human body sim custom commands
// setMeshCommands sets the commands that can be executed on the mesh
func setMeshCommands(mesh *fmesh.FMesh, commands step_sim.MeshCommandMap) {
timeComponent := mesh.ComponentByName("time")
// Print current time
commands["time:now"] = step_sim.NewMeshCommandDescriptor("Print current time", func(_ *fmesh.FMesh) {
tickCount := timeComponent.State().Get("tick_count")
simTime := timeComponent.State().Get("sim_time")
simWallTime := timeComponent.State().Get("sim_wall_time")
fmt.Println("Current tick count:", tickCount)
@hovsep
hovsep / step_sim_wrapper.go
Last active January 13, 2026 08:31
Simulation mesh wrapped into step_sim
// I like my main func to be clean and short
func main() {
simMesh := getSimulationMesh()
// Run the mesh in a step simulation
step_sim.NewApp(simMesh, initSim).Run()
}
// Here is our step_sim wrapper, it provides REPL and some built-in commands: pause, resume, exit, help
func NewApp(fm *fmesh.FMesh, simInitFunc SimInitFunc) *Application {
@hovsep
hovsep / get_simulation.go
Created January 13, 2026 07:57
Human body simulation mesh
// getSimulationMesh returns the main mesh of the simulation
func getSimulationMesh() *fmesh.FMesh {
// Set up the world
habitat := env.NewHabitat(component.NewCollection().Add(
factor.GetTimeComponent(),
factor.GetAirComponent(),
factor.GetSunComponent(),
))
// Add human beings
@hovsep
hovsep / can_bus_main.go
Created January 9, 2026 16:06
ISO-tp frames
func main() {
fm := getMesh()
// Initialize the mesh: set diagnostic frames to USB port, so the laptop will send them
laptopInstance.SendDataToUSB(
diagnostics.FrameGetEngineDTCs,
diagnostics.FrameGetSpeed,
diagnostics.FrameGetRPM,
diagnostics.FrameGetCoolantTemperature,
diagnostics.FrameGetCalibrationID,
@hovsep
hovsep / can_frame.go
Last active January 9, 2026 15:46
CAN frame structure
// Frame represents a simplified CAN frame
type Frame struct {
// CAN identifier (11-bit standard ID)
// Determines priority during arbitration: lower ID = higher priority
Id uint32
// Data Length Code (DLC)
// Indicates how many bytes of data are in the payload (0–8 for classic CAN, up to 64 for CAN FD)
DLC uint8
@hovsep
hovsep / chained_api.go
Last active January 8, 2026 08:40
FMesh chained api example
// Builder pattern (all chained calls are invoked on the same object):
p := component.New("processor").
WithDescription("main processor").
AddLabel("env", "prod").
AddLabel("tier", "backend").
AddInputs("in1", "in2").
AddOutputs("out1", "out2").
WithActivationFunc(func(this *component.Component) error {
return nil
})
@hovsep
hovsep / goflow_example.go
Created January 8, 2026 07:53
goflow example
package main
import (
"fmt"
"github.com/trustmaster/goflow"
)
// Greeter sends greetings
type Greeter struct {
Name <-chan string // input port
@hovsep
hovsep / results_extraction.go
Created January 8, 2026 07:50
fmesh results extraction example
func main() {
// Build mesh
numbersCruncher := getMesh()
// Init with data
numbersCruncher.ComponentByName("first-stage").InputByName("num").PutSignals(
signal.New(1),
signal.New(2),
signal.New(3),
)
@hovsep
hovsep / activation_func.go
Created January 8, 2026 07:26
FMesh component activation function example
func(this *component.Component) error {
num := this.InputByName("num").Signals().FirstPayloadOrDefault(0) // Read inputs
this.OutputByName("res").PutSignals(signal.New(num.(int) * 3)) // Provide outputs
return nil // Report possible errors
}