Skip to content

Commit

Permalink
jtutil vcd command to delay signals
Browse files Browse the repository at this point in the history
  • Loading branch information
jotego committed Jul 6, 2023
1 parent b624ee0 commit f6995e3
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions modules/jtframe/src/jtutil/cmd/vcd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Copyright © 2023 Jose Tejada <jose.tejada@jotego.es>
*/
package cmd

import (
"fmt"
"os"
"bufio"
"jtutil/vcd"
"strconv"

"github.com/spf13/cobra"
)

// vcdCmd represents the vcd command
var vcdCmd = &cobra.Command{
Use: "vcd",
Short: "Copy all signals in a VCD file delayed by 1 frame",
Long: `Copy all signals in a VCD file delayed by 1 frame`,
Run: func(cmd *cobra.Command, args []string) {
runVCD()
},
Args: cobra.NoArgs,
}

func init() {
rootCmd.AddCommand(vcdCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// vcdCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// vcdCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

func runVCD() {
const FRAME_PERIOD=16652300800
fin := &vcd.LnFile{}
fin.Open("debug.vcd")
defer fin.Close()

fout, e := os.Create("delayed.vcd")
if e!=nil {
fmt.Println(e)
return
}
wr := bufio.NewWriter(fout)
defer fout.Close()

// copy all lines and
// modify all time stamps by subtracting a whole frame period
for fin.Scan() {
txt := fin.Text()
if txt!="" && txt[0]=='#' {
told,_ := strconv.ParseUint( txt[1:],10,64 )
if told!=0 { told += FRAME_PERIOD }
txt = fmt.Sprintf("#%d",told)
}
wr.WriteString(txt)
wr.WriteString("\n")
}
}

0 comments on commit f6995e3

Please sign in to comment.