void ModbusRtu::processPacket() { QMutexLocker lock(&mMutex); quint8 cs = mCurrentSlave; if (mCrc != mCrcBuilder.getValue()) { resetStateEngine(); processPending(); mMutex.unlockInline(); emit errorReceived(CrcError, cs, 0); return; } if ((mFunction & 0x80) != 0) { quint8 errorCode = static_cast<quint8>(mData[0]); resetStateEngine(); processPending(); mMutex.unlockInline(); emit errorReceived(Exception, cs, errorCode); return; } if (mState == Function) { FunctionCode function = mFunction; resetStateEngine(); processPending(); mMutex.unlockInline(); emit errorReceived(Unsupported, cs, function); return; } FunctionCode function = mFunction; switch (function) { case ReadHoldingRegisters: case ReadInputRegisters: { QList<quint16> registers; for (int i=0; i<mData.length(); i+=2) { registers.append(toUInt16(mData, i)); } resetStateEngine(); processPending(); mMutex.unlockInline(); emit readCompleted(function, cs, registers); return; } case WriteSingleRegister: { quint16 value = toUInt16(mData, 0); quint16 startAddress = mStartAddress; resetStateEngine(); processPending(); mMutex.unlockInline(); emit writeCompleted(function, cs, startAddress, value); return; } default: break; } }
void Drf1600::processPacket(const QByteArray &dataRead) { Command cmd = mCurrentCommand; resetStateEngine(); switch (cmd) { case GetDeviceType: { int c = toUInt16(dataRead[0], dataRead[2]); switch (c) { case 0x436F: emit deviceTypeRetrieved(ZigbeeCoordinator); break; case 0x5275: emit deviceTypeRetrieved(ZigbeeRouter); break; default: emit errorReceived(Drf1600IncorrectReply); break; } break; } case ReadPanId: emit panIdRead(toUInt16(dataRead[0], dataRead[1])); break; case ReadShortAddress: emit shortAddressRead(toUInt16(dataRead[0], dataRead[1])); break; case SetBaudRate: /// @todo EV Check retrieved data emit baudrateSet(); break; case SetDeviceType: static quint8 MsgCoord[] = { 0x43, 0x6F, 0x6F, 0x72, 0x64, 0x3B, 0x00, 0x19 }; static quint8 MsgRouter[] = { 0x52, 0x6F, 0x75, 0x74, 0x65, 0x3B, 0x00, 0x19 }; if (checkReply(dataRead, MsgCoord, sizeof(MsgCoord)/sizeof(MsgCoord[0])) || checkReply(dataRead, MsgRouter, sizeof(MsgRouter)/sizeof(MsgRouter[0]))) { emit deviceTypeSet(); } else { emit errorReceived(Drf1600IncorrectReply); } break; case TestBaudrate: emit baudrateTested(toUInt16(dataRead[6], dataRead[7])); break; case WritePanId: emit panIdWritten(toUInt16(dataRead[0], dataRead[1])); break; default: break; } }
EncodedJSValue JSC_HOST_CALL jsXPathEvaluatorPrototypeFunctionEvaluate(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); JSXPathEvaluator* castedThis = jsDynamicCast<JSXPathEvaluator*>(thisValue); if (!castedThis) return throwVMTypeError(exec); ASSERT_GC_OBJECT_INHERITS(castedThis, JSXPathEvaluator::info()); XPathEvaluator& impl = castedThis->impl(); ExceptionCode ec = 0; const String& expression(exec->argument(0).isEmpty() ? String() : exec->argument(0).toString(exec)->value(exec)); if (exec->hadException()) return JSValue::encode(jsUndefined()); Node* contextNode(toNode(exec->argument(1))); if (exec->hadException()) return JSValue::encode(jsUndefined()); RefPtr<XPathNSResolver> customResolver; XPathNSResolver* resolver = toXPathNSResolver(exec->argument(2)); if (!resolver) { customResolver = JSCustomXPathNSResolver::create(exec, exec->argument(2)); if (exec->hadException()) return JSValue::encode(jsUndefined()); resolver = customResolver.get(); } uint16_t type(toUInt16(exec, exec->argument(3), NormalConversion)); if (exec->hadException()) return JSValue::encode(jsUndefined()); XPathResult* inResult(toXPathResult(exec->argument(4))); if (exec->hadException()) return JSValue::encode(jsUndefined()); JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.evaluate(expression, contextNode, resolver, type, inResult, ec))); setDOMException(exec, ec); return JSValue::encode(result); }
static std::unique_ptr<CryptoAlgorithmParameters> createAesKeyGenParams(ExecState* exec, JSValue value) { if (!value.isObject()) { throwTypeError(exec); return nullptr; } auto result = std::make_unique<CryptoAlgorithmAesKeyGenParams>(); JSValue lengthValue = getProperty(exec, value.getObject(), "length"); if (exec->hadException()) return nullptr; result->length = toUInt16(exec, lengthValue, EnforceRange); return WTF::move(result); }
static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) { ExceptionState exceptionState(info.GetIsolate(), ExceptionState::ConstructionContext, "TestException"); if (UNLIKELY(info.Length() < 1)) { exceptionState.throwTypeError(ExceptionMessages::notEnoughArguments(1, info.Length())); return; } unsigned argument; argument = toUInt16(info.GetIsolate(), info[0], NormalConversion, exceptionState); if (exceptionState.hadException()) return; TestException* impl = TestException::create(argument); v8::Local<v8::Object> wrapper = info.Holder(); wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8TestException::wrapperTypeInfo, wrapper); v8SetReturnValue(info, wrapper); }
static void constructor(const v8::FunctionCallbackInfo<v8::Value>& info) { ExceptionState exceptionState(ExceptionState::ConstructionContext, "TestException", info.Holder(), info.GetIsolate()); if (UNLIKELY(info.Length() < 1)) { setMinimumArityTypeError(exceptionState, 1, info.Length()); exceptionState.throwIfNeeded(); return; } unsigned argument; { argument = toUInt16(info.GetIsolate(), info[0], NormalConversion, exceptionState); if (exceptionState.throwIfNeeded()) return; } RefPtr<TestException> impl = TestException::create(argument); v8::Local<v8::Object> wrapper = info.Holder(); wrapper = impl->associateWithWrapper(info.GetIsolate(), &V8TestException::wrapperTypeInfo, wrapper); v8SetReturnValue(info, wrapper); }
uint16_t toUInt16(v8::Handle<v8::Value> value) { NonThrowableExceptionState exceptionState; return toUInt16(value, NormalConversion, exceptionState); }
static inline uint16_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) { return toUInt16(value, configuration, exceptionState); }
static inline uint16_t toIntegral(v8::Isolate* isolate, v8::Local<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState) { return toUInt16(isolate, value, configuration, exceptionState); }