home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Utilities / PdaLink / examples / PdaTime.c next >
Encoding:
C/C++ Source or Header  |  2001-07-17  |  5.5 KB  |  202 lines

  1. /*********************************************************************
  2. **                                                                  **
  3. **        PdaTime         -- Set Amiga or Pilot system time         **
  4. **                                                                  **
  5. *********************************************************************/
  6. /*
  7. **  Copyright © 1998-2000 Richard Körber  --  All Rights Reserved
  8. **    E-Mail: rkoerber@gmx.de
  9. **    URL:    http://shredzone.home.pages.de
  10. **
  11. ***************************************************************/
  12. /*
  13. **  This program is free software; you can redistribute it and/or modify
  14. **  it under the terms of the GNU General Public License as published by
  15. **  the Free Software Foundation; either version 2 of the License, or
  16. **  any later version.
  17. **
  18. **  This program is distributed in the hope that it will be useful,
  19. **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. **  GNU General Public License for more details.
  22. **
  23. **  You should have received a copy of the GNU General Public License
  24. **  along with this program; if not, write to the Free Software
  25. **  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. **
  27. **  The author (Richard Körber) reserves the right to revoke the
  28. **  GNU General Public License whenever he feels that it is necessary,
  29. **  especially when he found out that the licence has been abused,
  30. **  ignored or violated, and without prior notice.
  31. **
  32. **  You must not use this source code to gain profit of any kind!
  33. **
  34. ***************************************************************/
  35. /*
  36. **  Compiles with SAS/C, e.g.
  37. **      sc PdaTime.c NOSTACKCHECK DATA=NEAR STRMER CPU=68060 OPT
  38. */
  39.  
  40. #include <stdio.h>
  41. #include <string.h>
  42. #include <clib/alib_protos.h>
  43. #include <clib/exec_protos.h>
  44. #include <clib/dos_protos.h>
  45. #include <clib/utility_protos.h>
  46. #include <clib/pdalink_protos.h>
  47. #include <pragmas/exec_pragmas.h>
  48. #include <pragmas/dos_pragmas.h>
  49. #include <pragmas/utility_pragmas.h>
  50. #include <pragmas/pdalink_pragmas.h>
  51. #include <exec/memory.h>
  52. #include <dos/dos.h>
  53. #include <dos/dosasl.h>
  54. #include <libraries/pdalink.h>
  55.  
  56.  
  57. #define  VERSIONSTR   "0.3ß"
  58. #define  DATESTR      "7.1.2000"
  59. #define  COPYRIGHTSTR "2000"
  60. #define  EMAILSTR     "rkoerber@gmx.de"
  61. #define  URLSTR       "http://shredzone.home.pages.de"
  62.  
  63. #define  NORMAL       "\2330m"
  64. #define  BOLD         "\2331m"
  65. #define  ITALIC       "\2333m"
  66. #define  UNDERLINE    "\2334m"
  67.  
  68. #define  MKTAG(a,b,c,d)  ((ULONG) (a)<<24 | (ULONG) (b)<<16 | (ULONG) (c)<<8 | (ULONG) (d))
  69.  
  70. static char ver[] = "$VER: PdaTime " VERSIONSTR " (" DATESTR ") " EMAILSTR;
  71. static char titletxt[] = \
  72.   BOLD "PdaTime " VERSIONSTR " (C) " COPYRIGHTSTR " Richard Körber -- all rights reserved" NORMAL "\n"
  73.   BOLD "  WARNING:" NORMAL " This is an early beta release. If you don't\n"
  74.   "    know what this means, do " BOLD "NOT" NORMAL " use this program!\n\n";
  75. static char helptxt[] = \
  76.   "  " ITALIC "E-Mail: " NORMAL EMAILSTR "\n"
  77.   "  " ITALIC "URL:    " NORMAL URLSTR "\n\n"
  78.   ITALIC "Usage:" NORMAL "\n"
  79.   "  DEVICE/K       Serial device (\"serial.device\")\n"
  80.   "  UNIT/K/N       Serial unit (0)\n"
  81.   "  MAXBAUD/K/N    Maximum baud (57600)\n"
  82.   "\n";
  83.  
  84. struct Parameter
  85. {
  86.   STRPTR device;
  87.   LONG   *unit;
  88.   LONG   *maxbaud;
  89. }
  90. param;
  91.  
  92. static char template[] = "SD=DEVICE/K,SU=UNIT/K/N,SB=MAXBAUD/K/N";
  93.  
  94. extern struct DOSBase *DOSBase;
  95. struct Library *PdalinkBase;
  96. struct Library *UtilityBase;
  97. APTR socket = NULL;
  98. BOOL ignoreError = FALSE;
  99.  
  100.  
  101.  
  102. /*
  103. ** Open a connection to the Pilot
  104. */
  105. int Connect(void)
  106. {
  107.   LONG error;
  108.  
  109.   if(socket) return(TRUE);
  110.  
  111.   socket = PL_OpenSocketTags
  112.     (
  113.     PLTAG_ErrorPtr      , &error,
  114.     (param.device  ? PLTAG_SerialDevice  : TAG_IGNORE) , param.device,
  115.     (param.unit    ? PLTAG_SerialUnit    : TAG_IGNORE) , *param.unit ,
  116.     (param.maxbaud ? PLTAG_SerialMaxRate : TAG_IGNORE) , *param.maxbaud,
  117.     TAG_DONE
  118.     );
  119.  
  120.   if(socket)
  121.   {
  122.     Printf("Please press the HotSync button " ITALIC "now" NORMAL "\n");
  123.     if(PL_Accept(socket,10L)) {
  124.       Printf("Connection established, %ld bps\n",PL_GetBaudRate(socket));
  125.       return(TRUE);
  126.     }
  127.   }
  128.   else
  129.   {
  130.     Printf("** Socket error %ld\n",error);
  131.   }
  132.   return(FALSE);
  133. }
  134.  
  135. /*
  136. ** Close all databases and disconnect
  137. */
  138. void Disconnect(void)
  139. {
  140.   if(!socket) return;
  141.   DLP_AddSyncLogEntry(socket,"-- AMIGA made it possible --\n");
  142.   DLP_EndOfSync(socket,0);
  143.   PL_CloseSocket(socket);
  144. }
  145.  
  146. /*
  147. ** Show Pilot time
  148. */
  149. void cmd_show(void)
  150. {
  151.   struct DLP_SysTime time;
  152.  
  153.   if(!Connect()) return;
  154.   if(!DLP_OpenConduit(socket)) return;
  155.   if(!DLP_GetSysTime(socket,&time))
  156.   {
  157.     PutStr("** Couldn't get time\n");
  158.     return;
  159.   }
  160.  
  161.   Printf("%02ld.%02ld.%04ld %02ld:%02ld:%02ld\n",time.day,time.month,time.year,time.hour,time.minute,time.second);
  162. }
  163.  
  164. /*
  165. ** MAIN PART
  166. */
  167. int main(void)
  168. {
  169.   struct RDArgs *args;
  170.  
  171.   PutStr(titletxt);
  172.  
  173.   if(args = (struct RDArgs *)ReadArgs(template,(LONG *)¶m,NULL))
  174.   {
  175.     if(UtilityBase = OpenLibrary("utility.library",36L))
  176.     {
  177.       if(PdalinkBase = OpenLibrary("pdalink.library",0L))
  178.       {
  179.         cmd_show();
  180.  
  181.         if(socket)
  182.         {
  183.           if(!ignoreError && (PL_LastError(socket)!=0))
  184.             Printf("** Socket error code %ld\n",PL_LastError(socket));
  185.           Disconnect();
  186.         }
  187.         CloseLibrary(PdalinkBase);
  188.       }
  189.       else PutStr("** Couldn't open pdalink.library\n");
  190.       CloseLibrary(UtilityBase);
  191.     }
  192.     else PutStr("** Couldn't open utility.library\n");
  193.  
  194.     FreeArgs(args);
  195.   }
  196.   else PutStr(helptxt);
  197.  
  198.   return(0);
  199. }
  200.  
  201. /********************************************************************/
  202.