Android Question Timee Period Inconsistent

rgarnett1955

Active Member
Licensed User
Longtime User
Hi

I have a timer running in the Starter service viz:

B4X:
Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS
   
    DateTime.DateFormat = "dd/mm/yyyy"
    DateTime.TimeFormat = "hh:mm:ss.SSS"
   
    'Start the WiFi and connect a socket for comms with the embedded server
    initaliseComms
   
    If WiFiRealTimeDataTmr.IsInitialized = False Then
        WiFiRealTimeDataTmr.Initialize("tmr_WiFiRealTimeData", 2000)
    End If

   
    Conv.LittleEndian = True
   
    If dbStartup = 0 Then
            #If LOGGING_ON
        Log("DB Startup Failed - Main")
            #End If
    Else
        init_Sql1
    End If
       
    rtData_s.Initialize

    startTime = DateTime.Time(DateTime.Now)
End Sub

The timer calls an async stream write: viz:

B4X:
'======================================================================================
Sub tmr_WiFiRealTimeData_Tick
    If WifITransactionInProgress = True Then Sleep(1000)
    WifITransactionInProgress = True
    sendCommand(embeddedCmds.GetRealtimeData)
    Wait For CanContinue
End Sub

'==========================================
Sub sendCommand(cmdCode As Int) As Int
    If Astream.IsInitialized = False Then
        Return WIFI_ERROR
    End If

    Dim buffer(121) As Byte
    Dim strBuff As String

    Select cmdCode
        Case 0    ' Get Parameters from Controller
            strBuff = "$GetInstData,"
            buffer = strBuff.GetBytes("UTF8")
            Astream.Write(buffer)
            #If LOGGING_ON
'            Log("Tx: " & strBuff)
            #End If
    End Select
'    CmdTimeoutTmr.Enabled = True debug
   
    Return WIFI_OK
End Sub

The async write sends data to a server that responds with a fixed data frame of 107 bytes.

The async stream new data sub process and stores the data. This takes on average 42 ms.

A histogram of this is attached as a screen shot.




The problem is that the timer duration is inconsistent see plot attached. Most the time it is within a few millisec's of the timer setting, but at seemingly random intervals it jumps up to as high as 6.4 seconds then as the timer events are queued (my assumption) the time then drops to very low values. This causes problems with the data base as the unique key index (Julian Date/Time as double) is violated.




I suspect that another process is hogging resources at random intervals, however with this version of Android 9 (Pie?) the learned programmers at Google Inc have decided that CPU usage is not required by developers any more. This makes it difficult to work out which process is causing the problems. The Tablet is not connected to the internet it is using a dedicated WiFi access point on the embedded server. The only data transmitted is the clinetr equest 20 bytes and the server response 107 bytes. I am using prefixed async data.

The tablet is a Lenovo M10 (Tab5?). The system is still useable, but I would like to fix the problem if I can.

Has anyone got any ideas or suggestions?

Thanking you in anticipation

Rob
 

rgarnett1955

Active Member
Licensed User
Longtime User
Hi Errel,

I tried the partial lock bizzo and it worked pretty well. See the attached histograms.

I also captured the embedded clock time as this is transmitted in the data as a double Julian date. Interestingly this had a sharply tri-modal distribution.
It was 1 secs, 2 secs or 3 secs with little variation around these values.

Note that the Pr axis is log so that the max mins can be easily discerned.

I think that this shows that the timer callback is running consistently, but the log that reports the time has some jitter in the value it reports.

Note that the Pr axis is log so that the max mins can be easily discerned.

Thanks for your help

Best regards

Rob.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…