/* ** Modem Setup Installer ** ** Newton Developer Technical Support Sample Code ** Copyright © 1995 by Apple Computer, Inc. All rights reserved. ** ** To build your own modem setup... ** 1) Copy the entire project and rename the Project File appropriately. ** 2) Change the Package Name in Project Settings. ** 3) Edit the constants in Project Data for your modem. ** 4) Recompile and download. */ // ==================== MODEM GENERAL INFO ==================== constant kModemName := "Brand X Modem"; // type: string // range: length > 0 // // This is the name of the modem setup as seen in modem prefs. constant kVersion := 1; // type: integer // range: positive 30-bit integer value // // Use ONLY integers for version numbers!!! This number is // compared to the currently installed modem setup version // number (if any) to determine the appropriate wording for // a user confirmation slip (see :Install() for more info). constant kPackageName := "Brand X Modem:PIEDTS"; // type: string // range: length > 0 // // When you change the package name in the Project Settings // you must also change kPackageName to the exact same string. // This package is removed after the modem information is // added to the system or if the user cancels the installation. constant kOrganization := "Apple Computer, Inc."; // type: string // range: length > 0 // // Change this accordingly (for informational use). // ===================== LOCALIZATION INFO ==================== DefConst( 'kConfirmNewer, "You are about to install a NEWER version of the \"" & kModemName & "\" modem setup. Continue?" ); DefConst( 'kConfirmOlder, "You are about to install an OLDER version of the \"" & kModemName & "\" modem setup. Continue?" ); DefConst( 'kConfirmSame, "The \"" & kModemName & "\" modem setup is already installed. Reinstall?" ); // =================== MODEM PREFS ENTRIES ==================== constant kIdModem := true; // type: boolean // range: nil, true // default: true // // If true, the Newton Modem Tool will execute an ID sequence // in an attempt to identify the modem which is connected. // If the modem is identified, the NMT configures the active // modem profile accordingly. The ID sequence is run when // the Bind call is made to the NMT. NOTE: the modem is reset // during the ID sequence using the AT&F command. // If nil, the NMT skips the ID sequence and configures the // active profile to the default. Modem is not reset. constant kUseHardwareCD := true; // type: boolean // range: nil, true // default: true // // If true, the NMT will sense the CD line for determining loss // of carrier. External modems must use a cable which connects the // CD RS-232 signal to the Newtons GPi serial pin (pin 7 on MPÕs). // If nil, CD is ignored. constant kUseConfigString := true; // type: boolean // range: nil, true // default: true // // If true, before initiating a connection, send the current // configuration string to the modem (as determined by active // modem profile and the connection type). // If nil, no configuration string is sent. constant kUseDialOptions := true; // type: boolean // range: nil, true // default: true // // If true, before initiating a connection, after configString // is sent to modem, set modem dialing configuration according // to current option settings. // If nil, dial configuration string is not sent to modem. // Default dial config string: "ATM1L2X4S7=060S8=001S6=003\n" constant kHangUpAtDisconnect := true; // type: boolean // range: nil, true // default: true // // If true, when the NMT disconnects, hang up the modem. // If nil, when the NMT disconnects, no commands are sent to the modem. // =================== MODEM PROFILE ENTRIES ================== constant kSupportsCellular := nil; // type: boolean // range: nil, true // default: nil // // If true, indicates modem profile contails a // kConfigStrCellular. This string will be used for cellular // type data connections (e.g. turn on MNP 10). // If nil, the modem profile does not contain // kConfigStrCellular, and the normal data mode configuration // string will be used for cellular connections. constant kSupportsEC := nil; // type: boolean // range: nil, true // default: nil // // If true, indicates modem supports built in error correction, // and the profile contains configuration strings for error correction. constant kSupportsLCS := nil; // type: boolean // range: nil, true // default: nil // // If true, indicates modem supports Line Current Sense. LCS // is used for determining when a user has lifted the phone // handset off hook. Applications take advantage of this // feature by allowing the modem to determine when it // should release the line for a voice call. // If nil, the modem does not support LCS. In this case, // an application can use a dialog box and user interaction to // determine when to tell the modem to release the line (ATH). constant kDirectConnectOnly := true; // type: boolean // range: nil, true // default: true // // If true, indicates modem only supports direct connect mode // and can't speed buffer. In this case, for data connections, // the DTE speed must be adjusted to the modem speed after the // carrier is established. // If nil, indicates the modem supports speed buffering, and // use of CTS flow control. // NOTE: For FAX connections, flow control is required! // The string kConfigStrNoEC is used to configure the modem // for fax connections. If kDirectConnectOnly is true, // kConfigStrNoEC should enable software flow control. constant kConnectSpeeds := '[300, 1200, 2400, 4800, 7200, 9600, 12000, 14400]; // type: constant array of length > 0 // range: each element a positive 30-bit integer value // default: '[300, 1200, 2400, 4800, 7200, 9600, 12000, 14400] // // Indicates speeds at which the modem can connect. The value // of kConnectSpeeds does NOT effect how the modem is // configured. The intention is to allow the application to // read this value to determine the modem's capabilities. constant kConfigSpeed := 19200; // type: integer // unit: bps // range: positive 30-bit integer value // default: 19200 // // (bps) speed at which to configure the modem constant kCommandTimeout := 2000; // type: integer // unit: milliseconds // range: positive 30-bit integer value // default: 2000 // // (ms) how long we'll wait for modem response to a command before timing out constant kMaxCharsPerLine := 40; // type: integer // range: positive 30-bit integer value // default: 40 // // Indicates maximum number of characters per command line, // NOT COUNTING "AT" and ! The modem controller uses this // number to ensure the dial string does not exceed the modem's // capability. If the number of characters in the dial string // exceeds this number, the dial string will be split into // multiple commands, with ; appended to the intermediate // dial string commands. constant kInterCmdDelay := 25; // type: integer // unit: milliseconds // range: positive 30-bit integer value // default: 25 // // Indicates minimum amount of (ms) delay required between // modem commands. This is the time from the last response // received to the next command sent. constant kModemIDStr := nil; // type: string // range: nil, length > 0 // default: nil // // Modem response to the ATI4 command. If the modem responds // with more than one result string, kModemIDStr should // contain only one result string. constant kConfigStrNoEC := "ATE0&C1S12=12W2&K3&Q6\n"; // type: string // range: nil, length > 0 // default: "ATE0&C1S12=12W2&K3&Q6\n" // // Modem command string used to configure modem for a non- // error corrected connection. Uses speed buffering. This // string is used for FAX connections. constant kConfigStrECOnly := nil; // type: string // range: nil, length > 0 // default: nil // // Modem command string used to configure the modem for an // error corrected connection. Uses speed buffering. This // string should be nil for modems that do not support error // correction. constant kConfigStrECAndFallback := nil; // type: string // range: nil, length > 0 // default: nil // // Modem command string used to negotiate for error correction. // If error correction negotiation fails, the modem will fall // back to a non-error corrected connection. Uses speed // buffering. This string should be nil for modems that // do not support error correction. constant kConfigStrCellular := nil; // type: string // range: nil, length > 0 // default: nil // // Modem command string used to configure the modem to connect // over a cellular connection. This command should be used to // turn on MNP 10, and power attenuation. Uses speed // buffering. This string should be nil for modems that // do not support error correction. constant kConfigStrDirectConnect := "ATE0&C1S12=12W2&K0&Q0\n"; // type: string // range: nil, length > 0 // default: "ATE0&C1S12=12W2&K0&Q0\n" // // Modem command string used to configure the modem to connect // in direct mode. Speed buffering is disabled. After // connecting in data mode, the DTE speed will be adjusted to // match the modem speed. // ============================================================ // ---- End Project Data ---- // ---- File Install ---- // Before Script for "Installer" DefConst('kPackageRemove, func() begin local packages := GetPackages(); local index := ArrayPos(packages, kPackageName, 0, func(item, value) StrEqual(value.title, item)); if index then RemovePackage(packages[index]); end); Installer := { Install: func() begin // This function is called from the package's InstallScript and executes from pseudo-ROM. // We need a RAM-based frame to hold temporary variables during installation. local RamBasedSelf := { _proto: self, profileIndex: nil, entry: :InstallGetModemsEntry(), // get the "modems" entry from the system soup }; // next, check to see if a setup for "modem name" (e.g. "Brand X Modem") is installed RamBasedSelf.profileIndex := ArrayPos(RamBasedSelf.entry.modems, kModemName, 0, func(item, value) StrEqual(value.modemName, item)); if RamBasedSelf.profileIndex then begin // if one is installed, check the setup version number local versionInstalled := RamBasedSelf.entry.modems[RamBasedSelf.profileIndex].version; local message; if kVersion <> versionInstalled then if kVersion > versionInstalled then message := kConfirmNewer; else message := kConfirmOlder; else message := kConfirmSame; GetRoot():Confirm("Modem Profile Installer", message, RamBasedSelf, 'InstallConfirmScript); end; else // there is no modem setup currently installed for this modem, so add one begin AddArraySlot(RamBasedSelf.entry.modems, nil); RamBasedSelf.profileIndex := Length(RamBasedSelf.entry.modems) - 1; RamBasedSelf:InstallConfirmScript(true); end; end, viewBounds: {left: 0, top: 0, right: 100, bottom: 100}, InstallGetModemsEntry: func() begin local soup := GetStores()[0]:GetSoup(ROM_SystemSoupName); local cursor := Query( soup, { type: 'index, indexPath: 'tag, startKey: "Modems", validTest: func(item) StrEqual(item.tag, "Modems") } ); local entry := cursor:Entry(); if not entry or entry = 'deleted then // if the system soup does not yet have a "modems" entry, make one. begin entry := { tag: "Modems", modems: nil }; soup:Add(entry); end; if not entry.modems then // if the "modems" system soup entry does not yet have an array of modems then make one. entry.modems := []; entry; end, InstallConfirmScript: func(confirmed) // self is the RamBasedSelf frame begin if confirmed then // Install the modem setup in the system soup. begin entry.modems[profileIndex] := InstallSoupFrame; EntryChange(entry); end; AddDeferredAction(EnsureInternal(kPackageRemove), nil); end, InstallSoupFrame: { modemName: kModemName, version: kVersion, organization: kOrganization, modemPrefs: { idModem: kIdModem, // default true useHardwareCD: kUseHardwareCD, // default true useConfigString: kUseConfigString, // default true useDialOptions: kUseDialOptions, // default true hangUpAtDisconnect: kHangUpAtDisconnect, // default true }, modemProfile: { supportsCellular: kSupportsCellular, // default nil supportsEC: kSupportsEC, // default nil supportsLCS: kSupportsLCS, // default nil directConnectOnly: kDirectConnectOnly, // default true connectSpeeds: kConnectSpeeds, // default '[300, 1200, 2400, 4800, 7200, 9600, 12000, 14400] configSpeed: kConfigSpeed, // default 19200 (bps) commandTimeout: kCommandTimeout, // default 2000 (ms) maxCharsPerLine: kMaxCharsPerLine, // default 40 interCmdDelay: kInterCmdDelay, // default 25 (ms) modemIdStr: kModemIdStr, // default "unknown" configStrNoEC: kConfigStrNoEC, // default "ATE0&C1S12=12W2&K3&Q6\n" configStrECOnly: kConfigStrECOnly, // default nil configStrECAndFallback: kConfigStrECAndFallback, // default nil configStrCellular: kConfigStrCellular, // default nil configStrDirectConnect: kConfigStrDirectConnect, // default "ATE0&C1S12=12W2&K0&Q0\n" }, }, _proto: protoApp }; // After Script for "Installer" thisView := Installer; // Copyright © 1995 by Apple Computer, Inc. All rights reserved. RemoveSlot(thisView, 'viewBounds); RemoveSlot(thisView, '_proto); partData := { PT_modem: thisView }; InstallScript := func(partFrame, removeFrame) AddDeferredAction( func(partFrame) partFrame.partData.PT_modem:Install(), [partFrame] ); RemoveScript := nil; // ---- Beginning of section for non used Layout files ---- // End of output