/* should be called after any change to int_state or enabled_ints. */ void tms9902_device::field_interrupts() { bool new_int = (m_DSCH && m_DSCENB) || (m_RBRL && m_RIENB) || (m_XBRE && m_XBIENB) || (m_TIMELP && m_TIMENB); if (VERBOSE>8) LOG("TMS9902: interrupt flags (DSCH = %02x, DSCENB = %02x), (RBRL = %02x, RIENB = %02x), (XBRE = %02x, XBIENB = %02x), (TIMELP = %02x, TIMENB = %02x)\n", m_DSCH, m_DSCENB, m_RBRL, m_RIENB, m_XBRE, m_XBIENB, m_TIMELP, m_TIMENB); if (new_int != m_INT) { // Only consider edges m_INT = new_int; if (VERBOSE>3) LOG("TMS9902: /INT = %s\n", (m_INT)? "asserted" : "cleared"); int_callback(m_INT? ASSERT_LINE : CLEAR_LINE); } }
void OPCEthernet::processClientCommand() { char *p,*j; bool matched = false; bool (*bool_callback)(const char *itemID, const opcOperation opcOP, const bool value); byte (*byte_callback)(const char *itemID, const opcOperation opcOP, const byte value); int (*int_callback)(const char *itemID, const opcOperation opcOP, const int value); float (*float_callback)(const char *itemID, const opcOperation opcOP, const float value); client.println(F("HTTP/1.1 200 OK\r\nContent-Type: text/json\r\nConnection: close\r\n")); if (!strcmp(buffer, "itemsmap")) { sendOPCItemsMap(); } else { p = strtok_r(buffer,"=",&j); if (!j[0]) { for (int i = 0; i < OPCItemsCount; i++) { if (!strcmp(buffer, OPCItemList[i].itemID)) { // Execute the stored handler function for the command client.print(F("[{\"ItemId\":\"")); client.print(buffer); client.print(F("\",\"ItemValue\":\"")); switch (OPCItemList[i].itemType) { case opc_bool : bool_callback = (bool (*)(const char *itemID, const opcOperation opcOP, const bool value))(OPCItemList[i].ptr_callback); client.print(bool_callback(OPCItemList[i].itemID,opc_opread,NULL)); break; case opc_byte : byte_callback = (byte (*)(const char *itemID, const opcOperation opcOP, const byte value))(OPCItemList[i].ptr_callback); client.print(byte_callback(OPCItemList[i].itemID,opc_opread,NULL)); break; case opc_int : int_callback = (int (*)(const char *itemID, const opcOperation opcOP, const int value))(OPCItemList[i].ptr_callback); client.print(int_callback(OPCItemList[i].itemID,opc_opread,NULL)); break; case opc_float : float_callback = (float (*)(const char *itemID, const opcOperation opcOP, const float value))(OPCItemList[i].ptr_callback); client.print(float_callback(OPCItemList[i].itemID,opc_opread,NULL)); break; } /* end switch */ client.print(F("\"}]")); matched = true; break; } /* end if */ } /* end for */ } /* end if */ else { for (int i = 0; i < OPCItemsCount; i++) { if (!strcmp(buffer, OPCItemList[i].itemID)) { // Call the stored handler function for the command switch (OPCItemList[i].itemType) { case opc_bool : bool_callback = (bool (*)(const char *itemID, const opcOperation opcOP, const bool value))(OPCItemList[i].ptr_callback); bool_callback(OPCItemList[i].itemID,opc_opwrite,atoi(j)); break; case opc_byte : byte_callback = (byte (*)(const char *itemID, const opcOperation opcOP, const byte value))(OPCItemList[i].ptr_callback); byte_callback(OPCItemList[i].itemID,opc_opwrite,atoi(j)); break; case opc_int : int_callback = (int (*)(const char *itemID, const opcOperation opcOP, const int value))(OPCItemList[i].ptr_callback); int_callback(OPCItemList[i].itemID,opc_opwrite,atoi(j)); break; case opc_float : float_callback = (float (*)(const char *itemID, const opcOperation opcOP, const float))(OPCItemList[i].ptr_callback); float_callback(OPCItemList[i].itemID,opc_opwrite,atof(j)); break; } /* end case */ matched = true; break; } /* end if */ } /* end for */ } /* end else */ } /* end else */ }
void OPCSerial::processOPCCommands() { bool matched = false; char *p,*j; bool (*bool_callback)(const char *itemID, const opcOperation opcOP, const bool value); byte (*byte_callback)(const char *itemID, const opcOperation opcOP, const byte value); int (*int_callback)(const char *itemID, const opcOperation opcOP, const int value); float (*float_callback)(const char *itemID, const opcOperation opcOP, const float value); while (Serial.available() > 0) { char inChar = Serial.read(); if (inChar == '\r') { if (buffer[0] == '\0') sendOPCItemsMap(); else { // Lets search for read for (int i = 0; i < OPCItemsCount; i++) { if (!strncmp(buffer, OPCItemList[i].itemID, SERIALCOMMAND_MAXCOMMANDLENGTH)) { // Execute the stored handler function for the command switch (OPCItemList[i].itemType) { case opc_bool : bool_callback = (bool (*)(const char *itemID, const opcOperation opcOP, const bool value))(OPCItemList[i].ptr_callback); Serial.println(bool_callback(OPCItemList[i].itemID,opc_opread,NULL)); break; case opc_byte : byte_callback = (byte (*)(const char *itemID, const opcOperation opcOP, const byte value))(OPCItemList[i].ptr_callback); Serial.println(byte_callback(OPCItemList[i].itemID,opc_opread,NULL)); break; case opc_int : int_callback = (int (*)(const char *itemID, const opcOperation opcOP, const int value))(OPCItemList[i].ptr_callback); Serial.println(int_callback(OPCItemList[i].itemID,opc_opread,NULL)); break; case opc_float : float_callback = (float (*)(const char *itemID, const opcOperation opcOP, const float value))(OPCItemList[i].ptr_callback); Serial.println(float_callback(OPCItemList[i].itemID,opc_opread,NULL)); break; } matched = true; break; } /* endif */ } /* endfor */ if (!matched) { // Lets search for write p = strtok_r(buffer,"=",&j); for (int i = 0; i < OPCItemsCount; i++) { if (!strncmp(p, OPCItemList[i].itemID, SERIALCOMMAND_MAXCOMMANDLENGTH)) { // Call the stored handler function for the command switch (OPCItemList[i].itemType) { case opc_bool : bool_callback = (bool (*)(const char *itemID, const opcOperation opcOP, const bool value))(OPCItemList[i].ptr_callback); bool_callback(OPCItemList[i].itemID,opc_opwrite,atoi(j)); break; case opc_byte : byte_callback = (byte (*)(const char *itemID, const opcOperation opcOP, const byte value))(OPCItemList[i].ptr_callback); byte_callback(OPCItemList[i].itemID,opc_opwrite,atoi(j)); break; case opc_int : int_callback = (int (*)(const char *itemID, const opcOperation opcOP, const int value))(OPCItemList[i].ptr_callback); int_callback(OPCItemList[i].itemID,opc_opwrite,atoi(j)); break; case opc_float : float_callback = (float (*)(const char *itemID, const opcOperation opcOP, const float))(OPCItemList[i].ptr_callback); float_callback(OPCItemList[i].itemID,opc_opwrite,atof(j)); break; } break; } /* endif */ } /* endfor */ } } buffer[0] = '\0'; bufPos = 0; } else { if (bufPos < SERIALCOMMAND_BUFFER) { buffer[bufPos++] = inChar; buffer[bufPos] = '\0'; } } } }
void OPCNet::processOPCCommands() { char *p,*j; bool matched = false; bool (*bool_callback)(const char *itemID, const opcOperation opcOP, const bool value); byte (*byte_callback)(const char *itemID, const opcOperation opcOP, const byte value); int (*int_callback)(const char *itemID, const opcOperation opcOP, const int value); float (*float_callback)(const char *itemID, const opcOperation opcOP, const float value); client = server.accept(); if (client) { bufPos = 0; while (client.available()) buffer[bufPos++] = client.read(); if (bufPos > 2) { // avoid 13 10 chars buffer[bufPos-2] = '\0'; p = strtok_r(buffer,"/",&j); if (!j[0]) { if (!strcmp(buffer, "itemsmap")) { sendOPCItemsMap(); } else { p = strtok_r(buffer,"=",&j); if (!j[0]) { for (int i = 0; i < OPCItemsCount; i++) { if (!strcmp(buffer, OPCItemList[i].itemID)) { // Execute the stored handler function for the command client.print(F("[{\"ItemId\":\"")); client.print(buffer); client.print(F("\",\"ItemValue\":\"")); switch (OPCItemList[i].itemType) { case opc_bool : bool_callback = (bool (*)(const char *itemID, const opcOperation opcOP, const bool value))(OPCItemList[i].ptr_callback); client.print(bool_callback(OPCItemList[i].itemID,opc_opread,NULL)); break; case opc_byte : byte_callback = (byte (*)(const char *itemID, const opcOperation opcOP, const byte value))(OPCItemList[i].ptr_callback); client.print(byte_callback(OPCItemList[i].itemID,opc_opread,NULL)); break; case opc_int : int_callback = (int (*)(const char *itemID, const opcOperation opcOP, const int value))(OPCItemList[i].ptr_callback); client.print(int_callback(OPCItemList[i].itemID,opc_opread,NULL)); break; case opc_float : float_callback = (float (*)(const char *itemID, const opcOperation opcOP, const float value))(OPCItemList[i].ptr_callback); client.print(float_callback(OPCItemList[i].itemID,opc_opread,NULL)); break; } client.print(F("\"}]")); matched = true; break; } /* end if */ } /* end for */ } /* end if */ else { for (int i = 0; i < OPCItemsCount; i++) { if (!strcmp(buffer, OPCItemList[i].itemID)) { // Call the stored handler function for the command switch (OPCItemList[i].itemType) { case opc_bool : bool_callback = (bool (*)(const char *itemID, const opcOperation opcOP, const bool value))(OPCItemList[i].ptr_callback); bool_callback(OPCItemList[i].itemID,opc_opwrite,atoi(j)); break; case opc_byte : byte_callback = (byte (*)(const char *itemID, const opcOperation opcOP, const byte value))(OPCItemList[i].ptr_callback); byte_callback(OPCItemList[i].itemID,opc_opwrite,atoi(j)); break; case opc_int : int_callback = (int (*)(const char *itemID, const opcOperation opcOP, const int value))(OPCItemList[i].ptr_callback); int_callback(OPCItemList[i].itemID,opc_opwrite,atoi(j)); break; case opc_float : float_callback = (float (*)(const char *itemID, const opcOperation opcOP, const float))(OPCItemList[i].ptr_callback); float_callback(OPCItemList[i].itemID,opc_opwrite,atof(j)); break; } /* end case */ matched = true; break; } /* end if */ } /* end for */ } /* end else */ } } /* end else */ } /* end if */ // Close connection and free resources. client.stop(); } delay(50); // Poll every 50ms }