Shop OBEX P1 Docs P2 Docs Learn Events
test1 basic program — Parallax Forums

test1 basic program

The program below is sort of test code for different aspects of flexbasic. I try to work this thing in small pieces of code, so I can, hopefully find the bug, if one occurs.

Below I am having problems with the startlog/stoplog commands. It shows an error of 'u9fs', not sure what that is referencing.

Ray

Type help for the System Menu.                                                  



  startlog
'' sol_sta_so_bas.bas
''
'' December 19, 2023

mount "/host", _vfs_open_host()
mount "/sd", _vfs_open_sdcard()

dim sh01 as class using "shell.c"

'''' Varibles
dim inBuff as string
dim logFlag as long

'' Time and date
dim YYYY, MM, DD, HOURS, MINS, SECS as ulong
dim tmpYYYY, tmpMM, tmpDD, tmpHOURS, tmpMINS, tmpSECS as ulong
dim s$ as string
dim date as string
dim time as string
'''''''''''''''

'''' Stacks
dim stack_updateClock(64) as ulong
dim stack_dl(128) as long


'''' Misc
dim cpuID_1, cpuID_2 as long

'''' Start new COGs
cpuID_1 = cpu(updateClock(),@stack_updateClock(1))
pausems 250
cpuID_2 = cpu(data_log(),@stack_dl(1))
pausems 250


logFlag = FALSE

print "Type help for the System Menu."
print " "
''''''''''''''''''''''''''''''
'' main
do
    print "> ";
    input inBuff
    if inBuff = "quit" then
        exit
    else if inBuff = "setdate" then
        input "Enter year, month, and day as YYYY-MM-DD ", s$
        s$ = ltrim$(rtrim$(lcase$(s$)))
        if len(s$) <> 10 then
             print "Illegal date format: Date should be YYYY_MM-DD!"
        else
             tmpYYYY = val%(left$(s$, 4))
             tmpMM = val%(mid$(s$, 6, 2))
             tmpDD = val%(right$(s$, 2))

             if (InRange(tmpYYYY, 2000, 2040) = FALSE) orelse (InRange(tmpMM, 1, 12) = FALSE) orelse (InRange(tmpDD, 1, 31) = FALSE) then
                'date input parameter out of bounds
                print "Invalid YYYY/MM/DD format"

             else
                YYYY = tmpYYYY
                MM = tmpMM
                DD = tmpDD
                print "Date has been set to: ";
                print using "%%/%%/%%%%"; MM; DD; YYYY

             end if
        end if

    else if inBuff = "settime" then
        input "Enter time as HH:MM:SS ", s$
        s$ = ltrim$(rtrim$(lcase$(s$)))
        if len(s$) <> 8 then
            'time isn't in proper format. squawk about it
            print "Illegal time format: Should be HH:MM:SS!"
        else
            'good time length. process it       
            tmpHOURS = val%(left$(s$, 2))       'extract hours  (range 0-23)
            tmpMINS = val%(mid$(s$, 4, 2))  'extract minutes (range 0-59)
            tmpSECS = val%(right$(s$, 2))   'extract seconds (range 0-59)

            if (InRange(HOURS, 0, 23) = FALSE) orelse (InRange(MINS, 0, 59) = FALSE) orelse (InRange(SECS, 0, 59) = FALSE) then
                'time input parameter out of bounds
                print "Invalid HH:MM:SS format"
            else
                'time input parameters are good. Use the
                HOURS = tmpHOURS
                MINS = tmpMINS
                SECS = tmpSECS
                print "Time has been set to ";
                print using "%%:%%:%%"; HOURS; MINS; SECS
            end if
        end if      
    else if inBuff = "help" then
        menu()
    else if inBuff = "getdate" then
        print using "%%/%%/%%%%"; MM; DD; YYYY
    else if inBuff = "gettime" then
        print using "%%:%%:%%"; HOURS; MINS; SECS
    else if inBuff = "dir" then
        sh01.do_dir
    else if inBuff = "startlog" then
        logFlag = TRUE
    else if inBuff = "stoplog" then
        logFlag = FALSE

    else
        print "??"
    end if

loop

print "Program ended!"
end
''''''''''''''''''''''''''''''


'''' Subroutines
'' Clock (COG)
sub updateClock()
    dim oldSecs, newSecs as ulong
    oldSecs = 0
    newSecs = 0

    do
        newSecs = getSec()
        if newSecs > oldSecs then
            SECS = SECS + 1
            if (SECS > 59) then
                SECS = 0
                MINS= MINS + 1
                if (MINS > 59) then
                    MINS = 0
                    HOURS = HOURS + 1
                    if (HOURS > 23) then
                        HOURS = 0
                        DD = DD + 1
                    end if              
                end if
            end if
            if (DD > daysInMonth()) then
                DD = 1
                MM = MM + 1
                if (MM > 12) then
                    MM = 1
                    YYYY = YYYY + 1
                end if
                oldSecs = newSecs
            end if      
        end if

    loop
end sub

sub data_log()

do
    if logFlag = TRUE then
        open "/host/solsta.csv" for append as #3
        print #3, using "%%/%%/####, ";MM, DD, YYYY;
        print #3, using "##:%%:%%, ";hours, mins, secs;
        print #3, "S1, ";
        print #3, " "
        close #3
    end if
    pausems 2000
loop

end sub

sub menu
    print "         System Menu"
    print "help - Show the System Menu."
    print "quit - End the program."
    print "setdate - Set the RTC date."
    print "settime - Set the RTC time."
    print "getdate - Get the current date."
    print "gettime - Get the current time."
    print "dir - Show the dir of /host."
    print "startlog - Start the log."
    print "stoplog - Stop the log."
    print " "
end sub

''''''''''''''''''''''''''''''
'''' Functions
function daysInMonth() as uinteger
  ' february special case
  if MM = 2 then
    if (YYYY mod 4 = 0) then
      if (YYYY mod 100 <> 0) or (YYYY mod 1000 = 0) then
        return 29
      endif
    endif
    return 28
  endif
  if (MM = 4) or (MM=6) or (MM=9) or (MM=11) return 30
  return 31
end function


FUNCTION InRange(myVar as any, myMin as any, myMax as any) as long
'
' trivial generic function that returns TRUE if MYVAR is within the range specified by
' and including the values in MYMIN and MYMAX.  

    if myVar >= myMin andalso myVar <= myMax then
        return TRUE
    else
        return FALSE
    end if

END FUNCTION

'''''''''''''''''''''''''''''

Comments

  • I found one major problem, at least as it concerns my program. In the snippet of code, it seems that there is a problem between the COG that is started and the main program. It looks like they both start up, but are frozen to a stop. Are the two COGs fighting for dominance, and neither one is winning?

    I guess I might be missing some additional code, but not sure what that would be.

    Ray

    '' test2_bas
    ''
    mount "/host", _vfs_open_host()
    
    '''' Varibles
    dim inBuff as string
    
    
    dim stack_dl(128) as long
    dim cpuID_1 as long
    cpuID_1 = cpu(test_log(),@stack_dl(5))
    pausems 1000
    
    do
        print "> ";
        input inBuff
        if inBuff = "quit" then
            exit
    
        else
            print "??"
        end if  
    
    loop
    
    end
    ''''''''''''''''''''''''''''''''''''
    
    sub test_log()
    
    
    do
        open "/host/test1.csv" for append as #3
        pausems 500
        print #3, "Here I am"
    
        close #3
        pausems 500
    loop
    
    end sub
    
    
  • pik33pik33 Posts: 2,350
    edited 2024-02-10 21:52

    Don't use 2 cogs to access a filesystem, it will not work. Use only the cog that executed "mount". I had this problem while writing the audio player (it's in FlexBasic, here is the topic: https://forums.parallax.com/discussion/174334/prop2play-audio-player-for-a-p2-ec32-0-33-1024x600/p1 ).

Sign In or Register to comment.