Esempio n. 1
0
RVNET_DATATYPE RVnetSlaveProcess(uint8 *px_buf, RVNET_DATATYPE pkSize,
    uint8 device_address)
  {
    volatile uint8 *pxPack = px_buf;
    if (*pxPack == device_address)
      {
        if (CheckCRC(pxPack, pkSize))
          {
            pxPack++;
            switch (*pxPack)
              {
            case 0x00:
              pxPack++;
              pkSize = ReadDeviceID(pxPack);
              break;
            case 0x01:
            case 0x02:
              pxPack++;
              pkSize = ReadNBits(pxPack);
              break;
            case 0x03:
            case 0x04:
              pxPack++;
              pkSize = ReadNWords(pxPack);
              break;
            case 0x05:
              pxPack++;
              pkSize = WriteBit(pxPack);
              break;
            case 0x10:
              pxPack++;
              pkSize = WriteNWords(pxPack);
              break;
            default:
              pxPack++;
              pkSize = ErrorAddress(pxPack);
              break;

              }
          }
        else
          return 0;
      }
    else
      return 0;
    pkSize += 2; // Add heder
    SetCRC(px_buf, pkSize);
    pkSize += 2; // Add CRC
    return pkSize;
  }
Esempio n. 2
0
/*!
This method tries to get the device id back from the printer and does some basic verification.
*/
DRIVER_ERROR SystemServices::GetDeviceID(BYTE* strID, int iSize, BOOL bQuery)
{

    if (iSize < 3)  // must have at least enough space for count bytes and NULL terminator
    {
        return(SYSTEM_ERROR);
    }

	memset (strID, 0, iSize);

    if (bQuery)
    {
        // initialize the first 3 bytes to NULL (1st 2 bytes may be binary count of string
        // length so need to clear them as well as the "real" start of the string)
        // so that if ReadDeviceID() does nothing with buffer we won't act upon what
        // was in the buffer before calling it
        strID[0] = strID[1] = strID[2] = '\0';

        // we are going to try more then once because some printers lie and this
        // specifically fixes problems with the DJ630 & DJ640 printers.
        int i = 0;
        for(i = 0; i < 20; i++)
        {
            // get the string
            if((ReadDeviceID(strID, iSize) != NO_ERROR))
            {
                DBG1("Error from ReadDeviceID or No DevID Available\n");
                if(BusyWait((DWORD)100) == JOB_CANCELED)
                {
                    return JOB_CANCELED;
                }
                continue;  // go back and try again
            }
            // look for the existence of either of the defined manufacturer fields in the string
            // (need to look starting at strID[0] and at strID[2] since the first 2 bytes may or
            // may not be binary count bytes, one of which could be a binary 0 (NULL) which strstr()
            // will interpret as the end of string)
            else
            {
                if ((!strstr((const char*)strID, "MFG:") &&
                    !strstr((const char*)strID+2, "MFG:") &&
                    !strstr((const char*)strID, "MANUFACTURER:") &&
                    !strstr((const char*)strID+2, "MANUFACTURER:")) ||
                    (!strstr((const char*)strID, "MDL:") &&
                    !strstr((const char*)strID+2, "MDL:") &&
                    !strstr((const char*)strID, "MODEL:") &&
                    !strstr((const char*)strID+2, "MODEL:")) ||
                    ((strID[0] == '\0') && (strID[1] == '\0')))
                {
                    DBG1("Successful' DevID request was a lie.  Retry...waiting 100 ms\n");
                    if(BusyWait((DWORD)100) == JOB_CANCELED)
                    {
                        return JOB_CANCELED;
                    }
                    continue;  // go back and try again
                }
                else
                {
                    // If either of the first two bytes is 0, byte count is there, replace them.

                    if (strID[0] == 0 || strID[1] == 0)
                    {
                        strID[0] = strID[1] = ' ';
                    }
                    //DBG1("HPPCL: ReadDeviceID [%hs]\n", strID+2);
                    break; // SUCCESS!
                }
            }
        }
        if(i >= 20)
        {
            return BAD_DEVICE_ID;
        }
    }
    else
    {
        // for use when string doesn't have to be re-fetched from printer

        if (DevIDBuffSize > iSize)
        {
            return SYSTEM_ERROR;
        }

        // the first 2 bytes may be binary so could be 0 (NULL) so can't use strcpy
        // (could get strlen of strDevID if start @ strDevID+2 and then add 2
        //  if do this it wouldn't require that caller's buffer be >=
        //  DevIDBuffSize, only that is it longer that actual devID string read)
        memcpy(strID, strDevID, DevIDBuffSize);
    }
    return NO_ERROR;

    // This is old code from before the 630, 640 loop fix was done (above).  This can
    // eventually be removed.
    // check the read (or copied) DeviceID string for validity

    // check what may be the binary count of the string length (some platforms return
    // the raw DeviceID in which the 1st 2 bytes are a binary count of the string length,
    // other platforms strip off these count bytes)
    // if they are a binary count they shouldn't be zero, and if they aren't a binary
    // count they also shouldn't be zero (NULL) since that would mean end of string
/*    if ((strID[0] == '\0') && (strID[1] == '\0'))
    {
        return BAD_DEVICE_ID;
    }

    // look for the existence of either of the defined manufacturer fields in the string
    // (need to look starting at strID[0] and at strID[2] since the first 2 bytes may or
    //  may not be binary count bytes, one of which could be a binary 0 (NULL) which strstr()
    //  will interpret as the end of string)
    if (!strstr((const char*)strID, "MFG:") &&
        !strstr((const char*)strID+2, "MFG:") &&
        !strstr((const char*)strID, "MANUFACTURER:") &&
        !strstr((const char*)strID+2, "MANUFACTURER:"))
    {
        return BAD_DEVICE_ID;
    }*/

} //GetDeviceID