boolean CMouseBehaviour::Setup (unsigned nScreenWidth, unsigned nScreenHeight) { assert (m_nScreenWidth == 0); m_nScreenWidth = nScreenWidth; assert (m_nScreenWidth > 0); assert (m_nScreenHeight == 0); m_nScreenHeight = nScreenHeight; assert (m_nScreenHeight > 0); m_nPosX = (m_nScreenWidth+1) / 2; m_nPosY = (m_nScreenHeight+1) / 2; CBcmPropertyTags Tags; TPropertyTagSetCursorInfo TagSetCursorInfo; TagSetCursorInfo.nWidth = CURSOR_WIDTH; TagSetCursorInfo.nHeight = CURSOR_HEIGHT; TagSetCursorInfo.nUnused = 0; TagSetCursorInfo.nPixelPointer = BUS_ADDRESS ((uintptr) CursorSymbol); TagSetCursorInfo.nHotspotX = CURSOR_HOTSPOT_X; TagSetCursorInfo.nHotspotY = CURSOR_HOTSPOT_Y; if (!Tags.GetTag (PROPTAG_SET_CURSOR_INFO, &TagSetCursorInfo, sizeof TagSetCursorInfo, 6*4)) { return FALSE; } if (TagSetCursorInfo.nResponse != CURSOR_RESPONSE_VALID) { return FALSE; } return TRUE; }
boolean CDWHCIDevice::PowerOn (void) { CBcmPropertyTags Tags; TPropertyTagPowerState PowerState; PowerState.nDeviceId = DEVICE_ID_USB_HCD; PowerState.nState = POWER_STATE_ON | POWER_STATE_WAIT; if ( !Tags.GetTag (PROPTAG_SET_POWER_STATE, &PowerState, sizeof PowerState) || (PowerState.nState & POWER_STATE_NO_DEVICE) || !(PowerState.nState & POWER_STATE_ON)) { return FALSE; } return TRUE; }
boolean CMouseBehaviour::SetCursorState (unsigned nPosX, unsigned nPosY, boolean bVisible) { CBcmPropertyTags Tags; TPropertyTagSetCursorState TagSetCursorState; TagSetCursorState.nEnable = bVisible ? CURSOR_ENABLE_VISIBLE : CURSOR_ENABLE_INVISIBLE; TagSetCursorState.nPosX = nPosX; TagSetCursorState.nPosY = nPosY; TagSetCursorState.nFlags = CURSOR_FLAGS_FB_COORDS; if (!Tags.GetTag (PROPTAG_SET_CURSOR_STATE, &TagSetCursorState, sizeof TagSetCursorState, 4*4)) { return FALSE; } if (TagSetCursorState.nResponse != CURSOR_RESPONSE_VALID) { return FALSE; } return TRUE; }
CSPIMaster::CSPIMaster (unsigned nClockSpeed, unsigned CPOL, unsigned CPHA) : m_nClockSpeed (nClockSpeed), m_CPOL (CPOL), m_CPHA (CPHA), m_SCLK (11, GPIOModeAlternateFunction0), m_MOSI (10, GPIOModeAlternateFunction0), m_MISO ( 9, GPIOModeAlternateFunction0), m_CE0 ( 8, GPIOModeAlternateFunction0), m_CE1 ( 7, GPIOModeAlternateFunction0), m_nCoreClockRate (DEFAULT_CORE_CLOCK), m_nCSHoldTime (0), m_SpinLock (FALSE) { CBcmPropertyTags Tags; TPropertyTagClockRate TagClockRate; TagClockRate.nClockId = CLOCK_ID_CORE; if (Tags.GetTag (PROPTAG_GET_CLOCK_RATE, &TagClockRate, sizeof TagClockRate, 4)) { m_nCoreClockRate = TagClockRate.nRate; } }
boolean CSMSC951xDevice::Configure (void) { CBcmPropertyTags Tags; TPropertyTagMACAddress MACAddress; if (Tags.GetTag (PROPTAG_GET_MAC_ADDRESS, &MACAddress, sizeof MACAddress)) { m_MACAddress.Set (MACAddress.Address); } else { CLogger::Get ()->Write (FromSMSC951x, LogError, "Cannot get MAC address"); return FALSE; } CString MACString; m_MACAddress.Format (&MACString); CLogger::Get ()->Write (FromSMSC951x, LogDebug, "MAC address is %s", (const char *) MACString); if (GetNumEndpoints () != 3) { ConfigurationError (FromSMSC951x); return FALSE; } const TUSBEndpointDescriptor *pEndpointDesc; while ((pEndpointDesc = (TUSBEndpointDescriptor *) GetDescriptor (DESCRIPTOR_ENDPOINT)) != 0) { if ((pEndpointDesc->bmAttributes & 0x3F) == 0x02) // Bulk { if ((pEndpointDesc->bEndpointAddress & 0x80) == 0x80) // Input { if (m_pEndpointBulkIn != 0) { ConfigurationError (FromSMSC951x); return FALSE; } m_pEndpointBulkIn = new CUSBEndpoint (GetDevice (), pEndpointDesc); } else // Output { if (m_pEndpointBulkOut != 0) { ConfigurationError (FromSMSC951x); return FALSE; } m_pEndpointBulkOut = new CUSBEndpoint (GetDevice (), pEndpointDesc); } } } if ( m_pEndpointBulkIn == 0 || m_pEndpointBulkOut == 0) { ConfigurationError (FromSMSC951x); return FALSE; } if (!CUSBFunction::Configure ()) { CLogger::Get ()->Write (FromSMSC951x, LogError, "Cannot set interface"); return FALSE; } u8 MACAddressBuffer[MAC_ADDRESS_SIZE]; m_MACAddress.CopyTo (MACAddressBuffer); u16 usMACAddressHigh = (u16) MACAddressBuffer[4] | (u16) MACAddressBuffer[5] << 8; u32 nMACAddressLow = (u32) MACAddressBuffer[0] | (u32) MACAddressBuffer[1] << 8 | (u32) MACAddressBuffer[2] << 16 | (u32) MACAddressBuffer[3] << 24; if ( !WriteReg (ADDRH, usMACAddressHigh) || !WriteReg (ADDRL, nMACAddressLow)) { CLogger::Get ()->Write (FromSMSC951x, LogError, "Cannot set MAC address"); return FALSE; } if ( !WriteReg (LED_GPIO_CFG, LED_GPIO_CFG_SPD_LED | LED_GPIO_CFG_LNK_LED | LED_GPIO_CFG_FDX_LED) || !WriteReg (MAC_CR, MAC_CR_RCVOWN //| MAC_CR_PRMS // promiscous mode | MAC_CR_TXEN | MAC_CR_RXEN) || !WriteReg (TX_CFG, TX_CFG_ON)) { CLogger::Get ()->Write (FromSMSC951x, LogError, "Cannot start device"); return FALSE; } AddNetDevice (); return TRUE; }
CKernelOptions::CKernelOptions (void) : m_nWidth (0), m_nHeight (0), m_nLogLevel (LogDebug), m_nUSBPowerDelay (0), m_CPUSpeed (CPUSpeedLow), m_nSoCMaxTemp (60) { strcpy (m_LogDevice, "tty1"); strcpy (m_KeyMap, DEFAULT_KEYMAP); s_pThis = this; CBcmPropertyTags Tags; if (!Tags.GetTag (PROPTAG_GET_COMMAND_LINE, &m_TagCommandLine, sizeof m_TagCommandLine)) { return; } if (m_TagCommandLine.Tag.nValueLength >= sizeof m_TagCommandLine.String) { return; } m_TagCommandLine.String[m_TagCommandLine.Tag.nValueLength] = '\0'; m_pOptions = (char *) m_TagCommandLine.String; char *pOption; while ((pOption = GetToken ()) != 0) { char *pValue = GetOptionValue (pOption); if (strcmp (pOption, "width") == 0) { unsigned nValue; if ( (nValue = GetDecimal (pValue)) != INVALID_VALUE && 640 <= nValue && nValue <= 1980) { m_nWidth = nValue; } } else if (strcmp (pOption, "height") == 0) { unsigned nValue; if ( (nValue = GetDecimal (pValue)) != INVALID_VALUE && 480 <= nValue && nValue <= 1080) { m_nHeight = nValue; } } else if (strcmp (pOption, "logdev") == 0) { strncpy (m_LogDevice, pValue, sizeof m_LogDevice-1); m_LogDevice[sizeof m_LogDevice-1] = '\0'; } else if (strcmp (pOption, "loglevel") == 0) { unsigned nValue; if ( (nValue = GetDecimal (pValue)) != INVALID_VALUE && nValue <= LogDebug) { m_nLogLevel = nValue; } } else if (strcmp (pOption, "keymap") == 0) { strncpy (m_KeyMap, pValue, sizeof m_KeyMap-1); m_KeyMap[sizeof m_KeyMap-1] = '\0'; } else if (strcmp (pOption, "usbpowerdelay") == 0) { unsigned nValue; if ( (nValue = GetDecimal (pValue)) != INVALID_VALUE && 200 <= nValue && nValue <= 8000) { m_nUSBPowerDelay = nValue; } } else if (strcmp (pOption, "fast") == 0) { if (strcmp (pValue, "true") == 0) { m_CPUSpeed = CPUSpeedMaximum; } } else if (strcmp (pOption, "socmaxtemp") == 0) { unsigned nValue; if ( (nValue = GetDecimal (pValue)) != INVALID_VALUE && 40 <= nValue && nValue <= 78) { m_nSoCMaxTemp = nValue; } } } }
void CMQTTClient::Connect (const char *pHost, u16 usPort, const char *pClientIdentifier, const char *pUsername, const char *pPassword, u16 usKeepAliveSeconds, boolean bCleanSession, const char *pWillTopic, u8 uchWillQoS, boolean bWillRetain, const u8 *pWillPayload, size_t nWillPayloadLength) { assert (m_ConnectStatus == MQTTStatusDisconnected); if (m_pTopicBuffer == 0) { OnDisconnect (MQTTDisconnectInsufficientResources); return; } assert (m_pNetSubSystem != 0); CDNSClient DNSClient (m_pNetSubSystem); CIPAddress IPServer; if (!DNSClient.Resolve (pHost, &IPServer)) { CLogger::Get ()->Write (FromMQTTClient, LogError, "Cannot resolve: %s", pHost); OnDisconnect (MQTTDisconnectDNSError); return; } IPServer.Format (&m_IPServerString); CLogger::Get ()->Write (FromMQTTClient, LogDebug, "%s: Opening connection", (const char *) m_IPServerString); assert (m_pSocket == 0); m_pSocket = new CSocket (m_pNetSubSystem, IPPROTO_TCP); assert (m_pSocket != 0); if (m_pSocket->Connect (IPServer, usPort) != 0) { CLogger::Get ()->Write (FromMQTTClient, LogError, "Cannot connect: %s", pHost); delete m_pSocket; m_pSocket = 0; OnDisconnect (MQTTDisconnectConnectFailed); return; } m_nKeepAliveSeconds = usKeepAliveSeconds; m_bTimerRunning = FALSE; m_usNextPacketIdentifier = 1; m_ReceivePacket.Reset (); m_ConnectStatus = MQTTStatusConnectPending; CString ClientIdentifier; if (pClientIdentifier != 0) { ClientIdentifier = pClientIdentifier; if (ClientIdentifier.GetLength () > 23) { CLogger::Get ()->Write (FromMQTTClient, LogWarning, "Client ID exceeds 23 characters"); } } else { CBcmPropertyTags Tags; TPropertyTagSerial Serial; if (!Tags.GetTag (PROPTAG_GET_BOARD_SERIAL, &Serial, sizeof Serial)) { Serial.Serial[0] = 0; Serial.Serial[1] = 0; } ClientIdentifier.Format ("raspi%08x%08x", Serial.Serial[1], Serial.Serial[0]); } u8 uchConnectFlags = 0; if (bCleanSession) { uchConnectFlags |= MQTT_CONNECT_FLAG_CLEAN_SESSION; } if (pWillTopic != 0) { uchConnectFlags |= MQTT_CONNECT_FLAG_WILL; assert (uchWillQoS <= MQTT_QOS_EXACTLY_ONCE); uchConnectFlags |= uchWillQoS << MQTT_CONNECT_FLAG_WILL_QOS__SHIFT; if (bWillRetain) { uchConnectFlags |= MQTT_CONNECT_FLAG_WILL_RETAIN; } } if (pUsername != 0) { uchConnectFlags |= MQTT_CONNECT_FLAG_USER_NAME; if (pPassword != 0) { uchConnectFlags |= MQTT_CONNECT_FLAG_PASSWORD; } } CMQTTSendPacket Packet (MQTTConnect, m_nMaxPacketSize); Packet.AppendString ("MQTT"); Packet.AppendByte (MQTT_PROTOCOL_LEVEL); Packet.AppendByte (uchConnectFlags); Packet.AppendWord (usKeepAliveSeconds); Packet.AppendString (ClientIdentifier); if (pWillTopic != 0) { Packet.AppendString (pWillTopic); assert (nWillPayloadLength < 0x10000); Packet.AppendWord (nWillPayloadLength); if (nWillPayloadLength > 0) { assert (pWillPayload != 0); Packet.AppendData (pWillPayload, nWillPayloadLength); } } if (pUsername != 0) { Packet.AppendString (pUsername); if (pPassword != 0) { Packet.AppendString (pPassword); } } if (!SendPacket (&Packet)) { CloseConnection (MQTTDisconnectSendFailed); return; } }