Forum AmigaOne Zone

Forum użytkowników Amigi i nie tylko
Teraz jest czwartek, 28 mar 2024, 15:45

Strefa czasowa: UTC + 1




Utwórz nowy wątek Odpowiedz w wątku  [ Posty: 48 ]  Przejdź na stronę Poprzednia strona  1, 2, 3, 4
Autor Wiadomość
PostNapisane: niedziela, 29 paź 2017, 01:26 
Offline
Elitarny forumowicz
Elitarny forumowicz
Avatar użytkownika

Dołączył(a): piątek, 20 sty 2012, 05:09
Posty: 561
Lokalizacja: Warszawa
tchomasz napisał(a):
Odkopuję trochę temat.

Jak pobrać z systemu aktualną godzinę i datę?


Najpierw funkcją GetSysTime() z urządzenia timer.device pobierasz liczbę sekund od 1 stycznia 1978 roku, a następnie funkcją Amiga2Date() z biblioteki utility.library konwertujesz tą liczbę do aktualnej daty i godziny. :)

_________________
Robert "Hextreme" Szacki - Gear Works software


Udostępnij dla FacebookUdostępnij dla Twitter
Góra
 Zobacz profil  
Cytuj  
PostNapisane: poniedziałek, 30 paź 2017, 00:19 
Offline
Administrator
Administrator

Dołączył(a): poniedziałek, 16 sty 2012, 13:40
Posty: 230
Lokalizacja: okolice Lublina
Napisałem coś takiego - z racji tego, że obsługa urządzeń to dla mnie czarna magia, to nie wiem za bardzo dlaczego mi się to wiesza. Wiesza się na GetSysTime.
Kod:
#include <stdio.h>
#include <stdlib.h>
#include <proto/timer.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/utility.h>
#include <devices/timer.h>
#include <exec/types.h>

static int init(void);
static void close(void);

struct MsgPort *TimerMP = NULL;
struct Device *TimerBase = NULL;
struct timerequest *TimerIO = NULL;
struct IORequest timereq;
struct timeval *currentval = NULL;
long error; //OpenDevice

static int init(void)
{
 TimerMP=CreateMsgPort();
 if (!TimerMP)
 {
  return -1;
 }
 TimerIO=(struct timerequest *) CreateIORequest(TimerMP, sizeof(struct timerequest));
 if (!TimerIO)
 {
  return -1;
 }
 error=OpenDevice(TIMERNAME, UNIT_ECLOCK, (struct IORequest*)TimerIO, 0);
 if (0 != error)
 {
  return -1;
 }
 return 0;
}

static void close(void)
{
 if (TimerIO)
 {
  CloseDevice((struct IORequest*)TimerIO);
  DeleteIORequest(TimerIO);
 }
 if (TimerMP)
 {
  DeletePort(TimerMP);
 }
}

int main(void)
{
 if (0 == init())
 {
  GetSysTime(currentval);
 }
 close();
 return 0;
}

_________________
AmigaONE X5000/20


Góra
 Zobacz profil  
Cytuj  
PostNapisane: poniedziałek, 30 paź 2017, 03:39 
Offline
Doborowy forumowicz
Doborowy forumowicz

Dołączył(a): wtorek, 17 sty 2012, 17:21
Posty: 934
Brakowało

pobrania TimerBase

TimerBase = (struct Library *)TimerIO->tr_node.io_Device;

TimerBase - wskaźnik typu struct Library *

zarezerwowania pamięci na currentval

currentval=(struct timeval*)malloc(sizeof(struct timeval));

Poza tym ok


Kod:
#include <stdio.h>
#include <stdlib.h>
#include <proto/timer.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/utility.h>
#include <devices/timer.h>
#include <exec/types.h>

static int init(void);
static void close(void);

struct MsgPort *TimerMP = NULL;
struct Library *TimerBase = NULL;
struct timerequest *TimerIO = NULL;
struct IORequest timereq;
struct timeval *currentval;
long error; //OpenDevice

static int init(void)
{
 TimerMP=CreateMsgPort();
 if (!TimerMP)
 {
  return -1;
 }
 TimerIO=(struct timerequest *) CreateIORequest(TimerMP, sizeof(struct timerequest));
 if (!TimerIO)
 {
  return -1;
 }
 error=OpenDevice(TIMERNAME, UNIT_ECLOCK, (struct IORequest*)TimerIO, 0);
 if (0 != error)
 {
  return -1;
 }
TimerBase = (struct Library *)TimerIO->tr_node.io_Device;
 currentval=(struct timeval*)malloc(sizeof(struct timeval));
 if (!currentval)
 {
  return -1;
 }

 return 0;
}

static void close(void)
{
 if (currentval)
 {
  free(currentval);
 }
 if (TimerIO)
 {
  CloseDevice((struct IORequest*)TimerIO);
  DeleteIORequest(TimerIO);
 }
 if (TimerMP)
 {
  DeletePort(TimerMP);
 }
}

int main(void)
{
 if (0 == init())
 {

  GetSysTime(currentval);
printf("%d %d \n",currentval->tv_secs,currentval->tv_micro);
  GetSysTime(currentval);
printf("%d %d \n",currentval->tv_secs,currentval->tv_micro);
 }
 close();
 return 0;
}


Góra
 Zobacz profil  
Cytuj  
Wyświetl posty nie starsze niż:  Sortuj wg  
Utwórz nowy wątek Odpowiedz w wątku  [ Posty: 48 ]  Przejdź na stronę Poprzednia strona  1, 2, 3, 4

Strefa czasowa: UTC + 1


Kto przegląda forum

Użytkownicy przeglądający ten dział: Brak zidentyfikowanych użytkowników i 9 gości


Nie możesz rozpoczynać nowych wątków
Nie możesz odpowiadać w wątkach
Nie możesz edytować swoich postów
Nie możesz usuwać swoich postów
Nie możesz dodawać załączników

Szukaj:
Skocz do:  
Powered by phpBB® Forum Software © phpBB Group
Przyjazne użytkownikom polskie wsparcie phpBB3 - phpBB3.PL
phpBB SEO