- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This wiced_time_get_iso8601_time() does not do a bitwise AND of a number that is frequently greater than 65000, when it converts to a uint16_t. Consequently the result is normally wrong.
Specifics: the local variable uint16_t sub_second is computed as follows. You should always have "000" on the end of the final result, because you take a millisecond value and convert it to microseconds by multiplying by 1000.
wiced_time_get_utc_time_ms( &utc_time_ms );
second = utc_time_ms / 1000; /* Time is in milliseconds. Convert to seconds */
sub_second = (uint16_t) (( utc_time_ms % 1000 ) * 1000 ); /* Sub-second is in microseconds */
/************** Code corrected with int temp variable ***********************/
temp = (int) (utc_time_ms & 0xFFFF);
temp = (temp % 1000) * 1000;
printf("******* temp: %d; sub_sec: %d\r\n", temp, sub_second);
/************ temp and sub_second should be identical, but they almost never are.
Code extracted from WICED version 3.1.2
******/
Solved! Go to Solution.
- Tags:
- bugs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The real problem is that uint16_t isn't big enough to hold numbers up to 1000000 so sub_second needs to be a uint32_t. The modulus(%) operator limits the result to integers less than 1000000, so I don't think you need the bitwise AND (&). The following should always work:
uint32_t sub_second;
sub_second = (uint32_t) (( utc_time_ms % 1000 ) * 1000 ); /* Sub-second is in microseconds */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The real problem is that uint16_t isn't big enough to hold numbers up to 1000000 so sub_second needs to be a uint32_t. The modulus(%) operator limits the result to integers less than 1000000, so I don't think you need the bitwise AND (&). The following should always work:
uint32_t sub_second;
sub_second = (uint32_t) (( utc_time_ms % 1000 ) * 1000 ); /* Sub-second is in microseconds */