Skip to content

Commit b02c4fd

Browse files
robjusticetschak909
authored andcommitted
add clock SOS time format back in
1 parent 36c2669 commit b02c4fd

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

lib/clock/Clock.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ static std::string format_iso8601(const std::tm& time) {
2424
return std::string(buffer);
2525
}
2626

27+
// Helper function to format time into SOS set_time string
28+
static std::string format_sos(const std::tm& time) {
29+
char buffer[30];
30+
// Format: YYYYMMDD0HHMMSS000 - raw time, no timezone info supported.
31+
// ref SOS Reference Manual: https://archive.org/details/apple-iii-sos-reference-manual-volume-2/page/94/mode/2up
32+
std::strftime(buffer, sizeof(buffer), "%Y%m%d0%H%M%S000", &time);
33+
return std::string(buffer);
34+
}
35+
2736
std::string Clock::get_current_time_iso(const std::string& posixTimeZone) {
2837
set_timezone_env("TZ", posixTimeZone);
2938
std::time_t now = std::time(nullptr);
@@ -102,4 +111,16 @@ std::vector<uint8_t> Clock::get_current_time_apetime(const std::string& posixTim
102111
// Debug_printf("apetime: %s, %s\r\n", dstring.c_str(), posixTimeZone.c_str());
103112

104113
return apeTime;
114+
}
115+
116+
std::string Clock::get_current_time_sos(const std::string& posixTimeZone) {
117+
set_timezone_env("TZ", posixTimeZone);
118+
std::time_t now = std::time(nullptr);
119+
std::tm* localTime = std::localtime(&now);
120+
121+
// Format the time into Apple /// SOS set_time format YYYYMMDD0HHMMSS000
122+
std::string sosString = format_sos(*localTime);
123+
//Debug_printf("SOS set_time format time: %s\r\n", sosString.c_str());
124+
125+
return sosString;
105126
}

lib/clock/Clock.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Clock {
2020
// current local time in ApeTime format
2121
static std::vector<uint8_t> get_current_time_apetime(const std::string& posixTimeZone);
2222

23+
// current local time in SOS set_time format
24+
static std::string get_current_time_sos(const std::string& posixTimeZone);
25+
2326
};
2427

2528
#endif // CLASS_CLOCK_H

lib/device/iwm/clock.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,15 @@ void iwmClock::iwm_status(iwm_decoded_cmd_t cmd)
104104
break;
105105
}
106106
case 'S': {
107-
// Date and time, ASCII string in ISO format - This is a change from the original format: YYYYMMDDxHHMMSSxxx with 0 for every 'x' value, which was not TZ friendly, and I found no references to
107+
// Date and time, ASCII string in Apple /// SOS format: YYYYMMDD0HHMMSS000
108+
std::string sosTime = Clock::get_current_time_sos(Config.get_general_timezone());
109+
std::copy(sosTime.begin(), sosTime.end(), data_buffer);
110+
data_buffer[sosTime.size()] = '\0'; // this is a string in a buffer, we will null terminate it (this is also a change to the original that sent the char bytes without a null)
111+
data_len = sosTime.size() + 1; // and ensure the size reflects the null terminator
112+
break;
113+
}
114+
case 'I': {
115+
// Date and time, ASCII string in ISO format
108116
std::string utcTime = Clock::get_current_time_iso(Config.get_general_timezone());
109117
std::copy(utcTime.begin(), utcTime.end(), data_buffer);
110118
data_buffer[utcTime.size()] = '\0'; // this is a string in a buffer, we will null terminate it (this is also a change to the original that sent the char bytes without a null)

0 commit comments

Comments
 (0)