Comando de Bloqueio e Desbloqueio

551 views
Skip to first unread message

Roberto Almeida

unread,
Aug 23, 2013, 11:39:06 AM8/23/13
to tracca...@googlegroups.com
Caros,

Implementei no traccar socket o bloqueio e desbloqueio nos dispositivos suntech  e gps103.

Minha luta agora é conseguir fazer no traccar-web um botão onde ele grave na tabela abaixo no campo command o valor BLOQUEAR ou DESBLOQUEAR referente aquele determinado imei.

Tabela abaixo:

CREATE TABLE IF NOT EXISTS `comando` (
  `imei` varchar(17) NOT NULL,
  `command` varchar(80) NOT NULL,
  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`imei`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC COMMENT='Dados de comandos para envio ao GPS';

Alguém consegue ajudar?


--

Roberto Almeida
nolinux (at) gmail.com
Linux User: #391854
Message has been deleted

Mario Stanski Jr

unread,
Aug 23, 2013, 11:51:04 AM8/23/13
to tracca...@googlegroups.com, nol...@gmail.com, fal...@robertoalmeida.com
Roberto, 

Me adiciona no skype: mariojrrr
ou me manda um e-mail: ma...@getscale.com.br

Depois de muito sofrimento, eu consegui fazer alguns botões de configuração, acho que consigo fazer o botão do bloqueio e desbloqueio. 

Att,

Maxi Cabanillas

unread,
Aug 24, 2013, 2:04:53 PM8/24/13
to tracca...@googlegroups.com, nol...@gmail.com, fal...@robertoalmeida.com
amigo seria mas facil vc nao criar tabela vc deberia em traccar web adicionar device command + date

vc modificar el edit dispositivo para inserir command cuando vc save ele bloquiara seu carro

Maxi Cabanillas

unread,
Aug 24, 2013, 4:34:57 PM8/24/13
to tracca...@googlegroups.com, nol...@gmail.com, fal...@robertoalmeida.com
para modelo GPS103 envio codigo 



/*
 * Copyright 2012 - 2013 Anton Tananaev (anton.t...@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.traccar.protocol;

import java.util.Calendar;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.traccar.BaseProtocolDecoder;
import org.traccar.ServerManager;
import org.traccar.helper.Log;
import org.traccar.model.ExtendedInfoFormatter;
import org.traccar.model.Position;

public class Gps103ProtocolDecoder extends BaseProtocolDecoder {

    public Gps103ProtocolDecoder(ServerManager serverManager) {
        super(serverManager);
    }

    /**
     * Regular expressions pattern
     */
    static private Pattern pattern = Pattern.compile(
            "imei:" +
            "(\\d+)," +                         // IMEI
            "([^,]+)," +                        // Alarm
            "(\\d{2})/?(\\d{2})/?(\\d{2})\\s?" + // Local Date
            "(\\d{2}):?(\\d{2})," +             // Local Time
            "[^,]*," +
            "[FL]," +                           // F - full / L - low
            "(\\d{2})(\\d{2})(\\d{2})\\.(\\d{3})," + // Time UTC (HHMMSS.SSS)
            "([AV])," +                         // Validity
            "(\\d{2})(\\d{2}\\.\\d{4})," +      // Latitude (DDMM.MMMM)
            "([NS])," +
            "(\\d{3})(\\d{2}\\.\\d{4})," +      // Longitude (DDDMM.MMMM)
            "([EW])?," +
            "(\\d+\\.?\\d*)," +                 // Speed
            "(\\d+\\.\\d+)?" +                  // Course
            ".*");

    @Override
    protected Object decode(
            ChannelHandlerContext ctx, Channel channel, Object msg)
            throws Exception {

        String sentence = (String) msg;

        // Send response #1
        if (sentence.contains("##")) {
            if (channel != null) {
                channel.write("LOAD");
            }
            return null;
        }

        // Send response #2
        if (sentence.length() == 15 && Character.isDigit(sentence.charAt(0))) {
            if (channel != null) {
                channel.write("ON");
            }
            return null;
        }

        // Parse message
        Matcher parser = pattern.matcher(sentence);
        if (!parser.matches()) {
            Log.info("Parsing error");
            return null;
        }

        // Create new position
        Position position = new Position();
        ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("gps103");

        Integer index = 1;

        // Get device by IMEI
        String imei = parser.group(index++);
        try {
            position.setDeviceId(getDataManager().getDeviceByImei(imei).getId());
        } catch(Exception error) {
            Log.warning("Unknown device - " + imei);
            return null;
        }

        try {
            String comandobd = getDataManager().getComandoByImei(imei).getCommand();
            if ((channel != null) && (comandobd != null)) {
                if ("BLOQUEAR".equals(comandobd)) {
                    channel.write("**," + imei + ",J;");
                    Log.warning("Enviado comando: " + comandobd + " - Device: " + imei);
                    getDataManager().deleteComando(imei, comandobd);
                } else if ("DESBLOQUEAR".equals(comandobd)) {
                    channel.write("**," + imei + ",K;");
                    Log.warning("Enviado comando: " + comandobd + " - Device: " + imei);
                    getDataManager().deleteComando(imei, comandobd);
                }
            }
        } catch (Exception error) {
            //return null;
        }
        
        
        
        
        
        // Alarm message
        extendedInfo.set("alarm", parser.group(index++));
        
        // Date
        Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        time.clear();
        time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++)));
        time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1);
        time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++)));
        
        int localHours = Integer.valueOf(parser.group(index++));
        int localMinutes = Integer.valueOf(parser.group(index++));
        
        int utcHours = Integer.valueOf(parser.group(index++));
        int utcMinutes = Integer.valueOf(parser.group(index++));

        // Time
        time.set(Calendar.HOUR, localHours);
        time.set(Calendar.MINUTE, localMinutes);
        time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++)));
        time.set(Calendar.MILLISECOND, Integer.valueOf(parser.group(index++)));
        
        // Timezone calculation
        int deltaMinutes = (localHours - utcHours) * 60 + localMinutes - utcMinutes;
        if (deltaMinutes <= -12 * 60) {
            deltaMinutes += 24 * 60;
        } else if (deltaMinutes > 12 * 60) {
            deltaMinutes -= 24 * 60;
        }
        time.add(Calendar.MINUTE, -deltaMinutes);
        position.setTime(time.getTime());

        // Validity
        position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false);

        // Latitude
        Double latitude = Double.valueOf(parser.group(index++));
        latitude += Double.valueOf(parser.group(index++)) / 60;
        if (parser.group(index++).compareTo("S") == 0) latitude = -latitude;
        position.setLatitude(latitude);

        // Longitude
        Double longitude = Double.valueOf(parser.group(index++));
        longitude += Double.valueOf(parser.group(index++)) / 60;
        String hemisphere = parser.group(index++);
        if (hemisphere != null) {
            if (hemisphere.compareTo("W") == 0) longitude = -longitude;
        }
        position.setLongitude(longitude);

        // Altitude
        position.setAltitude(0.0);

        // Speed
        position.setSpeed(Double.valueOf(parser.group(index++)));

        // Course
        String course = parser.group(index++);
        if (course != null) {
            position.setCourse(Double.valueOf(course));
        } else {
            position.setCourse(0.0);
        }

        // Extended info
        position.setExtendedInfo(extendedInfo.toString());

        return position;
    }

}






El viernes, 23 de agosto de 2013 12:39:06 UTC-3, Roberto Almeida escribió:

Maxi Cabanillas

unread,
Aug 25, 2013, 10:54:55 PM8/25/13
to tracca...@googlegroups.com, nol...@gmail.com, fal...@robertoalmeida.com

Agora tracar-web posso enviar Comandos


El viernes, 23 de agosto de 2013 12:39:06 UTC-3, Roberto Almeida escribió:
Reply all
Reply to author
Forward
0 new messages