Code
import net from "net";
import { ProtocolParser, parseIMEI, Data, GPRS } from "complete-teltonika-parser";
const server = net.createServer();
server.on("connection", (socket) => {
console.log('connection..')
console.log('setEncoding=hex')
socket.setEncoding("hex");
socket.on("data", (packet) => {
console.log('data Event...')
var buffer = Buffer.from(packet);
//console.log(bufferPacket)
let parsed = new ProtocolParser(buffer.data)
// if (parsed.CodecType == "data sending") {
// let data = parsed.Content as Data
// data.AVL_Datas.map(row=>{
// console.log('row=>',row)
// })
// //console.log('data====>',data.AVL_Datas[0].IOelement)
// //console.log('data====>',data.AVL_Datas[0])
// } else {
// let gprs = parsed.Content as GPRS
// console.log('gprs====>',gprs)
// }
//socket.write("\x01");
//console.log(data);
});
socket.on("close",()=>{console.log('close Event...')});
socket.on("error",(err)=>{ console.log('error Event ErrorMessage==>',err.message); });
});
server.listen(786, () => {
console.log(`Server Listning TCP Poket from Iot Device..`);
});
Output
TSError: ⨯ Unable to compile TypeScript:
src/index.ts:21:41 - error TS2345: Argument of type 'Buffer' is not assignable to parameter of type 'string'.
21 let parsed = new ProtocolParser(packet)
~~~~~~