What is the problem? Date formatting? You can use String format:
String.format("%02x%02x%02x", year, month, day)
The methods you are using to get date components are deprecated. I would recommend to use Calendar class.
The problem is how can I convert this formmated YYMMHH string to 6 hex caracters .... eg. 06030e
the column information:
YYMMDD: GPS data date. 6 characters, in hexadecimal, e.g.: Nov.8th,2006: Represents the by 060B08.
Look at my code:
if (channel != null) {
Calendar cal = Calendar.getInstance();
Date date = new Date();
String date_str = String.format("%02x%02x%02x", cal.getTime().getYear(), cal.getTime().getMonth(), cal.getTime().getDay());
String hour_str = String.format("%02x%02x%02x", cal.getTime().getHours(), cal.getTime().getMinutes(), cal.getTime().getSeconds());
String content = "#1:" + imei + ":1:*,00000000,UP,"+ date_str.getBytes() +","+ hour_str.getBytes()+"#";
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
buf.writeBytes(content.getBytes(Charset.defaultCharset()));
channel.write(buf);
}
The returned string is wrong:
#1:359672050130411:1:*,00000000,UP,[B@7f07ff6a,[B@d4dd3b6#
Why are you calling "getBytes()"? Just use the formatted string.
I did this, look the return:
2016-03-27 11:34:27 DEBUG: [1B781E98: 6000 > 189.40.84.25] HEX: 23313a3335393637323035303133303431313a313a2a2c30303030303030302c55502c3734303230302c30623232316223 #1:359672050130411:1:*,00000000,UP,740200,0b221b#
740200 = 16-03-27
0b221b = 11:34:27
this is correct?
That's what you asked for. It's date and time in hex format. Why are you asking if it's correct? I don't even know what protocol you are trying to implement.
ok, I will finish all data types of the protocol and you send to your email to you add in traccar.
thank you for the help.
Thanks. Please send the documentation along with it if possible.
Hi Anton,
Could you help me?
I'm trying to develope a new protocol for traccar, and I need to write this to the channel:
#1:135790246811221:1:*,00000000,UP,06030e,0a100b#
where 06030e = date (YYMMDD in 6 characters, in hexadecimal)
and 0a100b = tim (HHMMSS in 6 characters,in hexadecimal)
I'm doing the code bellow but is not correct, could you help-me what I'm doing wrong? I'm not so familiar with java.:
thanks