void DrawBootloaderScreen(void)
{
#if BOOTLOADER
  FillMyBuffer(STARTING_ROW, LCD_ROW_NUM, 0x00);
  CopyRowsIntoMyBuffer(pBootloader, BOOTLOADER_START_ROW, BOOTLOADER_ROWS);
  
  // Draw version
  SetFont(MetaWatch5);
  gRow = 61;
  gColumn = 4;
  gBitColumnMask = BIT3;
  DrawString("V ", DRAW_OPT_BITWISE_OR);
  DrawString((char const *)VERSION, DRAW_OPT_BITWISE_OR);

  unsigned char i = 0;
  char const *pBootVer = BootVersion;

  PrintF("BL_VER addr:%04X", pBootVer);
  for (; i < 8; ++i) {PrintH(pBootVer[i]); PrintC(SPACE);}
  i = 0;

  while (*pBootVer && i++ < 8)
  {
    if ((*pBootVer < ZERO || *pBootVer > '9') && *pBootVer != '.') break;
    pBootVer ++;
  }
  
  if (i > 4) // at least x.x.x
  {
    gRow += 7;
    gColumn = 4;
    gBitColumnMask = BIT3;
    DrawString("B ", DRAW_OPT_BITWISE_OR);
    DrawString(BootVersion, DRAW_OPT_BITWISE_OR);
  }

  DrawLocalAddress(1, 80);
  
  SendMyBufferToLcd(STARTING_ROW, LCD_ROW_NUM);
#endif
}
int main() {

    int lock, condition, monitor, value, i;
    lock = CreateDistLock("DistLock", 8);
    condition = CreateDistCondition("DistCV",6);
    monitor = CreateDistMonitor("MonitorTest", 11, 10);

    AcquireDistLock(lock);
    /* Requires another program to be run that signals the lock*/
    WaitDistCondition(condition, lock);
    for(i = 0; i < 10; i++) {
        SetDistMonitor(monitor, i, i);
    }
    for(i = 0; i < 10; i++) {
        value = GetDistMonitor(monitor, i);
        PrintF("monitor[%d]: %d", sizeof("monitor[%d]: %d"), i, value);
    }
    DestroyDistMonitor(monitor);
    ReleaseDistLock(lock);
    DestroyCondition(condition);
    DestroyDistLock(lock);
}
Exemple #3
0
static void
StripUnneccesaryGlobEntries(const FTPCIPtr cip, FTPLineListPtr fileList)
{
    FTPLinePtr lp, nextLine;
    const char *cp;

    for (lp=fileList->first; lp != NULL; lp = nextLine)
    {
        nextLine = lp->next;
        cp = strrchr(lp->line, '/');
        if (cp == NULL)
            cp = strrchr(lp->line, '\\');
        if (cp == NULL)
            cp = lp->line;
        else
            cp++;
        if ((strcmp(cp, ".") == 0) || (strcmp(cp, "..") == 0))
        {
            PrintF(cip, "  Rglob omitted: [%s] (type 1)\n", lp->line);
            nextLine = RemoveLine(fileList, lp);
        }
    }
}	/* StripUnneccesaryGlobEntries */
Exemple #4
0
void CStatusBar::DrawShield (void)
{
	static int nIdShield = 0;

	int w, h, aw;
	char szShield [20];

CCanvas::Push ();
fontManager.SetScale (floor (float (CCanvas::Current ()->Width ()) / 640.0f));
CCanvas::SetCurrent (CurrentGameScreen ());
//LoadBitmap (gameData.pig.tex.cockpitBmIndex [gameStates.render.cockpit.nType + (gameStates.video.nDisplayMode ? gameData.models.nCockpits / 2 : 0)].index, 0);
fontManager.SetColorRGBi (BLACK_RGBA, 1, 0, 0);
Rect (SB_SHIELD_NUM_X, SB_SHIELD_NUM_Y, SB_SHIELD_NUM_X + (gameStates.video.nDisplayMode ? 27 : 13), SB_SHIELD_NUM_Y + m_info.fontHeight);
sprintf (szShield, "%d", m_info.nShields);
fontManager.Current ()->StringSize (szShield, w, h, aw);
fontManager.SetColorRGBi (RGBA_PAL2 (14, 14, 23), 1, 0, 0);
nIdShield = PrintF (&nIdShield, 
						  -(ScaleX (SB_SHIELD_NUM_X + (gameStates.video.nDisplayMode ? 13 : 6)) - w / 2), 
						  -(ScaleY (SB_SHIELD_NUM_Y) + HeightPad ()), 
						  "%d", m_info.nShields);
fontManager.SetScale (1.0f);
CCanvas::Pop ();
}
void PFonts::PrintOnScreen(float x, float y, float z, int Screenwidth, int Screenheight, 
						   const char *Text,int argument)
{
	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
	glPushMatrix();

	glLoadIdentity();							// Reset The Projection Matrix
	glOrtho(0,Screenwidth,0,Screenheight,-1,1); //Set orthographic projection based on the applications
	                                            // width and height

	if(z<-1)
	{
		z=-1;
	}

	if(z>1)
	{
		z=1;
	}

	glMatrixMode(GL_MODELVIEW);						// Select The Modelview Matrix
	glPushMatrix();								// Store The Modelview Matrix
	glLoadIdentity();

	glTranslatef(x,y,z);                   //Move to specified location on screen

	
	glRasterPos2f(0.0,0.0f);
	PrintF(Text,argument);

	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
	glPopMatrix();		

	glMatrixMode(GL_MODELVIEW);						// Select The Modelview Matrix
	glPopMatrix();

}
Exemple #6
0
void CCockpit::DrawEnergy (void)
{
	static int nIdEnergy = 0;

	char szEnergy [20];

#if 0
CBitmap* bmP = BitBlt (GAUGE_NUMERICAL, NUMERICAL_GAUGE_X, NUMERICAL_GAUGE_Y);
#else
PageInGauge (GAUGE_NUMERICAL);
CBitmap* bmP = gameData.pig.tex.bitmaps [0] + GaugeIndex (GAUGE_NUMERICAL);
#endif
CCanvas::Push ();
CCanvas::SetCurrent (CurrentGameScreen ());
fontManager.SetColorRGBi (RGBA_PAL2 (25, 18, 6), 1, 0, 0);
sprintf (szEnergy, "%d", m_info.nEnergy);
int w, h, aw;
fontManager.SetScale (floor (float (CCanvas::Current ()->Width ()) / 640.0f));
fontManager.Current ()->StringSize (szEnergy, w, h, aw);
nIdEnergy = PrintF (&nIdEnergy,-(ScaleX (NUMERICAL_GAUGE_X + bmP->Width () / 2) - w / 2), 
						  NUMERICAL_GAUGE_Y + (gameStates.video.nDisplayMode ? 5 : 2), szEnergy);
fontManager.SetScale (1.0f);
CCanvas::Pop ();
}
int main()
{
	/*all the error checking in exec is same as lock/cv so no need to repeat */

	PrintF("\nTrying invalid address in Fork:\n", sizeof("\nTrying invalid address in Fork:\n"), 0, 0);
	Fork((void*)4000);
	PrintF("\nTesting Exec\n", sizeof("\nTesting Exec\n"), 0, 0);
    Exec("../test/testfiles", 17);
    Fork(test);
    PrintF("\nTrying invalid address in Exec:\n", sizeof("\nTrying invalid address in Exec:\n"), 0, 0);
    Exec((char*) 33201, 4);
    PrintF("\nTrying invalid size in Exec:\n", sizeof("\nTrying invalid size in Exec:\n"), 0, 0);
    Exec("../test/testfiles", -1);
    PrintF("\nTrying executable name that doesn't exist:\n", sizeof("\nTrying executable name that doesn't exist:\n"), 0, 0);
    Exec("../test/nonsense", 16);
    PrintF("\nTesting Exec again\n", sizeof("\nTesting Exec again\n"), 0, 0);
    Exec("../test/testfiles", 17);

    /* DOESN"T PRINT CORRECT OUTPUT, BUT SHOWS THAT YOU CAN HAVE TWO PROCESSES GOING AT SAME TIME
    Exec("../test/lock_test", 17);
    Exec("../test/lock_test", 17);*/
}
Exemple #8
0
int
FTPLoginHost(const FTPCIPtr cip)
{
	ResponsePtr rp;
	int result = kErrLoginFailed;
	int anonLogin;
	int sentpass = 0;
	int fwloggedin;
	int firstTime;
	char cwd[512];

	if (cip == NULL)
		return (kErrBadParameter);
	if ((cip->firewallType < kFirewallNotInUse) || (cip->firewallType > kFirewallLastType))
		return (kErrBadParameter);

	if (strcmp(cip->magic, kLibraryMagic))
		return (kErrBadMagic);

	anonLogin = 0;
	if (cip->user[0] == '\0')
		(void) STRNCPY(cip->user, "anonymous");
	if ((strcmp(cip->user, "anonymous") == 0) || (strcmp(cip->user, "ftp") == 0)) {
		anonLogin = 1;
		/* Try to get the email address if you didn't specify
		 * a password when the user is anonymous.
		 */
		if (cip->pass[0] == '\0') {
			FTPInitializeAnonPassword(cip->lip);
			(void) STRNCPY(cip->pass, cip->lip->defaultAnonPassword);
		}
	}

	rp = InitResponse();
	if (rp == NULL) {
		result = kErrMallocFailed;
		cip->errNo = kErrMallocFailed;
		goto done2;
	}

	for (firstTime = 1, fwloggedin = 0; ; ) {
		/* Here's a mini finite-automaton for the login process.
		 *
		 * Originally, the FTP protocol was designed to be entirely
		 * implementable from a FA.  It could be done, but I don't think
		 * it's something an interactive process could be the most
		 * effective with.
		 */

		if (firstTime != 0) {
			rp->code = 220;
			firstTime = 0;
		} else if (result < 0) {
			goto done;
		}

		switch (rp->code) {
			case 220:	/* Welcome, ready for new user. */
				if ((cip->firewallType == kFirewallNotInUse) || (fwloggedin != 0)) {
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "USER %s", cip->user);
				} else if (cip->firewallType == kFirewallUserAtSite) {
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "USER %s@%s", cip->user, cip->host);
				} else if (cip->firewallType == kFirewallUserAtUserPassAtPass) {
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "USER %s@%s@%s", cip->user, cip->firewallUser, cip->host);
				} else if (cip->firewallType == kFirewallUserAtSiteFwuPassFwp) {
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "USER %s@%s %s", cip->user, cip->host, cip->firewallUser);
				} else if (cip->firewallType == kFirewallFwuAtSiteFwpUserPass) {
					/* only reached when !fwloggedin */
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "USER %s@%s", cip->firewallUser, cip->host);
				} else if (cip->firewallType > kFirewallNotInUse) {
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "USER %s", cip->firewallUser);
				} else {
					goto unknown;
				}
				break;

			case 230:	/* 230 User logged in, proceed. */
			case 231:	/* User name accepted. */
			case 202:	/* Command not implemented, superfluous at this site. */
				if ((cip->firewallType == kFirewallNotInUse) || (fwloggedin != 0))
					goto okay;

				/* Now logged in to the firewall. */
				fwloggedin++;

				if (cip->firewallType == kFirewallLoginThenUserAtSite) {
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "USER %s@%s", cip->user, cip->host);
				} else if (cip->firewallType == kFirewallUserAtUserPassAtPass) {
					goto okay;
				} else if (cip->firewallType == kFirewallOpenSite) {
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "OPEN %s", cip->host);
				} else if (cip->firewallType == kFirewallSiteSite) {
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "SITE %s", cip->host);
				} else if (cip->firewallType == kFirewallFwuAtSiteFwpUserPass) {
					/* only reached when !fwloggedin */
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "USER %s", cip->user);
				} else /* kFirewallUserAtSite */ {
					goto okay;
				}
				break;

			case 421:	/* 421 Service not available, closing control connection. */
				result = kErrHostDisconnectedDuringLogin;
				goto done;

			case 331:	/* 331 User name okay, need password. */
				if ((cip->firewallType == kFirewallNotInUse) || (fwloggedin != 0)) {
					if ((cip->pass[0] == '\0') && (cip->passphraseProc != NoGetPassphraseProc))
						(*cip->passphraseProc)(cip, &rp->msg, cip->pass, sizeof(cip->pass));
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "PASS %s", cip->pass);
				} else if (cip->firewallType == kFirewallUserAtSite) {
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "PASS %s", cip->pass);
				} else if (cip->firewallType == kFirewallUserAtUserPassAtPass) {
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "PASS %s@%s", cip->pass, cip->firewallPass);
				} else if (cip->firewallType == kFirewallUserAtSiteFwuPassFwp) {
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "PASS %s", cip->pass);
				} else if (cip->firewallType == kFirewallFwuAtSiteFwpUserPass) {
					/* only reached when !fwloggedin */
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "PASS %s", cip->firewallPass);
				} else if (cip->firewallType > kFirewallNotInUse) {
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "PASS %s", cip->firewallPass);
				} else {
					goto unknown;
				}
				sentpass++;
				break;

			case 332:	/* 332 Need account for login. */
			case 532: 	/* 532 Need account for storing files. */
				if ((cip->firewallType == kFirewallNotInUse) || (fwloggedin != 0)) {
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "ACCT %s", cip->acct);
				} else if (cip->firewallType == kFirewallUserAtSiteFwuPassFwp) {
					ReInitResponse(cip, rp);
					result = RCmd(cip, rp, "ACCT %s", cip->firewallPass);
				} else {
					/* ACCT not supported on firewall. */
					goto unknown;
				}
				break;

			case 530:	/* Not logged in. */
				result = (sentpass != 0) ? kErrBadRemoteUserOrPassword : kErrBadRemoteUser;
				goto done;

			case 501:	/* Syntax error in parameters or arguments. */
			case 503:	/* Bad sequence of commands. */
			case 550:	/* Can't set guest privileges. */
				goto done;

			default:
			unknown:
				if (rp->msg.first == NULL) {
					Error(cip, kDontPerror, "Lost connection during login.\n");
				} else {
					Error(cip, kDontPerror, "Unexpected response: %s\n",
						rp->msg.first->line
					);
				}
				goto done;
		}
	}

okay:
	/* Do the application's connect message callback, if present. */
	if (cip->onLoginMsgProc != 0)
		(*cip->onLoginMsgProc)(cip, rp);
	DoneWithResponse(cip, rp);
	result = 0;
	cip->loggedIn = 1;

	/* Make a note of what our root directory is.
	 * This is often different from "/" when not
	 * logged in anonymously.
	 */
	if (cip->startingWorkingDirectory != NULL) {
		free(cip->startingWorkingDirectory);
		cip->startingWorkingDirectory = NULL;
	}
	if ((cip->doNotGetStartingWorkingDirectory == 0) &&
		(FTPGetCWD(cip, cwd, sizeof(cwd)) == kNoErr))
	{
		cip->startingWorkingDirectory = StrDup(cwd);
	}

	/* When a new site is opened, ASCII mode is assumed (by protocol). */
	cip->curTransferType = 'A';
	PrintF(cip, "Logged in to %s as %s.\n", cip->host, cip->user);

	/* Don't leave cleartext password in memory. */
	if ((anonLogin == 0) && (cip->leavePass == 0))
		(void) memset(cip->pass, '*', strlen(cip->pass));

	if (result < 0)
		cip->errNo = result;
	return result;

done:
	DoneWithResponse(cip, rp);

done2:
	/* Don't leave cleartext password in memory. */
	if ((anonLogin == 0) && (cip->leavePass == 0))
		(void) memset(cip->pass, '*', strlen(cip->pass));
	if (result < 0)
		cip->errNo = result;
	return result;
}	/* FTPLoginHost */
Exemple #9
0
static void DrawCallNotification(unsigned char const *pVal, int Len)
{
    PrintW("-DrwCall:");
    PrintQ(pVal, Len);

    Draw_t const *pItem = CallItem;
    Draw_t Info;
    unsigned char i = 0;

    ClearSram(NOTIF_MODE);
    // quit icon
    memcpy(&Info, pItem++, sizeof(Draw_t));
    Draw(&Info, NULL, NOTIF_MODE);

    // small phone icon
    memcpy(&Info, pItem++, sizeof(Draw_t));
    Draw(&Info, NULL, NOTIF_MODE);

    // timestamp icon
    memcpy(&Info, pItem++, sizeof(Draw_t));
    Draw(&Info, NULL, NOTIF_MODE);

    // timestamp
    memcpy(&Info, pItem++, sizeof(Draw_t));
    Draw(&Info, NULL, NOTIF_MODE);

    // call from
    memcpy(&Info, pItem++, sizeof(Draw_t));
    Info.Width = sizeof(Text) - 1;
    Draw(&Info, Text, NOTIF_MODE);

    // caller name
    memcpy(&Info, pItem, sizeof(Draw_t));

    if (*pVal >= '0' && *pVal <= '9' || *pVal == '+')
    {
        SetCallerNumber(pVal, Len);
        pVal = NoName;
        Len = sizeof(NoName) - 1;
    }

    // split and draw first, last names and call number if available
//  while (Len >= 0)
//  {
//    i = 0; while (pVal[i] != SPACE && i < Len) i++;
//
//    PrintF(" W:%u", i);
//    Info.Width = i;
//    Draw(&Info, pVal, NOTIF_MODE);
//
//    memcpy(&Info, pItem, sizeof(Draw_t));
//    Info.Y += CALLER_NAME_HEIGHT;
//    pVal += i + 1;
//    Len -= i + 1;
//  }

    i = 0;
    while (pVal[i] != SPACE && i < Len) i++;

    PrintF(" W:%u", i);
    Info.Width = i;
    Draw(&Info, pVal, NOTIF_MODE);

    if (i < Len - 1)
    {
        memcpy(&Info, pItem, sizeof(Draw_t));
        Info.Y += CALLER_NAME_HEIGHT;
        pVal += i + 1;
        Len -= i + 1;
        Info.Width = Len;
        Draw(&Info, pVal, NOTIF_MODE);
    }

    if (pCallerNumber)
    {
        memcpy(&Info, &CallItem[CALLER_NUMBER_ITEM], sizeof(Draw_t));
        Info.Width = NumberLen;
        Draw(&Info, pCallerNumber, NOTIF_MODE);

        vPortFree(pCallerNumber);
        pCallerNumber = NULL;
    }

    CreateAndSendMessage(ChangeModeMsg, NOTIF_MODE | MSG_OPT_UPD_INTERNAL);
}
Exemple #10
0
void vApplicationStackOverflowHook(xTaskHandle *pxTask, char *pcTaskName)
{
  /* try to print task name */
  PrintF("# Stack overflow:%s",(tString*)pcTaskName);
  SoftwareReset();
}
Exemple #11
0
void PrettyPrinter::PrintOut(Zone* zone, AstNode* node) {
  PrettyPrinter printer(zone);
  PrintF("%s", printer.Print(node));
}
Exemple #12
0
void
RemoteGlobCollapse(const FTPCIPtr cip, const char *pattern, FTPLineListPtr fileList)
{
    FTPLinePtr lp, nextLine;
    char *patPrefix;
    char *patDir;
    char *cur, *prev;
    char *cp;
    char *newpath;
    size_t plen;

    /* Copy all characters before and including the last path delimiter. */
    patDir = NULL;
    cp = StrRFindLocalPathDelim(pattern);
    if (cp != NULL)
    {
        patDir = StrDup(pattern);
        if (patDir == NULL)
            return;
        patDir[(cp - pattern) + 1] = '\0';
    }

    /* Copy all characters before the first glob-char. */
    cp = strpbrk(pattern, kGlobChars);
    patPrefix = StrDup(pattern);
    if (patPrefix == NULL)
    {
        free(patDir);
        return;
    }
    if (cp != NULL)
    {
        plen = (size_t) (cp - pattern);
        patPrefix[plen] = '\0';
    }
    else
    {
        plen = strlen(patPrefix);
    }

    cur = prev = NULL;
    for (lp=fileList->first; lp != NULL; lp = nextLine)
    {
        nextLine = lp->next;
        if (ISTRNEQ(lp->line, patPrefix, plen))
        {
            if (Dynsrecpy(&cur, lp->line + plen, 0) == NULL)
                goto done;
            cp = strpbrk(cur, "/\\");
            if (cp != NULL)
                *cp = '\0';
            if ((prev != NULL) && (STREQ(cur, prev)))
            {
                PrintF(cip, "  Rglob omitted: [%s] (type 2)\n", lp->line);
                nextLine = RemoveLine(fileList, lp);
            }
            else if (PathContainsIntermediateDotDotSubDir(lp->line + plen))
            {
                PrintF(cip, "  Rglob omitted: [%s] (type 3)\n", lp->line);
                nextLine = RemoveLine(fileList, lp);
            }
            else
            {
                if (Dynsrecpy(&prev, cur, 0) == NULL)
                    goto done;

                /* We are playing with a dynamically
                 * allocated string, but since the
                 * following expression is guaranteed
                 * to be the same or shorter, we won't
                 * overwrite the bounds.
                 */
                (void) sprintf(lp->line, "%s%s", patPrefix, cur);
            }
        }
        else if (strpbrk(lp->line, "/\\") == NULL)
        {
            if (patDir != NULL)
            {
                newpath = NULL;
                if (Dynsrecpy(&newpath, patDir, lp->line, 0) == NULL)
                    goto done;
                PrintF(cip, "  Rglob changed: [%s] to [%s]\n", lp->line, newpath);
                free(lp->line);
                lp->line = newpath;
            }
        }
        else
        {
            PrintF(cip, "  Rglob omitted: [%s] (type 4)\n", lp->line);
            nextLine = RemoveLine(fileList, lp);
        }
    }

done:
    StrFree(&patDir);
    StrFree(&patPrefix);
    StrFree(&cur);
    StrFree(&prev);
}	/* RemoteGlobCollapse */
Exemple #13
0
int
FTPRemoteGlob(FTPCIPtr cip, FTPLineListPtr fileList, const char *pattern, int doGlob)
{
    char *cp;
    const char *lsflags;
    FTPLinePtr lp;
    int result;

    if (cip == NULL)
        return (kErrBadParameter);
    if (strcmp(cip->magic, kLibraryMagic))
        return (kErrBadMagic);

    if (fileList == NULL)
        return (kErrBadParameter);
    InitLineList(fileList);

    if ((pattern == NULL) || (pattern[0] == '\0'))
        return (kErrBadParameter);

    /* Note that we do attempt to use glob characters even if the remote
     * host isn't UNIX.  Most non-UNIX remote FTP servers look for UNIX
     * style wildcards.
     */
    if ((doGlob == 1) && (GLOBCHARSINSTR(pattern)))
    {
        /* Use NLST, which lists files one per line. */
        lsflags = "";

        /* Optimize for "NLST *" case which is same as "NLST". */
        if (strcmp(pattern, "*") == 0)
        {
            pattern = "";
            lsflags = (cip->hasNLST_a == kCommandNotAvailable) ? "" : "-a";
        }
        else if (strcmp(pattern, "**") == 0)
        {
            /* Hack; Lets you try "NLST -a" if you're daring. */
            /* Need to use "NLST -a" whenever possible,
             * because wu-ftpd doesn't do NLST right, IMHO.
             * (It doesn't include directories in the NLST
             *  if you do "NLST /the/dir" without -a.)
             */
            pattern = "";
            lsflags = (cip->hasNLST_a == kCommandNotAvailable) ? "" : "-a";
        }

        if ((result = FTPListToMemory2(cip, pattern, fileList, lsflags, 0, (int *) 0)) < 0)
        {
            if (*lsflags == '\0')
                return (result);
            if (strchr(lsflags, 'a') != NULL)
            {
                /* Try again, without "-a" */
                cip->hasNLST_a = kCommandNotAvailable;
                lsflags = "";
                if ((result = FTPListToMemory2(cip, pattern, fileList, lsflags, 0, (int *) 0)) < 0)
                {
                    return (result);
                }
                /* else proceed */
            }
            else
            {
                return (result);
            }
        }
#if 0
        DisposeLineListContents(fileList);
        InitLineList(fileList);
        AddLine(fileList, "../FAKEME1.txt");
        AddLine(fileList, "../../FAKEME2.txt");
        AddLine(fileList, "..\\FAKEME3.txt");
        AddLine(fileList, "..\\..\\FAKEME4.txt");
        AddLine(fileList, "...\\FAKEME5.txt");
        AddLine(fileList, "/tmp/bad/FAKEME6.txt");
        AddLine(fileList, "c:\\temp\\FAKEME7.txt");
        AddLine(fileList, "foo/../FAKEME8.txt");
        AddLine(fileList, "foo\\bar\\...\\FAKEME9.txt");
#endif
        if (fileList->first == NULL)
        {
            cip->errNo = kErrGlobNoMatch;
            return (kErrGlobNoMatch);
        }
        if (fileList->first == fileList->last)
        {
#define glberr(a) (ISTRNEQ(cp, a, strlen(a)))
            /* If we have only one item in the list, see if it really was
             * an error message we would recognize.
             */
            cp = strchr(fileList->first->line, ':');
            if (cp != NULL)
            {
                if (glberr(": No such file or directory"))
                {
                    (void) RemoveLine(fileList, fileList->first);
                    cip->errNo = kErrGlobFailed;
                    return (kErrGlobFailed);
                }
                else if (glberr(": No match"))
                {
                    cip->errNo = kErrGlobNoMatch;
                    return (kErrGlobNoMatch);
                }
            }
        }
        StripUnneccesaryGlobEntries(cip, fileList);
        RemoteGlobCollapse(cip, pattern, fileList);
        for (lp=fileList->first; lp != NULL; lp = lp->next)
            PrintF(cip, "  Rglob [%s]\n", lp->line);
    }
    else
    {
        /* Or, if there were no globbing characters in 'pattern', then the
         * pattern is really just a filename.  So for this case the
         * file list is really just a single file.
         */
        fileList->first = fileList->last = NULL;
        (void) AddLine(fileList, pattern);
    }
    return (kNoErr);
}	/* FTPRemoteGlob */
/*! Handle the messages routed to the display queue */
static void DisplayQueueMessageHandler(tMessage* pMsg)
{
  tMessage Msg;
  unsigned char i = 0;

  switch (pMsg->Type)
  {
  case WriteBufferMsg:
    WriteBufferHandler(pMsg);
    break;

  case SetWidgetListMsg:
    SetWidgetList(pMsg);
    break;
  
  case UpdateDisplayMsg:
    if ((!(pMsg->Options & MSG_OPT_UPD_INTERNAL) &&
          (pMsg->Options & MODE_MASK) == NOTIF_MODE) &&
        GetProperty(PROP_AUTO_BACKLIGHT))
      SendMessage(&Msg, AutoBacklightMsg, MSG_OPT_NONE);

    UpdateDisplayHandler(pMsg);
    break;
    
  case UpdateClockMsg:
    UpdateClock();
    break;
    
  case DrawClockWidgetMsg:
    DrawClockWidget(pMsg->Options);
    break;

  case MonitorBatteryMsg:
    MonitorBattery();
    break;

  case BluetoothStateChangeMsg:
    BluetoothStateChangeHandler(pMsg);
    break;

  case IdleUpdateMsg:
    IdleUpdateHandler();
    break;

  case ButtonStateMsg:
    ButtonStateHandler();
    break;

  case CallerIdMsg:
    pMsg->pBuffer[pMsg->Length] = NUL;
    ShowCall((char *)pMsg->pBuffer, pMsg->Options);
    break;
    
  case CallerNameMsg:
    if (pMsg->Length)
    {
      pMsg->pBuffer[pMsg->Length] = NUL;
      ShowCall((char *)pMsg->pBuffer, SHOW_NOTIF_CALLER_NAME);

      if (GetProperty(PROP_AUTO_BACKLIGHT)) SendMessage(&Msg, AutoBacklightMsg, MSG_OPT_NONE);
    }
    else ShowCall("", pMsg->Options);
    break;

  case MusicPlayStateMsg:
    HandleMusicPlayStateChange(pMsg->Options);
    break;
    
  case ChangeModeMsg:
    ChangeModeHandler(pMsg->Options);
    break;
  
  case ControlFullScreenMsg:
    SetProperty(PROP_PHONE_DRAW_TOP, pMsg->Options || *pMsg->pBuffer ? PROP_PHONE_DRAW_TOP : 0);
    break;

  case ModifyTimeMsg:
    ModifyTimeHandler(pMsg);
    break;

  case MenuModeMsg:
    MenuModeHandler(pMsg->Options);
    break;

  case MenuButtonMsg:
    MenuButtonHandler(pMsg->Options);
    break;

  case EnableButtonMsg:
    EnableButtonMsgHandler(pMsg);
    break;

  case DevTypeMsg:

    SetupMessageWithBuffer(&Msg, DevTypeRespMsg, BOARD_TYPE); //default G2
    if (Msg.pBuffer != NULL)
    {
      Msg.pBuffer[0] = BOARD_TYPE; // backward compatible
      Msg.Length = 1;

      if (GetMsp430HardwareRevision() < 'F')
      {
        Msg.Options = DIGITAL_WATCH_TYPE_G1;
        Msg.pBuffer[0] = DIGITAL_WATCH_TYPE_G1; // backward compatible
      }

      Msg.Options |= pMsg->Options & 0x80; // support ACK
      RouteMsg(&Msg);
    }

    PrintF("- DevTypeResp:%d", Msg.Options);

    // set ACK bit
    SendMessage(&Msg, ConnTypeMsg, pMsg->Options);
    break;

  case VerInfoMsg:
    SetupMessageWithBuffer(&Msg, VerInfoRespMsg, MSG_OPT_NONE);
    if (Msg.pBuffer != NULL)
    {
      /* exclude middle '.' */
      strncpy((char *)Msg.pBuffer, BUILD, 3);
      strncpy((char *)Msg.pBuffer + 3, BUILD + 4, 3);
      Msg.Length += strlen(BUILD) - 1;
        
      *(Msg.pBuffer + Msg.Length++) = (unsigned char)atoi(VERSION);
      
      while (VERSION[i++] != '.');
      *(Msg.pBuffer + Msg.Length++) = atoi(VERSION + i);
      *(Msg.pBuffer + Msg.Length++) = NULL;
      
      RouteMsg(&Msg);
    }
    PrintS("-Ver:"); for (i = 6; i < Msg.Length; ++i) PrintH(Msg.pBuffer[i]);
    break;
    
  case SetVibrateMode:
    SetVibrateModeHandler(pMsg);
    break;

  case SetRtcMsg:
    SetRtc((Rtc_t *)pMsg->pBuffer);

#if COUNTDOWN_TIMER
    if (CurrentPage[PageType] == CountdownPage && CountdownMode() == COUNTING)
      SendMessage(&Msg, CountDownMsg, MSG_OPT_CNTDWN_TIME);
#endif
    UpdateClock();
    break;
    
#if COUNTDOWN_TIMER
  case CountDownMsg:
    if (pMsg->Options == MSG_OPT_NONE)
    {
      PageType = PAGE_TYPE_INFO;
      CurrentPage[PageType] = CountdownPage;
    }
    DrawCountdownScreen(pMsg->Options);
    break;

  case SetCountdownDoneMsg:
    // for testing
//    Rtc_t Done;
//    Done.Month = 5;
//    Done.Day = 1;
//    Done.Hour = 0;
//    Done.Minute = 0;
//    SetDoneTime(&Done);

    // Valid only DoneTime is different
    if (SetDoneTime((Rtc_t *)pMsg->pBuffer)) SendMessage(&Msg, CountDownMsg, MSG_OPT_NONE);
    break;
#endif

  case ServiceMenuMsg:
    ServiceMenuHandler();
    break;
    
  case DisableButtonMsg:
    DisableButtonMsgHandler(pMsg);
    break;

  case ReadButtonConfigMsg:
    ReadButtonConfigHandler(pMsg);
    break;

  case SetBacklightMsg:
    SetBacklight(pMsg->Options);
    // testing
//    pMsg->Type = AccelMsg;
//    pMsg->Options = 1; //enable
//    HandleAccelerometer(pMsg);
    break;

  case AutoBacklightMsg:
    if (LightSenseCycle() < DARK_LEVEL) SetBacklight(LED_ON_OPTION);
    break;

  case BatteryConfigMsg:
    SetBatteryLevels(pMsg->pBuffer);
    break;

  case ReadBatteryVoltageMsg:
    ReadBatteryVoltageHandler();
    break;

  case ResetMsg:
    SoftwareResetHandler(pMsg);
    break;

  case NvalOperationMsg:
    NvalOperationHandler(pMsg);
    break;

  case SecInvertMsg:
    HandleSecInvert(pMsg->Options);
    break;

  case LoadTemplateMsg:
    LoadTemplateHandler(pMsg);
    break;

  case LinkAlarmMsg:
    if (LinkAlarmEnable)
    {
      SetupMessageWithBuffer(&Msg, SetVibrateMode, MSG_OPT_NONE);
      if (Msg.pBuffer != NULL)
      {
        *(tSetVibrateModePayload *)Msg.pBuffer = LnkAlmTone;
        RouteMsg(&Msg);
      }
    }
    break;

  case ModeTimeoutMsg:
    ModeTimeoutHandler();
    break;

  case WatchStatusMsg:
    PageType = PAGE_TYPE_INFO;
    CurrentPage[PageType] = StatusPage;
    DrawWatchStatusScreen();
    break;

//  case ListPairedDevicesMsg:
//    ListPairedDevicesHandler();
//    break;

  case WatchDrawnScreenTimeout:
    IdleUpdateHandler();
    break;

  case TermModeMsg:
    TermModeHandler();
    break;
    
  case LowBatteryWarningMsg:
    break;
    
  case LowBatteryBtOffMsg:
    UpdateClock();
    break;

#if __IAR_SYSTEMS_ICC__
  case EraseTemplateMsg:
    EraseTemplateHandler(pMsg);
    break;
    
  case WriteToTemplateMsg:
    WriteToTemplateHandler(pMsg);
    break;
#endif

  case AccelMsg:
    HandleAccelerometer(pMsg);
    break;

  case ReadLightSensorMsg:
    ReadLightSensorHandler();
    break;

  case RateTestMsg:
    SetupMessageWithBuffer(&Msg, DiagnosticLoopback, MSG_OPT_NONE);
    if (Msg.pBuffer != NULL)
    {
      /* don't care what data is */
      Msg.Length = 10;
      RouteMsg(&Msg);
    }
    break;
    
  default:
    PrintF("# Disp Msg: 0x%02x", pMsg->Type);
    break;
  }
}
void Init(void)
{  
  __disable_interrupt();

  ENABLE_LCD_LED();
  DISABLE_LCD_POWER();

  /* clear shipping mode, if set to allow configuration */
  PMMCTL0_H = PMMPW_H;
  PM5CTL0 &= ~LOCKLPM5;  
  PMMCTL0_H = 0x00;
  
  /* disable DMA during read-modify-write cycles */
  DMACTL4 = DMARMWDIS;

#ifdef BOOTLOADER
  /*
   * enable RAM alternate interrupt vectors
   * these are defined in AltVect.s43 and copied to RAM by cstartup
   */
  SYSCTL |= SYSRIVECT;
  ClearBootloaderSignature();
#else
  SaveResetSource();
#endif
  
  SetupClockAndPowerManagementModule();
  
  CheckResetCode();
  if (niReset != NORMAL_RESET_CODE)
  {
    InitProperty();
#if COUNTDOWN_TIMER
    InitCountdown();
#endif
  }
  
  InitBufferPool(); // message queue

  InitBattery();
  CheckClip();

  PrintF("*** %s:%s ***", niReset == FLASH_RESET_CODE ? "FLASH" :
    (niReset == MASTER_RESET_CODE ? "MASTER" : "NORMAL"), niBuild);
  
  ShowWatchdogInfo();
  WhoAmI();

  /* timer for battery checking at a regular frequency. */
  StartTimer(BatteryTimer);

  InitVibration();
  InitRealTimeClock(); // enable rtc interrupt

  LcdPeripheralInit();
  DrawSplashScreen();
  SerialRamInit();

  /* turn the radio on; initialize the serial port profile or BLE/GATT */
  CreateAndSendMessage(TurnRadioOnMsg, MSG_OPT_NONE);

  DISABLE_LCD_LED();
}
Exemple #16
0
void PrettyPrinter::PrintOut(AstNode* node) {
    PrettyPrinter printer;
    PrintF("%s", printer.Print(node));
}
Exemple #17
0
Fichier : Get.c Projet : aosm/ncftp
/* We need to make something we can give to popen.  This is simple
 * if it is a plain file, but if they wanted to page a compressed
 * file we have to prepend the correct filter before the pager name.
 */
int MakePageCmdLine(char *cmd, size_t siz, char *remote_file)
{
	int useZCat;
	int useGZCat;
	int binaryPage;
	int len;
	
	useZCat = 0;
	useGZCat = 0;
	binaryPage = 0;
	
	len = (int) strlen(remote_file);

	if (len > 2) {
 		    if (remote_file[len - 2] == '.') {
			/* Check for .Z files. */
			if (remote_file[len-1] == 'Z')
				useZCat = 1;

			/* Check for .z (gzip) files. */
			if (remote_file[len - 1] == 'z')
				useGZCat = 1;
		}
	}

	if (len > 3) {
		/* Check for ".gz" (gzip) files. */
		if (STREQ(remote_file + len - 3, ".gz"))
			useGZCat = 1;
	}

	/* Run compressed remote files through zcat, then the pager.
	 * If GZCAT was defined, we also try paging gzipped files.
	 */	
	if (useGZCat) {
#ifdef GZCAT
		(void) Strncpy(cmd, GZCAT, siz);
		(void) Strncat(cmd, " | ", siz);
		(void) Strncat(cmd, gPager, siz);
#else
		PrintF("NcFTP wasn't configured to page gzipped files.\n");
#endif
	} else if (useZCat) {
#ifdef ZCAT
		(void) Strncpy(cmd, ZCAT, siz);
		(void) Strncat(cmd, " | ", siz);
		(void) Strncat(cmd, gPager, siz);
#else
#	ifdef GZCAT
		/* gzcat can do .Z's also. */
		(void) Strncpy(cmd, GZCAT, siz);
		(void) Strncat(cmd, " | ", siz);
		(void) Strncat(cmd, gPager, siz);
#	else
		PrintF("NcFTP wasn't configured to page compressed files.\n");
#	endif
#endif
	} else {
		(void) Strncpy(cmd, gPager, siz);
	}

	binaryPage = (useZCat || useGZCat);
	return (binaryPage);
}	/* MakePageCmdLine */
Exemple #18
0
void SetWidgetList(tMessage *pMsg)
{
  static Widget_t *pCurrWidget = NULL; // point to Widget in current Widget[]
  static Widget_t *pNextWidget = NULL; // point to Widget in new Widget[]
  static unsigned char ChangedClockWidget = INVALID_ID;

  xSemaphoreTake(SramMutex, portMAX_DELAY);

  WidgetList_t *pMsgWgtLst = (WidgetList_t *)pMsg->pBuffer;
  unsigned char WidgetNum = pMsg->Length / WIDGET_HEADER_LEN;

  unsigned char i = 0;
  PrintF(">SetWLst I:%d %s %d %s %d", WGTLST_INDEX(pMsg->Options), "T:", WGTLST_TOTAL(pMsg->Options), "Num:", WidgetNum);
  for(; i<WidgetNum; ++i) {PrintH(pMsgWgtLst[i].Id); PrintH(pMsgWgtLst[i].Layout);} PrintR();

  if (pNextWidget == NULL) // first time call, only add widgets
  {
    pCurrWidget = pCurrWidgetList;
    pNextWidget = &Widget[0];
  }
  else
  {
    if (WGTLST_INDEX(pMsg->Options) == 0 &&
      (pCurrWidget != pCurrWidgetList || (pNextWidget != &Widget[0] && pNextWidget != &Widget[MAX_WIDGET_NUM])))
    { // last SetWLst failed in the middle.Clean up whole list
      PrintS("# Last SetWgtLst broken!");

      pCurrWidget = pCurrWidgetList;
      pNextWidget = &Widget[0] + (&Widget[MAX_WIDGET_NUM] - pCurrWidgetList);
    }
  }

  while (WidgetNum) // number of list items
  {
      /* old clock widgets */
    if (!IS_CLOCK_WIDGET(pMsgWgtLst->Layout) && pMsgWgtLst->Id <= CLOCK_WIDGET_ID_RANGE) TestFaceId(pMsgWgtLst);
    unsigned char Change = GetWidgetChange(pCurrWidget->Id, pCurrWidget->Layout, pMsgWgtLst->Id, pMsgWgtLst->Layout);
    
    switch (Change)
    {
    case WGT_CHG_CLK_FACE:
      PrintS("Chg ClkFce");
      if (ON_CURRENT_PAGE(pMsgWgtLst->Layout)) ChangedClockWidget = pMsgWgtLst->Id;
      
    case WGT_CHG_SETTING:
     //cpy layout to curr; cpy curr to next; msg, curr, next ++
      PrintF("=%02X", pCurrWidget->Id);
      pCurrWidget->Id = pMsgWgtLst->Id;
      pCurrWidget->Layout = pMsgWgtLst->Layout;
      *pNextWidget++ = *pCurrWidget++;
      pMsgWgtLst ++;
      WidgetNum --;
      break;

    case WGT_CHG_CLK_ADD:
      PrintS("+Clk");
      if (ON_CURRENT_PAGE(pMsgWgtLst->Layout)) ChangedClockWidget = pMsgWgtLst->Id;

    case WGT_CHG_ADD: //pCurrWidget->Id > pMsgWgtLst->Id)
     // add new widget: cpy msg to next; msg and next ++; curr stays
      PrintF("+%02X", pMsgWgtLst->Id);

      pNextWidget->Id = pMsgWgtLst->Id;
      pNextWidget->Layout = pMsgWgtLst->Layout;
      AssignWidgetBuffer(pNextWidget);

      pNextWidget ++;
      pMsgWgtLst ++;
      WidgetNum --;
      break;
      
    case WGT_CHG_REMOVE:
    // remove widget: curr ++
      PrintF("-%02X", pCurrWidget->Id);
      FreeWidgetBuffer(pCurrWidget);
      pCurrWidget ++;
      break;
      
    default: break;
    }
  }
  PrintR();

  // if part index + 1 == parts, SetWidgetList complete
  if (WGTLST_TOTAL(pMsg->Options) == WGTLST_INDEX(pMsg->Options) + 1)
  {
//    PrintS("C:");
//    for (i=0; pCurrWidgetList[i].Id != INVALID_ID && i < MAX_WIDGET_NUM; ++i) PrintH(pCurrWidgetList[i].Id);
//    PrintR();

    while (pCurrWidget->Id != INVALID_ID && pCurrWidget < &pCurrWidgetList[MAX_WIDGET_NUM])
    {
      FreeWidgetBuffer(pCurrWidget);
      pCurrWidget->Id = INVALID_ID;
      pCurrWidget ++;
    }

    for (i = 0; i < MAX_WIDGET_NUM; ++i)
    {
      if (pCurrWidgetList[i].Id != INVALID_ID)
      { // clear the widget id in the curr list
        pCurrWidgetList[i].Id = INVALID_ID;
      }
    }

    pNextWidget = pCurrWidgetList;
    pCurrWidgetList = &Widget[0] + (&Widget[MAX_WIDGET_NUM] - pCurrWidgetList);
    pCurrWidget = pCurrWidgetList;

//    PrintS("N:");
//    for (i=0; pCurrWidgetList[i].Id != INVALID_ID; ++i) PrintH(pCurrWidgetList[i].Id);
//    PrintR();
    PrintF("Tg:%04X", BufTag);

    if (ChangedClockWidget != INVALID_ID)
    {
      CreateAndSendMessage(DrawClockWidgetMsg, ChangedClockWidget);
      ChangedClockWidget = INVALID_ID;
    }
  }
  xSemaphoreGive(SramMutex);
}
Exemple #19
0
int
FTPPutFiles3(
    const FTPCIPtr cip,
    const char *const pattern,
    const char *const dstdir1,
    const int recurse,
    const int doGlob,
    const int xtype,
    int appendflag,
    const char *const tmppfx,
    const char *const tmpsfx,
    const int resumeflag,
    const int deleteflag,
    const FTPConfirmResumeUploadProc resumeProc,
    int UNUSED(reserved))
{
    FTPLineList globList;
    FTPFileInfoList files;
    FTPFileInfoPtr filePtr;
    int batchResult;
    int result;
    const char *dstdir;
    char dstdir2[512];

    LIBNCFTP_USE_VAR(reserved);
    if (cip == NULL)
        return (kErrBadParameter);
    if (strcmp(cip->magic, kLibraryMagic))
        return (kErrBadMagic);

    if (dstdir1 == NULL)
    {
        dstdir = NULL;
    }
    else
    {
        dstdir = STRNCPY(dstdir2, dstdir1);
        StrRemoveTrailingLocalPathDelim(dstdir2);
    }

    (void) FTPLocalGlob(cip, &globList, pattern, doGlob);
    if (recurse == kRecursiveYes)
    {
        appendflag = kAppendNo;
        (void) FTPLocalRecursiveFileList(cip, &globList, &files);
        if (files.first == NULL)
        {
            cip->errNo = kErrNoValidFilesSpecified;
            return (kErrNoValidFilesSpecified);
        }
        (void) ComputeRNames(&files, dstdir, 0, 1);
    }
    else
    {
        (void) LineListToFileInfoList(&globList, &files);
        (void) ComputeLNames(&files, NULL, NULL, 1);
        (void) ComputeRNames(&files, dstdir, 0, 0);
    }
    DisposeLineListContents(&globList);

#if 0
    for (filePtr = files.first; filePtr != NULL; filePtr = filePtr->next)
    {
        PrintF(cip, "  R=%s, L=%s, 2=%s, size=%lld, mdtm=%u, type=%c\n",
               filePtr->rname,
               filePtr->lname,
               filePtr->rlinkto ? filePtr->rlinkto : "",
               filePtr->size,
               (unsigned int) filePtr->mdtm,
               filePtr->type
              );
    }
#endif

    batchResult = kNoErr;
    for (filePtr = files.first; filePtr != NULL; filePtr = filePtr->next)
    {
        if (cip->connected == 0)
        {
            if (batchResult == kNoErr)
                batchResult = kErrRemoteHostClosedConnection;
            break;
        }
        if (filePtr->type == 'd')
        {
            /* mkdir */
            StrRemoveTrailingLocalPathDelim(filePtr->rname);
            result = FTPMkdir(cip, filePtr->rname, kRecursiveNo);
            if (result != kNoErr)
                batchResult = result;
#ifdef HAVE_SYMLINK
        }
        else if (filePtr->type == 'l')
        {
            /* symlink */
            /* no RFC way to create the link, though. */
            if ((filePtr->rlinkto != NULL) && (filePtr->rlinkto[0] != '\0'))
                (void) FTPSymlink(cip, filePtr->rname, filePtr->rlinkto);
#endif
        }
        else if (recurse != kRecursiveYes)
        {
            result = FTPPutOneF(cip, filePtr->lname, filePtr->rname, xtype, -1, appendflag, tmppfx, tmpsfx, resumeflag, deleteflag, resumeProc);
            if (files.nFileInfos == 1)
            {
                if (result != kNoErr)
                    batchResult = result;
            }
            else
            {
                if ((result != kNoErr) && (result != kErrLocalFileNewer) && (result != kErrRemoteFileNewer) && (result != kErrRemoteSameAsLocal))
                    batchResult = result;
            }
            if (result == kErrUserCanceled)
                cip->cancelXfer = 1;
            if (cip->cancelXfer > 0)
                break;
        }
        else
        {
            result = FTPPutOneF(cip, filePtr->lname, filePtr->rname, xtype, -1, appendflag, tmppfx, tmpsfx, resumeflag, deleteflag, resumeProc);
            if (files.nFileInfos == 1)
            {
                if (result != kNoErr)
                    batchResult = result;
            }
            else
            {
                if ((result != kNoErr) && (result != kErrLocalFileNewer) && (result != kErrRemoteFileNewer) && (result != kErrRemoteSameAsLocal))
                    batchResult = result;
            }
            if (result == kErrUserCanceled)
                cip->cancelXfer = 1;
            if (cip->cancelXfer > 0)
                break;
        }
    }
    DisposeFileInfoListContents(&files);
    if (batchResult < 0)
        cip->errNo = batchResult;
    return (batchResult);
}	/* FTPPutFiles3 */
Exemple #20
0
int
FTPOpenHost(const FTPCIPtr cip)
{
	int result;
	time_t t0, t1;
	int elapsed;
	int dials;

	if (cip == NULL)
		return (kErrBadParameter);
	if (strcmp(cip->magic, kLibraryMagic))
		return (kErrBadMagic);

	if (cip->host[0] == '\0') {
		cip->errNo = kErrBadParameter;
		return (kErrBadParameter);
	}

	for (	result = kErrConnectMiscErr, dials = 0;
		cip->maxDials < 0 || dials < cip->maxDials;
		dials++)
	{
		/* Allocate (or if the host was closed, reallocate)
		 * the transfer data buffer.
		 */
		result = FTPAllocateHost(cip);
		if (result < 0)
			return (result);

		if (dials > 0)
			PrintF(cip, "Retry Number: %d\n", dials);
		if (cip->redialStatusProc != 0)
			(*cip->redialStatusProc)(cip, kRedialStatusDialing, dials);
		(void) time(&t0);
		result = OpenControlConnection(cip, cip->host, cip->port);
		(void) time(&t1);
		if (result == kNoErr) {
			/* We were hooked up successfully. */
			PrintF(cip, "Connected to %s.\n", cip->host);

			result = FTPLoginHost(cip);
			if (result == kNoErr) {
				(void) FTPQueryFeatures(cip);
				break;
			}

			/* Close and try again. */
			(void) FTPCloseHost(cip);

			/* Originally we also stopped retyring if
			 * we got kErrBadRemoteUser and non-anonymous,
			 * but some FTP servers apparently do their
			 * max user check after the username is sent.
			 */
			if (result == kErrBadRemoteUserOrPassword /* || (result == kErrBadRemoteUser) */) {
				if (strcmp(cip->user, "anonymous") != 0) {
					/* Non-anonymous login was denied, and
					 * retrying is not going to help.
					 */
					break;
				}
			}
		} else if ((result != kErrConnectRetryableErr) && (result != kErrConnectRefused) && (result != kErrRemoteHostClosedConnection)) {
			/* Irrecoverable error, so don't bother redialing.
			 * The error message should have already been printed
			 * from OpenControlConnection().
			 */
			PrintF(cip, "Cannot recover from miscellaneous open error %d.\n", result);
			return result;
		}

		/* Retryable error, wait and then redial. */
		if (cip->redialDelay > 0) {
			/* But don't sleep if this is the last loop. */
			if ((cip->maxDials < 0) || (dials < (cip->maxDials - 1))) {
				elapsed = (int) (t1 - t0);
				if (elapsed < cip->redialDelay) {
					PrintF(cip, "Sleeping %u seconds.\n",
						(unsigned) cip->redialDelay - elapsed);
					if (cip->redialStatusProc != 0)
						(*cip->redialStatusProc)(cip, kRedialStatusSleeping, cip->redialDelay - elapsed);
					(void) sleep((unsigned) cip->redialDelay - elapsed);
				}
			}
		}
	}
	return (result);
}	/* FTPOpenHost */
Exemple #21
0
int
FTPOpenHostNoLogin(const FTPCIPtr cip)
{
	int result;
	time_t t0, t1;
	int elapsed;
	int dials;

	if (cip == NULL)
		return (kErrBadParameter);
	if (strcmp(cip->magic, kLibraryMagic))
		return (kErrBadMagic);

	if (cip->host[0] == '\0') {
		cip->errNo = kErrBadParameter;
		return (kErrBadParameter);
	}

	for (	result = kErrConnectMiscErr, dials = 0;
		cip->maxDials < 0 || dials < cip->maxDials;
		dials++)
	{

		/* Allocate (or if the host was closed, reallocate)
		 * the transfer data buffer.
		 */
		result = FTPAllocateHost(cip);
		if (result < 0)
			return (result);

		if (dials > 0)
			PrintF(cip, "Retry Number: %d\n", dials);
		if (cip->redialStatusProc != 0)
			(*cip->redialStatusProc)(cip, kRedialStatusDialing, dials);
		(void) time(&t0);
		result = OpenControlConnection(cip, cip->host, cip->port);
		(void) time(&t1);
		if (result == kNoErr) {
			/* We were hooked up successfully. */
			PrintF(cip, "Connected to %s.\n", cip->host);

			/* Not logging in... */
			if (result == kNoErr)
				break;
		} else if ((result != kErrConnectRetryableErr) && (result != kErrConnectRefused) && (result != kErrRemoteHostClosedConnection)) {
			/* Irrecoverable error, so don't bother redialing.
			 * The error message should have already been printed
			 * from OpenControlConnection().
			 */
			PrintF(cip, "Cannot recover from miscellaneous open error %d.\n", result);
			return result;
		}

		/* Retryable error, wait and then redial. */
		if (cip->redialDelay > 0) {
			/* But don't sleep if this is the last loop. */
			if ((cip->maxDials < 0) || (dials < (cip->maxDials - 1))) {
				elapsed = (int) (t1 - t0);
				if (elapsed < cip->redialDelay) {
					PrintF(cip, "Sleeping %u seconds.\n",
						(unsigned) cip->redialDelay - elapsed);
					if (cip->redialStatusProc != 0)
						(*cip->redialStatusProc)(cip, kRedialStatusSleeping, cip->redialDelay - elapsed);
					(void) sleep((unsigned) cip->redialDelay - elapsed);
				}
			}
		}
	}
	return (result);
}	/* FTPOpenHostNoLogin */
Exemple #22
0
/*! Handle the messages routed to the display queue */
static void DisplayQueueMessageHandler(tMessage *pMsg)
{
  tMessage Msg;

  switch (pMsg->Type)
  {
  case ShowCallMsg:
    HandleCallNotification(pMsg->Options, pMsg->pBuffer, pMsg->Length);
    break;

  case WriteBufferMsg:
    WriteBufferHandler(pMsg);
    break;

  case SetWidgetListMsg:
    SetWidgetList(pMsg);
    break;
  
  case UpdateDisplayMsg:
  
    if ((!(pMsg->Options & MSG_OPT_UPD_INTERNAL) &&
        (pMsg->Options & MODE_MASK) == NOTIF_MODE) &&
        GetProperty(PROP_AUTO_BACKLIGHT))
      SendMessage(AutoBacklightMsg, MSG_OPT_NONE);

    UpdateDisplayHandler(pMsg);
    break;

  case DrawMsg:
    DrawMsgHandler(pMsg);
    break;
    
  case UpdateClockMsg:
    UpdateClock();
    break;
    
  case DrawClockWidgetMsg:
    DrawClockWidget(pMsg->Options);
    break;

  case BluetoothStateChangeMsg:
    BluetoothStateChangeHandler(pMsg);
    break;

  case IdleUpdateMsg:
    IdleUpdateHandler();
    break;

  case ButtonStateMsg:
    ButtonStateHandler();
    break;

  case StopTimerMsg:
    StopTimer((eTimerId)pMsg->Options);
    break;

  case MonitorBatteryMsg:
    MonitorBattery();
    break;

  case MusicIconMsg:
      MusicIcon(pMsg->Options);
      break;

  case MusicStateMsg:
    HandleMusicStateChange(pMsg->Options);
    break;
    
  case ChangeModeMsg:
    ChangeMode(pMsg->Options);
    break;
  
  case ControlFullScreenMsg:
    SetProperty(PROP_PHONE_DRAW_TOP, pMsg->Options || *pMsg->pBuffer ? PROP_PHONE_DRAW_TOP : 0);
    break;

  case ModifyTimeMsg:
    ModifyTimeHandler(pMsg);
    break;

  case MenuModeMsg:
    MenuModeHandler(pMsg->Options);
    break;

  case MenuButtonMsg:
    MenuButtonHandler(pMsg->Options);
    break;

  case EnableButtonMsg:
    EnableButtonMsgHandler(pMsg);
    break;

  case DevTypeMsg:

    Msg.Length = 1;
    Msg.Type = DevTypeRespMsg;
    Msg.Options = BOARD_TYPE; //default G2

    if (CreateMessage(&Msg))
    {
      Msg.pBuffer[0] = BOARD_TYPE; // backward compatible

      if (GetMsp430HardwareRevision() < 'F')
      {
        Msg.Options = DIGITAL_WATCH_TYPE_G1;
        Msg.pBuffer[0] = DIGITAL_WATCH_TYPE_G1; // backward compatible
      }

      Msg.Options |= DEV_TYPE_EN_ACK; // support ACK
      RouteMsg(&Msg);
    }

    PrintF("- DevTypeResp:%u", Msg.Options);

    // set ACK and HFP/MAP bits
//    SendMessage(ConnTypeMsg, pMsg->Options);
    break;

  case VerInfoMsg:

    Msg.Length = BUILD_LENGTH + 4 + 3;
    Msg.Type = VerInfoRespMsg;
    Msg.Options = MSG_OPT_NONE;

    if (CreateMessage(&Msg))
    {
      GetBuildNumber(Msg.pBuffer);

      *(Msg.pBuffer + BUILD_LENGTH) = VERSION[0] - ZERO;
      *(Msg.pBuffer + BUILD_LENGTH + 1) = VERSION[2] - ZERO;
      *(Msg.pBuffer + BUILD_LENGTH + 2) = VERSION[4] - ZERO;
      *(Msg.pBuffer + BUILD_LENGTH + 3) = GetMsp430HardwareRevision();
      *(Msg.pBuffer + BUILD_LENGTH + 4) = BootVersion[0] - ZERO;
      *(Msg.pBuffer + BUILD_LENGTH + 5) = BootVersion[2] - ZERO;
      *(Msg.pBuffer + BUILD_LENGTH + 6) = BootVersion[4] - ZERO;

      RouteMsg(&Msg);
    }
    PrintE("-Ver(%u):", Msg.Length); PrintQ(Msg.pBuffer, Msg.Length);
    break;

  case LogMsg:
    SendStateLog();
    break;
    
  case VibrateMsg:
    SetVibrateModeHandler(pMsg);
    break;

  case SetRtcMsg:
    if (SetRtc((Rtc_t *)pMsg->pBuffer)) UpdateClock();
    break;
    
  case CountdownMsg:
    if (pMsg->Options == CDT_ENTER)
    {
      PageType = PAGE_TYPE_INFO;
      CurrentPage[PageType] = CountdownPage;
    }
    CountdownHandler(pMsg->Options);
    break;

  case ServiceMenuMsg:
    ServiceMenuHandler();
    break;

  case FieldTestMsg:
    HandleFieldTestMode(pMsg->Options);
    break;

  case DisableButtonMsg:
    DisableButtonMsgHandler(pMsg);
    break;

  case ReadButtonConfigMsg:
    ReadButtonConfigHandler(pMsg);
    break;

  case SetBacklightMsg:
    SetBacklight(pMsg->Options);
    // testing
//    pMsg->Type = AccelMsg;
//    pMsg->Options = 1; //enable
//    HandleAccelerometer(pMsg);
    break;

  case AutoBacklightMsg:
    if (LightSenseCycle() < DARK_LEVEL) SetBacklight(LED_ON);
    break;

  case BatteryConfigMsg:
    SetBatteryLevels(pMsg->pBuffer);
    break;

  case ReadBatteryVoltageMsg:
    ReadBatteryVoltageHandler();
    break;

  case ResetMsg:
    SoftwareReset(RESET_BUTTON_PRESS, pMsg->Options);
    break;

  case NvalOperationMsg:
    NvalOperationHandler(pMsg);
    break;

  case SecInvertMsg:
    HandleSecInvert(pMsg->Options);
    break;

  case LoadTemplateMsg:
    LoadTemplateHandler(pMsg);
    break;

  case LinkAlarmMsg:
    SendMessage(VibrateMsg, VIBRA_PATTERN_LNKALM);
    break;

  case ModeTimeoutMsg:
    ModeTimeoutHandler();
    break;

  case WatchStatusMsg:
    PageType = PAGE_TYPE_INFO;
    CurrentPage[PageType] = StatusPage;
    DrawWatchStatusScreen(TRUE);
    break;

  case TermModeMsg:
    TermModeHandler();
    break;
    
  case LowBatteryWarningMsg:
    break;
    
  case LowBatteryBtOffMsg:
    UpdateClock();
    break;

#if __IAR_SYSTEMS_ICC__
  case EraseTemplateMsg:
//    EraseTemplateHandler(pMsg);
    break;
    
  case WriteToTemplateMsg:
//    WriteToTemplateHandler(pMsg);
    break;
#endif

  case AccelMsg:
    HandleAccelerometer(pMsg);
    break;

  case ReadLightSensorMsg:
    ReadLightSensorHandler();
    break;

  case WatchDrawnScreenTimeout:
    IdleUpdateHandler();
    break;

  case RateTestMsg:
    /* don't care what data is */
    Msg.Length = 10;
    Msg.Type = DiagnosticLoopback;
    Msg.Options = MSG_OPT_NONE;
    if (CreateMessage(&Msg)) RouteMsg(&Msg);
    break;
    
  default:
    PrintF("# Disp Msg:x%02X", pMsg->Type);
    break;
  }
}
Exemple #23
0
void vApplicationFreeFailedHook(unsigned char * pBuffer)
{
  PrintF("@F:%04X", pBuffer);
}
Exemple #24
0
void CALLBACK WndProc(UINT32 message,UINT32 lParam,UINT32 wParam)
{
	switch (message)
	{
	case WM_CREATE:
		{
			CDC *pDC=GetDC();
			pDC->LCD_Init();
			pDC->LCD_On();
			pDC->Fill_Screen(WHITE);
			pDC->SetPixel(20,40,BLACK);
			pDC->MoveTo(20,20);
			pDC->LineTo(220,20);
			pDC->MoveTo(20,20);
			pDC->LineTo(20,300);
			pDC->MoveTo(20,300);
			pDC->LineTo(220,300);
			pDC->MoveTo(220,20);
			pDC->LineTo(220,300);
			//pDC->PrintAuthors(1,2);
			pDC->PrintMenu(50,100);
			
			char b[100];
			IToA(b,154);
			PrintF("abc%d%def%d%s..",12,34,5,"nihao");
		}
		
		break;
	case WM_TIMER:
		PrintF("WM_TIMER\n");
		break;
	case WM_LBUTTONDOWN:

		if (flag == 1)
		{
			MoveTo(lParam,wParam);
		}
		if (flag == 2)
		{
			tempX = lParam;
			tempY = wParam;
		}

		//PrintF("WM_LBUTTONDOWN\n");
		//PrintF("x=%d   y=%d\n",lParam,wParam);
		break;
	case WM_LBUTTONUP:

		if (flag == 1)
		{
			LineTo(lParam,wParam);
		}
		if (flag == 2)
		{
			PrintF("%d,%d,%d\n",abs(wParam-tempY),tempX,tempY);
			if (abs(lParam - tempX) >= abs(wParam - tempY))
			{
				DrawCircle((abs(wParam-tempY)/2+tempX),(tempY+wParam)/2,(abs(wParam - tempY)/2),BLACK);
			}
			else
			{
				DrawCircle((tempX+lParam)/2,(abs(tempX-lParam)/2+tempY),(abs(lParam - tempX)/2),BLACK);
			}
		}

		if (lParam < 176 && lParam > 50 && wParam > 100 && wParam < 116)
		{	
			if(flag == 0)
			{
				flag = 1;
				Fill_Screen(WHITE);
			}
		}
		if (lParam < 200 && lParam > 40 && wParam > 173 && wParam < 183)
		{	
			if (flag == 0)
			{
				flag = 2;
				Fill_Screen(WHITE);
			}
		}
		//PrintF("WM_LBUTTONUP\n");
		//PrintF("x=%d   y=%d\n",lParam,wParam);
		break;
	}
}
Exemple #25
0
void SetProperty(unsigned char Bits, unsigned char Val)
{
  niProperty |= Bits & Val; // set all 1 bits of Val
  niProperty &= ~Bits | Val; // set all 0 bits of Val
  PrintF("Prop:x%02X", niProperty);
}
Exemple #26
0
void vAssertCalled(void)
{
  PrintF("@ Assert");
  __no_operation();
}
Exemple #27
0
U0 Routine2(U8 *st)
{
    PrintF("Routine2:%s\n",st);
}
Exemple #28
0
void vApplicationStackOverflowHook(xTaskHandle *pxTask, char *TaskName)
{
  /* try to print task name */
  PrintF("@ Stack Oflw:%s", TaskName);
  SoftwareReset();
}
void DrawMsgHandler(tMessage *pMsg)
{
  static Draw_t *pInfo;
  static unsigned char *pData;
  static unsigned int Size = 0;

  if (pMsg->Options & DRAW_MSG_BEGIN)
  {
    pInfo = (Draw_t *)pMsg->pBuffer;
    pData = pMsg->pBuffer + DRAW_INFO_SIZE;

    if (!(pMsg->Options & DRAW_MSG_END))
    {
      pInfo = (Draw_t *)pvPortMalloc(DRAW_INFO_SIZE);
      PrintF("%cA:%04X %u", pInfo ? PLUS : NOK, pInfo, DRAW_INFO_SIZE);
      if (pInfo == NULL) return;

      memcpy(pInfo, pMsg->pBuffer, DRAW_INFO_SIZE);
      PrintF("Id:%02X X:%u Y:%u Opt:%02X", pInfo->Id, pInfo->X, pInfo->Y, pInfo->Opt);
      PrintF("W:%u H:%u WgtId:%02X", pInfo->Width, pInfo->Height, pInfo->WidgetId);
      PrintF("TxtLen:%u Align:%u", pInfo->TextLen, pInfo->Align);

      if (pInfo->Id & DRAW_ID_TYPE_BMP)
        Size = pInfo->Opt & DRAW_OPT_FILL ? 1 : WIDTH_IN_BYTES(pInfo->Width) * pInfo->Height;
      else Size = pInfo->TextLen;

      pData = (unsigned char *)pvPortMalloc(Size);
      PrintF("%cA:%04X %u", pData ? PLUS : NOK, pData, Size);
      if (pData == NULL)
      {
        vPortFree(pInfo);
        return;
      }

      Size = pMsg->Length - DRAW_INFO_SIZE;
      memcpy(pData, pMsg->pBuffer + DRAW_INFO_SIZE, Size);
    }
  }
  else // pure data in payload
  {
    if (pData == NULL)
    {
      PrintS("#DrwMsg:empty payload");
      return;
    }
    memcpy(pData + Size, pMsg->pBuffer, pMsg->Length);
    Size += pMsg->Length;
  }

  if (pMsg->Options & DRAW_MSG_END)
  {
    unsigned char Mode = (pMsg->Options & DRAW_MSG_MODE) >> 6;
    if (Mode == IDLE_MODE) CreateDrawBuffer(pInfo->WidgetId);

    Draw(pInfo, pData, Mode);

    if (Mode == IDLE_MODE && (pMsg->Options & DRAW_WIDGET_END))
      DrawWidgetToSram(pInfo->WidgetId);

    if (Size)
    {
      PrintF("-F:%04X %04X", pInfo, pData);
      vPortFree(pData);
      vPortFree(pInfo);
      Size = 0;
    }
  }
Exemple #30
0
void ShowStateInfo(void)
{
  if (!pStateLog) return;
  State_t *pState = (State_t *)pStateLog;

  PrintS("---- State before reset ----");
  if (pState->ResetSource > 0x22) pState->ResetSource = 0x22;
  PrintS(ResetReason[pState->ResetSource >> 1]);

  PrintF("ResetCode:%s %u", ResetCode[pState->ResetCode], pState->ResetValue);
  PrintF("RadioIdle:%u", pState->RadioReadyToSleep);
  PrintF("DisplayQueue:%u", pState->DisplayQueue);
  PrintF("WrapperQueue:%u", pState->WrapperQueue);

  if (pState->ResetSource == SYSRSTIV_WDTTO || pState->ResetSource == SYSRSTIV_WDTKEY)
  {
    PrintF("# WDT %s", pState->ResetSource == SYSRSTIV_WDTTO ? "Failsafe" : "Forced");
    pState->WdtNum ++;
  }

  PrintF("Total WDT:%u", pState->WdtNum);
  PrintF("MuxMode:%s", MuxMode[pState->MuxMode]);

  unsigned char i;

  PrintW("Property:");
  for (i = 0; i < 7; ++i)
  {
    if (pState->Property & (1 << i))
      {PrintW(Property[i]); PrintC(SPACE);}
  }
  PrintR();
  
  PrintF("State:%s", Bluetooth[pState->Bluetooth]);

  PrintW("Conn:");
  for (i = 0; i < 7; ++i)
  {
    if (pState->ConnType & (1 << i))
      {PrintW(ConnType[i]); PrintC(SPACE);}
  }
  PrintR();

  PrintF("Dscnn:%u", pState->Disconnects);
  PrintF("Battery:%u%c", pState->Battery, PERCENT);
  PrintF("SrvChgdHandle:%u", pState->SrvChgdHandle);
  PrintS("-------- State end --------");
}