Search in sources :

Example 1 with ServerMappingContainer

use of org.openmuc.framework.server.spi.ServerMappingContainer in project OpenMUC by isc-konstanz.

the class ModbusServer method bindMappings.

private void bindMappings(List<ServerMappingContainer> mappings) {
    if (logger.isDebugEnabled()) {
        logger.debug("Bind mappings of {} channel.", mappings.size());
    }
    for (final ServerMappingContainer container : mappings) {
        String serverAddress = container.getServerMapping().getServerAddress();
        PrimaryTable primaryTable = PrimaryTable.getEnumfromString(serverAddress.substring(0, serverAddress.indexOf(':')));
        int modbusAddress = Integer.parseInt(serverAddress.substring(serverAddress.indexOf(':') + 1, serverAddress.lastIndexOf(':')));
        String dataTypeStr = serverAddress.substring(serverAddress.lastIndexOf(':') + 1);
        DataType dataType = DataType.valueOf(dataTypeStr);
        logMapping(primaryTable, modbusAddress, dataType, container.getChannel());
        switch(primaryTable) {
            case INPUT_REGISTERS:
                addInputRegisters(spi, modbusAddress, dataType, container.getChannel());
                break;
            case HOLDING_REGISTERS:
                addHoldingRegisters(spi, modbusAddress, dataType, container.getChannel());
                break;
            case COILS:
                // TODO: create for coils
                break;
            case DISCRETE_INPUTS:
                // TODO: create for discrete inputs
                break;
            default:
        }
    }
}
Also used : ServerMappingContainer(org.openmuc.framework.server.spi.ServerMappingContainer)

Example 2 with ServerMappingContainer

use of org.openmuc.framework.server.spi.ServerMappingContainer in project OpenMUC by isc-konstanz.

the class DataManager method notifyServer.

/**
 * Updates a specified ServerService with mapped channels.
 *
 * @param serverService
 *            ServerService object to updating
 */
protected void notifyServer(ServerService serverService) {
    List<ServerMappingContainer> relatedServerMappings = new ArrayList<>();
    for (ChannelConfig config : rootConfig.channelConfigsById.values()) {
        for (ServerMapping serverMapping : config.getServerMappings()) {
            if (serverMapping.getId().equals(serverService.getId())) {
                relatedServerMappings.add(new ServerMappingContainer(this.getChannel(config.getId()), serverMapping));
            }
        }
    }
    serverService.serverMappings(relatedServerMappings);
}
Also used : ChannelConfig(org.openmuc.framework.config.ChannelConfig) ServerMapping(org.openmuc.framework.config.ServerMapping) ServerMappingContainer(org.openmuc.framework.server.spi.ServerMappingContainer) ArrayList(java.util.ArrayList)

Aggregations

ServerMappingContainer (org.openmuc.framework.server.spi.ServerMappingContainer)2 ArrayList (java.util.ArrayList)1 ChannelConfig (org.openmuc.framework.config.ChannelConfig)1 ServerMapping (org.openmuc.framework.config.ServerMapping)1